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_(str
| 49 | |
| 50 | |
| 51 | class POP3: |
| 52 | |
| 53 | """This class supports both the minimal and optional command sets. |
| 54 | Arguments can be strings or integers (where appropriate) |
| 55 | (e.g.: retr(1) and retr('1') both work equally well. |
| 56 | |
| 57 | Minimal Command Set: |
| 58 | USER name user(name) |
| 59 | PASS string pass_(string) |
| 60 | STAT stat() |
| 61 | LIST [msg] list(msg = None) |
| 62 | RETR msg retr(msg) |
| 63 | DELE msg dele(msg) |
| 64 | NOOP noop() |
| 65 | RSET rset() |
| 66 | QUIT quit() |
| 67 | |
| 68 | Optional Commands (some servers support these): |
| 69 | RPOP name rpop(name) |
| 70 | APOP name digest apop(name, digest) |
| 71 | TOP msg n top(msg, n) |
| 72 | UIDL [msg] uidl(msg = None) |
| 73 | CAPA capa() |
| 74 | STLS stls() |
| 75 | UTF8 utf8() |
| 76 | |
| 77 | Raises one exception: 'error_proto'. |
| 78 | |
| 79 | Instantiate with: |
| 80 | POP3(hostname, port=110) |
| 81 | |
| 82 | NB: the POP protocol locks the mailbox from user |
| 83 | authorization until QUIT, so be sure to get in, suck |
| 84 | the messages, and quit, each time you access the |
| 85 | mailbox. |
| 86 | |
| 87 | POP is a line-based protocol, which means large mail |
| 88 | messages consume lots of python cycles reading them |
| 89 | line-by-line. |
| 90 | |
| 91 | If it's available on your mail server, use IMAP4 |
| 92 | instead, it doesn't suffer from the two problems |
| 93 | above. |
| 94 | """ |
| 95 | |
| 96 | encoding = 'UTF-8' |
| 97 | |
| 98 | def __init__(self, host, port=POP3_PORT, |
| 99 | timeout=socket._GLOBAL_DEFAULT_TIMEOUT): |
| 100 | self.host = host |
| 101 | self.port = port |
| 102 | self._tls_established = False |
| 103 | sys.audit("poplib.connect", self, host, port) |
| 104 | self.sock = self._create_socket(timeout) |
| 105 | self.file = self.sock.makefile('rb') |
| 106 | self._debugging = 0 |
| 107 | self.welcome = self._getresp() |
| 108 |