Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > IMAP Checking Folder Size

Reply
Thread Tools

IMAP Checking Folder Size

 
 
Kevin F
Guest
Posts: n/a
 
      03-20-2006
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
found.




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()]
m.sort()
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(')', ''))
else:
size_folder = 0
print "%-30s%5d%10s" % (mailbox, int(number_of_messages[0]),
size_folder);
size_all += size_folder

print "\n%-30s%5i%10.3f MB\n" % ("Sum", number_of_messages_all,
size_all/1e6)

# Close the connection
M.logout()
 
Reply With Quote
 
 
 
 
Donn Cave
Guest
Posts: n/a
 
      03-20-2006
In article <dvmh9e$ev0o$>,
Kevin F <> wrote:
> 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
> found.


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


A general observation about imaplib, the caller usually has
some analysis to do on the returned data. For example, you
have to check that `result' value, before you can assume that
you got the data you asked for. I would suggest that you print
these values out somewhere, it will put you in a position where
you can probably answer your question better than we can.

Donn Cave,
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Support for IMAP IDLE in net/imap Abhishiv Saxena Ruby 4 07-04-2009 04:07 PM
imap and Tmail. Getting whole email with imap Adam Akhtar Ruby 1 12-15-2008 10:55 PM
net/imap - imap.search "TO" can't find email jasonnaylor Ruby 1 04-16-2008 04:05 AM
Writing IMAP->GMail proxy... Where to go for IMAP RFC help? Jon Fi Ruby 4 10-21-2006 09:00 PM
Curier-IMAP and imap.create() Henrik Ormåsen Ruby 0 08-19-2006 06:29 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57