Package org.apache.james.imap.api.message

Examples of org.apache.james.imap.api.message.IdRange$IdRangeComperator


                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


        ArrayList<IdRange> rangeList = new ArrayList<IdRange>();
        int pos = 0;
        while (commaPos != -1) {
            String range = nextWord.substring(pos, commaPos);
            IdRange set = parseRange(range);
            rangeList.add(set);

            pos = commaPos + 1;
            commaPos = nextWord.indexOf(',', pos);
        }
View Full Code Here

            if (pos == -1) {

                // Check if its a single "*" and so should return last message
                // in mailbox. See IMAP-289
                if (range.length() == 1 && range.charAt(0) == '*') {
                    return new IdRange(Long.MAX_VALUE, Long.MAX_VALUE);
                } else {
                    long value = parseUnsignedInteger(range);
                    return new IdRange(value);
                }
            } else {
                // Make sure we detect the low and high value
                // See https://issues.apache.org/jira/browse/IMAP-212
                long val1 = parseUnsignedInteger(range.substring(0, pos));
                long val2 = parseUnsignedInteger(range.substring(pos + 1));

                // handle "*:*" ranges. See IMAP-289
                if (val1 == Long.MAX_VALUE && val2 == Long.MAX_VALUE) {
                    return new IdRange(Long.MAX_VALUE, Long.MAX_VALUE);
                } else if (val1 <= val2) {
                    return new IdRange(val1, val2);
                } else if (val1 == Long.MAX_VALUE) {
                    // *:<num> message range must be converted to <num>:*
                    // See IMAP-290
                    return new IdRange(val2, Long.MAX_VALUE);
                } else {
                    return new IdRange(val2, val1);
                }
            }
        } catch (NumberFormatException e) {
            throw new DecodingException(HumanReadableText.INVALID_MESSAGESET, "Invalid message set.", e);
        }
