@Test public void saveMessageWithCustomMessageId() throws Exception { String batchId = UUID.randomUUID().toString(); String mimeMessageId = "<1128820400.0.1419205781342.JavaMail.contact@xwiki.org>"; ExtendedMimeMessage message = new ExtendedMimeMessage(); message.setMessageId(mimeMessageId); message.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit"); this.store.save(batchId, message); File batchDirectory = new File(new File(this.tmpDir, this.store.ROOT_DIRECTORY), URLEncoder.encode(batchId, "UTF-8")); File messageFile = new File(batchDirectory, URLEncoder.encode(message.getUniqueMessageId(), "UTF-8")); InputStream in = new FileInputStream(messageFile); String messageContent = IOUtils.toString(in, "UTF-8"); assertTrue(messageContent.contains("Message-ID: " + mimeMessageId)); assertTrue(messageContent.contains("Lorem ipsum dolor sit amet, consectetur adipiscing elit")); }
@Override public void save(String batchId, ExtendedMimeMessage message) throws MailStoreException { List<File> temporaryFiles = extractTemporaryFilesFromHeaders(message); String uniqueMessageId = message.getUniqueMessageId(); File messageFile = getMessageFile(batchId, uniqueMessageId); messageFile.getParentFile().mkdirs(); try { if (message.ensureSaved()) { uniqueMessageId = message.getUniqueMessageId(); messageFile = getMessageFile(batchId, uniqueMessageId); } message.writeTo(new FileOutputStream(messageFile)); for (File temporaryFile : temporaryFiles) { FileUtils.forceDelete(temporaryFile); } } catch (Exception e) { throw new MailStoreException(String.format( "Failed to save message (id [%s], batch id [%s]) into file [%s]", uniqueMessageId, batchId, messageFile), e); } }
FileSystemMailContentStore implements MailContentStore, Initializable { @Override public void save(String batchId, ExtendedMimeMessage message) throws MailStoreException { List<File> temporaryFiles = extractTemporaryFilesFromHeaders(message); String uniqueMessageId = message.getUniqueMessageId(); File messageFile = getMessageFile(batchId, uniqueMessageId); messageFile.getParentFile().mkdirs(); try { if (message.ensureSaved()) { uniqueMessageId = message.getUniqueMessageId(); messageFile = getMessageFile(batchId, uniqueMessageId); } message.writeTo(new FileOutputStream(messageFile)); for (File temporaryFile : temporaryFiles) { FileUtils.forceDelete(temporaryFile); } } catch (Exception e) { throw new MailStoreException(String.format( "Failed to save message (id [%s], batch id [%s]) into file [%s]", uniqueMessageId, batchId, messageFile), e); } } }
FileSystemMailContentStore implements MailContentStore, Initializable { @Override public void save(String batchId, ExtendedMimeMessage message) throws MailStoreException { List<File> temporaryFiles = extractTemporaryFilesFromHeaders(message); String uniqueMessageId = message.getUniqueMessageId(); File messageFile = getMessageFile(batchId, uniqueMessageId); messageFile.getParentFile().mkdirs(); try { if (message.ensureSaved()) { uniqueMessageId = message.getUniqueMessageId(); messageFile = getMessageFile(batchId, uniqueMessageId); } message.writeTo(new FileOutputStream(messageFile)); for (File temporaryFile : temporaryFiles) { FileUtils.forceDelete(temporaryFile); } } catch (Exception e) { throw new MailStoreException(String.format( "Failed to save message (id [%s], batch id [%s]) into file [%s]", uniqueMessageId, batchId, messageFile), e); } }  }
FileSystemMailContentStore implements MailContentStore, Initializable { @Override public void save(String batchId, ExtendedMimeMessage message) throws MailStoreException { List<File> temporaryFiles = extractTemporaryFilesFromHeaders(message); String uniqueMessageId = message.getUniqueMessageId(); File messageFile = getMessageFile(batchId, uniqueMessageId); messageFile.getParentFile().mkdirs(); try { if (message.ensureSaved()) { uniqueMessageId = message.getUniqueMessageId(); messageFile = getMessageFile(batchId, uniqueMessageId); } message.writeTo(new FileOutputStream(messageFile)); for (File temporaryFile : temporaryFiles) { FileUtils.forceDelete(temporaryFile); } } catch (Exception e) { throw new MailStoreException(String.format( "Failed to save message (id [%s], batch id [%s]) into file [%s]", uniqueMessageId, batchId, messageFile), e); } }  @Override void initialize(); @Override void save(String batchId, ExtendedMimeMessage message); @Override ExtendedMimeMessage load(Session session, String batchId, String uniqueMessageId); @Override void delete(String batchId, String uniqueMessageId); }
FileSystemMailContentStore implements MailContentStore, Initializable { @Override public void save(String batchId, ExtendedMimeMessage message) throws MailStoreException { List<File> temporaryFiles = extractTemporaryFilesFromHeaders(message); String uniqueMessageId = message.getUniqueMessageId(); File messageFile = getMessageFile(batchId, uniqueMessageId); messageFile.getParentFile().mkdirs(); try { if (message.ensureSaved()) { uniqueMessageId = message.getUniqueMessageId(); messageFile = getMessageFile(batchId, uniqueMessageId); } message.writeTo(new FileOutputStream(messageFile)); for (File temporaryFile : temporaryFiles) { FileUtils.forceDelete(temporaryFile); } } catch (Exception e) { throw new MailStoreException(String.format( "Failed to save message (id [%s], batch id [%s]) into file [%s]", uniqueMessageId, batchId, messageFile), e); } }  @Override void initialize(); @Override void save(String batchId, ExtendedMimeMessage message); @Override ExtendedMimeMessage load(Session session, String batchId, String uniqueMessageId); @Override void delete(String batchId, String uniqueMessageId); static final String ROOT_DIRECTORY; }