Search in sources :

Example 16 with Contact

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

the class ContactsCompletionView method defaultObject.

@Override
protected Object defaultObject(String completionText) {
    // Stupid simple example of guessing if we have an email or not
    int index = completionText.indexOf('@');
    if (index == -1) {
        try {
            // Check if it is a known Destination
            Contact c = BoteHelper.getContact(completionText);
            if (c != null)
                return new Person(c.getName(), c.getBase64Dest(), BoteHelper.decodePicture(c.getPictureBase64()));
            // Check if it is a name
            SortedSet<Contact> contacts = I2PBote.getInstance().getAddressBook().getAll();
            for (Contact contact : contacts) {
                if (contact.getName().startsWith(completionText))
                    return new Person(contact.getName(), contact.getBase64Dest(), BoteHelper.decodePicture(contact.getPictureBase64()));
            }
            // Try as a new Destination
            try {
                new EmailDestination(completionText);
                return new Person(completionText.substring(0, 5), completionText, null);
            } catch (GeneralSecurityException e) {
                // Not a valid Destination
                // Assume the user meant an external address
                completionText = completionText.replace(" ", "") + "@example.com";
                return new Person(completionText, completionText, null, true);
            }
        } catch (PasswordException e) {
            // TODO handle
            completionText = completionText.replace(" ", "") + "@example.com";
            return new Person(completionText, completionText, null, true);
        }
    } else {
        return new Person(completionText, completionText, null, true);
    }
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) EmailDestination(i2p.bote.email.EmailDestination) GeneralSecurityException(java.security.GeneralSecurityException) Person(i2p.bote.android.util.Person) Contact(i2p.bote.packet.dht.Contact)

Example 17 with Contact

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

the class MigrateTo028 method migrateAddressBook.

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();
}
Also used : AddressBook(i2p.bote.addressbook.AddressBook) EmailDestination(i2p.bote.email.EmailDestination) GeneralSecurityException(java.security.GeneralSecurityException) Contact(i2p.bote.packet.dht.Contact)

Example 18 with Contact

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

the class DirectoryEntryFolderTest method setUp.

@Before
public void setUp() throws Exception {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    testDir = new File(tempDir, "DirectoryEntryFolderTest-" + System.currentTimeMillis());
    folderDir = new File(testDir, "folder");
    folder = new DirectoryEntryFolder(folderDir);
    // contact1 and contact2 contain the same name; name in contact3 is different
    contact1 = new Contact(Base64.decode("QwSlRwEi0IY-mEz6owJfWVG-dZe2qHIcKFKyD8FvdEvdRwBCAxvGHjFocWgadAsrUqFspuWyRrpoa5Hh~SsFBxFjeTZ6Atx~IqWbtxt3pV5fzHLkvgFHx0jpTgIStssa98sD5NIU3unfuQAAAAAAAEgwRgIhAP2-AGnl0Jlpss4rXsAseDCelq~lwbMOtWKimogddYOvAiEAwdMyV12F0N9hQVnns0Zx3MMgoUlDozvGB1CZmx9ZGkA="));
    contact2 = new Contact(Base64.decode("QwSlRwEi0IY-mEz6owJfWVG-dZe2qHIcKFKyD8FvdEvdRwBCAt6JpsgAD~TrlH~bafT0CvUPk5jfQDcISB2IG6hCE1ASA1kh3urYt29bPVvhaRh2gDFk2eyz-MZRoMpZLz7hwpyrl783YwAAAAAAAEYwRAIgRlI6aoQ1tdUp5xAFHdh3Wm9bT6HvyWh8WkMgNwIWMQcCIBBCHzXcOD-xe3-CqRO2cWLvXCDFed5zmE7oEctVpbcQ"));
    contact3 = new Contact(Base64.decode("QwRwRpWqx-xkTC4mYzMJkJtryurqpo0vee2Qnq8uVXD92wBCA5J75fef~d-1BaJZyrP6Y9uYn3~tki2Vie5Fq7jTT7dbAyYGb-PF~7pxIxJwh0lAYALrIgtIt4uaG67xm739FYkBa1b2gwAAAAAAAEcwRQIgGgf3vd28-1YyUN41VLfszN0Nu9xC--LA2is5EJNq8a8CIQDyCK4GSDh1V2hmORmEzmF8xyazB1P~QbtVJHiognSSNA=="));
}
Also used : File(java.io.File) Contact(i2p.bote.packet.dht.Contact) Before(org.junit.Before)

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