Search in sources :

Example 21 with Email

use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.

the class OutboxProcessor method run.

@Override
public void run() {
    while (!Thread.interrupted()) {
        try {
            synchronized (this) {
                wakeupSignal = new CountDownLatch(1);
            }
            if (networkStatusSource.isConnected()) {
                log.debug("Processing outgoing emails in directory '" + outbox.getStorageDirectory() + "'.");
                FolderIterator<Email> iterator = outbox.iterate();
                try {
                    while (iterator.hasNext()) {
                        Email email = iterator.next();
                        log.info("Processing email with message Id: '" + email.getMessageID() + "'.");
                        // signature flag only makes sense locally
                        email.removeSignatureFlag();
                        try {
                            sendEmail(email);
                            fireOutboxListeners(email);
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                            throw e;
                        } catch (Exception e) {
                            log.error("Error sending email.", e);
                        }
                    }
                } catch (PasswordException e) {
                    log.debug("Can't scan outbox because a password is set and the application is locked.");
                }
            }
            int pause = configuration.getOutboxCheckInterval();
            wakeupSignal.await(pause, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
            break;
        } catch (RuntimeException e) {
            // catch unexpected exceptions to keep the thread running
            log.error("Exception caught in OutboxProcessor loop", e);
        }
    }
    log.debug("OutboxProcessor thread exiting.");
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) Email(i2p.bote.email.Email) CountDownLatch(java.util.concurrent.CountDownLatch) PasswordException(i2p.bote.fileencryption.PasswordException) MessagingException(javax.mail.MessagingException) GeneralSecurityException(java.security.GeneralSecurityException) AddressException(javax.mail.internet.AddressException) IOException(java.io.IOException) DhtException(i2p.bote.network.DhtException)

Example 22 with Email

use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.

the class AttachmentProvider method getAttachment.

private Part getAttachment(Uri uri) throws PasswordException, IOException, MessagingException {
    List<String> segments = uri.getPathSegments();
    String folderName = segments.get(0);
    String messageId = segments.get(1);
    int partNum = Integer.valueOf(segments.get(2));
    Email email = BoteHelper.getEmail(folderName, messageId);
    if (email != null) {
        if (partNum >= 0 && partNum < email.getParts().size())
            return email.getParts().get(partNum);
    }
    return null;
}
Also used : Email(i2p.bote.email.Email)

Example 23 with Email

use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.

the class I2PBote method initializeServices.

/**
 * Initializes daemon threads, doesn't start them yet.
 */
private void initializeServices() {
    I2PPacketDispatcher dispatcher = new I2PPacketDispatcher();
    i2pSession.addMuxedSessionListener(dispatcher, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY);
    backgroundThreads.add(passwordCache);
    I2PSendQueue sendQueue = new I2PSendQueue(i2pSession, dispatcher);
    backgroundThreads.add(sendQueue);
    // reads packets stored in the relayPacketFolder and sends them
    RelayPacketSender relayPacketSender = new RelayPacketSender(sendQueue, relayPacketFolder, configuration);
    backgroundThreads.add(relayPacketSender);
    I2PAppThread seedless = null;
    try {
        Class<? extends I2PAppThread> clazz = Class.forName("i2p.bote.service.seedless.SeedlessInitializer").asSubclass(I2PAppThread.class);
        Constructor<? extends I2PAppThread> ctor = clazz.getDeclaredConstructor(I2PSocketManager.class);
        seedless = ctor.newInstance(socketManager);
        backgroundThreads.add(seedless);
    } catch (ClassNotFoundException e) {
    } catch (NoSuchMethodException e) {
    } catch (InstantiationException e) {
    } catch (IllegalAccessException e) {
    } catch (InvocationTargetException e) {
    }
    dht = new KademliaDHT(sendQueue, dispatcher, configuration.getDhtPeerFile(), (DhtPeerSource) seedless);
    backgroundThreads.add(dht);
    dht.setStorageHandler(EncryptedEmailPacket.class, emailDhtStorageFolder);
    dht.setStorageHandler(IndexPacket.class, indexPacketDhtStorageFolder);
    dht.setStorageHandler(Contact.class, directoryDhtFolder);
    peerManager = new RelayPeerManager(sendQueue, getLocalDestination(), configuration.getRelayPeerFile());
    backgroundThreads.add(peerManager);
    dispatcher.addPacketListener(emailDhtStorageFolder);
    dispatcher.addPacketListener(indexPacketDhtStorageFolder);
    dispatcher.addPacketListener(new RelayPacketHandler(relayPacketFolder, dht, sendQueue, i2pSession));
    dispatcher.addPacketListener(peerManager);
    dispatcher.addPacketListener(relayPacketSender);
    ExpirationThread expirationThread = new ExpirationThread();
    expirationThread.addExpirationListener(emailDhtStorageFolder);
    expirationThread.addExpirationListener(indexPacketDhtStorageFolder);
    expirationThread.addExpirationListener(relayPacketSender);
    backgroundThreads.add(expirationThread);
    outboxProcessor = new OutboxProcessor(dht, outbox, peerManager, relayPacketFolder, identities, configuration, this);
    outboxProcessor.addOutboxListener(new OutboxListener() {

        /**
         * Moves sent emails to the "sent" folder
         */
        @Override
        public void emailSent(Email email) {
            try {
                outbox.setNew(email, false);
                log.debug("Moving email [" + email + "] to the \"sent\" folder.");
                outbox.move(email, sentFolder);
            } catch (Exception e) {
                log.error("Cannot move email from outbox to sent folder: " + email, e);
            }
        }
    });
    backgroundThreads.add(outboxProcessor);
    emailChecker = new EmailChecker(identities, configuration, incompleteEmailFolder, emailDhtStorageFolder, indexPacketDhtStorageFolder, this, sendQueue, dht, peerManager);
    backgroundThreads.add(emailChecker);
    deliveryChecker = new DeliveryChecker(dht, sentFolder, configuration, this);
    backgroundThreads.add(deliveryChecker);
}
Also used : RelayPacketHandler(i2p.bote.network.RelayPacketHandler) Email(i2p.bote.email.Email) EmailChecker(i2p.bote.service.EmailChecker) I2PSendQueue(i2p.bote.network.I2PSendQueue) RelayPeerManager(i2p.bote.service.RelayPeerManager) I2PAppThread(net.i2p.util.I2PAppThread) InvocationTargetException(java.lang.reflect.InvocationTargetException) OutboxProcessor(i2p.bote.service.OutboxProcessor) PasswordException(i2p.bote.fileencryption.PasswordException) GeneralSecurityException(java.security.GeneralSecurityException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoIdentityForSenderException(i2p.bote.email.NoIdentityForSenderException) IOException(java.io.IOException) I2PSessionException(net.i2p.client.I2PSessionException) I2PException(net.i2p.I2PException) ExecutionException(java.util.concurrent.ExecutionException) PasswordMismatchException(i2p.bote.fileencryption.PasswordMismatchException) URISyntaxException(java.net.URISyntaxException) MessagingException(javax.mail.MessagingException) DhtException(i2p.bote.network.DhtException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PasswordIncorrectException(i2p.bote.fileencryption.PasswordIncorrectException) DataFormatException(net.i2p.data.DataFormatException) DeliveryChecker(i2p.bote.service.DeliveryChecker) KademliaDHT(i2p.bote.network.kademlia.KademliaDHT) OutboxListener(i2p.bote.service.OutboxListener) DhtPeerSource(i2p.bote.network.DhtPeerSource) RelayPacketSender(i2p.bote.service.RelayPacketSender) I2PPacketDispatcher(i2p.bote.network.I2PPacketDispatcher) ExpirationThread(i2p.bote.service.ExpirationThread)

Example 24 with Email

use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.

the class ShowAttachment method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String folderName = request.getParameter("folder");
    String messageID = request.getParameter("messageID");
    Email email;
    try {
        email = JSPHelper.getEmail(folderName, messageID);
    } catch (PasswordException e) {
        throw new ServletException(e);
    }
    if (email == null)
        throw new ServletException("Message ID <" + messageID + "> not found in folder <" + folderName + ">.");
    List<Part> parts = null;
    try {
        parts = email.getParts();
    } catch (MessagingException e) {
        throw new ServletException("Can't parse mail. Message ID=" + messageID, e);
    }
    String partIndexStr = request.getParameter("part");
    int partIndex = -1;
    try {
        partIndex = Integer.valueOf(partIndexStr);
    } catch (NumberFormatException e) {
    }
    if (partIndex < 0 || partIndex >= parts.size())
        throw new ServletException("Invalid part index: <" + partIndexStr + ">, must be a number between 0 and " + (parts.size() - 1));
    Part part = parts.get(partIndex);
    try {
        response.setContentType(part.getContentType());
        String[] dispositionHeaders = part.getHeader("Content-Disposition");
        if (dispositionHeaders == null || dispositionHeaders.length == 0)
            response.setHeader("Content-Disposition", "attachment; filename=attachment");
        else
            response.setHeader("Content-Disposition", dispositionHeaders[0]);
    } catch (MessagingException e) {
        log.error("Can't get MIME type of part " + partIndex + ". Message ID=" + messageID, e);
    }
    // write the attachments' content to the servlet response stream
    try {
        InputStream input = part.getInputStream();
        OutputStream output = response.getOutputStream();
        byte[] buffer = new byte[1024];
        while (true) {
            int bytesRead = input.read(buffer);
            if (bytesRead <= 0)
                return;
            output.write(buffer, 0, bytesRead);
        }
    } catch (MessagingException e) {
        throw new ServletException("Can't get MIME type of part " + partIndex + ". Message ID=" + messageID, e);
    }
}
Also used : Email(i2p.bote.email.Email) MessagingException(javax.mail.MessagingException) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ServletException(javax.servlet.ServletException) PasswordException(i2p.bote.fileencryption.PasswordException) Part(javax.mail.Part)

Aggregations

Email (i2p.bote.email.Email)24 PasswordException (i2p.bote.fileencryption.PasswordException)10 MessagingException (javax.mail.MessagingException)8 IOException (java.io.IOException)7 GeneralSecurityException (java.security.GeneralSecurityException)6 InternetAddress (javax.mail.internet.InternetAddress)6 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Address (javax.mail.Address)4 Bitmap (android.graphics.Bitmap)3 Attachment (i2p.bote.email.Attachment)3 EmailIdentity (i2p.bote.email.EmailIdentity)3 Test (org.junit.Test)3 SuppressLint (android.annotation.SuppressLint)2 ContentAttachment (i2p.bote.android.util.ContentAttachment)2 Person (i2p.bote.android.util.Person)2 ContactsCompletionView (i2p.bote.android.widget.ContactsCompletionView)2 NoIdentityForSenderException (i2p.bote.email.NoIdentityForSenderException)2 EmailFolder (i2p.bote.folder.EmailFolder)2