javax.mail.Message.getContentType()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中javax.mail.Message.getContentType()方法的一些代码示例,展示了Message.getContentType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getContentType()方法的具体详情如下:
包路径:javax.mail.Message
类名称:Message
方法名:getContentType

Message.getContentType介绍

暂无

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

break;
case MailInputField.COLUMN_CONTENT_TYPE:
 r[index] = message.getContentType();
 break;
case MailInputField.COLUMN_FOLDER_NAME:

代码示例来源:origin: pentaho/pentaho-kettle

when( message.getReceivedDate() ).thenReturn( DATE1 );
when( message.getSentDate() ).thenReturn( DATE2 );
when( message.getContentType() ).thenReturn( CNTNT_TYPE_EMAIL );
when( message.getSize() ).thenReturn( CNTNT_SIZE );

代码示例来源:origin: spring-projects/spring-integration

@Override
protected AbstractIntegrationMessageBuilder<String> doTransform(javax.mail.Message mailMessage)
    throws Exception { // NOSONAR
  Object content = mailMessage.getContent();
  if (content instanceof String) {
    return this.getMessageBuilderFactory().withPayload((String) content);
  }
  if (content instanceof Multipart) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ((Multipart) content).writeTo(outputStream);
    return this.getMessageBuilderFactory().withPayload(
        new String(outputStream.toByteArray(), this.charset));
  }
  else if (content instanceof Part) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ((Part) content).writeTo(outputStream);
    return this.getMessageBuilderFactory().withPayload(
        new String(outputStream.toByteArray(), this.charset));
  }
  throw new IllegalArgumentException("failed to transform contentType ["
      + mailMessage.getContentType() + "] to String.");
}

代码示例来源:origin: pentaho/pentaho-kettle

.getMessage().getContentType() ) );
logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.EmailFrom.Label", Const.NVL( mailConn
 .getMessage().getFrom()[0].toString(), "" ) ) );

代码示例来源:origin: springernature/omelet

/**
 * Return format of email Message
 *
 * @param msg message to return the mail format from
 */
public String getMailFormat(Message msg) {
  String format = null;
  try {
    format = msg.getContentType();
  } catch (MessagingException e) {
    LOGGER.error(e);
  }
  return format;
}

代码示例来源:origin: google/mail-importer

@Override
public String getContentType() throws RuntimeMessagingException {
 try {
  return delegate.getContentType();
 } catch (MessagingException e) {
  throw new RuntimeMessagingException(e);
 }
}

代码示例来源:origin: org.apache.james/apache-jsieve-util

/**
 * Method getContentType returns string/mime representation of the message
 * type.
 *
 * @return String
 * @throws SieveMailException
 */
public String getContentType() throws SieveMailException {
  String result = null;
  if (mail != null) {
    try {
      result = mail.getContentType();
    } catch (MessagingException e) {
      throw new SieveMailException(e);
    }
  }
  return result;
}

代码示例来源:origin: Cognifide/bobcat

private String getMessageContent(Message message) throws IOException, MessagingException {
 String contentString = null;
 Object content = message.getContent();
 if (content instanceof Multipart) {
  StringBuilder contentBuilder = processMultipart((Multipart) content);
  contentString = contentBuilder.toString();
 } else if (message.getContentType().toLowerCase().contains("text")) {
  contentString = message.getContent().toString();
 }
 return contentString;
}

代码示例来源:origin: org.apache.james/apache-mailet-base

/**
   * Checks whether the input message is <code>format=flowed</code>.
   */
  public static boolean isFlowedTextMessage(Message m) throws MessagingException {
    ContentType ct = new ContentType(m.getContentType());
    String format = ct.getParameter("format");
    return ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed");
  }
}

代码示例来源:origin: org.apache.james/apache-mailet-base

/**
 * Obtains the content of the encoded message, if previously encoded as <code>format=flowed</code>.
 */
public static String deflow(Message m) throws IOException, MessagingException {
  ContentType ct = new ContentType(m.getContentType());
  String format = ct.getParameter("format");
  if (ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed")) {
    String delSp = ct.getParameter("delsp");
    return deflow((String) m.getContent(), delSp != null && delSp.equalsIgnoreCase("yes"));
    
  } else if (ct.getPrimaryType().equals("text")) {
    return (String) m.getContent();
  } else {
    return null;
  }
}

代码示例来源:origin: org.springframework.integration/spring-integration-mail

@Override
protected AbstractIntegrationMessageBuilder<String> doTransform(javax.mail.Message mailMessage) throws Exception {
  Object content = mailMessage.getContent();
  if (content instanceof String) {
    return this.getMessageBuilderFactory().withPayload((String) content);
  }
  if (content instanceof Multipart) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ((Multipart) content).writeTo(outputStream);
    return this.getMessageBuilderFactory().withPayload(
        new String(outputStream.toByteArray(), this.charset));
  }
  else if (content instanceof Part) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ((Part) content).writeTo(outputStream);
    return this.getMessageBuilderFactory().withPayload(
        new String(outputStream.toByteArray(), this.charset));
  }
  throw new IllegalArgumentException("failed to transform contentType ["
      + mailMessage.getContentType() + "] to String.");
}

代码示例来源:origin: org.jbundle.base/org.jbundle.base.mixed

