Search in sources :

Example 6 with EmailFolder

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

the class MoveToDialogFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mFolders = I2PBote.getInstance().getEmailFolders();
    mFolderDisplayNames = new ArrayList<String>();
    String curFolder = getArguments().getString(CURRENT_FOLDER);
    Iterator<EmailFolder> i = mFolders.iterator();
    while (i.hasNext()) {
        EmailFolder folder = i.next();
        if (folder.getName().equals(curFolder) || BoteHelper.isOutbox(folder.getName()))
            i.remove();
        else
            mFolderDisplayNames.add(BoteHelper.getFolderDisplayName(getActivity(), folder));
    }
}
Also used : EmailFolder(i2p.bote.folder.EmailFolder)

Example 7 with EmailFolder

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

the class AttachmentProviderTests method tearDown.

@After
public void tearDown() throws Exception {
    super.tearDown();
    EmailFolder inbox = I2PBote.getInstance().getInbox();
    for (Email email : BoteHelper.getEmails(inbox, null, true)) {
        inbox.delete(email.getMessageID());
    }
    System.setProperty("i2pbote.initialized", "false");
}
Also used : Email(i2p.bote.email.Email) EmailFolder(i2p.bote.folder.EmailFolder) After(org.junit.After)

Example 8 with EmailFolder

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

the class MapperFactory method createMessageMapper.

