identitiesSet.iterator().next().setDefaultIdentity(true); Identities identities = new Identities(configuration.getIdentitiesFile(), passwordHolder); for (EmailIdentity identity: identitiesSet) identities.add(identity); identities.save();
public synchronized void checkForMail(String key) throws PasswordException, IOException, GeneralSecurityException { if (!isCheckingForMail()) { previousMailCheckTime = lastMailCheckTime; lastMailCheckTime = System.currentTimeMillis(); } EmailIdentity identity = identities.get(key); if (identity != null) checkForMail(identity); }
@Override public void passwordCleared() { identities.clearPasswordProtectedData(); addressBook.clearPasswordProtectedData(); } });
/** * Looks for a Base64-encoded Email Destination in a string and returns * the identity that matches the Email Destination. If no Email Destination * is found, or if it doesn't match any Email Identity, <code>null</code> * is returned. * @param address * @throws PasswordException * @throws GeneralSecurityException * @throws IOException */ public EmailIdentity extractIdentity(String address) throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); String destinationStr = EmailDestination.extractBase64Dest(address); if (destinationStr != null) return get(destinationStr); else return null; }
public synchronized void checkForMail() throws PasswordException, IOException, GeneralSecurityException { if (!isCheckingForMail()) { if (identities.size() <= 0) log.info("Not checking for mail because no identities are defined."); else log.info("Checking mail for " + identities.size() + " Email Identities..."); previousMailCheckTime = lastMailCheckTime; lastMailCheckTime = System.currentTimeMillis(); for (EmailIdentity identity : identities.getAll()) { if (identity.getIncludeInGlobalCheck()) { checkForMail(identity); } } } else log.info("Not checking for mail because the last mail check hasn't finished."); }
identity = identities.get(key); identities.add(identity); else identities.identityUpdated(key); identities.setDefault(identity);
byte[] message = "Hopfen und Malz, Gott erhalt's!".getBytes(); Iterator<EmailIdentity> iterator = identities.iterator(); while (iterator.hasNext()) { EmailIdentity identity = iterator.next(); publicKeyChanged = privateKeyChanged = false; else { Identities newIdentities = new Identities(identitiesFile, passwordHolder); PublicKey newPublicKey = newIdentities.get(identity).getPublicSigningKey(); PrivateKey newPrivateKey = newIdentities.get(identity).getPrivateSigningKey(); publicKeyChanged = !Arrays.equals(encodedPublicKey, newPublicKey.getEncoded()); privateKeyChanged = !Arrays.equals(encodedPrivateKey, newPrivateKey.getEncoded());
@Before public void setUp() throws Exception { File tmpDir = new File(System.getProperty("java.io.tmpdir")); testDir = new File(tmpDir, "IdentitiesTest-" + System.currentTimeMillis()); identitiesFile = new File(testDir, "identities"); assertTrue("Can't create directory: " + testDir.getAbsolutePath(), testDir.mkdir()); passwordHolder = TestUtil.createPasswordCache(testDir); identities = new Identities(identitiesFile, passwordHolder); for (TestIdentity identity: TestUtil.createTestIdentities()) identities.add(identity.identity); }
/** * 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 } }
/** Publishes an email destination in the address directory. */ public void publishDestination(String destination, byte[] picture, String text) throws PasswordException, IOException, GeneralSecurityException, DhtException, InterruptedException { EmailIdentity identity = identities.get(destination); if (identity != null) { identity.setPicture(picture); identity.setText(text); if (identity.getFingerprint() == null) identity.generateFingerprint(); // if no fingerprint exists, generate one and save it in the next step identities.save(); Contact entry = new Contact(identity, identities, picture, text, identity.getFingerprint()); dht.store(entry); } }
Iterator<EmailIdentity> iterator = identities.iterator(); if (iterator == null) return null;
identities = new Identities(configuration.getIdentitiesFile(), passwordCache); addressBook = new AddressBook(configuration.getAddressBookFile(), passwordCache); initializeFolderAccess(passwordCache);
/** * Returns <code>true</code> if <code>address</code> contains a base64-encoded * email destination that is either in the address book or among the local * email identities. * @param address * @throws PasswordException * @throws GeneralSecurityException * @throws IOException */ public static boolean isKnown(String address) throws PasswordException, IOException, GeneralSecurityException { String destination = extractEmailDestination(address); if (destination == null) return false; else if (getInstance().getAddressBook().contains(destination)) return true; else return I2PBote.getInstance().getIdentities().contains(destination); }
identities.changePassword(oldPassword, newKey);
public void remove(String key) throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); EmailIdentity identity = get(key); if (identity != null) { identities.remove(identity); // if we deleted the default identity, set a new default if (identity.isDefaultIdentity() && !identities.isEmpty()) identities.iterator().next().setDefaultIdentity(true); // when the last identity is deleted, remove the file; see isEmpty() if (identities.isEmpty() && !identitiesFile.delete()) log.error("Can't delete file: " + identitiesFile.getAbsolutePath()); for (IdentitiesListener listener : identitiesListeners) listener.identityRemoved(key); } }
@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 static EmailIdentity getIdentity(String key) throws PasswordException, IOException, GeneralSecurityException { return I2PBote.getInstance().getIdentities().get(key); }
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(); }
EmailIdentity identity = identities.get(base64dest); if (identity != null) return identity.getPublicName() + " <" + identity.toBase64() + "@bote>"; // TODO: Make @bote optional
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);