|
| 1 | +Advanced Usage |
| 2 | +-------------- |
| 3 | +This document covers some more advanced features and tips for handling |
| 4 | +specific usages. |
| 5 | + |
| 6 | +Watching a mailbox asynchronously using idle |
| 7 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8 | +TODO |
| 9 | + |
| 10 | +Handling large mailboxes |
| 11 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 12 | +TODO |
| 13 | + |
| 14 | +Interactive Sessions |
| 15 | +~~~~~~~~~~~~~~~~~~~~ |
| 16 | +When developing program using IMAPClient is it sometimes useful to |
| 17 | +have an interactive shell to play with. IMAPClient ships with a module |
| 18 | +that lets you fire up an interactive shell with an IMAPClient instance |
| 19 | +connected to an IMAP server. |
| 20 | + |
| 21 | +Start a session like this:: |
| 22 | + |
| 23 | + python -m imapclient.interact -H <host> -u <user> ... |
| 24 | + |
| 25 | +Various options are available to specify the IMAP server details. See |
| 26 | +the help (--help) for more details. You'll be prompted for a username |
| 27 | +and password if one isn't provided on the command line. |
| 28 | + |
| 29 | +It is also possible to pass connection details as a configuration file |
| 30 | +like this:: |
| 31 | + |
| 32 | + python -m imapclient.interact -f <config file> |
| 33 | + |
| 34 | +See below for details of the :ref:`configuration file format<conf-files>`. |
| 35 | + |
| 36 | +If installed, IPython will be used as the embedded shell. Otherwise |
| 37 | +the basic built-in Python shell will be used. |
| 38 | + |
| 39 | +The connected IMAPClient instance is available as the variable |
| 40 | +"c". Here's an example session:: |
| 41 | + |
| 42 | + $ python -m imapclient.interact -H <host> -u <user> ... |
| 43 | + Connecting... |
| 44 | + Connected. |
| 45 | + |
| 46 | + IMAPClient instance is "c" |
| 47 | + In [1]: c.select_folder('inbox') |
| 48 | + Out[1]: |
| 49 | + {b'EXISTS': 2, |
| 50 | + b'FLAGS': (b'\\Answered', |
| 51 | + b'\\Flagged', |
| 52 | + b'\\Deleted', |
| 53 | + b'\\Seen', |
| 54 | + b'\\Draft'), |
| 55 | + b'PERMANENTFLAGS': (b'\\Answered', |
| 56 | + b'\\Flagged', |
| 57 | + b'\\Deleted', |
| 58 | + b'\\Seen', |
| 59 | + b'\\Draft'), |
| 60 | + b'READ-WRITE': True, |
| 61 | + b'RECENT': 0, |
| 62 | + b'UIDNEXT': 1339, |
| 63 | + b'UIDVALIDITY': 1239278212} |
| 64 | + |
| 65 | + In [2]: c.search() |
| 66 | + Out[2]: [1123, 1233] |
| 67 | + |
| 68 | + In [3]: c.logout() |
| 69 | + Out[3]: b'Logging out' |
| 70 | + |
| 71 | + |
| 72 | +.. _conf-files: |
| 73 | + |
| 74 | +Configuration File Format |
| 75 | ++++++++++++++++++++++++++ |
| 76 | +Both the IMAPClient interactive shell and the live tests take |
| 77 | +configuration files which specify how to to connect to an IMAP |
| 78 | +server. The configuration file format is the same for both. |
| 79 | + |
| 80 | +Configuration files use the INI format and must always have a section |
| 81 | +called ``DEFAULT``. Here's a simple example:: |
| 82 | + |
| 83 | + [DEFAULT] |
| 84 | + host = imap.mailserver.com |
| 85 | + username = bob |
| 86 | + password = sekret |
| 87 | + ssl = True |
| 88 | + |
| 89 | +The supported options are: |
| 90 | + |
| 91 | +==================== ======= ========================================================================================= |
| 92 | +Name Type Description |
| 93 | +==================== ======= ========================================================================================= |
| 94 | +host string IMAP hostname to connect to. |
| 95 | +username string The username to authenticate as. |
| 96 | +password string The password to use with ``username``. |
| 97 | +port int Server port to connect to. Defaults to 143 unless ``ssl`` is True. |
| 98 | +ssl bool Use SSL/TLS to connect. |
| 99 | +starttls bool Use STARTTLS to connect. |
| 100 | +ssl_check_hostname bool If true and SSL is in use, check that certificate matches the hostname (defaults to true) |
| 101 | +ssl_verify_cert bool If true and SSL is in use, check that the certifcate is valid (defaults to true). |
| 102 | +ssl_ca_file string If SSL is true, use this to specify certificate authority certs to validate with. |
| 103 | +timeout int Time out I/O operations after this many seconds. |
| 104 | +oauth2 bool If true, use OAUTH2 to authenticate (``username`` and ``password`` are ignored). |
| 105 | +oauth2_client_id string OAUTH2 client id. |
| 106 | +oauth2_client_secret string OAUTH2 client secret. |
| 107 | +oauth2_refresh_token string OAUTH2 token for refreshing the secret. |
| 108 | +==================== ======= ========================================================================================= |
| 109 | + |
| 110 | +Acceptable boolean values are "1", "yes", "true", and "on", for true; |
| 111 | +and "0", "no", "false", and "off", for false. |
0 commit comments