473,413 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

IMAP Checking Folder Size

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()
Mar 20 '06 #1
1 3391
In article <dv***********@netnews.upenn.edu>,
Kevin F <ne*******@gmail.com> 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, do**@u.washington.edu
Mar 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hardeep Rakhra | last post by:
Heya, I'm trying to compile php with imap support on solaris 9, however when i run ./configure with all the relevant options it doesn't pick up the extensions and reports "checking for IMAP...
2
by: nh_capricorn | last post by:
Hi, I am fairly new to .NET (coming from a Java background) and I am trying to port an application that I originally wrote in Java, to .NET / C#. My problem is that I cannot find a C# analog for...
0
by: necroph | last post by:
Hello everybody, i am using an imap-component to read e-mails from an exchange-Server. This is allready done. My problem is that the content of that mails looks confusing. My first try was just...
0
by: Kevin F | last post by:
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...
0
by: Kevin F | last post by:
I've been trying to implement this script, it polls an IMAP inbox for unread messages and displays the sender and subject in a scrollable window using Tkinter. However, when I try to change the...
0
by: Kevin F | last post by:
Sorry to repost... but 4am didn't get much responses. I've been trying to implement this script, it polls an IMAP inbox for unread messages and displays the sender and subject in a scrollable...
5
by: Kun | last post by:
Hey guys, I would like to have a code in python (as simple as possible) to scan a specific folder in my mailbox and if the subject is equal to, say, 'BIKES', I would like to have the code...
1
by: CodeSeeker | last post by:
I have an application, which uses pop3 to read the messages from the mailbox, and it has been working fine for so many year. We recently have started changing this application to use java mail IMAP 4...
3
by: kpfunf | last post by:
I have the following code that works in accessing my personal folder inbox and subfolders. Option Explicit Sub SaveAttachmentsToFolder() On Error GoTo SaveAttachmentsToFolder_err ' Declare...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.