# S-nail

S-nail is a mail processing system with a command syntax reminiscent of ed with lines replaced by messages. It is intended to provide the functionality of the POSIX mailx command and offers (mostly optional) extensions for line editing, IDNA, MIME, S/MIME, SMTP and POP3 (and IMAP). It is usable as a mail batch language. This manual was written based on version v14.7.1 of S-nail, and assumes that the configuration option v15-compat is set.

## Sending mail with an external SMTP server

Configuration files are `$HOME/.mailrc` and the systemwide `/etc/mail.rc`. Add the following text to the appropriate file, changing bold strings:

    # ArchLinux-specific locations of certificates
    set ssl-ca-dir=/etc/ssl/certs
    set ssl-verify=strict

    # To save a copy of sent messages somewhere
    set record=sentmail.mbox

    # This may be interesting to gain some speedup when sending mail
    set mimetypes-load-control

    # This is optional, but you should get the big picture
    # by reading the manual before you leave that off
    set from="Your Name <youremail@domain>"

    # It may be necessary to set hostname and/or smtp-hostname
    # if the "SERVER" of smtp and "domain" of from don't match.
    # Reading the "URL syntax" and smtp manual entries may be worthwhile,
    # but NOTE that USER and PASS must be URL percent encoded -
    # S-nail offers the urlencode STRING command which helps
    set smtp=(smtp[s]/submission)://[USER[:PASS]@]SERVER[:PORT] \
        smtp-auth=login/plain... \
        smtp-use-starttls

    # E.g. here is a real life example of a very huge free mail provider
    # The plain smtp:// proto is optional
    set smtp=USER:PASS@smtp.gmXil.com smtp-auth=plain smtp-use-starttls

    # And here is a pretty large one which does not allow sending mails
    # if there is a domain name mismatch on the SMTP protocol level,
    # which would bite us if the value of from does not match, e.g.,
    # for people who have a sXXXXeforge project and want to speak
    # with the mailing list under their project account (in from),
    # still sending the message through their normal mail provider
    set smtp=smtps://USER:PASS@smtp.yaXXex.ru:465 smtp-auth=plain \
        hostname=yaXXex.com smtp-hostname=

It is possible to define multiple accounts by using the account command; see the manual page for details. Note that, when storing passwords in `$HOME/.mailrc`, you should set appropriate permissions with `chmod 0600`. When you set the netrc-lookup option you can as well store user credentials in `$HOME/.netrc` (or $NETRC) instead; e.g., here is a real life example that sets up SMTP, POP3 as well as IMAP, storing all user credentials in a separate file:

    set v15-compat netrc-lookup
    set smtp=smtps://smtp.yXXXXx.ru:465 smtp-auth=plain smtp-hostname= \
            hostname=yXXXXx.com
    set pop3-keepalive=240
    ghost xp 'fi pop3s://pop.yXXXXx.ru'
    set imap-keepalive=240
    ghost xi 'fi imaps://imap.yXXXXx.ru'

and, in `$HOME/.netrc`:

    machine *.yXXXXx.ru login USER password PASS

### Testing and sending emails

To test the configuration as above:

    $ echo "message" | mailx -vv -s "subject" receiver@mail.com

## Configuration and interactive usage

