Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
POP3 Class Reference

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
 

Data Fields

 host
 
 port
 
 sock
 
 file
 
 welcome
 

Static Public Attributes

tuple timestamp = re.compile(r'\+OK.*(<[^>]+>)')
 

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 32 of file poplib.py.

Constructor & Destructor Documentation

def __init__ (   self,
  host,
  port = POP3_PORT 
)

Definition at line 75 of file poplib.py.

75 
76  def __init__(self, host, port = POP3_PORT):
77  self.host = host
78  self.port = port
79  msg = "getaddrinfo returns an empty list"
80  self.sock = None
81  for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM):
82  af, socktype, proto, canonname, sa = res
83  try:
84  self.sock = socket.socket(af, socktype, proto)
85  self.sock.connect(sa)
86  except socket.error, msg:
87  if self.sock:
88  self.sock.close()
89  self.sock = None
90  continue
91  break
92  if not self.sock:
93  raise socket.error, msg
94  self.file = self.sock.makefile('rb')
95  self._debugging = 0
96  self.welcome = self._getresp()
97 

Member Function Documentation

def 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()'

Definition at line 280 of file poplib.py.

References POP3._shortcmd(), hmac.digest(), dospath.join(), POP3.welcome, FTP.welcome, and NNTP.welcome.

281  def apop(self, user, secret):
282  """Authorisation
283 
284  - only possible if server has supplied a timestamp in initial greeting.
285 
286  Args:
287  user - mailbox user;
288  secret - secret shared between client and server.
289 
290  NB: mailbox is locked by server from here to 'quit()'
291  """
292  m = self.timestamp.match(self.welcome)
293  if not m:
294  raise error_proto('-ERR APOP not supported by server')
295  import md5
296  digest = md5.new(m.group(1)+secret).digest()
297  digest = ''.join(map(lambda x:'%02x'%ord(x), digest))
298  return self._shortcmd('APOP %s %s' % (user, digest))
299 
def dele (   self,
  which 
)
Delete message number 'which'.

Result is 'response'.

Definition at line 236 of file poplib.py.

References POP3._shortcmd().

237  def dele(self, which):
238  """Delete message number 'which'.
239 
240  Result is 'response'.
241  """
242  return self._shortcmd('DELE %s' % which)
243 
def getwelcome (   self)

Definition at line 173 of file poplib.py.

References POP3.welcome, FTP.welcome, and NNTP.welcome.

174  def getwelcome(self):
175  return self.welcome
176 
def list (   self,
  which = None 
)
Request listing, return result.

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

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

Definition at line 214 of file poplib.py.

References POP3._longcmd(), and POP3._shortcmd().

215  def list(self, which=None):
216  """Request listing, return result.
217 
218  Result without a message number argument is in form
219  ['response', ['mesg_num octets', ...]].
220 
221  Result when a message number argument is given is a
222  single response: the "scan listing" for that message.
223  """
224  if which:
225  return self._shortcmd('LIST %s' % which)
226  return self._longcmd('LIST')
227 
def noop (   self)
Does nothing.

One supposes the response indicates the server is alive.

Definition at line 244 of file poplib.py.

References POP3._shortcmd().

245  def noop(self):
246  """Does nothing.
247 
248  One supposes the response indicates the server is alive.
249  """
250  return self._shortcmd('NOOP')
251 
def 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 191 of file poplib.py.

References POP3._shortcmd().

192  def pass_(self, pswd):
193  """Send password, return response
194 
195  (response includes message count, mailbox size).
196 
197  NB: mailbox is locked by server from here to 'quit()'
198  """
199  return self._shortcmd('PASS %s' % pswd)
200 
def quit (   self)
Signoff: commit changes on server, unlock mailbox, close connection.

Definition at line 257 of file poplib.py.

References POP3._shortcmd(), Chunk.file, POP3.file, FTP.file, NNTP.file, Hook.file, DumbWriter.file, MiniFieldStorage.file, Breakpoint.file, FieldStorage.file, HTTP.file, POP3.sock, FTP.sock, NNTP.sock, HTTPConnection.sock, and HTTPSConnection.sock.

258  def quit(self):
259  """Signoff: commit changes on server, unlock mailbox, close connection."""
260  try:
261  resp = self._shortcmd('QUIT')
262  except error_proto, val:
263  resp = val
264  self.file.close()
265  self.sock.close()
266  del self.file, self.sock
267  return resp
def retr (   self,
  which 
)
Retrieve whole message number 'which'.

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

Definition at line 228 of file poplib.py.

References POP3._longcmd().

229  def retr(self, which):
230  """Retrieve whole message number 'which'.
231 
232  Result is in form ['response', ['line', ...], octets].
233  """
234  return self._longcmd('RETR %s' % which)
235 
def rpop (   self,
  user 
)
Not sure what this does.

Definition at line 273 of file poplib.py.

References POP3._shortcmd().

274  def rpop(self, user):
275  """Not sure what this does."""
276  return self._shortcmd('RPOP %s' % user)
277 
def rset (   self)
Not sure what this does.

Definition at line 252 of file poplib.py.

References POP3._shortcmd().

253  def rset(self):
254  """Not sure what this does."""
255  return self._shortcmd('RSET')
256 
def set_debuglevel (   self,
  level 
)

Definition at line 177 of file poplib.py.

References POP3._debugging.

178  def set_debuglevel(self, level):
179  self._debugging = level
180 
def stat (   self)
Get mailbox status.

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

Definition at line 201 of file poplib.py.

References POP3._debugging, and POP3._shortcmd().

202  def stat(self):
203  """Get mailbox status.
204 
205  Result is tuple of 2 ints (message count, mailbox size)
206  """
207  retval = self._shortcmd('STAT')
208  rets = retval.split()
209  if self._debugging: print '*stat*', `rets`
210  numMessages = int(rets[1])
211  sizeMessages = int(rets[2])
212  return (numMessages, sizeMessages)
213 
def 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 300 of file poplib.py.

References POP3._longcmd().

301  def top(self, which, howmuch):
302  """Retrieve message header of message number 'which'
303  and first 'howmuch' lines of message body.
304 
305  Result is in form ['response', ['line', ...], octets].
306  """
307  return self._longcmd('TOP %s %s' % (which, howmuch))
308 
def 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 309 of file poplib.py.

References POP3._longcmd(), and POP3._shortcmd().

310  def uidl(self, which=None):
311  """Return message digest (unique id) list.
312 
313  If 'which', result contains unique id for that message
314  in the form 'response mesgnum uid', otherwise result is
315  the list ['response', ['mesgnum uid', ...], octets]
316  """
317  if which:
318  return self._shortcmd('UIDL %s' % which)
319  return self._longcmd('UIDL')
320 
def user (   self,
  user 
)
Send user name, return response

(should indicate password required).

Definition at line 183 of file poplib.py.

References POP3._shortcmd().

184  def user(self, user):
185  """Send user name, return response
186 
187  (should indicate password required).
188  """
189  return self._shortcmd('USER %s' % user)
190 

Field Documentation

file

Definition at line 93 of file poplib.py.

host

Definition at line 76 of file poplib.py.

port

Definition at line 77 of file poplib.py.

sock

Definition at line 79 of file poplib.py.

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

Definition at line 278 of file poplib.py.

welcome

Definition at line 95 of file poplib.py.


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