/** * Returns the values of all "Reply-To" headers (usually zero or one). * Unlike {@link #getReplyTo()}, this method does not return * the "From" address if there is no "Reply To" address.<br/> * Not to be confused with {@link #getReplyAddress(Identities)}. * @throws MessagingException */ public Address[] getReplyToAddresses() throws MessagingException { String s = getHeader("Reply-To", ","); return (s == null) ? null : InternetAddress.parseHeader(s, true); }
/** * Verifies that the email contains a valid signature.<br/> * If the <code>SIGNATURE_VALID_HEADER</code> is present, its value is * used.<br/> * If not, the value of the <code>SIGNATURE_HEADER</code> header * field is verified (which is more CPU intensive). * @return <code>true</code> if the signature is valid; <code>false</code> * if it is invalid or an error occurred. */ public boolean isSignatureValid() { try { String[] sigValidFlag = getHeader(SIGNATURE_VALID_HEADER); if (sigValidFlag==null || sigValidFlag.length==0) return verifySignature(); else return "true".equalsIgnoreCase(sigValidFlag[0]); } catch (MessagingException e) { log.error("Cannot get header field: " + SIGNATURE_VALID_HEADER, e); return false; } }
String[] bccHeaders = null; try { bccHeaders = getHeader("BCC"); saveChanges(); if (bccToKeep!=null && isBCC(bccToKeep))
@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)")); }
String[] signatureHeaders; try { signatureHeaders = getHeader(SIGNATURE_HEADER); } catch (MessagingException e) { log.error("Cannot get header field: " + SIGNATURE_HEADER, e);
@Test public void testHeaderRemoval() throws MessagingException, IOException, GeneralSecurityException, PasswordException { Email newEmail; Collection<UnencryptedEmailPacket> packets; ByteArrayOutputStream outputStream; KeyUpdateHandler keyUpdateHandler = TestUtil.createDummyKeyUpdateHandler(); // verify that all BCC addresses are removed when sending to a TO: address EmailIdentity identity2 = identities.get(bccEmail); packets = bccEmail.createEmailPackets(identity2, keyUpdateHandler, null, I2PBotePacket.MAX_DATAGRAM_SIZE); outputStream = new ByteArrayOutputStream(); for (UnencryptedEmailPacket packet: packets) outputStream.write(packet.getContent()); newEmail = new Email(outputStream.toByteArray()); assertNull("BCC headers were not removed!", newEmail.getHeader("BCC")); assertEquals(3, newEmail.getAllRecipients().length); // verify that the recipient is not removed if it is a BCC: addresses packets = bccEmail.createEmailPackets(bccIdentity, keyUpdateHandler, bccEmailDestination, I2PBotePacket.MAX_DATAGRAM_SIZE); // use the plain email dest because that is what the Email class compares against outputStream = new ByteArrayOutputStream(); for (UnencryptedEmailPacket packet: packets) outputStream.write(packet.getContent()); newEmail = new Email(outputStream.toByteArray()); assertNotNull("BCC header expected!", newEmail.getHeader("BCC")); assertEquals("One BCC header expected!", 1, newEmail.getHeader("BCC").length); assertEquals(4, newEmail.getAllRecipients().length); }
@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)")); }