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);
}
}
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();
}
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=="));
}
Aggregations