The ArchLinux version of S-nail includes the builtin command line editor with history capabilities as well as regular expression and coloured message display support. Because S-nail strives for POSIX standard compliance some settings have to be adjusted before using it interactively doesn't baffle all descriptions, however. Reading the lengthy and yet still pretty awkward manual is unavoidable, but, at a minimum:

    # (The template configuration /etc/mail.rc also provides some commented basics;
    # in particular it shows all options that POSIX mandates at program startup)

    # Start into interactive mode even if the standard mailbox is empty
    set emptystart

    # Default directory where we act in (relative to $HOME), list content with folder command
    set folder=mail
    # The MBOX file -- the leading `+' means "relative to folder"
    set MBOX=+mbox

    set DEAD=+dead

    # When composing a message, let period `.' on a line by itself finalize composition,
    # before start directly into $EDITOR
    set dot
    set editalong

    # Start $PAGER when a message is longer than VALUE lines; without VALUE: screen $LINES
    set crt=

    # Colourize headers when displaying messages (note that $PAGER may require special flags,
    # e.g., less(1) needs the -R option; S-nail will however set the $LESS environment
    # variable accordingly, but only if that was not set before..)
    set colour-pager

    # A nicer prompt
    set prompt="\033[31m?\?[\$ \@]\& \033[0m"

    # Add more entries to the history
    set history-gabby

    # Make the history persistent
    set NAIL_HISTFILE=+.s-nailhist
    set NAIL_HISTSIZE=-1

    # When displaying messages, show only these headers
    retain date from to cc subject

    # Try to get around weird MIME attachment specifications
    set mime-counter-evidence

    # Force some MIME attachments to be displayed as raw text
    # (instead of simply not being displayed at all).
    # Look once at the output of the command mimetypes (or try: ?mime)
    set pipe-application/javascript=@
    set pipe-application/json=@
    set pipe-application/x-latex=@
    set pipe-application/x-perl=@
    set pipe-application/x-sh=@
    set pipe-application/x-shar=@
    set pipe-application/x-tex=@
    set pipe-application/x-texinfo=@
    set pipe-application/x-xfig=@

    # Display HTML parts inline
    #set pipe-text/html="lynx -stdin -dump -force_html"

    # Create some new commands so that, e.g., `ls /tmp' will..
    ghost ls '!ls -latro'
    ghost ps '!ps axu'

Once you're in it, the command list will print all available builtin commands. ArchLinux compiles in the "DOCSTRINGS" feature, so that typing `?X' tries to expand "X" and print a help string; since S-nail will allow abbreviations of all commands this is sometimes handy; try, e.g., ?h, ?he and ?hel ... The command help will print a short summary of the most frequent used commands.

### Viewing messages

When starting into interactive mode a summary of the content of the initially opened mailbox is printed, via the headers command. In here messages are given numbers (starting at 1) which uniquely identify messages. Messages can be printed with the print command, or short: p. By default the current message (dot) is printed, but just like with many other commands it is possible to specify lists of messages, as is documented in the manual section "Specifying messages"; e.g., p:u will display all unread messages, p. will print the dot, p 1 5 will print the messages 1 and 5 and p- and p+ will print the last and the next message, respectively. The command from (f) is nice for an overview, e.g., f '@<@arch linux' will print the header summary of all messages that contain the string "arch linux" in some message header, whereas f '@arch linux' will only match those with "arch linux" in their subject; finally, f @u[^[:space:]]+e finds... well, nothing at the moment; that is, be aware that quoting may be necessary when there is whitespace in search expressions etc. Dependend on the terminal you are using the command line editor will offer shortcuts to more easily scroll through the header display.

- newmail prints listing of new messages
- he (headers) reprints the message list
- z-, z+, Z pages the message list
- folders shows listing of mailboxes
- folder or fi changes the mailbox file
- r replies to all
- R replies to the sender
- move or mv moves a message
- (un)flag marks a message as (un)flagged
- new marks a message unread
- seen marks it read
- P prints a message with all headers
- p prints a message and all non-ignored headers.

### Message composition

Composition is started by typing mail user@host or by replying to a message. When you return from $EDITOR you will be placed into the native editor, where many operations can be performed using tilde escapes (listed by ~?). Of particular interest is ~@, which allows the attachment list to be edited.

To send the mail, signal EOT with `Ctrl+d` or type "." on its own line (the latter requires the dot option).

## Using an IMAP mailbox

The following is only a quick hint, it is also possible to define folder to point to an IMAP server folder, for example.

    # or many servers will expire the session
    set imap-keepalive=240
    set imap-cache=~/.imap_cache

    # You may want to define shortcuts to folders, for example:
    shortcut myimap "imaps://USER:PASS@server:port"

Category:

- Email clients