Managesieve command-line client
sieve-connect [-s <hostname>] [-p <portspec>] [-u <user>] [a <authzid>] [-m <authmech>] [-r realm] [-e execscript] [... longopts ...] sieve-connect [--localsieve <script>] [--remotesieve <script>] [--debug] [--dumptlsinfo] [--server <hostname>] [--port <portspec>] [--4|--6] [--user <authentication_id>] [--authzid <authzid>] [--realm <realm>] [--passwordfd <n>] [--clientkey <file> --clientcert <file>]|[--clientkeycert <file>] [--notlsverify|--nosslverify] [--tlscertfingerprint|--sslcertfingerprint <dgsttype:digest>] [--tlscapath <ca_directory>]|[--tlscafile <ca_file>] [--noclearauth] [--noclearchan] [--authmech <mechanism>] [--ignoreserverversion] [--upload|--download|--list|--delete|--checkscript|--edit| --activate|--deactivate]|[--exec <script>] [--help|--man]
sieve-connect is a client for the \*(C`MANAGESIEVE\*(C' protocol, which is an RFC-specified protocol for manipulation of \*(C`Sieve\*(C' scripts in a repository. More simply, sieve-connect lets you control your mail-filtering rule files on a mail server.
sieve-connect can be invoked with an action from the command-line to make it easy to script one-shot actions, it can be provided with a script file or it can be left to enter an interactive command-loop, where it supports tab-completion (if the supporting Perl module is available) and basic navigation of the local file-system in the style of \*(C`FTP\*(C' clients.
sieve-connect supports the use of \*(C`TLS\*(C' via the \*(C`STARTTLS\*(C' command, including authentication via client certificates. \*(C`sieve-connect\*(C' also supports whichever \*(C`SASL\*(C' mechanisms your Authen::SASL::Perl library provides, as long as they do not require \s-1SASL\s0 protection layers.
In Interactive mode, a \*(C`help\*(C' command is available. Command parameters with a \*(C`%\*(C' in them are examined to see if they match %KEYWORD, where \*(C`KEYWORD\*(C' is always in upper-case. The list of keywords may be retrieved with the \*(C`keywords\*(C' command and includes items such as %DATE, %USER, etc.
Option names may be given as the shortest unique prefix.
The remote sieve script name defaults to the same as the local sieve script name, so just specify the local one if only one is needed; it was a deliberate decision to have the defaults this way around, to make people think about names in the local filesystem. There is no default script name.
The --debug option turns on diagnostic traces. The --debugsasl option asks the \s-1SASL\s0 library for debugging. The --dumptlsinfo shows the \s-1TLS\s0 (\s-1SSL\s0) peer information; if specified together with --debug then the server's \s-1PEM\s0 certificate will be provided as debug trace.
The --version option shows version information. When combined with --debug it will show implementation dependency versions. The --help and --man options provide usage information.
The server can be a host or \s-1IP\s0 address, IPv4 or IPv6.
If a server is provided by --server then that takes precedence. If that option is not present, then $IMAP_SERVER from the environment is checked and, if it's not a unix-domain socket path, is used with any port specification stripped off.
Next, unless --nosrv is given, checks are made for \s-1SRV\s0 records so as to search for a default server; if the Mozilla::PublicSuffix Perl module is available, these checks are done for every level of the hostname upto (but not including) the public suffix. If that module is not available, a crude heuristic is used: as long as there are three dots in the hostname, \s-1SRV\s0 records for the part of the hostname after the first dot are tried. If this is inappropriate, install Mozilla::PublicSuffix.
If no \s-1SRV\s0 records are found which point to a 'sieve', 'imaps' or 'imap' protocol service, of if a record is found which says \*(L"no such service in this domain\*(R" (by having a target of \*(L".\*(R"), then the final default server is localhost.
The port can be any Perl port specification, default is sieve(4190). A port from an \s-1SRV\s0 record will take precedence. The Perl specification provides a name to look up in the system services database (/etc/services) followed in parentheses by a default value to use if the name is not found. Thus this default will honour a value of 2000 from /etc/services.
The --4 or --6 options may be used to coerce IPv4 or IPv6.
By default, the server is taken to be a domain, for which \s-1SRV\s0 records are looked up; use --nosrv to inhibit \s-1SRV\s0 record lookup.
The --user option will be required unless you're on a Unix system with getpwuid() available and your Cyrus account name matches your system account name. --authmech can be used to force a particular authentication mechanism. --authzid can be used to request authorisation to act as the specified id. --realm can be used to try to pass realm information to the authentication mechanism. If you want to provide a password programmatically, use --passwordfd to state which file descriptor (typically 0) the password can be read from. Everything until the newline before \s-1EOF\s0 is the password, so it can contain embedded newlines. Do not provide passwords on a command-line or in a process environment.
Unless modified at install/packaging time, by default \s-1SSL\s0 certificate authority certificates are searched for. The first attempt is to try, in turn, for environment variables $SSL_CERT_DIR & $SSL_CERT_FILE which are the names supported by the OpenSSL library and so often supported by client commands. Next, if the OpenSSL command \*(C`version\*(C' is available and the output \*(C`OPENSSLDIR\*(C' can be parsed and the \*(C`certs\*(C' directory exists within that directory, then that location will be used. Finally, a fixed list of common locations are searched and the first one to exist is used. Invoking with --debug will show more details during the \*(C`setup:\*(C' phase.
Precedence above these defaults is given to the --tlscafile option if given, else the --tlscapath option if that is given. The former is one file containing certificates, the latter is a directory.
Alternatively, if you are willing to accept the risk of man-in-the-middle active attacks and you are unable to arrange for the relevant Certificate Authority certificate to be available, then you can lower your safety with the --notlsverify option, also spelt --nosslverify.
If you don't want to (only) rely on \s-1CA\s0 systems you can explicitly set an expected server certificate fingerprint using the --tlscertfingerprint option, also spelt --sslcertfingerprint. If you wish to ignore \s-1CA\s0 validation, you still need to disable that explicitly (see above), as the default is to add an extra constraint (pinning, within valid \s-1CA\s0 certificates). This option specifies the X.509 certificate fingerprint (not a public key fingerprint), as given by OpenSSL. The first part of the value should be an algorithm name, such as \*(C`sha256\*(C' or \*(C`sha1\*(C'. That is followed by a colon, and then the fingerprint data in its usual colon-delimited hexadecimal notation. Eg: \*(C`--tlscertfingerprint sha256:24:B4:..28-more-fields..:A8:58\*(C'
For \s-1SSL\s0 client certificate authentication, either --clientkeycert may be used to refer to a file with both the key and cert present or both --clientkey and --clientcert should point to the relevant files. The data should be in \s-1PEM\s0 file-format.
The --noclearauth option will prevent use of cleartext authentication mechanisms unless protected by \s-1TLS\s0. The --noclearchan option will mandate use of some confidentiality layer; at this time only \s-1TLS\s0 is supported.
By default, the server's \*(L"\s-1VERSION\s0\*(R" capability will be used to filter the commands available. Use --ignoreserverversion to prevent this.
The remaining options denote actions. One, and only one, action may be present. If no action is present, the interactive mode is entered. If the exec action is present, commands are read from the script instead.
Note that --check and --edit require a server which advertises a \*(L"\s-1VERSION\s0\*(R" capability, see --ignoreserverversion to override.
(If --server is not explicitly stated, it may be provided at the end of the command-line for compatibility with sieveshell.)
$IMAP_SERVER for a default \s-1IMAP\s0 server.
$USERNAME and $LOGNAME where the \*(C`getpwuid()\*(C' function is not available.
$SSL_CERT_DIR and $SSL_CERT_FILE for locating default Certificate Authority trust anchors.
$VISUAL, else $EDITOR, for the edit action.
If the authentication protocol negotiates a protection layer then things will rapidly Go Bad. A mitigating factor is that no protection layer should be negotiated whilst under \s-1STARTTLS\s0 protection. Just use \s-1TLS\s0!
When listing scripts, the format is based upon the raw server output, assuming that the server uses quoted-strings for the script names. The output is just passed back on the basis that it's a fairly good interface to pass to a program. But a server could choose to use literal strings, even though the results are defined as line-break separated \*(-- that would mean that some linebreaks are special. Hopefully no server will do this.
If sieve-connect fails to connect to an IPv4 server without the -4 option being explicitly passed, then you've encountered a portability issue in the IO::Socket::INET6 Perl library and need to upgrade that.
Most historical implementations used port 2000 for ManageSieve. \s-1RFC5804\s0 allocates port 4190. This tool uses a port-spec of \*(L"sieve(4190)\*(R" as the default port, which means that an /etc/services (or substitute) entry for \*(L"sieve\*(R" as a \s-1TCP\s0 service takes precedence, but if that is not present, will assume 4190 as the default. This change means that if you're still using port 2000 and do not have an /etc/services entry, updating to/beyond release 0.75 of this tool will break invocations which do not specify a port. The specification of the default port was moved to the user-configurable section at the top of the script and administrators may wish to override the shipped default. You can bypass all of this mess by publishing \s-1SRV\s0 records, per \s-1RFC5804\s0.
The Net::DNS Perl module does not (at time of writing) provide full support for weighted prioritised \s-1SRV\s0 records and I have not made any effort to fix this; whatever the default sort algorithm provides for \s-1SRV\s0 is what is used for ordering.
If you don't specify a server and don't export $IMAP_SERVER in the environment then the search mechanism is safer and more thorough if the Mozilla::PublicSuffix Perl module is installed. In particular, if your hostname is also your domain name and the parent domain is administered by someone you don't trust, then you'll regret not installing that module.
Probably need to sit down and work through the final \s-1RFC\s0 and see if any functionality is still missing.
Actually uses \s-1STARTTLS\s0. Can handle script names with embedded whitespace. Author needs access to a server which handles embedded quote characters properly to complete testing of that.
sieve-connect was written as a demonstration for the \*(C`info-cyrus\*(C' mailing-list, 2006-11-14. It was a single-action-and-quit script for scripting purposes. The command-loop code was written (two days) later and deliberately designed to be compatible with sieveshell.
Versions prior to 0.85 did not actually verify the peer certificate identity, although this author stupidly believed that it did. API/expectations mismatch.
Phil Pennock <[email protected]> is guilty, m'Lud.
There is a low-volume announcement list for new releases; the web interface is at http://mail.globnix.net/mailman/listinfo/sieve-connect-announce <http://mail.globnix.net/mailman/listinfo/sieve-connect-announce> or you can send mail, mailto:[email protected]?subject=subscribe <mailto:[email protected]?subject=subscribe>
Perl. Authen::SASL. IO::Socket::INET6. IO::Socket::SSL (at least version 1.14). Pod::Usage. Net::DNS for \s-1SRV\s0 lookup. Pod::Simple::Text for built-in man command (optional). Term::ReadKey to get passwords without echo. Various other Perl modules which are believed to be standard. Term::ReadLine will significantly improve interactive mode. Term::ReadLine::Gnu will improve it further by allowing tab-completion. Mozilla::PublicSuffix is highly recommended and will improve security.
sieve-connect is regularly tested with the timsieved server distributed with the Cyrus \s-1IMAP\s0 server. Further interoperability testing is underway, more is desired (test accounts appreciated!).