Module poplib :: Class POP3
[hide private]
[frames] | no frames]

_ClassType POP3

Known Subclasses:

This class supports both the minimal and optional command sets.
Arguments can be strings or integers (where appropriate)
(e.g.: retr(1) and retr('1') both work equally well.

Minimal Command Set:
        USER name               user(name)
        PASS string             pass_(string)
        STAT                    stat()
        LIST [msg]              list(msg = None)
        RETR msg                retr(msg)
        DELE msg                dele(msg)
        NOOP                    noop()
        RSET                    rset()
        QUIT                    quit()

Optional Commands (some servers support these):
        RPOP name               rpop(name)
        APOP name digest        apop(name, digest)
        TOP msg n               top(msg, n)
        UIDL [msg]              uidl(msg = None)

Raises one exception: 'error_proto'.

Instantiate with:
        POP3(hostname, port=110)

NB:     the POP protocol locks the mailbox from user
        authorization until QUIT, so be sure to get in, suck
        the messages, and quit, each time you access the
        mailbox.

        POP is a line-based protocol, which means large mail
        messages consume lots of python cycles reading them
        line-by-line.

        If it's available on your mail server, use IMAP4
        instead, it doesn't suffer from the two problems
        above.

Instance Methods [hide private]
 
__init__(self, host, port=110)
 
_putline(self, line)
 
_putcmd(self, line)
 
_getline(self)
 
_getresp(self)
 
_getlongresp(self)
 
_shortcmd(self, line)
 
_longcmd(self, line)
 
getwelcome(self)
 
set_debuglevel(self, level)
 
user(self, user)
Send user name, return response
 
pass_(self, pswd)
Send password, return response
 
stat(self)
Get mailbox status.
 
list(self, which=None)
Request listing, return result.
 
retr(self, which)
Retrieve whole message number 'which'.
 
dele(self, which)
Delete message number 'which'.
 
noop(self)
Does nothing.
 
rset(self)
Not sure what this does.
 
quit(self)
Signoff: commit changes on server, unlock mailbox, close connection.
 
rpop(self, user)
Not sure what this does.
 
apop(self, user, secret)
Authorisation
 
top(self, which, howmuch)
Retrieve message header of message number 'which' and first 'howmuch' lines of message body.
 
uidl(self, which=None)
Return message digest (unique id) list.
Class Variables [hide private]
  timestamp = re.compile(r'\+OK.*(<[^>]+>)')
Method Details [hide private]

user(self, user)

 

Send user name, return response

(should indicate password required).

pass_(self, pswd)

 

Send password, return response

(response includes message count, mailbox size).

NB: mailbox is locked by server from here to 'quit()'

stat(self)

 

Get mailbox status.

Result is tuple of 2 ints (message count, mailbox size)

list(self, which=None)

 

Request listing, return result.

Result without a message number argument is in form ['response', ['mesg_num octets', ...], octets].

Result when a message number argument is given is a single response: the "scan listing" for that message.

retr(self, which)

 

Retrieve whole message number 'which'.

Result is in form ['response', ['line', ...], octets].

dele(self, which)

 

Delete message number 'which'.

Result is 'response'.

noop(self)

 

Does nothing.

One supposes the response indicates the server is alive.

apop(self, user, secret)

 
Authorisation

- only possible if server has supplied a timestamp in initial greeting.

Args:
        user    - mailbox user;
        secret  - secret shared between client and server.

NB: mailbox is locked by server from here to 'quit()'

top(self, which, howmuch)

 

Retrieve message header of message number 'which' and first 'howmuch' lines of message body.

Result is in form ['response', ['line', ...], octets].

uidl(self, which=None)

 

Return message digest (unique id) list.

If 'which', result contains unique id for that message in the form 'response mesgnum uid', otherwise result is the list ['response', ['mesgnum uid', ...], octets]