IMAP - get size of mailboxes

Jeff Epler jepler at unpythonic.net
Mon Sep 13 12:14:42 EDT 2004


I played with imaplib a bit, and I think you want to use something like
    # Find the first and last messages
    m = [int(x) for x in msg[0].split()]
    m.sort()
    message_set = "%d:%d" % (m[0], m[-1])

    # Get the RFC822.SIZE for each message
    result, sizes_response = M.fetch(message_set, "(UID RFC822.SIZE)")
.. and parse sizes_response which looks like this:
    >>> for i in range(10): print sizes_response[i]
    ... 
    1 (UID 1 RFC822.SIZE 889)
    2 (UID 3 RFC822.SIZE 3386)
    3 (UID 4 RFC822.SIZE 2629)
    4 (UID 5 RFC822.SIZE 989)
    5 (UID 6 RFC822.SIZE 1566)
    6 (UID 7 RFC822.SIZE 1591)
    7 (UID 8 RFC822.SIZE 1894)
    8 (UID 9 RFC822.SIZE 1546)
    9 (UID 10 RFC822.SIZE 1372)
    10 (UID 11 RFC822.SIZE 917)

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040913/4012b872/attachment.sig>


More information about the Python-list mailing list