/**
   * Get the message content as a string.
   * @param message The message.
   * @return The message content.
   */
  public String getContentString(Message message)
  {
    try {
      String strContentType = message.getContentType();
      Object content = message.getContent();
      if (content instanceof MimeMultipart)
      {
        for (int index = 0; ; index++)
        {
          BodyPart bodyPart = ((javax.mail.internet.MimeMultipart)content).getBodyPart(index);
          Object contents = bodyPart.getContent();
          if (contents != null)
            return contents.toString();
        }
      }
      return message.getContent().toString();     // pend(don) FIX THIS!
    } catch (IOException ex)    {
      ex.printStackTrace();
    } catch (MessagingException ex)    {
      ex.printStackTrace();
    }
    return null;
  }
}

代码示例来源:origin: org.apache.james.hupa/hupa-server

private boolean hasAttachment(Message message) throws MessagingException {
  if (message.getContentType().startsWith("multipart/")) {
    try {
      Object content;
      content = message.getContent();
      if (content instanceof Multipart) {
        Multipart mp = (Multipart) content;
        if (mp.getCount() > 1) {
          for (int i = 0; i < mp.getCount(); i++) {
            String disp = mp.getBodyPart(i).getDisposition();
            if (disp != null
                && disp.equalsIgnoreCase(Part.ATTACHMENT)) {
              return true;
            }
          }
        }
      }
    } catch (IOException e) {
      logger.error("Error while get content of message " + message.getMessageNumber());
    }
    
  }
  return false;
}

代码示例来源:origin: org.apache.james/apache-mailet-base

/**
 * If the message is <code>format=flowed</code> 
 * set the encoded version as message content.
 */
public static void deflowMessage(Message m) throws MessagingException, IOException {
  ContentType ct = new ContentType(m.getContentType());
  String format = ct.getParameter("format");
  if (ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed")) {
    String delSp = ct.getParameter("delsp");
    String deflowed = deflow((String) m.getContent(), delSp != null && delSp.equalsIgnoreCase("yes"));
    
    ct.getParameterList().remove("format");
    ct.getParameterList().remove("delsp");
    
    if (ct.toString().contains("flowed")) {
      LOGGER.error("FlowedMessageUtils dind't remove the flowed correctly");
    }
    m.setContent(deflowed, ct.toString());
    m.saveChanges();
  }
}

代码示例来源:origin: org.mnode.mstor/mstor

content.setName("data");
content.setDataProvider(new JcrDataProviderImpl(mout.toByteArray()));
content.setMimeType(message.getContentType());
content.setLastModified(java.util.Calendar.getInstance());

代码示例来源:origin: org.apache.james/apache-mailet-base

/**
 * Encodes the message content (if text/plain).
 */
public static void flowMessage(Message m, boolean delSp, int width) throws MessagingException, IOException {
  ContentType ct = new ContentType(m.getContentType());
  if (!ct.getBaseType().equals("text/plain")) {
    return;
  }
  String format = ct.getParameter("format");
  String text = format != null && format.equals("flowed") ? deflow(m) : (String) m.getContent();
  String coded = flow(text, delSp, width);
  ct.setParameter("format", "flowed");
  if (delSp) {
    ct.setParameter("delsp", "yes");
  }
  m.setContent(coded, ct.toString());
  m.saveChanges();
}

代码示例来源:origin: actframework/actframework

for (Address address : addresses) {
  if (address.toString().contains(email)) {
    String type = message.getContentType();
    if (type.startsWith("text")) {
      String s = message.getContent().toString();

代码示例来源:origin: org.actframework/act

for (Address address : addresses) {
  if (address.toString().contains(email)) {
    String type = message.getContentType();
    if (type.startsWith("text")) {
      String s = message.getContent().toString();

代码示例来源:origin: com.gitlab.jhonsapp/simple-email

public EmailMessage convertMessage(Message m) throws MailException {
  emailMessage = new EmailMessage();
  try {
    emailMessage.setFromAddresses(MailUtility.getInternetAddressses(m.getFrom()));
    emailMessage.getToAddresses().addAll(MailUtility.getInternetAddressses(m.getRecipients(RecipientType.TO)));
    emailMessage.setCcAddresses(MailUtility.getInternetAddressses(m.getRecipients(RecipientType.CC)));
    emailMessage.setBccAddresses(MailUtility.getInternetAddressses(m.getRecipients(RecipientType.BCC)));
    emailMessage.setSubject(m.getSubject());
    emailMessage.setMessageId(m.getHeader("Message-ID")[0]);
    emailMessage.getHeaders().addAll(MailUtility.getHeaders(m.getAllHeaders()));
    if (m.getContentType().toLowerCase().contains("multipart/")) {
      addMultiPart((MimeMultipart) m.getContent());
    }
    else if (m.isMimeType("text/plain")) {
      emailMessage.setTextBody((String) m.getContent());
    }
  }
  catch (IOException e) {
    throw new MailException(e);
  }
  catch (MessagingException e) {
    throw new MailException(e);
  }
  return emailMessage;
}

代码示例来源:origin: org.apache.james/apache-mailet-base

/**
 * Encodes the input text and sets it as the new message content.
 */
public static void setFlowedContent(Message m, String text, boolean delSp, int width, boolean preserveCharset, String charset) throws MessagingException {
  String coded = flow(text, delSp, width);
  if (preserveCharset) {
    ContentType ct = new ContentType(m.getContentType());
    charset = ct.getParameter("charset");
  }
  ContentType ct = new ContentType();
  ct.setPrimaryType("text");
  ct.setSubType("plain");
  if (charset != null) {
    ct.setParameter("charset", charset);
  }
  ct.setParameter("format", "flowed");
  if (delSp) {
    ct.setParameter("delsp", "yes");
  }
  m.setContent(coded, ct.toString());
  m.saveChanges();
}

相关文章