Package org.apache.james.mailbox.model

Examples of org.apache.james.mailbox.model.MessageResult


        mailboxManager.addListener(path, this, mailboxSession);

        MessageResultIterator messages = mailboxManager.getMailbox(path, mailboxSession).getMessages(MessageRange.all(), FetchGroupImpl.MINIMAL, mailboxSession);
        synchronized (this) {
            while(messages.hasNext()) {
                MessageResult mr = messages.next();
                applicableFlags.add(mr.getFlags());
                add(mr.getUid());
            }
           
         
            // \RECENT is not a applicable flag in imap so remove it from the list
            applicableFlags.remove(Flags.Flag.RECENT);
View Full Code Here


                       
                        List<Long> uids = new ArrayList<Long>();

                        MessageResultIterator results = mailbox.getMessages(messageSet, FetchGroupImpl.MINIMAL, mailboxSession);
                        while(results.hasNext()) {
                            MessageResult r = results.next();
                            long uid = r.getUid();
                           
                            boolean fail = false;
                           
                            // Check if UNCHANGEDSINCE 0 was used and the Message contains the request flag.
                            // In such cases we need to fail for this message.
                            //
                            // From RFC4551:
                            //       Use of UNCHANGEDSINCE with a modification sequence of 0 always
                            //       fails if the metadata item exists.  A system flag MUST always be
                            //       considered existent, whether it was set or not.
                            if (unchangedSince == 0) {
                                String[] uFlags = r.getFlags().getUserFlags();
                                for (int a = 0; a < uFlags.length; a++) {
                                    if (userFlags.contains(uFlags[a])) {
                                        fail = true;
                                        break;
                                    }
                                }
                            }
                           
                            // Check if the mod-sequence of the message is <= the unchangedsince.
                            //
                            // See RFC4551 3.2. STORE and UID STORE Commands
                            if (!fail && r.getModSeq() <= unchangedSince) {
                                uids.add(uid);
                            } else {
                                if (useUids) {
                                    failed.add(uid);
                                } else {
                                    failed.add((long) selected.msn(uid));
                                }
                            }
                        }
                        List<MessageRange> mRanges = MessageRange.toRanges(uids);
                        for (int a = 0 ; a < mRanges.size(); a++) {
                            setFlags(request, mailboxSession, mailbox, mRanges.get(a), session, tag, imapCommand, responder);
                        }
                    } else {
                        setFlags(request, mailboxSession, mailbox, messageSet, session, tag, imapCommand, responder);
                    }
                   
                }

               
            }
            final boolean omitExpunged = (!useUids);
            unsolicitedResponses(session, responder, omitExpunged, useUids);
           
            // check if we had some failed uids which didn't pass the UNCHANGEDSINCE filter
            if (failed.isEmpty()) {
                okComplete(imapCommand, tag, responder);
            } else {
                // Convert the MessageRanges to an array of IdRange.
                // TODO: Maybe this should get moved in an util class
                List<MessageRange> ranges = MessageRange.toRanges(failed);
                IdRange[] idRanges = new IdRange[ranges.size()];
                for (int i = 0 ; i < ranges.size(); i++) {
                    MessageRange r = ranges.get(i);
                    if (r.getType() == Type.ONE) {
                        idRanges[i] = new IdRange(r.getUidFrom());
                    } else {
                        idRanges[i] = new IdRange(r.getUidFrom(), r.getUidTo());
                    }
                }
                // we need to return the failed sequences
                //
                // See RFC4551 3.2. STORE and UID STORE Commands
View Full Code Here

            //      - QRESYNC was enabled via ENABLE QRESYNC
            //
            if (unchangedSince != -1 || qresyncEnabled || condstoreEnabled) {
                MessageResultIterator results = mailbox.getMessages(messageSet, FetchGroupImpl.MINIMAL, mailboxSession);
                while(results.hasNext()) {
                    MessageResult r = results.next();
                    // Store the modseq for the uid for later usage in the response
                    modSeqs.put(r.getUid(),r.getModSeq());
                }
            }
           
            for (Map.Entry<Long, Flags> entry : flagsByUid.entrySet()) {
                final long uid = entry.getKey();
View Full Code Here

    protected void addFlagsResponses(final ImapSession session, final SelectedMailbox selected, final ImapProcessor.Responder responder, boolean useUid, MessageRange messageSet, MessageManager mailbox, MailboxSession mailboxSession) throws MailboxException {

        final MessageResultIterator it = mailbox.getMessages(messageSet, FetchGroupImpl.MINIMAL,  mailboxSession);
        while (it.hasNext()) {
            MessageResult mr = it.next();
            final long uid = mr.getUid();
            int msn = selected.msn(uid);
            if (msn == SelectedMailbox.NO_SUCH_MESSAGE) {
                if (session.getLog().isDebugEnabled()) {
                    session.getLog().debug("No message found with uid " + uid + " in the uid<->msn mapping for mailbox " + selected.getPath().getFullName(mailboxSession.getPathDelimiter()) +" , this may be because it was deleted by a concurrent session. So skip it..");
               
                   

                // skip this as it was not found in the mapping
                //
                // See IMAP-346
                continue;
            }

            boolean qresyncEnabled = EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_QRESYNC);
            boolean condstoreEnabled = EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_CONDSTORE);

            final Flags flags = mr.getFlags();
            final Long uidOut;
            if (useUid || qresyncEnabled) {
                uidOut = uid;
            } else {
                uidOut = null;
            }
            if (selected.isRecent(uid)) {
                flags.add(Flags.Flag.RECENT);
            } else {
                flags.remove(Flags.Flag.RECENT);
            }
            final FetchResponse response;
           
            // Check if we also need to return the MODSEQ in the response. This is true if CONDSTORE or
            // if QRESYNC was enabled, and the mailbox supports the permant storage of mod-sequences
            if ((condstoreEnabled || qresyncEnabled) && mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT).isModSeqPermanent()) {
                response = new FetchResponse(msn, flags, uidOut, mr.getModSeq(), null, null, null, null, null, null);
            } else {
                response = new FetchResponse(msn, flags, uidOut, null, null, null, null, null, null, null);
            }
            responder.respond(response);
        }
View Full Code Here

        FetchGroup resultToFetch = getFetchGroup(fetch);

        for (int i = 0; i < ranges.size(); i++) {
            MessageResultIterator messages = mailbox.getMessages(ranges.get(i), resultToFetch, mailboxSession);
            while (messages.hasNext()) {
                final MessageResult result = messages.next();
                try {
                    final FetchResponse response = builder.build(fetch, result, mailbox, session, useUids);
                    responder.respond(response);
                } catch (MessageRangeException e) {
                    // we can't for whatever reason find the message so
                    // just skip it and log it to debug
                    if (session.getLog().isDebugEnabled()) {
                        session.getLog().debug("Unable to find message with uid " + result.getUid(), e);
                    }
                } catch (MailboxException e) {
                    // we can't for whatever reason find parse all requested parts of the message. This may because it was deleted while try to access the parts.
                    // So we just skip it
                    //
                    // See IMAP-347
                    if (session.getLog().isDebugEnabled()) {
                        session.getLog().debug("Unable to fetch message with uid " + result.getUid() + ", so skip it", e);
                    }
                }
            }
           
            // Throw the exception if we received one
View Full Code Here

    public MessageResult next() {
        if (next == null || !next.hasNext())
          throw new NoSuchElementException();
       
        final Message<Id> message = next.next();
        MessageResult result;
        try {
            result = ResultUtils.loadMessageResult(message, group);
            cursor = result.getUid();
        } catch (MailboxException e) {
            result = new UnloadedMessageResult<Id>(message, e);
        }

        cursor++;
View Full Code Here

            }
        });

        long i = 1;
        while (it.hasNext()) {
            MessageResult r = it.next();
            Assert.assertEquals(i++, r.getUid());
        }
        Assert.assertEquals(10, i);

    }
