@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 batchDirectory = new File(new File(this.tmpDir, this.store.ROOT_DIRECTORY), URLEncoder.encode(batchId,"UTF-8")); batchDirectory.mkdirs(); File messageFile = new File(batchDirectory, URLEncoder.encode(messageId,"UTF-8")); messageFile.createNewFile(); String newLine = System.getProperty("line.separator"); try (FileWriter fileWriter = new FileWriter(messageFile, true)) { 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"); } Session session = Session.getInstance(new Properties()); MimeMessage message = this.store.load(session, batchId, messageId); assertEquals(mimeMessageId, message.getMessageID()); assertEquals("Lorem ipsum dolor sit amet, consectetur adipiscing elit", message.getContent()); }
@Override public ExtendedMimeMessage load(Session session, String batchId, String uniqueMessageId) throws MailStoreException { File messageFile = null; try { messageFile = getMessageFile(batchId, uniqueMessageId); InputStream is = new FileInputStream(messageFile); return new ExtendedMimeMessage(session, is); } catch (Exception e) { throw new MailStoreException(String.format( "Failed to load message (id [%s], batch id [%s]) from file [%s]", uniqueMessageId, batchId, messageFile), e); } }
FileSystemMailContentStore implements MailContentStore, Initializable { @Override public ExtendedMimeMessage load(Session session, String batchId, String uniqueMessageId) throws MailStoreException { File messageFile = null; try { messageFile = getMessageFile(batchId, uniqueMessageId); InputStream is = new FileInputStream(messageFile); return new ExtendedMimeMessage(session, is); } catch (Exception e) { throw new MailStoreException(String.format( "Failed to load message (id [%s], batch id [%s]) from file [%s]", uniqueMessageId, batchId, messageFile), e); } } }
FileSystemMailContentStore implements MailContentStore, Initializable { @Override public ExtendedMimeMessage load(Session session, String batchId, String uniqueMessageId) throws MailStoreException { File messageFile = null; try { messageFile = getMessageFile(batchId, uniqueMessageId); InputStream is = new FileInputStream(messageFile); return new ExtendedMimeMessage(session, is); } catch (Exception e) { throw new MailStoreException(String.format( "Failed to load message (id [%s], batch id [%s]) from file [%s]", uniqueMessageId, batchId, messageFile), e); } }  }
FileSystemMailContentStore implements MailContentStore, Initializable { @Override public ExtendedMimeMessage load(Session session, String batchId, String uniqueMessageId) throws MailStoreException { File messageFile = null; try { messageFile = getMessageFile(batchId, uniqueMessageId); InputStream is = new FileInputStream(messageFile); return new ExtendedMimeMessage(session, is); } catch (Exception e) { throw new MailStoreException(String.format( "Failed to load message (id [%s], batch id [%s]) from 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 ExtendedMimeMessage load(Session session, String batchId, String uniqueMessageId) throws MailStoreException { File messageFile = null; try { messageFile = getMessageFile(batchId, uniqueMessageId); InputStream is = new FileInputStream(messageFile); return new ExtendedMimeMessage(session, is); } catch (Exception e) { throw new MailStoreException(String.format( "Failed to load message (id [%s], batch id [%s]) from 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; }