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() 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |