use of i2p.bote.email.EmailDestination in project i2p.i2p-bote by i2p.
the class ResponsePacketTest method createDataPacket.
private DataPacket createDataPacket() throws GeneralSecurityException, IOException {
byte[] dataToStore = new byte[] { 2, 109, -80, -37, -106, 83, -33, -39, -94, -76, -112, -98, 99, 25, -61, 44, -92, -85, 1, 10, -128, -2, -27, -86, -126, -33, -11, 42, 56, 3, -97, -101, 111, 7, -96, 25, 121, 74, 89, -40, -33, 82, -50, -18, 49, 106, 13, -121, 53, -83, -2, 35, -7, 71, -71, 26, 90, 1 };
byte[] messageIdBytes = new byte[] { -69, -24, -109, 1, 69, -122, -69, 113, -68, -90, 55, -28, 105, 97, 125, 70, 51, 58, 14, 2, -13, -53, 90, -29, 36, 67, 36, -94, -108, -125, 11, 123 };
UniqueId messageId = new UniqueId(messageIdBytes, 0);
int fragmentIndex = 0;
UnencryptedEmailPacket unencryptedPacket = new UnencryptedEmailPacket(new ByteArrayInputStream(dataToStore), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
unencryptedPacket.setNumFragments(1);
EmailDestination destination = new EmailDestination("0XuJjhgp58aOhvHHgpaxoQYsCUfDS6BECMEoVxFGEFPdk3y8lbzIsq9eUyeizFleMacYwoscCir8nQLlW34lxfRmirkNpD9vU1XnmjnZ5hGdnor1qIDqz3KJ040dVQ617MwyG97xxYLT0FsH907vBXgdc4RCHwKd1~9siagA5CSMaA~wM8ymKXLypiZGYexENLmim7nMzJTQYoOM~fVS99UaGJleDBN3pgZ2EvRYDQV2VqKH7Gee07R3y7b~c0tAKVHS0IbPQfTVJigrIHjTl~ZczxpaeTM04T8IgxKnO~lSmR1w7Ik8TpEkETwT9PDwUqQsjmlSY8E~WwwGMRJVyIRZUkHeRZ0aFq7us8W9EKzYtjjiU1z0QFpZrTfJE8oqCbnH5Lqv5Q86UdTPpriJC1N99E77TpCTnNzcBnpp6ko2JCy2IJUveaigKxS6EmS9KarkkkBRsckOKZZ6UNTOqPZsBCsx0Q9WvDF-Uc3dtouXWyenxRptaQsdkZyYlEQv");
return new EncryptedEmailPacket(unencryptedPacket, destination);
}
use of i2p.bote.email.EmailDestination in project i2p.i2p-bote by i2p.
the class GeneralHelper method getOneLocalRecipient.
/**
* Returns the recipient address for an email that has been received by
* the local node.<br/>
* If the email was sent to more than one local Email Destination, one
* of them is returned.<br/>
* If the email does not contain a local Email Destination, a non-local
* recipient is returned.<br/>
* If the email contains no recipients at all, or if an error occurred,
* <code>null</code> is returned.
* @param email
* @throws PasswordException
* @throws GeneralSecurityException
* @throws IOException
*/
public static Address getOneLocalRecipient(Email email) throws PasswordException, IOException, GeneralSecurityException {
Address[] recipients;
try {
recipients = email.getAllRecipients();
} catch (MessagingException e) {
return null;
}
if (recipients == null)
return null;
Identities identities = I2PBote.getInstance().getIdentities();
Iterator<EmailIdentity> iterator = identities.iterator();
if (iterator == null)
return null;
while (iterator.hasNext()) {
EmailDestination localDestination = iterator.next();
String base64Dest = localDestination.toBase64();
for (Address recipient : recipients) if (recipient.toString().contains(base64Dest))
return recipient;
}
if (recipients.length > 0)
return recipients[0];
else
return null;
}
use of i2p.bote.email.EmailDestination in project i2p.i2p-bote by i2p.
the class AddressBook method loadFromProperties.
protected boolean loadFromProperties(Properties properties, boolean append, boolean replace) {
if (contacts == null || !append) {
contacts = new TreeSet<Contact>(new ContactComparator());
}
int index = 0;
while (true) {
String prefix = "contact" + index + ".";
String name = properties.getProperty(prefix + "name");
if (name == null)
break;
String destBase64 = properties.getProperty(prefix + "destination");
if (destBase64 == null)
continue;
try {
EmailDestination destination = new EmailDestination(destBase64);
String pictureBase64 = properties.getProperty(prefix + "picture");
String text = properties.getProperty(prefix + "text");
Contact contact = new Contact(name, destination, pictureBase64, text);
if (append && replace && contacts.contains(contact)) {
contacts.remove(contact);
}
contacts.add(contact);
} catch (GeneralSecurityException e) {
log.error("Not a valid Email Destination: <" + destBase64 + ">", e);
}
index++;
}
return index > 0;
}
use of i2p.bote.email.EmailDestination 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);
}
}
Aggregations