Search in sources :

Example 1 with EmailMetadata

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);
            }
    }
}
Also used : UniqueId(i2p.bote.UniqueId) PacketInfo(i2p.bote.email.EmailMetadata.PacketInfo) EmailMetadata(i2p.bote.email.EmailMetadata) PasswordException(i2p.bote.fileencryption.PasswordException)

Example 2 with EmailMetadata

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()));
    }
}
Also used : MessagingException(javax.mail.MessagingException) EmailIdentity(i2p.bote.email.EmailIdentity) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) GeneralSecurityException(java.security.GeneralSecurityException) EmailStatus(i2p.bote.folder.Outbox.EmailStatus) EmailMetadata(i2p.bote.email.EmailMetadata) IOException(java.io.IOException) IndexPacket(i2p.bote.packet.dht.IndexPacket) EmailDestination(i2p.bote.email.EmailDestination) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) DhtException(i2p.bote.network.DhtException)

Example 3 with EmailMetadata

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);
    }
}
Also used : EmailMetadata(i2p.bote.email.EmailMetadata) IOException(java.io.IOException)

Example 4 with EmailMetadata

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);
}
Also used : EmailMetadata(i2p.bote.email.EmailMetadata) File(java.io.File)

Example 5 with EmailMetadata

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);
    }
}
Also used : EmailMetadata(i2p.bote.email.EmailMetadata) IOException(java.io.IOException)

Aggregations

EmailMetadata (i2p.bote.email.EmailMetadata)8 IOException (java.io.IOException)5 UniqueId (i2p.bote.UniqueId)1 EmailDestination (i2p.bote.email.EmailDestination)1 EmailIdentity (i2p.bote.email.EmailIdentity)1 PacketInfo (i2p.bote.email.EmailMetadata.PacketInfo)1 EncryptedInputStream (i2p.bote.fileencryption.EncryptedInputStream)1 PasswordException (i2p.bote.fileencryption.PasswordException)1 EmailStatus (i2p.bote.folder.Outbox.EmailStatus)1 DhtException (i2p.bote.network.DhtException)1 EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)1 IndexPacket (i2p.bote.packet.dht.IndexPacket)1 UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 GeneralSecurityException (java.security.GeneralSecurityException)1 MessagingException (javax.mail.MessagingException)1