Search in sources :

Example 6 with Contact

use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.

the class I2PBote method lookupInDirectory.

public Contact lookupInDirectory(String name) throws InterruptedException {
    Hash key = EmailIdentity.calculateHash(name);
    if (null == dht) {
        return null;
    }
    DhtResults results = dht.findOne(key, Contact.class);
    if (!results.isEmpty()) {
        DhtStorablePacket packet = results.getPackets().iterator().next();
        if (packet instanceof Contact) {
            Contact contact = (Contact) packet;
            try {
                if (contact.verify())
                    return contact;
            } catch (GeneralSecurityException e) {
                log.error("Can't verify Contact", e);
            }
        }
    }
    return null;
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) GeneralSecurityException(java.security.GeneralSecurityException) Hash(net.i2p.data.Hash) DhtResults(i2p.bote.network.DhtResults) Contact(i2p.bote.packet.dht.Contact)

Example 7 with Contact

use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.

the class AddressBook method remove.

public void remove(String destination) throws PasswordException {
    initializeIfNeeded();
    Contact contact = get(destination);
    if (contact != null)
        contacts.remove(contact);
}
Also used : Contact(i2p.bote.packet.dht.Contact)

Example 8 with Contact

use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.

the class AddressBook method saveToProperties.

protected Properties saveToProperties() {
    SortedProperties properties = new SortedProperties();
    int index = 0;
    for (Contact contact : contacts) {
        String prefix = "contact" + index + ".";
        properties.setProperty(prefix + "name", contact.getName());
        String base64Dest = contact.getDestination().toBase64();
        properties.setProperty(prefix + "destination", base64Dest);
        String pictureBase64 = contact.getPictureBase64();
        properties.setProperty(prefix + "picture", (pictureBase64 == null ? "" : pictureBase64));
        String text = contact.getText();
        properties.setProperty(prefix + "text", (text == null ? "" : text));
        index++;
    }
    return properties;
}
Also used : SortedProperties(i2p.bote.util.SortedProperties) Contact(i2p.bote.packet.dht.Contact)

Example 9 with Contact

use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.

the class AddressDisplayFilter method getImapNameAndDestination.

/**
 * Looks up the name associated with a Base64-encoded Email Destination
 * in the address book and the local identities, and returns a string
 * that contains the name and the Base64-encoded destination + <code>@bote</code>.<br/>
 * If <code>address</code> already contains a name, it is replaced with
 * the one from the address book or identities.<br/>
 * If no name is found in the address book or the identities, or if
 * <code>address</code> does not contain a valid Email Destination,
 * <code>[UNK] address</code> is returned.
 * @param address A Base64-encoded Email Destination, and optionally a name
 * @throws PasswordException
 * @throws GeneralSecurityException
 * @throws IOException
 */
public String getImapNameAndDestination(String address) throws PasswordException, IOException, GeneralSecurityException {
    String base64dest = EmailDestination.extractBase64Dest(address);
    if (base64dest != null) {
        // try the address book
        Contact contact = addressBook.get(base64dest);
        if (contact != null)
            // TODO: Make @bote optional
            return contact.getName() + " <" + contact.getBase64Dest() + "@bote>";
        // if no address book entry, try the email identities
        EmailIdentity identity = identities.get(base64dest);
        if (identity != null)
            // TODO: Make @bote optional
            return identity.getPublicName() + " <" + identity.toBase64() + "@bote>";
        // not known - append [UNK] if a name was provided
        if (!base64dest.equals(address)) {
            int gtIndex = address.lastIndexOf('>');
            return "{UNK} " + address.substring(0, gtIndex) + "@bote>";
        }
    }
    if (address.indexOf('@') < address.indexOf('.'))
        // External, will never be in Bote addressbook
        return address;
    // A plain B64 address or something unknown
    return address + "@bote";
}
Also used : Contact(i2p.bote.packet.dht.Contact)

Example 10 with Contact

use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.

the class AddressDisplayFilter method getName.

/**
 * Looks up the name associated with a Base64-encoded Email Destination
 * in the address book and the local identities, and returns a string
 * that contains the name.<br/>
 * If <code>address</code> already contains a name, it is replaced with
 * the one from the address book or identities.<br/>
 * If no name is found in the address book or the identities, or if
 * <code>address</code> does not contain a valid Email Destination,
 * an empty string is returned.
 * @param address A Base64-encoded Email Destination, and optionally a name
 * @throws PasswordException
 * @throws GeneralSecurityException
 * @throws IOException
 */
public String getName(String address) throws PasswordException, IOException, GeneralSecurityException {
    String base64dest = EmailDestination.extractBase64Dest(address);
    if (base64dest != null) {
        // try the address book
        Contact contact = addressBook.get(base64dest);
        if (contact != null)
            return contact.getName();
        // if no address book entry, try the email identities
        EmailIdentity identity = identities.get(base64dest);
        if (identity != null)
            return identity.getPublicName();
    }
    return "";
}
Also used : Contact(i2p.bote.packet.dht.Contact)

Aggregations

Contact (i2p.bote.packet.dht.Contact)18 GeneralSecurityException (java.security.GeneralSecurityException)7 EmailDestination (i2p.bote.email.EmailDestination)4 PasswordException (i2p.bote.fileencryption.PasswordException)4 IOException (java.io.IOException)4 File (java.io.File)3 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AddressBook (i2p.bote.addressbook.AddressBook)2 Person (i2p.bote.android.util.Person)2 SortedProperties (i2p.bote.util.SortedProperties)2 FileInputStream (java.io.FileInputStream)2 Before (org.junit.Before)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1