View Full Code Here

        try {
            mailboxManager.startProcessingRequest(session);
            Iterator<MessageResult> results = manager.getMessages(MessageRange.all(), METADATA_GROUP, session);
            List<MessageMetaData> mList = new ArrayList<MessageMetaData>();
            while (results.hasNext()) {
                MessageResult result = results.next();
                MessageMetaData metaData = new MessageMetaData(Long.toString(result.getUid()), result.getSize());
                mList.add(metaData);
            }
            return Collections.unmodifiableList(mList);
        } catch (MailboxException e) {
            throw new IOException("Unable to retrieve messages", e);
View Full Code Here

                int j=0;
                Iterator<MessageResult> messageResultIterator = srcMessageManager.getMessages(MessageRange.all(), GROUP, srcMailboxSession);
               
                while (messageResultIterator.hasNext()) {

                    MessageResult messageResult = messageResultIterator.next();
                    InputStreamContent content = (InputStreamContent) messageResult.getFullContent();

                    dstMailboxManager.startProcessingRequest(dstMailboxSession);
                    dstMessageManager.appendMessage(content.getInputStream(), messageResult.getInternalDate(), dstMailboxSession, messageResult.getFlags().contains(Flag.RECENT), messageResult.getFlags());
                    dstMailboxManager.endProcessingRequest(dstMailboxSession);
                    log.info("Message #" + j + " appended in destination mailbox with path=" + mailboxPath.toString());
                    j++;

                }
View Full Code Here

TOP

Related Classes of org.apache.james.mailbox.model.MessageResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.