librelist archives

« back to archive

handling of ranges in IMAPClient

handling of ranges in IMAPClient

From:
Ross Boylan
Date:
2011-11-14 @ 23:35
IMAP allows ranges like 500:*.  However, the documentation says
IMAPClient takes either an integer or a list of integers for a message
or UID sequence.

Is there a way to achieve selections list 500:*?

Can an xrange object serve as a selection list?

Thanks.
Ross Boylan

Re: [imapclient] handling of ranges in IMAPClient

From:
Ross Boylan
Date:
2011-11-14 @ 23:58
On Mon, 2011-11-14 at 15:35 -0800, Ross Boylan wrote:
> IMAP allows ranges like 500:*.  However, the documentation says
> IMAPClient takes either an integer or a list of integers for a message
> or UID sequence.
> 
> Is there a way to achieve selections list 500:*?
> 
> Can an xrange object serve as a selection list?
> 
> Thanks.
> Ross Boylan
I think this code below, from imapclient.py, answers the questions.

String arguments like '500:*' are permissible, either as a single
argument or an element of a list.

xrange objects are not allowed.


def messages_to_str(messages):
    """Convert a sequence of messages ids or a single integer message id
    into an id list string for use with IMAP commands
    """
    if isinstance(messages, (str, int, long)):
        messages = (messages,)
    elif not isinstance(messages, (tuple, list)):
        raise ValueError('invalid message list: %r' % messages)
    return ','.join([str(m) for m in messages])

Re: [imapclient] handling of ranges in IMAPClient

From:
Menno Smits
Date:
2011-12-07 @ 02:52
On Mon, 14 Nov 2011 15:58:41 -0800, Ross Boylan wrote:

> I think this code below, from imapclient.py, answers the questions.
>
> String arguments like '500:*' are permissible, either as a single
> argument or an element of a list.
>
> xrange objects are not allowed.
>
>
> def messages_to_str(messages):
>     """Convert a sequence of messages ids or a single integer message 
> id
>     into an id list string for use with IMAP commands
>     """
>     if isinstance(messages, (str, int, long)):
>         messages = (messages,)
>     elif not isinstance(messages, (tuple, list)):
>         raise ValueError('invalid message list: %r' % messages)
>     return ','.join([str(m) for m in messages])

Sorry for taking so long reply. I've been overseas (getting married) 
and have had intermittent access to email.

I'm glad you managed to figure this out. Message ids can indeed be 
passed as strings, ints, longs or tuples/lists of ints/longs. I'm adding 
a ticket now to make this clearer in the documentation.

Regards,
Menno