#!/usr/bin/env python
from setuptools import setup
setup(
  name = 'cs.pop3',
  author = 'Cameron Simpson',
  author_email = 'cs@cskk.id.au',
  version = '20220312',
  url = 'https://bitbucket.org/cameron_simpson/css/commits/all',
  description =
    ('POP3 stuff, particularly a streaming downloader and a simple command line '    
 'which runs it.'),
  long_description =
    ('POP3 stuff, particularly a streaming downloader and a simple command line '    
 'which runs it.\n'    
 '\n'    
 '*Latest release 20220312*:\n'    
 'Make POP3Command.cmd_dl an instance method (static methods broke with the '    
 'latest cs.cmdutils release).\n'    
 '\n'    
 'I spend some time on a geostationary satellite connection,\n'    
 'where round trip ping times are over 600ms when things are good.\n'    
 '\n'    
 'My mail setup involves fetching messages from my inbox\n'    
 'for local storage in my laptop, usually using POP3.\n'    
 'The common standalone tools for this are `fetchmail` and `getmail`.\n'    
 'However, both are very subject to the link latency,\n'    
 'in that they request a message, collect it, issue a delete, then repeat.\n'    
 'On a satellite link that incurs a cost of over a second per message,\n'    
 'making catch up after a period offline a many minutes long exercise in '    
 'tedium.\n'    
 '\n'    
 "This module does something I've been meaning to do for literally years:\n"    
 'a bulk fetch. It issues `RETR`ieves for every message up front as fast as '    
 'possible.\n'    
 'A separate thread collects the messages as they are delivered\n'    
 'and issues `DELE`tes for the saved messages as soon as each is saved.\n'    
 '\n'    
 'This results in a fetch process which is orders of magnitude faster.\n'    
 'Even on a low latency link the throughput is much faster;\n'    
 'on the satellite it is gobsmackingly faster.\n'    
 '\n'    
 '## Class `ConnectionSpec(ConnectionSpec, builtins.tuple)`\n'    
 '\n'    
 'A specification for a POP3 connection.\n'    
 '\n'    
 '*Method `ConnectionSpec.connect(self)`*:\n'    
 'Connect according to this `ConnectionSpec`, return the `socket`.\n'    
 '\n'    
 '*Method `ConnectionSpec.from_spec(spec)`*:\n'    
 'Construct an instance from a connection spec string\n'    
 'of the form '    
 '[`tcp:`|`ssl:`][*user*`@`]*[tcp_host!]server_hostname*[`:`*port*].\n'    
 '\n'    
 'The optional prefixes `tcp:` and `ssl:` indicate that the connection\n'    
 'should be cleartext or SSL/TLS respectively.\n'    
 'The default is SSL/TLS.\n'    
 '\n'    
 '*Property `ConnectionSpec.netrc_entry`*:\n'    
 'The default `NetrcEntry` for this `ConnectionSpec`.\n'    
 '\n'    
 '*Property `ConnectionSpec.password`*:\n'    
 'The password for this connection, obtained from the `.netrc` file\n'    
 'via the key *user*`@`*host*`:`*port*.\n'    
 '\n'    
 '## Class `NetrcEntry(NetrcEntry, builtins.tuple)`\n'    
 '\n'    
 'A `namedtuple` representation of a `netrc` entry.\n'    
 '\n'    
 '*Method `NetrcEntry.by_account(account_name, netrc_hosts=None)`*:\n'    
 'Look up an entry by the `account` field value.\n'    
 '\n'    
 '*Method `NetrcEntry.get(machine, netrc_hosts=None)`*:\n'    
 'Look up an entry by the `machine` field value.\n'    
 '\n'    
 '## Class `POP3(cs.resources.MultiOpenMixin, '    
 'cs.context.ContextManagerMixin)`\n'    
 '\n'    
 'Simple POP3 class with support for streaming use.\n'    
 '\n'    
 '*Method `POP3.client_auth(self, user, password)`*:\n'    
 'Perform a client authentication.\n'    
 '\n'    
 '*Method `POP3.client_begin(self)`*:\n'    
 'Read the opening server response.\n'    
 '\n'    
 '*Method `POP3.client_bg(self, rq_line, is_multiline=False, notify=None)`*:\n'    
 'Dispatch a request `rq_line` in the background.\n'    
 'Return a `Result` to collect the request result.\n'    
 '\n'    
 'Parameters:\n'    
 '* `rq_line`: POP3 request text, without any terminating CRLF\n'    
 '* `is_multiline`: true if a multiline response is expected,\n'    
 '  default `False`\n'    
 '* `notify`: a optional handler for `Result.notify`,\n'    
 '  applied if not `None`\n'    
 '\n'    
 '*Note*: DOES NOT flush the send stream.\n'    
 'Call `self.flush()` when a batch of requests has been submitted,\n'    
 'before trying to collect the `Result`s.\n'    
 '\n'    
 'The `Result` will receive `[etc,lines]` on success\n'    
 'where:\n'    
 '* `etc` is the trailing portion of an ok response line\n'    
 '* `lines` is a list of unstuffed text lines from the response\n'    
 '  if `is_multiline` is true, `None` otherwise\n'    
 'The `Result` gets a list instead of a tuple\n'    
 'so that a handler may clear it in order to release memory.\n'    
 '\n'    
 'Example:\n'    
 '\n'    
 "    R = self.client_bg(f'RETR {msg_n}', is_multiline=True, notify=notify)\n"    
 '\n'    
 '*Method `POP3.client_dele_bg(self, msg_n)`*:\n'    
 'Queue a delete request for message `msg_n`,\n'    
 'return ` Result` for collection.\n'    
 '\n'    
 '*Method `POP3.client_quit_bg(self)`*:\n'    
 'Queue a QUIT request.\n'    
 'return ` Result` for collection.\n'    
 '\n'    
 '*Method `POP3.client_retr_bg(self, msg_n, notify=None)`*:\n'    
 'Queue a retrieve request for message `msg_n`,\n'    
 'return ` Result` for collection.\n'    
 '\n'    
 'If `notify` is not `None`, apply it to the `Result`.\n'    
 '\n'    
 '*Method `POP3.client_uidl(self)`*:\n'    
 'Return a mapping of message number to message UID string.\n'    
 '\n'    
 '*Method `POP3.dl_bg(self, msg_n, maildir, deleRs)`*:\n'    
 'Download message `msg_n` to Maildir `maildir`.\n'    
 'Return the `Result` for the `RETR` request.\n'    
 '\n'    
 'After a successful save,\n'    
 'queue a `DELE` for the message\n'    
 'and add its `Result` to `deleRs`.\n'    
 '\n'    
 '*Method `POP3.flush(self)`*:\n'    
 'Flush the send stream.\n'    
 '\n'    
 '*Method `POP3.get_multiline(self)`*:\n'    
 'Generator yielding unstuffed lines from a multiline response.\n'    
 '\n'    
 '*Method `POP3.get_ok(self)`*:\n'    
 "Read server response, require it to be `'OK+'`.\n"    
 'Returns the `etc` part.\n'    
 '\n'    
 '*Method `POP3.get_response(self)`*:\n'    
 'Read a server response.\n'    
 'Return `(ok,status,etc)`\n'    
 "where `ok` is true if `status` is `'+OK'`, false otherwise;\n"    
 '`status` is the status word\n'    
 'and `etc` is the following text.\n'    
 'Return `(None,None,None)` on EOF from the receive stream.\n'    
 '\n'    
 '*Method `POP3.readline(self)`*:\n'    
 'Read a CRLF terminated line from `self.recvf`.\n'    
 'Return the text preceeding the CRLF.\n'    
 'Return `None` at EOF.\n'    
 '\n'    
 '*Method `POP3.readlines(self)`*:\n'    
 'Generator yielding lines from `self.recf`.\n'    
 '\n'    
 '*Method `POP3.sendline(self, line, do_flush=False)`*:\n'    
 'Send a line (excluding its terminating CRLF).\n'    
 'If `do_flush` is true (default `False`)\n'    
 'also flush the sending stream.\n'    
 '\n'    
 '*Method `POP3.shutdown(*a, **kw)`*:\n'    
 'Quit and disconnect.\n'    
 '\n'    
 '*Method `POP3.startup(*a, **kw)`*:\n'    
 'Connect to the server and log in.\n'    
 '\n'    
 '## Class `POP3Command(cs.cmdutils.BaseCommand)`\n'    
 '\n'    
 'Command line implementation for POP3 operations.\n'    
 '\n'    
 'Credentials are obtained via the `.netrc` file presently.\n'    
 '\n'    
 'Connection specifications consist of an optional leading mode prefix\n'    
 'followed by a netrc(5) account name\n'    
 'or an explicit connection specification\n'    
 'from which to derive:\n'    
 '* `user`: the user name to log in as\n'    
 '* `tcp_host`: the hostname to which to establish a TCP connection\n'    
 '* `port`: the TCP port to connect on, default 995 for TLS/SSL or 110 for '    
 'cleartext\n'    
 '* `sni_host`: the TLS/SSL SNI server name, which may be different from the '    
 '`tcp_host`\n'    
 '\n'    
 'The optional mode prefix is one of:\n'    
 '* `ssl:`: use TLS/SSL - this is the default\n'    
 '* `tcp:`: use cleartext - this is useful for ssh port forwards\n'    
 '  to some not-publicly-exposed clear text POP service;\n'    
 '  in particular streaming performs better this way,\n'    
 '  I think because the Python SSL layer does not buffer writes\n'    
 '\n'    
 'Example connection specifications:\n'    
 '* `username@mail.example.com`:\n'    
 '  use TLS/SSL to connect to the POP3S service at `mail.example.com`,\n'    
 '  logging in as `username`\n'    
 '* `mail.example.com`:\n'    
 '  use TLS/SSL to connect to the POP3S service at `mail.example.com`,\n'    
 '  logging in with the same login as the local effective user\n'    
 '* `tcp:username@localhost:1110`:\n'    
 '  use cleartext to connect to `localhost:1110`,\n'    
 '  typically an ssh port forward to a remote private cleartext POP service,\n'    
 '  logging in as `username`\n'    
 '* `username@localhost!mail.example.com:1995`:\n'    
 '  use TLS/SSL to connect to `localhost:1995`,\n'    
 '  usually an ssh port forward to a remote private TLS/SSL POP service,\n'    
 '  logging in as `username` and passing `mail.exampl.com`\n'    
 '  as the TLS/SSL server name indication\n'    
 '  (which allows certificate verification to proceed correctly)\n'    
 '\n'    
 'Note that the specification may also be a `netrc` account name.\n'    
 'If the specification matches such an account name\n'    
 'then values are derived from the `netrc` entry.\n'    
 "The entry's `machine` name becomes the TCP connection specification,\n"    
 "the entry's `login` provides a default for the username,\n"    
 "the entry's `account` host part provides the `sni_host`.\n"    
 '\n'    
 'Example `netrc` entry:\n'    
 '\n'    
 '    machine username@localhost:1110\n'    
 '      account username@mail.example.com\n'    
 '      password ************\n'    
 '\n'    
 'Such an entry allows you to use the specification '    
 '`tcp:username@mail.example.com`\n'    
 'and obtain the remaining detail via the `netrc` entry.\n'    
 '\n'    
 'Command line usage:\n'    
 '\n'    
 '    Usage: pop3 subcommand [...]\n'    
 '      Subcommands:\n'    
 '        dl [{ssl,tcp}:]{netrc_account|[user@]host[!sni_name][:port]} '    
 'maildir\n'    
 '        help [-l] [subcommand-names...]\n'    
 '          Print the full help for the named subcommands,\n'    
 '          or for all subcommands if no names are specified.\n'    
 '          -l  Long help even if no subcommand-names provided.\n'    
 '\n'    
 '*Method `POP3Command.cmd_dl(self, argv)`*:\n'    
 'Collect messages from a POP3 server and deliver to a Maildir.\n'    
 '\n'    
 'Usage: {cmd} [{{ssl,tcp}}:]{{netrc_account|[user@]host[!sni_name][:port]}} '    
 'maildir\n'    
 '\n'    
 '# Release Log\n'    
 '\n'    
 '\n'    
 '\n'    
 '*Release 20220312*:\n'    
 'Make POP3Command.cmd_dl an instance method (static methods broke with the '    
 'latest cs.cmdutils release).\n'    
 '\n'    
 '*Release 20211208*:\n'    
 '* POP3.startup: do not start the worker queue until authenticated.\n'    
 '* POP3.get_response: return (None,None,None) at EOF.\n'    
 '* POP3.shutdown: catch exceptions from client QUIT.\n'    
 '\n'    
 '*Release 20210407.2*:\n'    
 'Provide "pop3" console_script.\n'    
 '\n'    
 '*Release 20210407.1*:\n'    
 'Bump for cs.cmdutils minor bugfix, also fix a few docstring typos.\n'    
 '\n'    
 '*Release 20210407*:\n'    
 'Initial PyPI release.'),
  install_requires = ['cs.cmdutils>=20210407.1', 'cs.lex', 'cs.logutils', 'cs.pfx', 'cs.queues', 'cs.resources', 'cs.result>=20210407', 'cs.threads'],
  classifiers = ['Programming Language :: Python', 'Programming Language :: Python :: 3', 'Environment :: Console', 'Topic :: Communications :: Email :: Post-Office :: POP3', 'Topic :: Internet', 'Topic :: Utilities', 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Operating System :: OS Independent', 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)'],
  entry_points = {'console_scripts': ['pop3 = cs.pop3:POP3Command.run_argv']},
  keywords = ['python3'],
  license = 'GNU General Public License v3 or later (GPLv3+)',
  long_description_content_type = 'text/markdown',
  package_dir = {'': 'lib/python'},
  py_modules = ['cs.pop3'],
)
