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

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


    }


    @Test
    public void testMerge() {
        IdRange r = new IdRange(0, 2);
        IdRange r2 = new IdRange(1, 4);
        IdRange r3 = new IdRange(6, 7);
       
        List<IdRange> ranges = new ArrayList<IdRange>();
        ranges.add(r);
        ranges.add(r2);
        ranges.add(r3);
       
        List<IdRange> merged = IdRange.mergeRanges(ranges);
        assertEquals(2, merged.size());
        Iterator<IdRange> rIt = merged.iterator();
        checkIdRange(new IdRange(0, 4),rIt.next());
        checkIdRange(r3,rIt.next());
        assertFalse(rIt.hasNext());
    }
View Full Code Here


    }
   

    @Test
    public void testMerge2() {
        IdRange r = new IdRange(0, 10);
        IdRange r2 = new IdRange(1, 4);
        IdRange r3 = new IdRange(5, 7);
       
        List<IdRange> ranges = new ArrayList<IdRange>();
        ranges.add(r);
        ranges.add(r2);
        ranges.add(r3);
       
        List<IdRange> merged = IdRange.mergeRanges(ranges);
        assertEquals(1, merged.size());
        Iterator<IdRange> rIt = merged.iterator();
        checkIdRange(new IdRange(0, 10),rIt.next());
        assertFalse(rIt.hasNext());
    }
View Full Code Here

        assertFalse(rIt.hasNext());
    }
   
    @Test
    public void testMerge3() {
        IdRange r = new IdRange(0, 10);
        IdRange r2 = new IdRange(1, 4);
        IdRange r3 = new IdRange(10, 15);
       
        List<IdRange> ranges = new ArrayList<IdRange>();
        ranges.add(r);
        ranges.add(r2);
        ranges.add(r3);
       
        List<IdRange> merged = IdRange.mergeRanges(ranges);
        assertEquals(1, merged.size());
        Iterator<IdRange> rIt = merged.iterator();
        checkIdRange(new IdRange(0, 15),rIt.next());
        assertFalse(rIt.hasNext());
    }
View Full Code Here

        assertFalse(rIt.hasNext());
    }
   
    @Test
    public void testMerge4() {
        IdRange r = new IdRange(0, 1);
        IdRange r2 = new IdRange(1, 1);
        IdRange r3 = new IdRange(2, 2);
       
        List<IdRange> ranges = new ArrayList<IdRange>();
        ranges.add(r);
        ranges.add(r2);
        ranges.add(r3);
       
        List<IdRange> merged = IdRange.mergeRanges(ranges);
        assertEquals(1, merged.size());
        Iterator<IdRange> rIt = merged.iterator();
        checkIdRange(new IdRange(0, 2),rIt.next());
        assertFalse(rIt.hasNext());
    }
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

        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.ILLEGAL_ARGUMENTS, "Invalid message set.", e);
        }
View Full Code Here

    }

    @Test
    public void testSequenceSetUpperUnlimited() throws Exception {
        expectsGetSelectedMailbox();
        final IdRange[] ids = { new IdRange(1, Long.MAX_VALUE) };
        final SearchQuery.NumericRange[] ranges = { new SearchQuery.NumericRange(
                42, 100L) };
        mockery.checking(new Expectations() {{
            oneOf(selectedMailbox).uid(with(equal(1)));will(returnValue(42L));
            allowing(selectedMailbox).getFirstUid(); will(returnValue(1L));
View Full Code Here

    }

    @Test
    public void testSequenceSetMsnRange() throws Exception {
        expectsGetSelectedMailbox();
        final IdRange[] ids = { new IdRange(1, 5) };
        final SearchQuery.NumericRange[] ranges = { new SearchQuery.NumericRange(
                42, 1729) };
        mockery.checking(new Expectations() {{
            oneOf(selectedMailbox).uid(with(equal(1)));will(returnValue(42L));
            oneOf(selectedMailbox).uid(with(equal(5)));will(returnValue(1729L));
View Full Code Here

    }

    @Test
    public void testSequenceSetSingleMsn() throws Exception {
        expectsGetSelectedMailbox();
        final IdRange[] ids = { new IdRange(1) };
        final SearchQuery.NumericRange[] ranges = { new SearchQuery.NumericRange(
                42) };
        mockery.checking(new Expectations() {{
            exactly(2).of(selectedMailbox).uid(with(equal(1)));will(returnValue(42L));
        }});
View Full Code Here

TOP

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

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.