@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); } }
public Collection<UnencryptedEmailPacket> createEmailPackets(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler, String bccToKeep, int maxPacketSize) throws MessagingException, GeneralSecurityException, PasswordException { ArrayList<UnencryptedEmailPacket> packets = new ArrayList<UnencryptedEmailPacket>(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); String[] bccHeaders = null; try { bccHeaders = getHeader("BCC"); saveChanges(); if (bccToKeep!=null && isBCC(bccToKeep)) setHeader("BCC", bccToKeep); else removeHeader("BCC"); if (!isAnonymous()) sign(senderIdentity, keyUpdateHandler); compressTo(outputStream); } catch (IOException e) { throw new MessagingException("Can't write the email to an OutputStream.", e); } catch (GeneralSecurityException e) { throw new GeneralSecurityException("Can't sign email.", e); } finally { removeHeader("BCC"); if (bccHeaders != null) for (String bccAddress: bccHeaders) addHeader("BCC", bccAddress); } InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); int packetIndex = 0; try { while (true) { UnencryptedEmailPacket packet = new UnencryptedEmailPacket(inputStream, messageId, packetIndex, maxPacketSize); packets.add(packet); packetIndex++; if (inputStream.available() <= 0) break; } } catch (IOException e) { log.error("Can't read from ByteArrayInputStream.", e); } int numPackets = packetIndex; for (UnencryptedEmailPacket packet: packets) packet.setNumFragments(numPackets); return packets; }
Email extends MimeMessage { public Collection<UnencryptedEmailPacket> createEmailPackets(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler, String bccToKeep, int maxPacketSize) throws MessagingException, GeneralSecurityException, PasswordException { ArrayList<UnencryptedEmailPacket> packets = new ArrayList<UnencryptedEmailPacket>(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); String[] bccHeaders = null; try { bccHeaders = getHeader("BCC"); saveChanges(); if (bccToKeep!=null && isBCC(bccToKeep)) setHeader("BCC", bccToKeep); else removeHeader("BCC"); if (!isAnonymous()) sign(senderIdentity, keyUpdateHandler); compressTo(outputStream); } catch (IOException e) { throw new MessagingException("Can't write the email to an OutputStream.", e); } catch (GeneralSecurityException e) { throw new GeneralSecurityException("Can't sign email.", e); } finally { removeHeader("BCC"); if (bccHeaders != null) for (String bccAddress: bccHeaders) addHeader("BCC", bccAddress); } InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); int packetIndex = 0; try { while (true) { UnencryptedEmailPacket packet = new UnencryptedEmailPacket(inputStream, messageId, packetIndex, maxPacketSize); packets.add(packet); packetIndex++; if (inputStream.available() <= 0) break; } } catch (IOException e) { log.error("Can't read from ByteArrayInputStream.", e); } int numPackets = packetIndex; for (UnencryptedEmailPacket packet: packets) packet.setNumFragments(numPackets); return packets; } }
Email extends MimeMessage { public Collection<UnencryptedEmailPacket> createEmailPackets(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler, String bccToKeep, int maxPacketSize) throws MessagingException, GeneralSecurityException, PasswordException { ArrayList<UnencryptedEmailPacket> packets = new ArrayList<UnencryptedEmailPacket>(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); String[] bccHeaders = null; try { bccHeaders = getHeader("BCC"); saveChanges(); if (bccToKeep!=null && isBCC(bccToKeep)) setHeader("BCC", bccToKeep); else removeHeader("BCC"); if (!isAnonymous()) sign(senderIdentity, keyUpdateHandler); compressTo(outputStream); } catch (IOException e) { throw new MessagingException("Can't write the email to an OutputStream.", e); } catch (GeneralSecurityException e) { throw new GeneralSecurityException("Can't sign email.", e); } finally { removeHeader("BCC"); if (bccHeaders != null) for (String bccAddress: bccHeaders) addHeader("BCC", bccAddress); } InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); int packetIndex = 0; try { while (true) { UnencryptedEmailPacket packet = new UnencryptedEmailPacket(inputStream, messageId, packetIndex, maxPacketSize); packets.add(packet); packetIndex++; if (inputStream.available() <= 0) break; } } catch (IOException e) { log.error("Can't read from ByteArrayInputStream.", e); } int numPackets = packetIndex; for (UnencryptedEmailPacket packet: packets) packet.setNumFragments(numPackets); return packets; } Email(boolean includeSendTime);  Email(InputStream emailStream, InputStream metadataStream, PasswordHolder passwordHolder);  Email(InputStream inputStream, boolean compressed);  Email(byte[] bytes);  Email(Email original); }
Email extends MimeMessage { public Collection<UnencryptedEmailPacket> createEmailPackets(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler, String bccToKeep, int maxPacketSize) throws MessagingException, GeneralSecurityException, PasswordException { ArrayList<UnencryptedEmailPacket> packets = new ArrayList<UnencryptedEmailPacket>(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); String[] bccHeaders = null; try { bccHeaders = getHeader("BCC"); saveChanges(); if (bccToKeep!=null && isBCC(bccToKeep)) setHeader("BCC", bccToKeep); else removeHeader("BCC"); if (!isAnonymous()) sign(senderIdentity, keyUpdateHandler); compressTo(outputStream); } catch (IOException e) { throw new MessagingException("Can't write the email to an OutputStream.", e); } catch (GeneralSecurityException e) { throw new GeneralSecurityException("Can't sign email.", e); } finally { removeHeader("BCC"); if (bccHeaders != null) for (String bccAddress: bccHeaders) addHeader("BCC", bccAddress); } InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); int packetIndex = 0; try { while (true) { UnencryptedEmailPacket packet = new UnencryptedEmailPacket(inputStream, messageId, packetIndex, maxPacketSize); packets.add(packet); packetIndex++; if (inputStream.available() <= 0) break; } } catch (IOException e) { log.error("Can't read from ByteArrayInputStream.", e); } int numPackets = packetIndex; for (UnencryptedEmailPacket packet: packets) packet.setNumFragments(numPackets); return packets; } Email(boolean includeSendTime);  Email(InputStream emailStream, InputStream metadataStream, PasswordHolder passwordHolder);  Email(InputStream inputStream, boolean compressed);  Email(byte[] bytes);  Email(Email original); void setContent(String text, List<Attachment> attachments); void setMetadata(EmailMetadata metadata); EmailMetadata getMetadata(); boolean isAnonymous(); String getOneFromAddress(); String getOneRecipient(); void setHashCash(HashCash hashCash); @Override void updateHeaders(); void sign(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler); void setSignatureFlag(); void removeSignatureFlag(); boolean isSignatureValid(); void checkAddresses(); static void checkSender(Address address); static void checkRecipient(Address address); Collection<Address> getAllFromAddresses(); Collection<Address> getAllAddresses(boolean includeFrom); Address[] getReplyToAddresses(); String getReplyAddress(Identities identities); Address[] getToAddresses(); Address[] getCCAddresses(); Address[] getBCCAddresses(); void removeBoteSuffixes(); static String removeBoteSuffix(String addr); void setMessageID(String messageIdString); void setMessageID(UniqueId messageId); @Override String getMessageID(); void setRecent(boolean recent); boolean isRecent(); void setUnread(boolean unread); boolean isUnread(); void setCreateTime(Date createTime); boolean isDelivered(); void setReplied(boolean replied); boolean isReplied(); void setDeleted(boolean deleted); boolean isDeleted(); int getDeliveryPercentage(); Date getCreateTime(); @Override Date getReceivedDate(); @Override synchronized void setFlags(Flags flag, boolean set); @Override Flags getFlags(); Collection<UnencryptedEmailPacket> createEmailPackets(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler, String bccToKeep, int maxPacketSize); String getText(); boolean isContainingAttachments(); List<Part> getParts(); @Override String toString(); }
Email extends MimeMessage { public Collection<UnencryptedEmailPacket> createEmailPackets(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler, String bccToKeep, int maxPacketSize) throws MessagingException, GeneralSecurityException, PasswordException { ArrayList<UnencryptedEmailPacket> packets = new ArrayList<UnencryptedEmailPacket>(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); String[] bccHeaders = null; try { bccHeaders = getHeader("BCC"); saveChanges(); if (bccToKeep!=null && isBCC(bccToKeep)) setHeader("BCC", bccToKeep); else removeHeader("BCC"); if (!isAnonymous()) sign(senderIdentity, keyUpdateHandler); compressTo(outputStream); } catch (IOException e) { throw new MessagingException("Can't write the email to an OutputStream.", e); } catch (GeneralSecurityException e) { throw new GeneralSecurityException("Can't sign email.", e); } finally { removeHeader("BCC"); if (bccHeaders != null) for (String bccAddress: bccHeaders) addHeader("BCC", bccAddress); } InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); int packetIndex = 0; try { while (true) { UnencryptedEmailPacket packet = new UnencryptedEmailPacket(inputStream, messageId, packetIndex, maxPacketSize); packets.add(packet); packetIndex++; if (inputStream.available() <= 0) break; } } catch (IOException e) { log.error("Can't read from ByteArrayInputStream.", e); } int numPackets = packetIndex; for (UnencryptedEmailPacket packet: packets) packet.setNumFragments(numPackets); return packets; } Email(boolean includeSendTime);  Email(InputStream emailStream, InputStream metadataStream, PasswordHolder passwordHolder);  Email(InputStream inputStream, boolean compressed);  Email(byte[] bytes);  Email(Email original); void setContent(String text, List<Attachment> attachments); void setMetadata(EmailMetadata metadata); EmailMetadata getMetadata(); boolean isAnonymous(); String getOneFromAddress(); String getOneRecipient(); void setHashCash(HashCash hashCash); @Override void updateHeaders(); void sign(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler); void setSignatureFlag(); void removeSignatureFlag(); boolean isSignatureValid(); void checkAddresses(); static void checkSender(Address address); static void checkRecipient(Address address); Collection<Address> getAllFromAddresses(); Collection<Address> getAllAddresses(boolean includeFrom); Address[] getReplyToAddresses(); String getReplyAddress(Identities identities); Address[] getToAddresses(); Address[] getCCAddresses(); Address[] getBCCAddresses(); void removeBoteSuffixes(); static String removeBoteSuffix(String addr); void setMessageID(String messageIdString); void setMessageID(UniqueId messageId); @Override String getMessageID(); void setRecent(boolean recent); boolean isRecent(); void setUnread(boolean unread); boolean isUnread(); void setCreateTime(Date createTime); boolean isDelivered(); void setReplied(boolean replied); boolean isReplied(); void setDeleted(boolean deleted); boolean isDeleted(); int getDeliveryPercentage(); Date getCreateTime(); @Override Date getReceivedDate(); @Override synchronized void setFlags(Flags flag, boolean set); @Override Flags getFlags(); Collection<UnencryptedEmailPacket> createEmailPackets(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler, String bccToKeep, int maxPacketSize); String getText(); boolean isContainingAttachments(); List<Part> getParts(); @Override String toString();  }