private void migrateAddressBookIfNeeded(Configuration configuration, PasswordHolder passwordHolder) throws FileNotFoundException, IOException, GeneralSecurityException, PasswordException { File addressBookFile = configuration.getAddressBookFile(); if (!addressBookFile.exists()) return; BufferedReader input = null; try { InputStream encryptedStream = new EncryptedInputStream(new FileInputStream(addressBookFile), passwordHolder); input = new BufferedReader(new InputStreamReader(encryptedStream)); // No PasswordException occurred, so read the input stream and call migrateAddressBook() if needed List<String> lines = Util.readLines(encryptedStream); if (!isAddressBookFileMigrated(lines)) migrateAddressBook(lines, configuration, passwordHolder); } finally { if (input != null) input.close(); } }
files.add(configuration.getAddressBookFile()); File[] emailFolders = new File[] {configuration.getInboxDir(), configuration.getOutboxDir(), configuration.getSentFolderDir(), configuration.getTrashFolderDir()};; for (File dir: emailFolders)
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(); } }
File oldAddrBookFile = new File(configuration.getAddressBookFile().getParentFile(), "addressBook.txt"); if (oldAddrBookFile.exists()) { log.debug("Migrating address book: <" + oldIdentitiesFile + ">"); File newAddrBookFile = configuration.getAddressBookFile(); encrypt(oldAddrBookFile, newAddrBookFile); oldAddrBookFile.delete();
addressBook = new AddressBook(configuration.getAddressBookFile(), passwordCache); initializeFolderAccess(passwordCache); initializeExternalThemeDir();