Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
poplib.POP3 Class Reference
Inheritance diagram for poplib.POP3:
Inheritance graph
[legend]
Collaboration diagram for poplib.POP3:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getwelcome
def set_debuglevel
def user
def pass_
def stat
def list
def retr
def dele
def noop
def rset
def quit
def rpop
def apop
def top
def uidl

Public Attributes

 host
 port
 sock
 file
 welcome

Static Public Attributes

string encoding = 'UTF-8'
tuple timestamp = re.compile(br'\+OK.*(<[^>]+>)')

Private Member Functions

def _create_socket
def _putline
def _putcmd
def _getline
def _getresp
def _getlongresp
def _shortcmd
def _longcmd

Private Attributes

 _debugging

Detailed Description

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.

Definition at line 36 of file poplib.py.


Constructor & Destructor Documentation

def poplib.POP3.__init__ (   self,
  host,
  port = POP3_PORT,
  timeout = socket._GLOBAL_DEFAULT_TIMEOUT 
)

Definition at line 81 of file poplib.py.

00081 
00082                  timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
00083         self.host = host
00084         self.port = port
00085         self.sock = self._create_socket(timeout)
00086         self.file = self.sock.makefile('rb')
00087         self._debugging = 0
00088         self.welcome = self._getresp()

Here is the caller graph for this function:


Member Function Documentation

def poplib.POP3._create_socket (   self,
  timeout 
) [private]

Reimplemented in poplib.POP3_SSL.

Definition at line 89 of file poplib.py.

00089 
00090     def _create_socket(self, timeout):
00091         return socket.create_connection((self.host, self.port), timeout)

Here is the call graph for this function:

def poplib.POP3._getline (   self) [private]

Definition at line 109 of file poplib.py.

00109 
00110     def _getline(self):
00111         line = self.file.readline()
00112         if self._debugging > 1: print('*get*', repr(line))
00113         if not line: raise error_proto('-ERR EOF')
00114         octets = len(line)
00115         # server can send any combination of CR & LF
00116         # however, 'readline()' returns lines ending in LF
00117         # so only possibilities are ...LF, ...CRLF, CR...LF
00118         if line[-2:] == CRLF:
00119             return line[:-2], octets
00120         if line[0] == CR:
00121             return line[1:-1], octets
00122         return line[:-1], octets
00123 

Here is the caller graph for this function:

def poplib.POP3._getlongresp (   self) [private]

Definition at line 137 of file poplib.py.

00137 
00138     def _getlongresp(self):
00139         resp = self._getresp()
00140         list = []; octets = 0
00141         line, o = self._getline()
00142         while line != b'.':
00143             if line.startswith(b'..'):
00144                 o = o-1
00145                 line = line[1:]
00146             octets = octets + o
00147             list.append(line)
00148             line, o = self._getline()
00149         return resp, list, octets
00150 

Here is the call graph for this function:

Here is the caller graph for this function:

def poplib.POP3._getresp (   self) [private]

Definition at line 127 of file poplib.py.

00127 
00128     def _getresp(self):
00129         resp, o = self._getline()
00130         if self._debugging > 1: print('*resp*', repr(resp))
00131         if not resp.startswith(b'+'):
00132             raise error_proto(resp)
00133         return resp
00134 

Here is the call graph for this function:

Here is the caller graph for this function:

def poplib.POP3._longcmd (   self,
  line 
) [private]

Definition at line 160 of file poplib.py.

00160 
00161     def _longcmd(self, line):
00162         self._putcmd(line)
00163         return self._getlongresp()
00164 

Here is the call graph for this function:

Here is the caller graph for this function:

def poplib.POP3._putcmd (   self,
  line 
) [private]

Definition at line 99 of file poplib.py.

00099 
00100     def _putcmd(self, line):
00101         if self._debugging: print('*cmd*', repr(line))
00102         line = bytes(line, self.encoding)
00103         self._putline(line)
00104 