View Full Code Here

                }
                List<MessageRange> ranges = MessageRange.toRanges(idList);
                idRanges = new IdRange[ranges.size()];
                for (int i = 0 ; i <ranges.size(); i++) {
                    MessageRange range = ranges.get(i);
                    idRanges[i] = new IdRange(range.getUidFrom(), range.getUidTo());
                }
               
                boolean esearch = false;
                for (int i = 0; i < resultOptions.size(); i++) {
                    if (SearchResultOption.SAVE != resultOptions.get(i)) {
                        esearch = true;
                        break;
                    }
                }
               
                if (esearch) {
                    long min = -1;
                    long max = -1;
                    long count = ids.length;

                    if (ids.length > 0) {
                        min = ids[0];
                        max = ids[ids.length -1];
                    }
                  
                   
                    // Save the sequence-set for later usage. This is part of SEARCHRES
                    if (resultOptions.contains(SearchResultOption.SAVE)) {
                        if (resultOptions.contains(SearchResultOption.ALL) || resultOptions.contains(SearchResultOption.COUNT)) {
                            // if the options contain ALL or COUNT we need to save the complete sequence-set
                            SearchResUtil.saveSequenceSet(session, idRanges);
                        } else {
                            List<IdRange> savedRanges = new ArrayList<IdRange>();
                            if (resultOptions.contains(SearchResultOption.MIN)) {
                                // Store the MIN
                                savedRanges.add(new IdRange(min))
                            }
                            if (resultOptions.contains(SearchResultOption.MAX)) {
                                // Store the MAX
                                savedRanges.add(new IdRange(max));
                            }
                            SearchResUtil.saveSequenceSet(session, savedRanges.toArray(new IdRange[0]));
                        }
                    }
                    response = new ESearchResponse(min, max, count, idRanges, highestModSeq, tag, useUids, resultOptions);
View Full Code Here

        // First of check if we have any messages in the mailbox
        // if not we don't need to go through all of this
        if (selected.existsCount() > 0) {
            for (int i = 0; i < length; i++) {
                final IdRange range = sequenceNumbers[i];

                long lowVal = range.getLowVal();
                long highVal = range.getHighVal();
                if (useUids) {
                    // Take care of "*" and "*:*" values by return the last
                    // message in
                    // the mailbox. See IMAP-289
                    if (lowVal == Long.MAX_VALUE && highVal == Long.MAX_VALUE) {
View Full Code Here

                if (uidSet == null) {
                    // See mailbox had some messages stored before, if not we don't need to query at all
                    long uidNext = metaData.getUidNext();
                    if ( uidNext != 1) {
                        // Use UIDNEXT -1 as max uid as stated in the QRESYNC RFC
                        uidSet = new IdRange[] {new IdRange(1, uidNext -1)};
                    }
                }
               
                if (uidSet != null) {
                    // RFC5162 3.1. QRESYNC Parameter to SELECT/EXAMINE
                    //
                    // Message sequence match data:
                    //
                    //      A client MAY provide a parenthesized list of a message sequence set
                    //      and the corresponding UID sets.  Both MUST be provided in ascending
                    //      order.  The server uses this data to restrict the range for which it
                    //      provides expunged message information.
                    //
                    //
                    //      Conceptually, the client provides a small sample of sequence numbers
                    //      for which it knows the corresponding UIDs.  The server then compares
                    //      each sequence number and UID pair the client provides with the
                    //      current state of the mailbox.  If a pair matches, then the client
                    //      knows of any expunges up to, and including, the message, and thus
                    //      will not include that range in the VANISHED response, even if the
                    //      "mod-sequence-value" provided by the client is too old for the server
                    //      to have data of when those messages were expunged.
                    //
                    //      Thus, if the Nth message number in the first set in the list is 4,
                    //      and the Nth UID in the second set in the list is 8, and the mailbox's
                    //      fourth message has UID 8, then no UIDs equal to or less than 8 are
                    //      present in the VANISHED response.  If the (N+1)th message number is
                    //      12, and the (N+1)th UID is 24, and the (N+1)th message in the mailbox
                    //      has UID 25, then the lowest UID included in the VANISHED response
                    //      would be 9.
                    if (knownSequences != null && knownUids != null) {
                       
                        // Add all uids which are contained in the knownuidsset to a List so we can later access them via the index
                        List<Long> knownUidsList = new ArrayList<Long>();
                        for (int a = 0; a < knownUids.length; a++) {
                            Iterator<Long> it =  knownUids[a].iterator();
                           
                            while(it.hasNext()) {
                                knownUidsList.add(it.next());
                            }
                        }
                      
                       
                       
                        // loop over the known sequences and check the UID for MSN X again the known UID X
                        long firstUid = 1;
                        int index = 0;
                        for (int a = 0; a < knownSequences.length; a++) {
                            boolean done = false;
                            Iterator<Long> it =  knownSequences[a].iterator();
                            while(it.hasNext()) {
                               
                                // Check if we have uids left to check against
                                if (knownUidsList.size() > index++) {
                                    int msn = it.next().intValue();
                                    long knownUid = knownUidsList.get(index);
                                   
                                    // Check if the uid mathc if not we are done here
                                    if (selected.uid(msn) != knownUid) {
                                        done = true;
                                        break;
                                    } else {
                                        firstUid = knownUid;
                                    }
                                   
                                } else {
                                    done = true;
                                    break;
                                }

                            }
                           
                            // We found the first uid to start with
                            if (done) {
                                firstUid++;
                               
                                // Ok now its time to filter out the IdRanges which we are not interested in
                                List<IdRange> filteredUidSet = new ArrayList<IdRange>();
                                for ( int i = 0; i < uidSet.length; i++) {
                                    IdRange r = uidSet[i];
                                    if (r.getLowVal() < firstUid) {
                                        if (r.getHighVal() > firstUid) {
                                            r.setLowVal(firstUid);
                                            filteredUidSet.add(r);
                                        }
                                    } else {
                                        filteredUidSet.add(r);
                                    }
View Full Code Here

     */
    private void checkIdRanges(IdRange[] ranges, boolean checkOrder) throws DecodingException {
        long last = 0;
        for (int i = 0; i < ranges.length; i++ ) {
           
            IdRange r = ranges[i];
            long low = r.getLowVal();
            long high = r.getHighVal();
            if (low == Long.MAX_VALUE || high == Long.MAX_VALUE) {
                throw new DecodingException(HumanReadableText.INVALID_MESSAGESET, "* is not allowed in the sequence-set");
            }
            if (checkOrder) {
                if (low < last) {
View Full Code Here

            unsolicitedResponses(session, responder, false);

            // in case of MULTIAPPEND support we will push more then one UID
            // here
            okComplete(command, tag, ResponseCode.appendUid(uidValidity, new IdRange[] { new IdRange(uid) }), responder);
        } catch (MailboxNotFoundException e) {
            // Indicates that the mailbox does not exist
            // So TRY CREATE
            tryCreate(session, tag, command, responder, e);
            /*
 
View Full Code Here

                            // See IMAP-287
                            //
                            // Disable this as this is now done directly in the scope of the copy operation.
                            // See MAILBOX-85
                            //mailbox.setFlags(new Flags(Flags.Flag.RECENT), true, false, mr, mailboxSession);
                            resultRanges.add(new IdRange(mr.getUidFrom(), mr.getUidTo()));
                        }
                    }
                }
                IdRange[] resultUids = IdRange.mergeRanges(resultRanges).toArray(new IdRange[0]);
View Full Code Here

     * @see org.apache.james.imap.encode.ImapResponseComposer#sequenceSet(org.apache.james.imap.api.message.IdRange[])
     */
    public ImapResponseComposer sequenceSet(IdRange[] ranges) throws IOException {
        StringBuilder sb = new StringBuilder();
        for (int i = 0 ; i< ranges.length; i++) {
            IdRange range = ranges[i];
            sb.append(range.getFormattedString());
            if (i + 1 < ranges.length) {
                sb.append(",");
            }
        }
        return message(sb.toString());
View Full Code Here

TOP

Related Classes of org.apache.james.imap.api.message.IdRange$IdRangeComperator

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.