473,387 Members | 1,619 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,387 software developers and data experts.

imaplib : error reporting use 'randomly' exception or return value

imaplib use exception to report errors, but some problems must be
detected by checking the return value !
For example, when trying to append into a mailbox with wrong ACL,
imaplib return 'NO', but dont raise any exception (I give a sample at
the end).
This make error handling more complicate, because any imap statement
is supposed to be followed by a test of the returned value!

Why not report all problems using exceptions ?

It easy to modify imaplib.py to manage this because most of the imap
call are made through function
_simple_command this way :

def _simple_command(self, name, *args):
return self._command_complete(name, self._command(name,
*args))

I propose to replace it by something like :

def _simple_command(self, name, *args):
typ, dat=self._command_complete(name, self._command(name,
*args))
if typ!='OK':
raise self.error(dat[-1])
return typ, dat

Any comment ?

Here is an example, append on a mailbox with the wrong ACL fail by
returning a 'NO'

import imaplib

server='localhost'
lo*********@asxnet.loc'
passwd='password'

c=imaplib.IMAP4(server)
c.login(login, passwd)
c.setacl('INBOX', login, '') # set wrong ACL, removing 'i'
typ, dat=c.append('INBOX', None, None, "From: fo*@bar.com\nTo: %s
\nSubject: test append\n\nHello\n" % (login))
print typ, dat

output:

NO ['Permission denied']

Feb 1 '07 #1
1 2126

I looked carefully imaplib.py and wrote this version of
_simple_command that take care of the way the function is used by
other to keep the same functionality

class bye(imaplib.IMAP4.abort): pass
class bad(imaplib.IMAP4.abort): pass

def _simple_command(self, name, *args):

typ, dat=self._command_complete(name, self._command(name,
*args))
if typ!='OK':
if name in ('LOGOUT',):
return typ, dat

if name in ('EXAMINE', 'SELECT'):
self.state = 'AUTH'

if typ=='BYE': raise self.bye(dat[-1])
elif typ=='BAD': raise self.bad(dat[-1])
else: raise self.error(dat[-1])

return typ, dat
On 1 fév, 23:28, "aspineux" <aspin...@gmail.comwrote:
imaplib use exception to report errors, but some problems must be
detected by checking the return value !
For example, when trying to append into a mailbox with wrong ACL,
imaplib return 'NO', but dont raise any exception (I give a sample at
the end).
This make error handling more complicate, because any imap statement
is supposed to be followed by a test of the returned value!

Why not report all problems using exceptions ?

It easy to modify imaplib.py to manage this because most of the imap
call are made through function
_simple_command this way :

def _simple_command(self, name, *args):
return self._command_complete(name, self._command(name,
*args))

I propose to replace it by something like :

def _simple_command(self, name, *args):
typ, dat=self._command_complete(name, self._command(name,
*args))
if typ!='OK':
raise self.error(dat[-1])
return typ, dat

Any comment ?

Here is an example, append on a mailbox with the wrong ACL fail by
returning a 'NO'

import imaplib

server='localhost'
login='t...@asxnet.loc'
passwd='password'

c=imaplib.IMAP4(server)
c.login(login, passwd)
c.setacl('INBOX', login, '') # set wrong ACL, removing 'i'
typ, dat=c.append('INBOX', None, None, "From: f...@bar.com\nTo: %s
\nSubject: test append\n\nHello\n" % (login))
print typ, dat

output:

NO ['Permission denied']

Feb 2 '07 #2

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

Similar topics

2
by: Bill Sneddon | last post by:
Anyone have an example they are willing to share that shows how to use the store command in imaplib? store( message_set, command, flag_list) Alters flag dispositions for messages in mailbox. ...
1
by: Colin Brown | last post by:
The Python 2.3 documentation in imaplib says: Internaldate2tuple( datestr) Converts an IMAP4 INTERNALDATE string to Coordinated Universal Time. Returns a time module tuple. Time2Internaldate(...
2
by: Max M | last post by:
I am using the fetch command from the imaplib to fetch messages. I get a result, but I am a bit uncertain as to how I should interpret it. The result is described at...
0
by: Wolfgang Kohnen | last post by:
Hello out there! I am new to python and so far I like it a lot. Now I want to create some IMAP mailboxes on my cyrus imapd, with quotas and each user should be subscribed to her/his own spam...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
0
by: smkkaleem | last post by:
I am stuck with the error I have posted above in the question title I am developing ASP.NET 2.0 web site and I have added a new rdlc file to my project by using the following process: -Right...
5
by: csgraham74 | last post by:
Hi guys, Basically i have been developing in dotnet for a couple of years but ive had a few issues in regards to error handling. For example - I have a class that i call passing in a stored...
0
by: venugopalsripada | last post by:
Hi, I use imaplib to download emails from my AOL accounts. I have 6 accounts. I am recieving ('NO', ) as a return value for search(None, 'ALL') for one of the accounts while all other acocunts are...
0
by: aspineux | last post by:
setacl and getacl look to be already "Cyrus" specific (according the doc), why not to extend imaplib a little bit more ? Here are some code I wrote and tested to support cyrus "expire" that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.