470,647 Members | 1,178 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

IMAP Folder Size Information

I'm trying to use the following code to get my remote server's folder
size information. Unfortunately, i'm getting the error:

Traceback (most recent call last):
File "/Life/School/Homework/Spring 2006/OPIM
399/Tutorial/IMAP/mailboxsize.py", line 23, in -toplevel-
number_of_messages_all += int(number_of_messages[0])
ValueError: invalid literal for int(): The requested item could not be

What seems to be the problem?

My code is here:

import sys, os, string, imaplib, getpass

imap_server = "webmail.xxxxx.xxxxx.edu"

# Open a connection to the IMAP server
M = imaplib.IMAP4_SSL(imap_server)
M.login('xxxx', getpass.getpass())

# The list of all folders
result,list = M.list()

print "%-30s%5s%10s\n" % ("Folder", "# Msg", "Size")

number_of_messages_all = 0
size_all = 0

for item in list[:]:
x = item.split()
mailbox = string.join(x[2:])

# Select the desired folder
result, number_of_messages = M.select(mailbox, readonly=1)
number_of_messages_all += int(number_of_messages[0])

size_folder = 0
# Go through all the messages in the selected folder
typ, msg = M.search(None, 'ALL')
# Find the first and last messages
m = [int(x) for x in msg[0].split()]
if m:
message_set = "%d:%d" % (m[0], m[-1])
result, sizes_response = M.fetch(message_set, "(UID RFC822.SIZE)")
for i in range(m[-1]):
tmp = sizes_response[i].split()
size_folder += int(tmp[-1].replace(')', ''))
size_folder = 0
print "%-30s%5d%10s" % (mailbox, int(number_of_messages[0]),
size_all += size_folder

print "\n%-30s%5i%10.3f MB\n" % ("Sum", number_of_messages_all,

# Close the connection
Mar 20 '06 #1
0 1398

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Fabian Müller | last post: by
reply views Thread by dekoffie | last post: by
reply views Thread by necroph | last post: by
1 post views Thread by Kevin F | last post: by
reply views Thread by Kevin F | last post: by
5 posts views Thread by Kun | last post: by
reply views Thread by slimdizzy | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.