r"""IMAP4 client class. Instantiate with: IMAP4([host[, port[, timeout=None]]]) host - host's name (default: localhost); port - port number (default: standard IMAP4 port). timeout - socket timeout (default: None) If timeout is not given
| 133 | |
| 134 | |
| 135 | class IMAP4: |
| 136 | |
| 137 | r"""IMAP4 client class. |
| 138 | |
| 139 | Instantiate with: IMAP4([host[, port[, timeout=None]]]) |
| 140 | |
| 141 | host - host's name (default: localhost); |
| 142 | port - port number (default: standard IMAP4 port). |
| 143 | timeout - socket timeout (default: None) |
| 144 | If timeout is not given or is None, |
| 145 | the global default socket timeout is used |
| 146 | |
| 147 | All IMAP4rev1 commands are supported by methods of the same |
| 148 | name (in lowercase). |
| 149 | |
| 150 | All arguments to commands are converted to strings, except for |
| 151 | AUTHENTICATE, and the last argument to APPEND which is passed as |
| 152 | an IMAP4 literal. If necessary (the string contains any |
| 153 | non-printing characters or white-space and isn't enclosed with |
| 154 | either parentheses or double quotes) each string is quoted. |
| 155 | However, the 'password' argument to the LOGIN command is always |
| 156 | quoted. If you want to avoid having an argument string quoted |
| 157 | (eg: the 'flags' argument to STORE) then enclose the string in |
| 158 | parentheses (eg: "(\Deleted)"). |
| 159 | |
| 160 | Each command returns a tuple: (type, [data, ...]) where 'type' |
| 161 | is usually 'OK' or 'NO', and 'data' is either the text from the |
| 162 | tagged response, or untagged results from command. Each 'data' |
| 163 | is either a string, or a tuple. If a tuple, then the first part |
| 164 | is the header of the response, and the second part contains |
| 165 | the data (ie: 'literal' value). |
| 166 | |
| 167 | Errors raise the exception class <instance>.error("<reason>"). |
| 168 | IMAP4 server errors raise <instance>.abort("<reason>"), |
| 169 | which is a sub-class of 'error'. Mailbox status changes |
| 170 | from READ-WRITE to READ-ONLY raise the exception class |
| 171 | <instance>.readonly("<reason>"), which is a sub-class of 'abort'. |
| 172 | |
| 173 | "error" exceptions imply a program error. |
| 174 | "abort" exceptions imply the connection should be reset, and |
| 175 | the command re-tried. |
| 176 | "readonly" exceptions imply the command should be re-tried. |
| 177 | |
| 178 | Note: to use this module, you must read the RFCs pertaining to the |
| 179 | IMAP4 protocol, as the semantics of the arguments to each IMAP4 |
| 180 | command are left to the invoker, not to mention the results. Also, |
| 181 | most IMAP servers implement a sub-set of the commands available here. |
| 182 | """ |
| 183 | |
| 184 | class error(Exception): pass # Logical errors - debug required |
| 185 | class abort(error): pass # Service errors - close and retry |
| 186 | class readonly(abort): pass # Mailbox status changed to READ-ONLY |
| 187 | class _responsetimeout(TimeoutError): pass # No response during IDLE |
| 188 | |
| 189 | def __init__(self, host='', port=IMAP4_PORT, timeout=None): |
| 190 | self.debug = Debug |
| 191 | self.state = 'LOGOUT' |
| 192 | self.literal = None # A literal argument to a command |
no outgoing calls
no test coverage detected
searching dependent graphs…