use of i2p.bote.addressbook.AddressBook in project i2p.i2p-bote by i2p.
the class GeneralHelper method saveContact.
/**
* Updates a contact in the address book if the Destination <code>destinationString</code> exists,
* or adds a new contact to the address book.
* @param destinationString A base64-encoded Email Destination key
* @param name
* @param pictureBase64
* @param text
* @return null if sucessful, or an error message if an error occured
* @throws PasswordException
* @throws GeneralSecurityException
*/
public static String saveContact(String destinationString, String name, String pictureBase64, String text) throws PasswordException, GeneralSecurityException {
destinationString = Util.fixAddress(destinationString);
AddressBook addressBook = getInstance().getAddressBook();
Contact contact = addressBook.get(destinationString);
if (contact != null) {
contact.setName(name);
contact.setPictureBase64(pictureBase64);
contact.setText(text);
} else {
EmailDestination destination;
try {
destination = new EmailDestination(destinationString);
} catch (GeneralSecurityException e) {
Log log = new Log(GeneralHelper.class);
log.error("Can't save contact to address book.", e);
return e.getLocalizedMessage();
}
contact = new Contact(name, destination, pictureBase64, text);
addressBook.add(contact);
}
try {
addressBook.save();
return null;
} catch (IOException e) {
return e.getLocalizedMessage();
}
}
use of i2p.bote.addressbook.AddressBook 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.addressbook.AddressBook in project i2p.i2p-bote by i2p.
the class GeneralHelper method deleteContact.
/**
* Deletes a contact from the address book.
* @param destination A base64-encoded email destination
* @return null if sucessful, or an error message if an error occured
* @throws GeneralSecurityException
* @throws PasswordException
*/
public static String deleteContact(String destination) throws PasswordException, GeneralSecurityException {
AddressBook addressBook = getInstance().getAddressBook();
addressBook.remove(destination);
try {
addressBook.save();
return null;
} catch (IOException e) {
return e.getLocalizedMessage();
}
}
Aggregations