/** * Returns the address replies to this email should be sent to. * If a <code>Reply-To</code> header exists, its value is returned. * Otherwise, if the recipient is a local identity (i.e. the email * was sent by somebody else), the sender is used; if the recipient * is not a local identity (sender was us), the recipient is used. * <br/> * Not to be confused with {@link #getReplyToAddresses()}. * @param identities * @throws MessagingException * @throws GeneralSecurityException * @throws IOException * @throws PasswordException */ public String getReplyAddress(Identities identities) throws MessagingException, PasswordException, IOException, GeneralSecurityException { Address[] replyTo = getReplyToAddresses(); if (replyTo!=null && replyTo.length>0) return replyTo[0].toString(); else { String sender = getOneFromAddress(); EmailIdentity senderIdentity = identities.extractIdentity(sender); if (senderIdentity != null) return getOneRecipient(); // sent by local user, so reply to recipient else return sender; // sent by other party, so reply to sender } }
@Test public void testSendEmail() throws Exception { EmailIdentity identity = TestUtil.createTestIdentities().get(0).identity; String address = "tester <" + identity.getKey() + ">"; when(identities.extractIdentity(address)).thenReturn(identity); testEmail = new Email(true); testEmail.setFrom(new InternetAddress(address)); 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())); }
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(); }
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);