Search in sources :

Example 1 with IdentityComparator

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();
}
Also used : IdentityComparator(i2p.bote.email.Identities.IdentityComparator) EmailIdentity(i2p.bote.email.EmailIdentity) TreeSet(java.util.TreeSet) Identities(i2p.bote.email.Identities)

Aggregations

EmailIdentity (i2p.bote.email.EmailIdentity)1 Identities (i2p.bote.email.Identities)1 IdentityComparator (i2p.bote.email.Identities.IdentityComparator)1 TreeSet (java.util.TreeSet)1