Here is the call graph for this function:

Here is the caller graph for this function:

def poplib.POP3._putline (   self,
  line 
) [private]

Definition at line 92 of file poplib.py.

00092 
00093     def _putline(self, line):
00094         if self._debugging > 1: print('*put*', repr(line))
00095         self.sock.sendall(line + CRLF)
00096 

Here is the caller graph for this function:

def poplib.POP3._shortcmd (   self,
  line 
) [private]

Definition at line 153 of file poplib.py.

00153 
00154     def _shortcmd(self, line):
00155         self._putcmd(line)
00156         return self._getresp()
00157 

Here is the call graph for this function:

Here is the caller graph for this function:

def poplib.POP3.apop (   self,
  user,
  password 
)
Authorisation

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

Args:
user     - mailbox user;
password - mailbox password.

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

Definition at line 274 of file poplib.py.

00274 
00275     def apop(self, user, password):
00276         """Authorisation
00277 
00278         - only possible if server has supplied a timestamp in initial greeting.
00279 
00280         Args:
00281                 user     - mailbox user;
00282                 password - mailbox password.
00283 
00284         NB: mailbox is locked by server from here to 'quit()'
00285         """
00286         secret = bytes(password, self.encoding)
00287         m = self.timestamp.match(self.welcome)
00288         if not m:
00289             raise error_proto('-ERR APOP not supported by server')
00290         import hashlib
00291         digest = m.group(1)+secret
00292         digest = hashlib.md5(digest).hexdigest()
00293         return self._shortcmd('APOP %s %s' % (user, digest))
00294 

Here is the call graph for this function:

def poplib.POP3.dele (   self,
  which 
)
Delete message number 'which'.

Result is 'response'.

Definition at line 230 of file poplib.py.

00230 
00231     def dele(self, which):
00232         """Delete message number 'which'.
00233 
00234         Result is 'response'.
00235         """
00236         return self._shortcmd('DELE %s' % which)
00237 

Here is the call graph for this function:

def poplib.POP3.getwelcome (   self)

Definition at line 167 of file poplib.py.

00167 
00168     def getwelcome(self):
00169         return self.welcome
00170 

def poplib.POP3.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.

Definition at line 208 of file poplib.py.

00208 
00209     def list(self, which=None):
00210         """Request listing, return result.
00211 
00212         Result without a message number argument is in form
00213         ['response', ['mesg_num octets', ...], octets].
00214 
00215         Result when a message number argument is given is a
00216         single response: the "scan listing" for that message.
00217         """
00218         if which is not None:
00219             return self._shortcmd('LIST %s' % which)
00220         return self._longcmd('LIST')
00221 

Here is the call graph for this function:

Here is the caller graph for this function:

def poplib.POP3.noop (   self)
Does nothing.

One supposes the response indicates the server is alive.

Definition at line 238 of file poplib.py.

00238 
00239     def noop(self):
00240         """Does nothing.
00241 
00242         One supposes the response indicates the server is alive.
00243         """
00244         return self._shortcmd('NOOP')
00245 

Here is the call graph for this function:

def poplib.POP3.pass_ (   self,
  pswd 
)
Send password, return response

(response includes message count, mailbox size).

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

Definition at line 185 of file poplib.py.

00185 
00186     def pass_(self, pswd):
00187         """Send password, return response
00188 
00189         (response includes message count, mailbox size).
00190 
00191         NB: mailbox is locked by server from here to 'quit()'
00192         """
00193         return self._shortcmd('PASS %s' % pswd)
00194 

Here is the call graph for this function:

def poplib.POP3.quit (   self)
Signoff: commit changes on server, unlock mailbox, close connection.

Definition at line 251 of file poplib.py.

00251 
00252     def quit(self):
00253         """Signoff: commit changes on server, unlock mailbox, close connection."""
00254         try:
00255             resp = self._shortcmd('QUIT')
00256         except error_proto as val:
00257             resp = val
00258         self.file.close()
00259         self.sock.close()
00260         del self.file, self.sock
00261         return resp

