@Test public void testSendAnonymousEmail() throws Exception { testEmail = new Email(true); testEmail.setFrom(new InternetAddress("anonymous")); testEmail.addRecipient(RecipientType.TO, new InternetAddress("Erika Mustermann <m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY>")); testEmail.setSubject("Test", "UTF-8"); testEmail.setText("foobar"); op.sendEmail(testEmail); ArgumentCaptor<DhtStorablePacket> arg = ArgumentCaptor.forClass(DhtStorablePacket.class); verify(dht, times(2)).store(arg.capture()); List<DhtStorablePacket> values = arg.getAllValues(); assertTrue(values.get(0) instanceof EncryptedEmailPacket); assertTrue(values.get(1) instanceof IndexPacket); assertTrue(((IndexPacket)values.get(1)).contains(((EncryptedEmailPacket)values.get(0)).getDhtKey())); }
void sendEmail(Email email) throws MessagingException, DhtException, GeneralSecurityException, PasswordException, IOException, InterruptedException { EmailIdentity senderIdentity = null; if (!email.isAnonymous()) { String sender = email.getOneFromAddress(); senderIdentity = identities.extractIdentity(sender); if (senderIdentity == null) { log.error("No identity matches the sender/from field: " + sender + " in email: " + email); outbox.setStatus(email, new EmailStatus(Status.NO_IDENTITY_MATCHES, sender)); } } outbox.setStatus(email, new EmailStatus(Status.SENDING)); Address[] recipients = email.getAllRecipients(); boolean containsExternalRecipients = false; for (int i=0; i<recipients.length; i++) { Address recipient = recipients[i]; if (isExternalAddress(recipient)) containsExternalRecipients = true; else sendToOne(senderIdentity, recipient.toString(), email); outbox.setStatus(email, new EmailStatus(Status.SENT_TO, i+1, recipients.length)); } if (containsExternalRecipients) { if (configuration.isGatewayEnabled()) { sendToOne(senderIdentity, configuration.getGatewayDestination(), email); outbox.setStatus(email, new EmailStatus(Status.EMAIL_SENT)); } else { outbox.setStatus(email, new EmailStatus(Status.GATEWAY_DISABLED)); throw new MessagingException("The email contains external addresses, but the gateway is disabled."); } } }
OutboxProcessor extends I2PAppThread { void sendEmail(Email email) throws MessagingException, DhtException, GeneralSecurityException, PasswordException, IOException, InterruptedException { EmailIdentity senderIdentity = null; if (!email.isAnonymous()) { String sender = email.getOneFromAddress(); senderIdentity = identities.extractIdentity(sender); if (senderIdentity == null) { log.error("No identity matches the sender/from field: " + sender + " in email: " + email); outbox.setStatus(email, new EmailStatus(Status.NO_IDENTITY_MATCHES, sender)); } } outbox.setStatus(email, new EmailStatus(Status.SENDING)); Address[] recipients = email.getAllRecipients(); boolean containsExternalRecipients = false; for (int i=0; i<recipients.length; i++) { Address recipient = recipients[i]; if (isExternalAddress(recipient)) containsExternalRecipients = true; else sendToOne(senderIdentity, recipient.toString(), email); outbox.setStatus(email, new EmailStatus(Status.SENT_TO, i+1, recipients.length)); } if (containsExternalRecipients) { if (configuration.isGatewayEnabled()) { sendToOne(senderIdentity, configuration.getGatewayDestination(), email); outbox.setStatus(email, new EmailStatus(Status.EMAIL_SENT)); } else { outbox.setStatus(email, new EmailStatus(Status.GATEWAY_DISABLED)); throw new MessagingException("The email contains external addresses, but the gateway is disabled."); } } } }
OutboxProcessor extends I2PAppThread { void sendEmail(Email email) throws MessagingException, DhtException, GeneralSecurityException, PasswordException, IOException, InterruptedException { EmailIdentity senderIdentity = null; if (!email.isAnonymous()) { String sender = email.getOneFromAddress(); senderIdentity = identities.extractIdentity(sender); if (senderIdentity == null) { log.error("No identity matches the sender/from field: " + sender + " in email: " + email); outbox.setStatus(email, new EmailStatus(Status.NO_IDENTITY_MATCHES, sender)); } } outbox.setStatus(email, new EmailStatus(Status.SENDING)); Address[] recipients = email.getAllRecipients(); boolean containsExternalRecipients = false; for (int i=0; i<recipients.length; i++) { Address recipient = recipients[i]; if (isExternalAddress(recipient)) containsExternalRecipients = true; else sendToOne(senderIdentity, recipient.toString(), email); outbox.setStatus(email, new EmailStatus(Status.SENT_TO, i+1, recipients.length)); } if (containsExternalRecipients) { if (configuration.isGatewayEnabled()) { sendToOne(senderIdentity, configuration.getGatewayDestination(), email); outbox.setStatus(email, new EmailStatus(Status.EMAIL_SENT)); } else { outbox.setStatus(email, new EmailStatus(Status.GATEWAY_DISABLED)); throw new MessagingException("The email contains external addresses, but the gateway is disabled."); } } } OutboxProcessor(DHT dht, Outbox outbox, RelayPeerManager peerManager, RelayPacketFolder relayPacketFolder, Identities identities, Configuration configuration, NetworkStatusSource networkStatusSource); }
OutboxProcessor extends I2PAppThread { void sendEmail(Email email) throws MessagingException, DhtException, GeneralSecurityException, PasswordException, IOException, InterruptedException { EmailIdentity senderIdentity = null; if (!email.isAnonymous()) { String sender = email.getOneFromAddress(); senderIdentity = identities.extractIdentity(sender); if (senderIdentity == null) { log.error("No identity matches the sender/from field: " + sender + " in email: " + email); outbox.setStatus(email, new EmailStatus(Status.NO_IDENTITY_MATCHES, sender)); } } outbox.setStatus(email, new EmailStatus(Status.SENDING)); Address[] recipients = email.getAllRecipients(); boolean containsExternalRecipients = false; for (int i=0; i<recipients.length; i++) { Address recipient = recipients[i]; if (isExternalAddress(recipient)) containsExternalRecipients = true; else sendToOne(senderIdentity, recipient.toString(), email); outbox.setStatus(email, new EmailStatus(Status.SENT_TO, i+1, recipients.length)); } if (containsExternalRecipients) { if (configuration.isGatewayEnabled()) { sendToOne(senderIdentity, configuration.getGatewayDestination(), email); outbox.setStatus(email, new EmailStatus(Status.EMAIL_SENT)); } else { outbox.setStatus(email, new EmailStatus(Status.GATEWAY_DISABLED)); throw new MessagingException("The email contains external addresses, but the gateway is disabled."); } } } OutboxProcessor(DHT dht, Outbox outbox, RelayPeerManager peerManager, RelayPacketFolder relayPacketFolder, Identities identities, Configuration configuration, NetworkStatusSource networkStatusSource); @Override void run(); void checkForEmail(); void addOutboxListener(OutboxListener listener); }
OutboxProcessor extends I2PAppThread { void sendEmail(Email email) throws MessagingException, DhtException, GeneralSecurityException, PasswordException, IOException, InterruptedException { EmailIdentity senderIdentity = null; if (!email.isAnonymous()) { String sender = email.getOneFromAddress(); senderIdentity = identities.extractIdentity(sender); if (senderIdentity == null) { log.error("No identity matches the sender/from field: " + sender + " in email: " + email); outbox.setStatus(email, new EmailStatus(Status.NO_IDENTITY_MATCHES, sender)); } } outbox.setStatus(email, new EmailStatus(Status.SENDING)); Address[] recipients = email.getAllRecipients(); boolean containsExternalRecipients = false; for (int i=0; i<recipients.length; i++) { Address recipient = recipients[i]; if (isExternalAddress(recipient)) containsExternalRecipients = true; else sendToOne(senderIdentity, recipient.toString(), email); outbox.setStatus(email, new EmailStatus(Status.SENT_TO, i+1, recipients.length)); } if (containsExternalRecipients) { if (configuration.isGatewayEnabled()) { sendToOne(senderIdentity, configuration.getGatewayDestination(), email); outbox.setStatus(email, new EmailStatus(Status.EMAIL_SENT)); } else { outbox.setStatus(email, new EmailStatus(Status.GATEWAY_DISABLED)); throw new MessagingException("The email contains external addresses, but the gateway is disabled."); } } } OutboxProcessor(DHT dht, Outbox outbox, RelayPeerManager peerManager, RelayPacketFolder relayPacketFolder, Identities identities, Configuration configuration, NetworkStatusSource networkStatusSource); @Override void run(); void checkForEmail(); void addOutboxListener(OutboxListener listener);  }