use of i2p.bote.email.Identities.IdentityComparator in project i2p.i2p-bote by i2p.
the class MigrateTo028 method migrateIdentities.
/**
* @param configuration
* @throws PasswordException
* @throws GeneralSecurityException
* @throws IOException
* @throws Exception
*/
private void migrateIdentities(List<String> lines, Configuration configuration, PasswordHolder passwordHolder) throws IOException, GeneralSecurityException, PasswordException {
SortedSet<EmailIdentity> identitiesSet = new TreeSet<EmailIdentity>(new IdentityComparator());
String defaultIdentityString = null;
for (String line : lines) {
if (line.toLowerCase().startsWith("default"))
defaultIdentityString = line.substring("default ".length());
else {
EmailIdentity identity = parse(line);
if (identity != null)
identitiesSet.add(identity);
}
}
// set the default identity; if none defined, make the first one the default
EmailIdentity defaultIdentity = get(identitiesSet, defaultIdentityString);
if (defaultIdentity != null)
defaultIdentity.setDefaultIdentity(true);
else if (!identitiesSet.isEmpty())
identitiesSet.iterator().next().setDefaultIdentity(true);
Identities identities = new Identities(configuration.getIdentitiesFile(), passwordHolder);
for (EmailIdentity identity : identitiesSet) identities.add(identity);
identities.save();
}
Aggregations