Search in sources :

Example 1 with FolderListener

use of i2p.bote.folder.FolderListener in project i2p.i2p-bote by i2p.

the class BoteMailbox method startListening.

protected void startListening() {
    folderListener = new FolderListener() {

        public void elementAdded(String messageId) {
            try {
                // Add new emails to map
                Email email = folder.getEmail(messageId);
                email.setFlag(Flag.RECENT, true);
                messageMap.put(email, new BoteMessage(email, getMailboxId()));
                updateMessages();
            } catch (PasswordException e) {
                throw new RuntimeException(_t("Password required or invalid password provided"), e);
            } catch (MessagingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public void elementUpdated() {
        // Noop, BoteMessage has a reference to the Email
        }

        public void elementRemoved(String messageId) {
            // Remove old email from map
            Set<Email> emails = messageMap.keySet();
            Iterator<Email> iter = emails.iterator();
            while (iter.hasNext()) {
                Email email = iter.next();
                if (email.getMessageID().equals(messageId)) {
                    iter.remove();
                    break;
                }
            }
            updateMessages();
        }
    };
    folder.addFolderListener(folderListener);
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) Email(i2p.bote.email.Email) Set(java.util.Set) FolderListener(i2p.bote.folder.FolderListener) MessagingException(javax.mail.MessagingException) Iterator(java.util.Iterator)

Aggregations

Email (i2p.bote.email.Email)1 PasswordException (i2p.bote.fileencryption.PasswordException)1 FolderListener (i2p.bote.folder.FolderListener)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 MessagingException (javax.mail.MessagingException)1