use of i2p.bote.email.EmailIdentity in project i2p.i2p-bote by i2p.
the class I2PBote method publishDestination.
/**
* Publishes an email destination in the address directory.
*/
public void publishDestination(String destination, byte[] picture, String text) throws PasswordException, IOException, GeneralSecurityException, DhtException, InterruptedException {
EmailIdentity identity = identities.get(destination);
if (identity != null) {
identity.setPicture(picture);
identity.setText(text);
if (identity.getFingerprint() == null)
// if no fingerprint exists, generate one and save it in the next step
identity.generateFingerprint();
identities.save();
Contact entry = new Contact(identity, identities, picture, text, identity.getFingerprint());
dht.store(entry);
}
}
use of i2p.bote.email.EmailIdentity in project i2p.i2p-bote by i2p.
the class MigrateTo028 method migrateIdentities.
/**
* @param configuration
* @throws PasswordException
* @throws GeneralSecurityException
* @throws IOException
* @throws Exception
*/
private void migrateIdentities(List<String> lines, Configuration configuration, PasswordHolder passwordHolder) throws IOException, GeneralSecurityException, PasswordException {
SortedSet<EmailIdentity> identitiesSet = new TreeSet<EmailIdentity>(new IdentityComparator());
String defaultIdentityString = null;
for (String line : lines) {
if (line.toLowerCase().startsWith("default"))
defaultIdentityString = line.substring("default ".length());
else {
EmailIdentity identity = parse(line);
if (identity != null)
identitiesSet.add(identity);
}
}
// set the default identity; if none defined, make the first one the default
EmailIdentity defaultIdentity = get(identitiesSet, defaultIdentityString);
if (defaultIdentity != null)
defaultIdentity.setDefaultIdentity(true);
else if (!identitiesSet.isEmpty())
identitiesSet.iterator().next().setDefaultIdentity(true);
Identities identities = new Identities(configuration.getIdentitiesFile(), passwordHolder);
for (EmailIdentity identity : identitiesSet) identities.add(identity);
identities.save();
}
use of i2p.bote.email.EmailIdentity in project i2p.i2p-bote by i2p.
the class StoreRequestTest method setUp.
@Before
public void setUp() throws Exception {
byte[] emailContent = 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 };
UniqueId messageId = new UniqueId(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 }, 0);
String base64Identity = "piYT1uJ3O8~bBPZmTvehMbp3-Zksg5enhvIlp2X8txqL25l0WdQMWwyt30UAOVQqxGdnMPTqqjh~-zoa~rCQORo~J1gRxLwCX9LlHQqaIimJilrbN-rhKy4Xlft054wbgQjLSC-WICE4W64KDfitwRzdr7lV6lz~0KFiZ8erZ-~WPMG1CgWEku9lILQUdUHyFBguPcK9oPDq7oGBuFGy8w0CvAq7ex3nmbL7zQVA~VqILtOGeGK2fidCuuofj4AQsTcXmH9O0nxZGCIJBhf~4EWmazvxu8XVB8pabNQvRDbmFu6q85JTwmxC45lCjqNw30hp8q2zoqP-zchjWOrxFUhSumpBdD0xXJR~qmhejh4WnuRnnam9j3fcxH5i~T7xWgmvIbpZEI4kyc9VEbXbLI7k-bU2A6sdP-AGt5~TjGLcxpdsPnOLRXO-Dsi7E9-3Kc84s4TmdpEJdtHn1dxYyeeT-ysVOqXjv5w5Cuk0XJpUIJG8n7aXHpNb-QLxPD3yAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADWF3qnAX-p41Po~VNmOUzS-Yt~noD8-e~L3P5rZXBWf-XtB4hkloo6m1jwqphEdf1";
EmailIdentity identity = new EmailIdentity(base64Identity);
EmailDestination destination = new EmailDestination(identity.getKey());
int fragmentIndex = 0;
UnencryptedEmailPacket emailPacket = new UnencryptedEmailPacket(new ByteArrayInputStream(emailContent), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
emailPacket.setNumFragments(1);
dhtPacket = new EncryptedEmailPacket(emailPacket, destination);
storeRequest = new StoreRequest(dhtPacket);
}
use of i2p.bote.email.EmailIdentity in project i2p.i2p-bote by i2p.
the class OutboxProcessorTest method testSendEmail.
@Test
public void testSendEmail() throws Exception {
EmailIdentity identity = TestUtil.createTestIdentities().get(0).identity;
String address = "tester <" + identity.getKey() + ">";
when(identities.extractIdentity(address)).thenReturn(identity);
testEmail = new Email(true);
testEmail.setFrom(new InternetAddress(address));
testEmail.addRecipient(RecipientType.TO, new InternetAddress("Erika Mustermann <m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY>"));
testEmail.setSubject("Test", "UTF-8");
testEmail.setText("foobar");
op.sendEmail(testEmail);
ArgumentCaptor<DhtStorablePacket> arg = ArgumentCaptor.forClass(DhtStorablePacket.class);
verify(dht, times(2)).store(arg.capture());
List<DhtStorablePacket> values = arg.getAllValues();
assertTrue(values.get(0) instanceof EncryptedEmailPacket);
assertTrue(values.get(1) instanceof IndexPacket);
assertTrue(((IndexPacket) values.get(1)).contains(((EncryptedEmailPacket) values.get(0)).getDhtKey()));
}
use of i2p.bote.email.EmailIdentity in project i2p.i2p-bote by i2p.
the class EmailChecker method checkForMail.
public synchronized void checkForMail() throws PasswordException, IOException, GeneralSecurityException {
if (!isCheckingForMail()) {
if (identities.size() <= 0)
log.info("Not checking for mail because no identities are defined.");
else
log.info("Checking mail for " + identities.size() + " Email Identities...");
previousMailCheckTime = lastMailCheckTime;
lastMailCheckTime = System.currentTimeMillis();
for (EmailIdentity identity : identities.getAll()) {
if (identity.getIncludeInGlobalCheck()) {
checkForMail(identity);
}
}
} else
log.info("Not checking for mail because the last mail check hasn't finished.");
}
Aggregations