@Override
public MessageMapper createMessageMapper(MailboxSession mailboxSession) throws MailboxException {
    return new AbstractMessageMapper(mailboxSession, uidProvider, modSeqProvider) {

        @Override
        public long countMessagesInMailbox(Mailbox mailbox) throws MailboxException {
            String mailboxName = mailbox.getName().toLowerCase();
            BoteMailbox boteMailbox = getMailboxes().get(mailboxName);
            return boteMailbox == null ? -1 : boteMailbox.getNumMessages();
        }

        @Override
        public long countUnseenMessagesInMailbox(Mailbox mailbox) throws MailboxException {
            int count = 0;
            BoteMailbox boteMailbox = (BoteMailbox) mailbox;
            for (BoteMessage message : boteMailbox.getAllMessages()) if (!message.isSeen())
                count++;
            return count;
        }

        @Override
        public void delete(Mailbox mailbox, MailboxMessage message) throws MailboxException {
            EmailFolder folder = ((BoteMailbox) mailbox).getFolder();
            MessageId messageId = message.getMessageId();
            boolean deleted = folderManager.deleteEmail(folder, messageId.serialize());
            if (!deleted)
                log.error("Can't delete Message " + messageId + " from folder " + folder);
        }

        @Override
        public Map<MessageUid, MessageMetaData> expungeMarkedForDeletionInMailbox(Mailbox mailbox, MessageRange set) throws MailboxException {
            final Map<MessageUid, MessageMetaData> filteredResult = new HashMap<>();
            Iterator<MailboxMessage> it = findInMailbox(mailbox, set, FetchType.Metadata, -1);
            while (it.hasNext()) {
                MailboxMessage message = it.next();
                if (message.isDeleted()) {
                    filteredResult.put(message.getUid(), new SimpleMessageMetaData(message));
                    delete(mailbox, message);
                }
            }
            return filteredResult;
        }

        @Override
        public MessageUid findFirstUnseenMessageUid(Mailbox mailbox) throws MailboxException {
            BoteMailbox boteMailbox = (BoteMailbox) mailbox;
            for (BoteMessage message : boteMailbox.getAllMessages()) if (!message.isSeen())
                return message.getUid();
            return null;
        }

        @Override
        public Iterator<MailboxMessage> findInMailbox(Mailbox mailbox, MessageRange set, FetchType type, int limit) throws MailboxException {
            BoteMailbox boteBox = (BoteMailbox) mailbox;
            return boteBox.getMessages(set, limit).iterator();
        }

        @Override
        public List<MessageUid> findRecentMessageUidsInMailbox(Mailbox mailbox) throws MailboxException {
            final List<MessageUid> results = new ArrayList<>();
            BoteMailbox boteMailbox = (BoteMailbox) mailbox;
            for (BoteMessage message : boteMailbox.getAllMessages()) if (message.isRecent())
                results.add(message.getUid());
            Collections.sort(results);
            return results;
        }

        @Override
        public void endRequest() {
        }

        @Override
        public MessageMetaData copy(Mailbox mailbox, MessageUid uid, long modSeq, MailboxMessage original) throws MailboxException {
            BoteMailbox boteBox = (BoteMailbox) mailbox;
            try {
                BoteMessage newMessage = new BoteMessage((BoteMessage) original);
                newMessage.setUid(uid);
                newMessage.setModSeq(modSeq);
                Flags flags = original.createFlags();
                // Mark message as recent as it is a copy
                flags.add(Flag.RECENT);
                newMessage.setFlags(flags);
                boteBox.add(newMessage);
                return new SimpleMessageMetaData(newMessage);
            } catch (Exception e) {
                throw new MailboxException("Can't copy message [" + original + "] to folder [" + mailbox + "]");
            }
        }

        @Override
        public MessageMetaData move(Mailbox mailbox, MailboxMessage message) throws MailboxException {
            MessageMetaData metadata = copy(mailbox, message);
            delete(mailbox, message);
            return metadata;
        }

        @Override
        public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
            Flags flags = new Flags();
            flags.add(Flag.ANSWERED);
            flags.add(Flag.DELETED);
            flags.add(Flag.RECENT);
            flags.add(Flag.SEEN);
            return flags;
        }

        /**
         * Updates the metadata
         */
        @Override
        protected MessageMetaData save(Mailbox mailbox, MailboxMessage message) throws MailboxException {
            // (I2P-Bote does this already, plus the email shouldn't show up in "sent" until it's actually been sent to the DHT)
            if (!(message instanceof BoteMessage))
                return new SimpleMessageMetaData(message);
            BoteMailbox boteBox = (BoteMailbox) mailbox;
            BoteMessage boteMessage = (BoteMessage) message;
            try {
                boteBox.saveMetadata(boteMessage);
                return new SimpleMessageMetaData(message);
            } catch (Exception e) {
                throw new MailboxException("Can't add message to folder " + boteBox.getFolder(), e);
            }
        }

        @Override
        protected void begin() throws MailboxException {
        // not implemented for now
        }

        @Override
        protected void commit() throws MailboxException {
        // not implemented for now
        }

        @Override
        protected void rollback() throws MailboxException {
        // not implemented for now
        }
    };
}
Also used : MessageMetaData(org.apache.james.mailbox.model.MessageMetaData) SimpleMessageMetaData(org.apache.james.mailbox.store.SimpleMessageMetaData) MailboxException(org.apache.james.mailbox.exception.MailboxException) MessageUid(org.apache.james.mailbox.MessageUid) HashMap(java.util.HashMap) SimpleMessageMetaData(org.apache.james.mailbox.store.SimpleMessageMetaData) ArrayList(java.util.ArrayList) Flags(javax.mail.Flags) MailboxException(org.apache.james.mailbox.exception.MailboxException) MailboxNotFoundException(org.apache.james.mailbox.exception.MailboxNotFoundException) SubscriptionException(org.apache.james.mailbox.exception.SubscriptionException) Mailbox(org.apache.james.mailbox.store.mail.model.Mailbox) MessageRange(org.apache.james.mailbox.model.MessageRange) AbstractMessageMapper(org.apache.james.mailbox.store.mail.AbstractMessageMapper) MailboxMessage(org.apache.james.mailbox.store.mail.model.MailboxMessage) EmailFolder(i2p.bote.folder.EmailFolder) MessageId(org.apache.james.mailbox.model.MessageId)

Aggregations

EmailFolder (i2p.bote.folder.EmailFolder)8 Intent (android.content.Intent)2 Email (i2p.bote.email.Email)2 IncompleteEmailFolder (i2p.bote.folder.IncompleteEmailFolder)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Bitmap (android.graphics.Bitmap)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 Toolbar (android.support.v7.widget.Toolbar)1 DisplayMetrics (android.util.DisplayMetrics)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)1 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)1 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)1 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)1 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)1 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)1 DerivedKey (i2p.bote.fileencryption.DerivedKey)1 PasswordException (i2p.bote.fileencryption.PasswordException)1