@Test
public void testCreateEmailPackets() throws MessagingException, IOException, GeneralSecurityException, SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, PasswordException {
for (Email email: emails) {
EmailIdentity identity = identities.get(email);
KeyUpdateHandler keyUpdateHandler = TestUtil.createDummyKeyUpdateHandler();
Collection<UnencryptedEmailPacket> packets = email.createEmailPackets(identity, keyUpdateHandler, null, I2PBotePacket.MAX_DATAGRAM_SIZE);
assertTrue("Expected more email packets. #packets = " + packets.size(), packets.size() > email.getText().length()/I2PBotePacket.MAX_DATAGRAM_SIZE/2);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
for (UnencryptedEmailPacket packet: packets)
outputStream.write(packet.getContent());
Email newEmail = new Email(outputStream.toByteArray());
assertEquals(email.getContent(), newEmail.getContent());
for (UnencryptedEmailPacket packet: packets)
assertTrue("Email packet exceeds max size!", packet.toByteArray().length <= I2PBotePacket.MAX_DATAGRAM_SIZE);
}
}