public Collection<EmailIdentity> getAll() throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); return identities; }
public Iterator<EmailIdentity> iterator() throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); if (identities == null) return null; return identities.iterator(); }
public int size() throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); return identities.size(); }
/** * Returns the default identity, or <code>null</code> if no default is set. * @throws GeneralSecurityException * @throws IOException */ public EmailIdentity getDefault() throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); if (identities == null) return null; for (EmailIdentity identity: identities) if (identity.isDefaultIdentity()) return identity; return null; }
/** * Returns <code>true</code> if any of the <code>Identities</code> matches * the two public keys of a given {@link EmailDestination} * (Note that an <code>EmailIdentity</code> is an <code>EmailDestination</code>). * @param base64Dest A base64-encoded Email Destination * @throws PasswordException * @throws GeneralSecurityException * @throws IOException */ public boolean contains(String base64Dest) throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); if (identities==null || base64Dest==null) return false; for (EmailIdentity identity: identities) if (base64Dest.equals(identity.toBase64())) return true; return false; }
/** * Looks up an {@link EmailIdentity} by its Base64 key (the two public keys, to be * more precise).<br/> * Returns An <code>EmailIdentity</code>, or <code>null</code> if nothing is found. * @param key * @throws PasswordException * @throws GeneralSecurityException * @throws IOException */ public EmailIdentity get(String key) throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); if (identities == null) return null; for (EmailIdentity identity: identities) if (identity.getKey().equals(key)) return identity; return null; }
public void add(EmailIdentity identity) throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); if (identities.isEmpty()) identity.setDefaultIdentity(true); identities.add(identity); for (IdentitiesListener listener : identitiesListeners) listener.identityAdded(identity.getKey()); }
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); } }
/** * Sets the default identity. Assumes this <code>Identities</code> already * contains <code>defaultIdentity</code>. * @throws GeneralSecurityException * @throws IOException */ public void setDefault(EmailIdentity defaultIdentity) throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); // clear the old default for (EmailIdentity identity: identities) identity.setDefaultIdentity(false); defaultIdentity.setDefaultIdentity(true); this.defaultIdentity = defaultIdentity; }
/** Saves all identities to file. */ public void save() throws IOException, GeneralSecurityException, PasswordException { initializeIfNeeded(); OutputStream encryptedStream = new EncryptedOutputStream(new SecureFileOutputStream(identitiesFile), passwordHolder); try { Properties properties = saveToProperties(); properties.store(new OutputStreamWriter(encryptedStream, "UTF-8"), null); } catch (IOException e) { log.error("Can't save email identities to file <" + identitiesFile.getAbsolutePath() + ">.", e); throw e; } finally { encryptedStream.close(); } }
/** * 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; }
/** * Looks up an {@link EmailIdentity} that has the same public encryption key and the * same public signing key as a given {@link EmailDestination}.<br/> * Returns <code>null</code> if nothing is found. * @param destination * @throws PasswordException * @throws GeneralSecurityException * @throws IOException */ public EmailIdentity get(EmailDestination destination) throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); if (identities == null) return null; for (EmailIdentity identity: identities) if (identity.getPublicEncryptionKey().equals(destination.getPublicEncryptionKey()) && identity.getPublicSigningKey().equals(destination.getPublicSigningKey())) return identity; return null; }