removeHeader("BCC"); if (!isAnonymous()) sign(senderIdentity, keyUpdateHandler); compressTo(outputStream); } catch (IOException e) {
public void sendEmail(Email email) throws MessagingException, PasswordException, IOException, GeneralSecurityException { email.checkAddresses(); // sign email unless sender is anonymous if (!email.isAnonymous()) { String sender = email.getOneFromAddress(); EmailIdentity senderIdentity = identities.extractIdentity(sender); if (senderIdentity == null) throw new NoIdentityForSenderException(sender); email.sign(senderIdentity, identities); } email.setSignatureFlag(); // set the signature flag so the signature isn't reverified every time the email is loaded outbox.add(email); if (outboxProcessor != null) outboxProcessor.checkForEmail(); }
@Test public void testSign() throws MessagingException, SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException, GeneralSecurityException, PasswordException { assertEquals(emails.size()-1, identities.size()); // -1 for the anonymous email that was not added to the map for (Email email: emails) { EmailIdentity identity = identities.get(email); if (identity == null) continue; // sign and verify signature email.sign(identity, TestUtil.createDummyKeyUpdateHandler()); assertTrue(email.isSignatureValid()); // write the email to a byte array, make a new email from the byte array, and verify the signature ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); KeyUpdateHandler keyUpdateHandler = TestUtil.createDummyKeyUpdateHandler(); for (UnencryptedEmailPacket packet: email.createEmailPackets(identity, keyUpdateHandler, null, I2PBotePacket.MAX_DATAGRAM_SIZE)) outputStream.write(packet.getContent()); email = new Email(outputStream.toByteArray()); assertTrue(email.isSignatureValid()); } }