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'
login='test@xxxxxxxxxx'
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: foo@xxxxxxx\nTo: %s
\nSubject: test append\n\nHello\n" % (login))
print typ, dat

output:

NO ['Permission denied']

.



Relevant Pages

  • Re: [Lit.] Buffer overruns
    ... append that byte to s, allocating space, maybe raising an exception ...
    (sci.crypt)
  • RE: CDO problems with synchronous store event sink
    ... registered the handler for sync events at the root of my mailbox. ... Stream Open throws an exception with code 0x800a0cb3, ...
    (microsoft.public.exchange2000.applications)
  • Re: CreateMailbox fails ASP.net
    ... I had created a mailbox create page for our Exchange 5.5 environment. ... > when i use homeMDB string as ... > i get this exception ...
    (microsoft.public.exchange2000.development)
  • Re: DataSet Append Attempt Produces Error
    ... The "this.dispose" is supposed to release the form when the append ... now, I'm just reporting the error message itself, ie, "catch ... (Exception e)" ... >> catch (SqlException sqle) ...
    (microsoft.public.dotnet.languages.csharp)
  • Newbie Help with IMAPLIB Module
    ... I am just learning Python and need some assistance with the IMAPLIB ... mailbox of the IMAP server. ... "This session is the first session ... def imapcheck(): ...
    (comp.lang.python)