/** * Creates an <code>Email</code> from an InputStream containing a compressed or uncompressed MIME email. * @param inputStream * @param compressed <code>true</code> if the stream contains compressed data * @throws MessagingException * @throws IOException */ public Email(InputStream inputStream, boolean compressed) throws MessagingException, IOException { super(Session.getDefaultInstance(new Properties()), compressed?Email.decompress(inputStream):inputStream); messageId = new UniqueId(); includeSendTime = getSentDate() != null; metadata = new EmailMetadata(); }
/** * Removes all headers that are not on the whitelist, and initializes some * basic header fields.<br/> * Called by {@link #saveChanges()}, see JavaMail JavaDoc. * @throws MessagingException */ @Override public void updateHeaders() throws MessagingException { super.updateHeaders(); scrubHeaders(); removeRecipientNames(); // Depending on includeSendTime, set the send time or remove the send time field if (includeSendTime) { // Ensure the "Date" field is set in UTC time, using the English locale. MailDateFormat formatter = new MailDateFormat(); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); // always use UTC for outgoing mail if (getSentDate() == null) setHeader("Date", formatter.format(new Date())); else setHeader("Date", formatter.format(getSentDate())); } else removeHeader("Date"); }
@Test public void testProvidedDateIsConvertedToUTC() throws Exception { ByteArrayInputStream in = new ByteArrayInputStream(TEST_EMAIL_WITH_TIMEZONE.getBytes()); Email email = new Email(in, false); assertNotNull(email.getSentDate()); assertThat(email.getHeader("Date", null), endsWith("-0700")); email.updateHeaders(); assertNotNull(email.getSentDate()); assertThat(email.getHeader("Date", null), endsWith("+0000 (GMT)")); }
@Test public void testDefaultDateIsUTC() throws Exception { Email email = new Email(true); assertNull(email.getSentDate()); email.updateHeaders(); assertNotNull(email.getSentDate()); assertThat(email.getHeader("Date", null), endsWith("+0000 (GMT)")); }
case DATE: value1 = email1.getSentDate(); if (value1 == null) value1 = email1.getReceivedDate(); value2 = email2.getSentDate(); if (value2 == null) value2 = email2.getReceivedDate();