List of usage examples for javax.mail.internet MimeMessage getMessageID
public String getMessageID() throws MessagingException
From source file:org.apache.james.core.MimeMessageUtil.java
/** * /* w ww.ja va 2s.c o m*/ * @param message * @param headerOs * @param bodyOs * @param ignoreList * @throws MessagingException * @throws IOException * @throws UnsupportedDataTypeException */ public static void writeToInternal(MimeMessage message, OutputStream headerOs, OutputStream bodyOs, String[] ignoreList) throws MessagingException, IOException { if (message.getMessageID() == null) { message.saveChanges(); } writeHeadersTo(message, headerOs, ignoreList); // Write the body to the output stream writeMessageBodyTo(message, bodyOs); }
From source file:org.xwiki.mail.internal.factory.files.SerializedFilesMimeMessageIteratorTest.java
@Test public void createMessage() throws Exception { String mailID1 = "<1128820400.0.1419205781342.JavaMail.contact@xwiki.org>"; String mailID2 = "<1128820400.1.1419205781342.JavaMail.contact@xwiki.org>"; String mailID3 = "<1128820400.2.1419205781342.JavaMail.contact@xwiki.org>"; createSerializedMessage(mailID1);/*from w w w . java 2 s . c o m*/ createSerializedMessage(mailID2); createSerializedMessage(mailID3); Map<String, Object> parameters = new HashMap<>(); parameters.put("parameters", Collections.EMPTY_MAP); Environment environment = mock(Environment.class); when(environment.getPermanentDirectory()).thenReturn(new File(TEMPORARY_DIRECTORY)); ComponentManager componentManager = mock(ComponentManager.class); when(componentManager.getInstance(eq(Environment.class))).thenReturn(environment); SerializedFilesMimeMessageIterator iterator = new SerializedFilesMimeMessageIterator(this.batchId, parameters, componentManager); ArrayList<String> listID = new ArrayList<>(); listID.add(mailID1); listID.add(mailID2); listID.add(mailID3); assertTrue(iterator.hasNext()); MimeMessage message1 = iterator.next(); assertTrue(listID.contains(message1.getMessageID())); listID.remove(message1.getMessageID()); assertTrue(iterator.hasNext()); MimeMessage message2 = iterator.next(); assertTrue(listID.contains(message2.getMessageID())); listID.remove(message1.getMessageID()); assertTrue(iterator.hasNext()); MimeMessage message3 = iterator.next(); assertTrue(listID.contains(message2.getMessageID())); listID.remove(message3.getMessageID()); assertFalse(iterator.hasNext()); }
From source file:com.adaptris.mail.ApacheMailClient.java
@Override // Messages marked as read (as in they match the filter) will be added to the list of messages to delete. public void setMessageRead(MimeMessage msg) throws MailException { try {//w w w . j a v a 2 s . c o m messagesToDelete.add(msg.getMessageID()); } catch (MessagingException e) { throw wrapException(e); } }
From source file:com.adaptris.mail.ApacheMailClient.java
@Override public void resetMessage(MimeMessage msg) throws MailException { try {/*from w w w . j ava 2s. c om*/ messagesToDelete.remove(msg.getMessageID()); } catch (MessagingException e) { throw wrapException(e); } }
From source file:com.adaptris.core.mail.RawMailConsumer.java
@Override protected List<AdaptrisMessage> createMessages(MimeMessage mime) throws MailException, CoreException { List<AdaptrisMessage> result = new ArrayList<AdaptrisMessage>(); try {//from w w w . j a v a 2 s. c o m log.trace("Start Processing [{}]", mime.getMessageID()); AdaptrisMessage msg = defaultIfNull(getMessageFactory()).newMessage(); String uuid = msg.getUniqueId(); try (OutputStream out = msg.getOutputStream()) { mime.writeTo(out); } if (useEmailMessageIdAsUniqueId()) { msg.setUniqueId(StringUtils.defaultIfBlank(mime.getMessageID(), uuid)); } headerHandler().handle(mime, msg); result.add(msg); } catch (MessagingException | IOException e) { throw new MailException(e.getMessage(), e); } return result; }
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 a v a2 s . c o 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:mitm.application.djigzo.james.mailets.Attach.java
@Override public void serviceMail(Mail mail) { try {/*from w w w . j av a 2 s . co m*/ MimeMessage sourceMessage = mail.getMessage(); MimeMessage newMessage = retainMessageID ? new MimeMessageWithID(MailSession.getDefaultSession(), sourceMessage.getMessageID()) : new MimeMessage(MailSession.getDefaultSession()); if (StringUtils.isNotEmpty(filename)) { newMessage.setFileName(filename); } Multipart mp = new MimeMultipart(); HeaderMatcher contentMatcher = new ContentHeaderNameMatcher(); mp.addBodyPart(BodyPartUtils.makeContentBodyPart(sourceMessage, contentMatcher)); newMessage.setContent(mp); /* * create a matcher that matches on everything expect content-* */ HeaderMatcher nonContentMatcher = new NotHeaderNameMatcher(contentMatcher); /* * copy all non-content headers from source message to the new message */ HeaderUtils.copyHeaders(sourceMessage, newMessage, nonContentMatcher); newMessage.saveChanges(); mail.setMessage(newMessage); } catch (MessagingException e) { getLogger().error("Error attaching the message.", e); } catch (IOException e) { getLogger().error("Error attaching the message.", e); } }
From source file:org.xwiki.mail.internal.FileSystemMailContentStoreTest.java
@Test public void loadMessage() throws Exception { String batchId = UUID.randomUUID().toString(); String messageId = "ar1vm0Wca42E/dDn3dsH8ogs3/s="; String mimeMessageId = "<1128820400.0.1419205781342.JavaMail.contact@xwiki.org>"; File tempDir = new File(TEMPORARY_DIRECTORY); File batchDirectory = new File(new File(tempDir, this.mocker.getComponentUnderTest().ROOT_DIRECTORY), URLEncoder.encode(batchId, "UTF-8")); batchDirectory.mkdirs();/*w w w .ja va 2 s . c o m*/ File messageFile = new File(batchDirectory, URLEncoder.encode(messageId, "UTF-8")); messageFile.createNewFile(); String newLine = System.getProperty("line.separator"); FileWriter fileWriter = new FileWriter(messageFile, true); // Unique string is <hashcode>.<id>.<currentTime>.JavaMail.<suffix> fileWriter.append("Message-ID: " + mimeMessageId + newLine); fileWriter.append("MIME-Version: 1.0" + newLine); fileWriter.append("Content-Type: text/plain; charset=us-ascii" + newLine); fileWriter.append("Content-Transfer-Encoding: 7bit" + newLine + newLine); fileWriter.append("Lorem ipsum dolor sit amet, consectetur adipiscing elit"); fileWriter.close(); Session session = Session.getInstance(new Properties()); MimeMessage message = this.mocker.getComponentUnderTest().load(session, batchId, messageId); assertEquals(mimeMessageId, message.getMessageID()); assertEquals("Lorem ipsum dolor sit amet, consectetur adipiscing elit", message.getContent()); }
From source file:com.spartasystems.holdmail.smtp.SMTPHandler.java
@Override public void done() { try {// w w w .j a v a 2 s. c o m Session s = Session.getDefaultInstance(new Properties()); MimeMessage mimeMsg = new MimeMessage(s, new ByteArrayInputStream(data)); // set any data from the mimemessage itself MessageHeaders headers = getHeaders(mimeMsg); Message message = new Message(0, mimeMsg.getMessageID(), headers.get("Subject"), this.senderEmail, new Date(), senderHost, this.data.length, IOUtils.toString(data, CharEncoding.UTF_8), this.recipients, headers); messageService.saveMessage(message); logger.info("Stored SMTP message from " + message.getSenderEmail() + " to " + StringUtils.join(message.getRecipients(), ",")); } catch (Exception e) { logger.error("Couldn't handle message: " + e.getMessage(), e); } }
From source file:mitm.common.mail.repository.hibernate.MailRepositoryItemEntity.java
private void initMessageID(MimeMessage message) { try {//from ww w . j av a2 s . c o m messageID = StringUtils.abbreviate(message.getMessageID(), MESSAGE_ID_MAX_LENGTH); } catch (MessagingException e) { logger.debug("Error getting messageID.", e); } }