@Override public void passwordCleared() { identities.clearPasswordProtectedData(); addressBook.clearPasswordProtectedData(); } });
public void remove(String destination) throws PasswordException { initializeIfNeeded(); Contact contact = get(destination); if (contact != null) contacts.remove(contact); }
public void save() throws IOException, PasswordException, GeneralSecurityException { initializeIfNeeded(); OutputStream encryptedStream = new EncryptedOutputStream(new SecureFileOutputStream(addressFile), 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 <" + addressFile.getAbsolutePath() + ">.", e); throw e; } finally { encryptedStream.close(); } }
private void migrateAddressBook(List<String> lines, Configuration configuration, PasswordHolder passwordHolder) throws IOException, GeneralSecurityException, PasswordException { AddressBook addressBook = new AddressBook(configuration.getAddressBookFile(), passwordHolder); for (String line: lines) { String[] fields = line.split("\\t", 2); try { EmailDestination destination = new EmailDestination(fields[0]); String name = null; if (fields.length > 1) name = fields[1]; Contact contact = new Contact(name, destination); addressBook.add(contact); } catch (GeneralSecurityException e) { log.error("Not a valid Email Destination: <" + fields[0] + ">", e); } } addressBook.save(); } }
@Test public void testExportImport() throws Exception { File exportFile = new File(testDir, "ExportImportTest-" + System.currentTimeMillis() + ".txt"); addressBook.export(exportFile, null); File tmpAddressBookFile = new File(testDir, "ExportImportAB-" + System.currentTimeMillis()); AddressBook tmpAddressBook = new AddressBook(tmpAddressBookFile, passwordHolder); FileInputStream fis = new FileInputStream(exportFile); try { tmpAddressBook.importFromFileDescriptor(fis.getFD(), null, false, false); SortedSet<Contact> start = addressBook.getAll(); SortedSet<Contact> end = tmpAddressBook.getAll(); for (Contact contact : start) { assertThat(contact, isIn(end)); } for (Contact contact : end) { assertThat(contact, isIn(start)); } } finally { try { fis.close(); } catch (IOException e) { } assertTrue("Can't delete file: " + exportFile.getAbsolutePath(), exportFile.delete()); assertTrue("Can't delete file: " + tmpAddressBookFile.getAbsolutePath(), tmpAddressBookFile.delete()); } } }
@Before public void setUp() throws Exception { File tmpDir = new File(System.getProperty("java.io.tmpdir")); testDir = new File(tmpDir, "AddressBookTest-" + System.currentTimeMillis()); addressBookFile = new File(testDir, "addressBook"); assertTrue("Can't create directory: " + testDir.getAbsolutePath(), testDir.mkdir()); passwordHolder = TestUtil.createPasswordCache(testDir); addressBook = new AddressBook(addressBookFile, passwordHolder); for (TestUtil.TestIdentity identity : TestUtil.createTestIdentities()) addressBook.add(new Contact(identity.identity.getPublicName(), identity.identity)); }
public SortedSet<Contact> getAll() throws PasswordException { initializeIfNeeded(); return contacts; }
addressBook = new AddressBook(configuration.getAddressBookFile(), passwordCache); initializeFolderAccess(passwordCache); initializeExternalThemeDir();
public static Contact getContact(String destination) throws PasswordException { return getInstance().getAddressBook().get(destination); }
/** * 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); }
addressBook.changePassword(oldPassword, newKey); for (EmailFolder folder: getEmailFolders()) { lsnr.updateStatus(ChangePasswordStatus.RE_ENCRYPTING_FOLDER, folder.getName());
public void add(Contact contact) throws PasswordException { initializeIfNeeded(); contacts.add(contact); }
if (base64dest != null) { Contact contact = addressBook.get(base64dest); if (contact != null) return contact.getName() + " <" + contact.getBase64Dest() + "@bote>"; // TODO: Make @bote optional
public int size() throws PasswordException { initializeIfNeeded(); return contacts.size(); }
if (base64dest != null) { Contact contact = addressBook.get(base64dest); if (contact != null) return contact.getName();
/** * Looks up an {@link Contact} by its Base64 key. If none is found, * <code>null</code> is returned. * @param destination */ public Contact get(String destination) throws PasswordException { initializeIfNeeded(); if (contacts==null || destination==null || destination.isEmpty()) return null; for (Contact contact: contacts) if (destination.equals(contact.getBase64Dest())) return contact; return null; }
if (base64dest != null) { Contact contact = addressBook.get(base64dest); if (contact != null) return contact.getName() + " <" + contact.getBase64Dest() + ">";
/** * Returns <code>true</code> if a given Base64-encoded Email Destination * is in the address book. * @param base64dest */ public boolean contains(String base64dest) throws PasswordException { initializeIfNeeded(); if (base64dest == null) return false; for (Contact contact: contacts) if (base64dest.equals(contact.getBase64Dest())) return true; return false; }