IMAP - get size of mailboxes

foten valinor at linuxmail.org
Fri Sep 10 08:20:43 EDT 2004


Hi guys,
I'm trying to make a script (or similar) to display and print the
folder size information for my outlook mailbox.
(So nothing for exchange administrators, just for my own mailbox
that keeps bouncing against the 45 MB limit ...)

The standard way (right-click on Outlook Today, Properties:Folder Size...)
has a
number of deficiencies:
- the window is fixed size, so you can either see the full folder name or
the size
- can't sort by size,
- can't print

So I came up with the folloing approach:
Please correct any flaws you see, since I'm new into python.
The problem (except for bad coding) is that I can't think of a way to get
the size of the mailbox.

Ideas any one?

#! /usr/local/util/python/2.2.2/bin/python
import sys
import os
import string
import imaplib
import getpass

user        = os.environ['USER']
imap_server = "xxx-yyy.com"

# Open a connection to the IMAP server
M = imaplib.IMAP4(imap_server)
M.login(getpass.getuser(), getpass.getpass())
result,list = M.list()

print "%-30s%5s%10s\n" % ("Folder", "no Msg", "Result")

for item in list[:]:
    x = item.split()
    mailbox = string.join(x[2:])
    result, size  = M.select(mailbox,readonly=1)
    print "%-30s%5d%10s" % (mailbox, int(size[0]), result);

M.logout()



More information about the Python-list mailing list