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

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

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

Message.getContentType介绍

暂无

代码示例

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

  1. break;
  2. case MailInputField.COLUMN_CONTENT_TYPE:
  3. r[index] = message.getContentType();
  4. break;
  5. case MailInputField.COLUMN_FOLDER_NAME:

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

  1. when( message.getReceivedDate() ).thenReturn( DATE1 );
  2. when( message.getSentDate() ).thenReturn( DATE2 );
  3. when( message.getContentType() ).thenReturn( CNTNT_TYPE_EMAIL );
  4. when( message.getSize() ).thenReturn( CNTNT_SIZE );

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

  1. @Override
  2. protected AbstractIntegrationMessageBuilder<String> doTransform(javax.mail.Message mailMessage)
  3. throws Exception { // NOSONAR
  4. Object content = mailMessage.getContent();
  5. if (content instanceof String) {
  6. return this.getMessageBuilderFactory().withPayload((String) content);
  7. }
  8. if (content instanceof Multipart) {
  9. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  10. ((Multipart) content).writeTo(outputStream);
  11. return this.getMessageBuilderFactory().withPayload(
  12. new String(outputStream.toByteArray(), this.charset));
  13. }
  14. else if (content instanceof Part) {
  15. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  16. ((Part) content).writeTo(outputStream);
  17. return this.getMessageBuilderFactory().withPayload(
  18. new String(outputStream.toByteArray(), this.charset));
  19. }
  20. throw new IllegalArgumentException("failed to transform contentType ["
  21. + mailMessage.getContentType() + "] to String.");
  22. }

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

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

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

  1. /**
  2. * Return format of email Message
  3. *
  4. * @param msg message to return the mail format from
  5. */
  6. public String getMailFormat(Message msg) {
  7. String format = null;
  8. try {
  9. format = msg.getContentType();
  10. } catch (MessagingException e) {
  11. LOGGER.error(e);
  12. }
  13. return format;
  14. }

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

  1. @Override
  2. public String getContentType() throws RuntimeMessagingException {
  3. try {
  4. return delegate.getContentType();
  5. } catch (MessagingException e) {
  6. throw new RuntimeMessagingException(e);
  7. }
  8. }

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

  1. /**
  2. * Method getContentType returns string/mime representation of the message
  3. * type.
  4. *
  5. * @return String
  6. * @throws SieveMailException
  7. */
  8. public String getContentType() throws SieveMailException {
  9. String result = null;
  10. if (mail != null) {
  11. try {
  12. result = mail.getContentType();
  13. } catch (MessagingException e) {
  14. throw new SieveMailException(e);
  15. }
  16. }
  17. return result;
  18. }

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

  1. private String getMessageContent(Message message) throws IOException, MessagingException {
  2. String contentString = null;
  3. Object content = message.getContent();
  4. if (content instanceof Multipart) {
  5. StringBuilder contentBuilder = processMultipart((Multipart) content);
  6. contentString = contentBuilder.toString();
  7. } else if (message.getContentType().toLowerCase().contains("text")) {
  8. contentString = message.getContent().toString();
  9. }
  10. return contentString;
  11. }

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

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

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

  1. /**
  2. * Obtains the content of the encoded message, if previously encoded as <code>format=flowed</code>.
  3. */
  4. public static String deflow(Message m) throws IOException, MessagingException {
  5. ContentType ct = new ContentType(m.getContentType());
  6. String format = ct.getParameter("format");
  7. if (ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed")) {
  8. String delSp = ct.getParameter("delsp");
  9. return deflow((String) m.getContent(), delSp != null && delSp.equalsIgnoreCase("yes"));
  10. } else if (ct.getPrimaryType().equals("text")) {
  11. return (String) m.getContent();
  12. } else {
  13. return null;
  14. }
  15. }

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

  1. @Override
  2. protected AbstractIntegrationMessageBuilder<String> doTransform(javax.mail.Message mailMessage) throws Exception {
  3. Object content = mailMessage.getContent();
  4. if (content instanceof String) {
  5. return this.getMessageBuilderFactory().withPayload((String) content);
  6. }
  7. if (content instanceof Multipart) {
  8. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  9. ((Multipart) content).writeTo(outputStream);
  10. return this.getMessageBuilderFactory().withPayload(
  11. new String(outputStream.toByteArray(), this.charset));
  12. }
  13. else if (content instanceof Part) {
  14. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  15. ((Part) content).writeTo(outputStream);
  16. return this.getMessageBuilderFactory().withPayload(
  17. new String(outputStream.toByteArray(), this.charset));
  18. }
  19. throw new IllegalArgumentException("failed to transform contentType ["
  20. + mailMessage.getContentType() + "] to String.");
  21. }

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

  1. /**
  2. * Get the message content as a string.
  3. * @param message The message.
  4. * @return The message content.
  5. */
  6. public String getContentString(Message message)
  7. {
  8. try {
  9. String strContentType = message.getContentType();
  10. Object content = message.getContent();
  11. if (content instanceof MimeMultipart)
  12. {
  13. for (int index = 0; ; index++)
  14. {
  15. BodyPart bodyPart = ((javax.mail.internet.MimeMultipart)content).getBodyPart(index);
  16. Object contents = bodyPart.getContent();
  17. if (contents != null)
  18. return contents.toString();
  19. }
  20. }
  21. return message.getContent().toString(); // pend(don) FIX THIS!
  22. } catch (IOException ex) {
  23. ex.printStackTrace();
  24. } catch (MessagingException ex) {
  25. ex.printStackTrace();
  26. }
  27. return null;
  28. }
  29. }

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

  1. private boolean hasAttachment(Message message) throws MessagingException {
  2. if (message.getContentType().startsWith("multipart/")) {
  3. try {
  4. Object content;
  5. content = message.getContent();
  6. if (content instanceof Multipart) {
  7. Multipart mp = (Multipart) content;
  8. if (mp.getCount() > 1) {
  9. for (int i = 0; i < mp.getCount(); i++) {
  10. String disp = mp.getBodyPart(i).getDisposition();
  11. if (disp != null
  12. && disp.equalsIgnoreCase(Part.ATTACHMENT)) {
  13. return true;
  14. }
  15. }
  16. }
  17. }
  18. } catch (IOException e) {
  19. logger.error("Error while get content of message " + message.getMessageNumber());
  20. }
  21. }
  22. return false;
  23. }

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

  1. /**
  2. * If the message is <code>format=flowed</code>
  3. * set the encoded version as message content.
  4. */
  5. public static void deflowMessage(Message m) throws MessagingException, IOException {
  6. ContentType ct = new ContentType(m.getContentType());
  7. String format = ct.getParameter("format");
  8. if (ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed")) {
  9. String delSp = ct.getParameter("delsp");
  10. String deflowed = deflow((String) m.getContent(), delSp != null && delSp.equalsIgnoreCase("yes"));
  11. ct.getParameterList().remove("format");
  12. ct.getParameterList().remove("delsp");
  13. if (ct.toString().contains("flowed")) {
  14. LOGGER.error("FlowedMessageUtils dind't remove the flowed correctly");
  15. }
  16. m.setContent(deflowed, ct.toString());
  17. m.saveChanges();
  18. }
  19. }

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

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

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

  1. /**
  2. * Encodes the message content (if text/plain).
  3. */
  4. public static void flowMessage(Message m, boolean delSp, int width) throws MessagingException, IOException {
  5. ContentType ct = new ContentType(m.getContentType());
  6. if (!ct.getBaseType().equals("text/plain")) {
  7. return;
  8. }
  9. String format = ct.getParameter("format");
  10. String text = format != null && format.equals("flowed") ? deflow(m) : (String) m.getContent();
  11. String coded = flow(text, delSp, width);
  12. ct.setParameter("format", "flowed");
  13. if (delSp) {
  14. ct.setParameter("delsp", "yes");
  15. }
  16. m.setContent(coded, ct.toString());
  17. m.saveChanges();
  18. }

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

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

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

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

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

  1. public EmailMessage convertMessage(Message m) throws MailException {
  2. emailMessage = new EmailMessage();
  3. try {
  4. emailMessage.setFromAddresses(MailUtility.getInternetAddressses(m.getFrom()));
  5. emailMessage.getToAddresses().addAll(MailUtility.getInternetAddressses(m.getRecipients(RecipientType.TO)));
  6. emailMessage.setCcAddresses(MailUtility.getInternetAddressses(m.getRecipients(RecipientType.CC)));
  7. emailMessage.setBccAddresses(MailUtility.getInternetAddressses(m.getRecipients(RecipientType.BCC)));
  8. emailMessage.setSubject(m.getSubject());
  9. emailMessage.setMessageId(m.getHeader("Message-ID")[0]);
  10. emailMessage.getHeaders().addAll(MailUtility.getHeaders(m.getAllHeaders()));
  11. if (m.getContentType().toLowerCase().contains("multipart/")) {
  12. addMultiPart((MimeMultipart) m.getContent());
  13. }
  14. else if (m.isMimeType("text/plain")) {
  15. emailMessage.setTextBody((String) m.getContent());
  16. }
  17. }
  18. catch (IOException e) {
  19. throw new MailException(e);
  20. }
  21. catch (MessagingException e) {
  22. throw new MailException(e);
  23. }
  24. return emailMessage;
  25. }

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

  1. /**
  2. * Encodes the input text and sets it as the new message content.
  3. */
  4. public static void setFlowedContent(Message m, String text, boolean delSp, int width, boolean preserveCharset, String charset) throws MessagingException {
  5. String coded = flow(text, delSp, width);
  6. if (preserveCharset) {
  7. ContentType ct = new ContentType(m.getContentType());
  8. charset = ct.getParameter("charset");
  9. }
  10. ContentType ct = new ContentType();
  11. ct.setPrimaryType("text");
  12. ct.setSubType("plain");
  13. if (charset != null) {
  14. ct.setParameter("charset", charset);
  15. }
  16. ct.setParameter("format", "flowed");
  17. if (delSp) {
  18. ct.setParameter("delsp", "yes");
  19. }
  20. m.setContent(coded, ct.toString());
  21. m.saveChanges();
  22. }

相关文章