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