public String getOneRecipient() throws MessagingException { Address[] recipients = getAllRecipients(); if (recipients==null || recipients.length==0) return null; else return recipients[0].toString(); }
public Collection<Address> getAllAddresses(boolean includeFrom) throws MessagingException { Collection<Address> addresses = new ArrayList<Address>(); // If we want to check validity, fetch these separately // (because these can contain 'anonymous'). if (includeFrom) { addresses.addAll(getAllFromAddresses()); } Address[] recipients = getAllRecipients(); if (recipients != null) addresses.addAll(Arrays.asList(recipients)); // Reply-To should not be anonymous, check with recipients Address[] replyTo = getReplyToAddresses(); if (replyTo != null) addresses.addAll(Arrays.asList(replyTo)); return addresses; }
@Override public String toString() { StringBuilder result = new StringBuilder("MsgId: ").append(getMessageID()); try { result = result.append("From: ").append(getOneFromAddress()); result = result.append("Recipients: "); for (Address recipient: getAllRecipients()) { if (result.length() > 1000) { result = result.append("..."); break; } if (result.length() > 0) result = result.append(", "); String recipientAddress = recipient.toString(); if (recipientAddress.length() > 20) result = result.append(recipientAddress).append("..."); else result = result.append(recipientAddress); } } catch (MessagingException e) { log.error("Error getting sender or recipients."); result.append("#Error#"); } return result.toString(); } }
Address[] recipients; try { recipients = email.getAllRecipients();
@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); }
Address[] recipients = email.getAllRecipients(); boolean containsExternalRecipients = false; for (int i=0; i<recipients.length; i++) {