Author: norman Date: Fri Oct 7 20:17:01 2011 New Revision: 1180198 URL: http://svn.apache.org/viewvc?rev=1180198&view=rev Log: Start on work to make sure event can not get missed on select. See IMAP-342
Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java?rev=1180198&r1=1180197&r2=1180198&view=diff ============================================================================== --- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java (original) +++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java Fri Oct 7 20:17:01 2011 @@ -61,8 +61,6 @@ import org.apache.james.mailbox.MessageR abstract class AbstractSelectionProcessor<M extends AbstractMailboxSelectionRequest> extends AbstractMailboxProcessor<M> implements PermitEnableCapabilityProcessor { - private final Flags flags = new Flags(); - final StatusResponseFactory statusResponseFactory; private final boolean openReadOnly; @@ -73,11 +71,7 @@ abstract class AbstractSelectionProcesso super(acceptableClass, next, mailboxManager, statusResponseFactory); this.statusResponseFactory = statusResponseFactory; this.openReadOnly = openReadOnly; - flags.add(Flags.Flag.ANSWERED); - flags.add(Flags.Flag.DELETED); - flags.add(Flags.Flag.DRAFT); - flags.add(Flags.Flag.FLAGGED); - flags.add(Flags.Flag.SEEN); + } /* @@ -403,7 +397,9 @@ abstract class AbstractSelectionProcesso if (currentMailbox != null) { getStatusResponseFactory().untaggedOk(HumanReadableText.QRESYNC_CLOSED, ResponseCode.closed()); } - sessionMailbox = createNewSelectedMailbox(mailbox, mailboxSession, session, mailboxPath); + session.selected(new SelectedMailboxImpl(getMailboxManager(), session, mailboxPath)); + + sessionMailbox = session.getSelected(); } else { // TODO: Check if we need to handle CONDSTORE there too @@ -414,25 +410,6 @@ abstract class AbstractSelectionProcesso return metaData; } - private SelectedMailbox createNewSelectedMailbox(final MessageManager mailbox, final MailboxSession mailboxSession, ImapSession session, MailboxPath path) throws MailboxException { - - MessageResultIterator messages = mailbox.getMessages(MessageRange.all(), FetchGroupImpl.MINIMAL, mailboxSession); - Flags applicableFlags = new Flags(flags); - List<Long> uids = new ArrayList<Long>(); - while(messages.hasNext()) { - MessageResult mr = messages.next(); - applicableFlags.add(mr.getFlags()); - uids.add(mr.getUid()); - } - - - // \RECENT is not a applicable flag in imap so remove it from the list - applicableFlags.remove(Flags.Flag.RECENT); - - final SelectedMailbox sessionMailbox = new SelectedMailboxImpl(getMailboxManager(), uids.iterator(),applicableFlags, session, path); - session.selected(sessionMailbox); - return sessionMailbox; - } private void addRecent(final MessageManager.MetaData metaData, SelectedMailbox sessionMailbox) throws MailboxException { final List<Long> recentUids = metaData.getRecent(); Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java?rev=1180198&r1=1180197&r2=1180198&view=diff ============================================================================== --- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java (original) +++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java Fri Oct 7 20:17:01 2011 @@ -22,6 +22,7 @@ package org.apache.james.imap.processor. import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -34,6 +35,9 @@ import org.apache.james.mailbox.MailboxE import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxPath; import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.MessageRange; +import org.apache.james.mailbox.MessageResult; +import org.apache.james.mailbox.MessageResultIterator; /** * Default implementation of {@link SelectedMailbox} @@ -54,15 +58,41 @@ public class SelectedMailboxImpl impleme private ImapSession session; - public SelectedMailboxImpl(final MailboxManager mailboxManager, final Iterator<Long> uids, final Flags applicableFlags, final ImapSession session, final MailboxPath path) throws MailboxException { + + private final static Flags FLAGS = new Flags(); + static { + FLAGS.add(Flags.Flag.ANSWERED); + FLAGS.add(Flags.Flag.DELETED); + FLAGS.add(Flags.Flag.DRAFT); + FLAGS.add(Flags.Flag.FLAGGED); + FLAGS.add(Flags.Flag.SEEN); + } + + + public SelectedMailboxImpl(final MailboxManager mailboxManager, final ImapSession session, final MailboxPath path) throws MailboxException { recentUids = new TreeSet<Long>(); recentUidRemoved = false; + MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); + MessageResultIterator messages = mailboxManager.getMailbox(path, mailboxSession).getMessages(MessageRange.all(), FetchGroupImpl.MINIMAL, mailboxSession); + Flags applicableFlags = new Flags(FLAGS); + List<Long> uids = new ArrayList<Long>(); + while(messages.hasNext()) { + MessageResult mr = messages.next(); + applicableFlags.add(mr.getFlags()); + uids.add(mr.getUid()); + } + + + // \RECENT is not a applicable flag in imap so remove it from the list + applicableFlags.remove(Flags.Flag.RECENT); + + events = new MailboxEventAnalyser(session, path, applicableFlags); // Ignore events from our session events.setSilentFlagChanges(true); mailboxManager.addListener(path, events, mailboxSession); - converter = new UidToMsnConverter(session, uids); + converter = new UidToMsnConverter(session, uids.iterator()); mailboxManager.addListener(path, converter, mailboxSession); this.mailboxManager = mailboxManager; this.path = path; --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org