List of usage examples for javax.mail.internet MimeMessage getHeader
@Override public String[] getHeader(String name) throws MessagingException
From source file:org.alfresco.repo.imap.AlfrescoImapFolder.java
/** * Extract a <code>NodeRef</code> from the message id. * <br>Typical message id is "<74bad8aa-75a5-4063-8e46-9d1b5737f43b@alfresco.org>" * <br>See {@link AbstractMimeMessage#updateMessageID()} * //from w ww.j a v a2s . co m * @param message MimeMessage * @return null if nothing is found */ private NodeRef extractNodeRef(MimeMessage message) { String uuid = null; String messageId = null; NodeRef result = null; NodeService nodeService = serviceRegistry.getNodeService(); try { messageId = message.getMessageID(); } catch (MessagingException me) { // we cannot use message id to extract nodeRef } if (messageId != null) { if (messageId.startsWith("<")) { messageId = messageId.substring(1); } if (messageId.indexOf("@") != -1) { uuid = messageId.substring(0, messageId.indexOf("@")); } else { uuid = messageId; } result = new NodeRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore", uuid); if (nodeService.exists(result) == false) { result = null; } } if (result == null) { //check X-Alfresco-NodeRef-ID header try { if (message.getHeader(AlfrescoImapConst.X_ALF_NODEREF_ID) != null) { uuid = message.getHeader(AlfrescoImapConst.X_ALF_NODEREF_ID)[0]; result = new NodeRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore", uuid); if (nodeService.exists(result) == false) { result = null; } } } catch (MessagingException e) { //Do nothing } } return result; }
From source file:org.apache.axis.transport.mail.MailWorker.java
/** * Read all mime headers, returning the value of Content-Length and * SOAPAction./*from w w w .jav a 2 s.c o m*/ * @param mimeMessage InputStream to read from * @param contentType The content type. * @param contentLocation The content location * @param soapAction StringBuffer to return the soapAction into */ private void parseHeaders(MimeMessage mimeMessage, StringBuffer contentType, StringBuffer contentLocation, StringBuffer soapAction) throws Exception { contentType.append(mimeMessage.getContentType()); contentLocation.append(mimeMessage.getContentID()); String values[] = mimeMessage.getHeader(HTTPConstants.HEADER_SOAP_ACTION); if (values != null) soapAction.append(values[0]); }
From source file:org.apache.axis2.transport.mail.MailRequestResponseClient.java
private Message getMessage(String requestMsgId) throws Exception { MimeMessage response = null;/*from w w w. j av a 2 s . co m*/ Folder folder = store.getFolder(MailConstants.DEFAULT_FOLDER); folder.open(Folder.READ_WRITE); Message[] msgs = folder.getMessages(); log.debug(msgs.length + " messages in mailbox"); loop: for (Message m : msgs) { MimeMessage mimeMessage = (MimeMessage) m; String[] inReplyTo = mimeMessage.getHeader(MailConstants.MAIL_HEADER_IN_REPLY_TO); log.debug("Found message " + mimeMessage.getMessageID() + " in reply to " + Arrays.toString(inReplyTo)); if (inReplyTo != null && inReplyTo.length > 0) { for (int j = 0; j < inReplyTo.length; j++) { if (requestMsgId.equals(inReplyTo[j])) { log.debug("Identified message " + mimeMessage.getMessageID() + " as the response to " + requestMsgId + "; retrieving it from the store"); // We need to create a copy so that we can delete the original and close the folder response = new MimeMessage(mimeMessage); log.debug("Flagging message " + mimeMessage.getMessageID() + " for deletion"); mimeMessage.setFlag(Flags.Flag.DELETED, true); break loop; } } } log.warn("Don't know what to do with message " + mimeMessage.getMessageID() + "; skipping"); } folder.close(true); return response; }
From source file:org.apache.axis2.transport.mail.server.MailSorter.java
private String getMailHeader(String headerName, MimeMessage mimeMessage) throws AxisFault { try {/* w w w .j av a2 s . co m*/ String values[] = mimeMessage.getHeader(headerName); if (values != null) { return values[0]; } else { return null; } } catch (MessagingException e) { throw new AxisFault(e.getMessage(), e); } }
From source file:org.apache.axis2.transport.mail.SimpleMailListener.java
private String getMailHeader(MimeMessage msg, String headerName) throws AxisFault { try {//from www .j av a 2 s .c o m String values[] = msg.getHeader(headerName); if (values != null) { return parseHeaderForQuotes(values[0]); } else { return null; } } catch (MessagingException e) { throw new AxisFault(e.getMessage(), e); } }
From source file:org.apache.james.postage.mail.MailMatchingUtils.java
public static String getUniqueHeader(MimeMessage message, String header) { String[] idHeaders;//from ww w .j a va 2 s . c o m try { idHeaders = message.getHeader(header); } catch (MessagingException e) { throw new PostageRuntimeException(e); } if (idHeaders != null && idHeaders.length > 0) { return idHeaders[0]; // there should be exactly one. } return null; }
From source file:org.apache.james.transport.mailets.delivery.MailDispatcher.java
private List<String> removeDeliveryHeaders(MimeMessage message) throws MessagingException { List<String> deliveredToHeader = Arrays .asList(Optional.fromNullable(message.getHeader(DELIVERED_TO)).or(NO_HEADERS)); message.removeHeader(DELIVERED_TO);/*w w w . ja va2s . co m*/ return deliveredToHeader; }
From source file:org.apache.james.transport.mailets.delivery.MailDispatcherTest.java
@Test public void dispatchShouldPreserveDeliveredTo() throws Exception { MailDispatcher testee = MailDispatcher.builder().log(mock(Log.class)).mailetContext(fakeMailContext) .mailStore(mailStore).consume(false).build(); String delivered_to_1 = "delivered_to_1"; String delivered_to_2 = "delivered_to_2"; MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder() .addHeaders(new MimeMessageBuilder.Header(MailDispatcher.DELIVERED_TO, delivered_to_1), new MimeMessageBuilder.Header(MailDispatcher.DELIVERED_TO, delivered_to_2)) .build();//from www . j a v a2 s.c o m FakeMail mail = FakeMail.builder().sender(MailAddressFixture.OTHER_AT_JAMES) .recipients(MailAddressFixture.ANY_AT_JAMES).mimeMessage(mimeMessage).state("state").build(); testee.dispatch(mail); assertThat(mimeMessage.getHeader(MailDispatcher.DELIVERED_TO)).containsExactly(delivered_to_1, delivered_to_2); }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldSetTheDateHeaderWhenNone() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).build(); dsnBounce.init(mailetConfig);/*ww w . j av a 2 s . com*/ MailAddress senderMailAddress = new MailAddress("sender@domain.com"); FakeMail mail = FakeMail.builder().sender(senderMailAddress) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).name(MAILET_NAME) .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z"))) .build(); dsnBounce.service(mail); List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); assertThat(sentMail.getSender()).isNull(); assertThat(sentMail.getRecipients()).containsOnly(senderMailAddress); MimeMessage sentMessage = sentMail.getMsg(); assertThat(sentMessage.getHeader(RFC2822Headers.DATE)).isNotNull(); }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldNotModifyTheDateHeaderWhenAlreadyPresent() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).build(); dsnBounce.init(mailetConfig);/* w w w . j a v a 2 s . co m*/ MailAddress senderMailAddress = new MailAddress("sender@domain.com"); String expectedDate = "Wed, 28 Sep 2016 14:25:52 +0000 (UTC)"; FakeMail mail = FakeMail.builder().sender(senderMailAddress) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content") .addHeader(RFC2822Headers.DATE, expectedDate)) .name(MAILET_NAME).recipient("recipient@domain.com") .lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z"))).build(); dsnBounce.service(mail); List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); assertThat(sentMail.getSender()).isNull(); assertThat(sentMail.getRecipients()).containsOnly(senderMailAddress); MimeMessage sentMessage = sentMail.getMsg(); assertThat(sentMessage.getHeader(RFC2822Headers.DATE)[0]).isEqualTo(expectedDate); }