Here is the call graph for this function:

Here is the caller graph for this function:

def poplib.POP3.retr (   self,
  which 
)
Retrieve whole message number 'which'.

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

Definition at line 222 of file poplib.py.

00222 
00223     def retr(self, which):
00224         """Retrieve whole message number 'which'.
00225 
00226         Result is in form ['response', ['line', ...], octets].
00227         """
00228         return self._longcmd('RETR %s' % which)
00229 

Here is the call graph for this function:

def poplib.POP3.rpop (   self,
  user 
)
Not sure what this does.

Definition at line 267 of file poplib.py.

00267 
00268     def rpop(self, user):
00269         """Not sure what this does."""
00270         return self._shortcmd('RPOP %s' % user)
00271 

Here is the call graph for this function:

def poplib.POP3.rset (   self)
Unmark all messages marked for deletion.

Definition at line 246 of file poplib.py.

00246 
00247     def rset(self):
00248         """Unmark all messages marked for deletion."""
00249         return self._shortcmd('RSET')
00250 

Here is the call graph for this function:

Here is the caller graph for this function:

def poplib.POP3.set_debuglevel (   self,
  level 
)

Definition at line 171 of file poplib.py.

00171 
00172     def set_debuglevel(self, level):
00173         self._debugging = level
00174 

def poplib.POP3.stat (   self)
Get mailbox status.

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

Definition at line 195 of file poplib.py.

00195 
00196     def stat(self):
00197         """Get mailbox status.
00198 
00199         Result is tuple of 2 ints (message count, mailbox size)
00200         """
00201         retval = self._shortcmd('STAT')
00202         rets = retval.split()
00203         if self._debugging: print('*stat*', repr(rets))
00204         numMessages = int(rets[1])
00205         sizeMessages = int(rets[2])
00206         return (numMessages, sizeMessages)
00207 

Here is the call graph for this function:

def poplib.POP3.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].

Definition at line 295 of file poplib.py.

00295 
00296     def top(self, which, howmuch):
00297         """Retrieve message header of message number 'which'
00298         and first 'howmuch' lines of message body.
00299 
00300         Result is in form ['response', ['line', ...], octets].
00301         """
00302         return self._longcmd('TOP %s %s' % (which, howmuch))
00303 

Here is the call graph for this function:

def poplib.POP3.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]

Definition at line 304 of file poplib.py.

00304 
00305     def uidl(self, which=None):
00306         """Return message digest (unique id) list.
00307 
00308         If 'which', result contains unique id for that message
00309         in the form 'response mesgnum uid', otherwise result is
00310         the list ['response', ['mesgnum uid', ...], octets]
00311         """
00312         if which is not None:
00313             return self._shortcmd('UIDL %s' % which)
00314         return self._longcmd('UIDL')
00315 
try:

Here is the call graph for this function:

def poplib.POP3.user (   self,
  user 
)
Send user name, return response

(should indicate password required).

Definition at line 177 of file poplib.py.

00177 
00178     def user(self, user):
00179         """Send user name, return response
00180 
00181         (should indicate password required).
00182         """
00183         return self._shortcmd('USER %s' % user)
00184 

Here is the call graph for this function:


Member Data Documentation

Definition at line 86 of file poplib.py.

string poplib.POP3.encoding = 'UTF-8' [static]

Definition at line 78 of file poplib.py.

Definition at line 85 of file poplib.py.

Definition at line 82 of file poplib.py.

Definition at line 83 of file poplib.py.

Definition at line 84 of file poplib.py.

tuple poplib.POP3.timestamp = re.compile(br'\+OK.*(<[^>]+>)') [static]

Definition at line 272 of file poplib.py.

Definition at line 87 of file poplib.py.


The documentation for this class was generated from the following file: