use of i2p.bote.email.EmailMetadata in project i2p.i2p-bote by i2p.
the class DeliveryChecker method checkDelivery.
/**
* Checks the DHT for all undelivered packets belonging to a given email.
* @param email
* @throws InterruptedException
*/
private void checkDelivery(Email email) throws InterruptedException {
EmailMetadata metadata = email.getMetadata();
Collection<PacketInfo> packets = metadata.getUndeliveredPacketKeys();
synchronized (sentFolder) {
boolean updateMetadata = false;
for (PacketInfo packet : packets) {
UniqueId delAuth = dht.findDeleteAuthorizationKey(packet.dhtKey, packet.delVerificationHash);
if (delAuth != null) {
metadata.setPacketDelivered(packet.dhtKey, true);
updateMetadata = true;
log.debug("Delivery of email packet with DHT key " + packet.dhtKey + " confirmed.");
}
}
if (updateMetadata)
try {
sentFolder.saveMetadata(email);
} catch (Exception e) {
log.error("Can't save email metadata.", e);
}
}
}
use of i2p.bote.email.EmailMetadata in project i2p.i2p-bote by i2p.
the class OutboxProcessor method sendToOne.
/**
* Sends an {@link Email} to one recipient.
* @param senderIdentity The sender's Email Identity, or <code>null</code> for anonymous emails
* @param recipient
* @param email
* @throws MessagingException
* @throws DhtException
* @throws GeneralSecurityException
* @throws PasswordException
* @throws InterruptedException
*/
private void sendToOne(EmailIdentity senderIdentity, String recipient, Email email) throws MessagingException, DhtException, GeneralSecurityException, PasswordException, InterruptedException {
// only used for logging
String logSuffix = null;
try {
logSuffix = "Recipient = '" + recipient + "' Message ID = '" + email.getMessageID() + "'";
log.info("Sending email: " + logSuffix);
EmailDestination recipientDest = new EmailDestination(recipient);
EmailIdentity.IdentityConfig identityConfig;
if (email.isAnonymous())
identityConfig = configuration;
else
identityConfig = senderIdentity.getWrappedConfig(configuration);
int hops = identityConfig.getNumStoreHops();
long minDelay = identityConfig.getRelayMinDelay() * 60 * 1000;
long maxDelay = identityConfig.getRelayMaxDelay() * 60 * 1000;
int relayRedundancy = identityConfig.getRelayRedundancy();
int maxPacketSize = getMaxEmailPacketSize(hops);
Collection<UnencryptedEmailPacket> emailPackets = email.createEmailPackets(senderIdentity, identities, recipient, maxPacketSize);
IndexPacket indexPacket = new IndexPacket(recipientDest);
EmailMetadata metadata = email.getMetadata();
for (UnencryptedEmailPacket unencryptedPacket : emailPackets) {
EncryptedEmailPacket emailPacket = new EncryptedEmailPacket(unencryptedPacket, recipientDest);
send(emailPacket, hops, minDelay, maxDelay, relayRedundancy);
indexPacket.put(emailPacket);
metadata.addPacketInfo(recipientDest, emailPacket.getDhtKey(), emailPacket.getDeleteVerificationHash());
}
send(indexPacket, hops, minDelay, maxDelay, relayRedundancy);
outbox.saveMetadata(email);
} catch (GeneralSecurityException e) {
log.error("Invalid recipient address. " + logSuffix, e);
outbox.setStatus(email, new EmailStatus(Status.INVALID_RECIPIENT, recipient));
throw e;
} catch (MessagingException e) {
log.error("Can't create email packets. " + logSuffix, e);
outbox.setStatus(email, new EmailStatus(Status.ERROR_CREATING_PACKETS, e.getLocalizedMessage()));
throw e;
} catch (DhtException e) {
log.error("Can't store email packet on the DHT. " + logSuffix, e);
outbox.setStatus(email, new EmailStatus(Status.ERROR_SENDING, e.getLocalizedMessage()));
throw e;
} catch (IOException e) {
log.error("Can't save metadata. " + logSuffix, e);
outbox.setStatus(email, new EmailStatus(Status.ERROR_SAVING_METADATA, e.getLocalizedMessage()));
}
}
use of i2p.bote.email.EmailMetadata in project i2p.i2p-bote by i2p.
the class EmailFolder method setNew.
public void setNew(Email email, boolean isNew) throws PasswordException, GeneralSecurityException {
EmailMetadata metadata = email.getMetadata();
metadata.setUnread(isNew);
try {
saveMetadata(email);
} catch (IOException e) {
log.error("Can't read metadata file for message ID <" + email.getMessageID() + ">", e);
}
}
use of i2p.bote.email.EmailMetadata in project i2p.i2p-bote by i2p.
the class EmailFolder method saveMetadata.
public void saveMetadata(Email email) throws PasswordException, FileNotFoundException, IOException, GeneralSecurityException {
EmailMetadata metadata = email.getMetadata();
File metaFile = getMetadataFile(email.getMessageID());
saveMetadata(metadata, metaFile);
}
use of i2p.bote.email.EmailMetadata in project i2p.i2p-bote by i2p.
the class EmailFolder method setReplied.
public void setReplied(String messageId, boolean replied) throws PasswordException, GeneralSecurityException {
EmailMetadata metadata = getMetadata(messageId);
metadata.setReplied(replied);
try {
saveMetadata(metadata, getMetadataFile(messageId));
} catch (IOException e) {
log.error("Can't read metadata file for message ID <" + messageId + ">", e);
}
}
Aggregations