\chapter{\masqmail}

%TODO: have text by oliver here?


\section{Target field}
Its original author, Oliver Kurth, sees \masqmail\ so:
\begin{quote}
MasqMail is a mail server designed for hosts that do not have a permanent internet connection eg. a home network or a single host at home. It has special support for connections to different ISPs. It replaces sendmail or other MTAs such as qmail or exim.
\end{quote}

\masqmail\ is inteded to cover a specific niche: non-permanent internet connection and different \NAME{ISP}s.

Although it can basically replace other \MTA{}s, it is not generally aimed to do so. The package description of \debian\citeweb{packages.debian:masqmail} states this more clearly by changing the last sentence to:
\begin{quote}
In these cases, MasqMail is a slim replacement for full-blown MTAs such as sendmail, exim, qmail or postfix.
\end{quote}
\masqmail\ is a good replacement ``in these cases'', but not generally, since is lacks features essential for running on mail servers. It is primarily not secure enough for being accessable from untrusted locations.

The program is best used in home networks, which are non-permanently connected to the internet. \masqmail\ sends mail to local destinations, like users on the same machine and on other machines in the local net, immediately. Email to recipients outside the local net are queued when offline and sent when a online connection gets established.

Further more does \masqmail\ respect online connections through different \NAME{ISP}s; a common thing for dial-up connections. In particular can different sender addresses be set, dependent on the \NAME{ISP} that is used. This prevents mail to be likely classified as spam.



\section{Typical usage}
This section describes situations that make senseful use of \masqmail.

A home network consisting of some workstations without a server. The network is connected to the internet by dial-up or broadband. Going online is initiated by computers inside the local net. \NAME{IP} addresses change at least once every day.

Every workstation would be equiped with \masqmail. Mail transfer within the same machine or within the local net works straight forward. Outgoing mail to the internet is sent, to the concerning \NAME{ISP} for relaying, whenever the router goes online. Receiving of mail from outside needs to be done by a mail fetch program, like the \masqmail\ internal \NAME{POP3} client or \name{fetchmail} for example. The configuration for \masqmail\ would be the same on every computer, except the hostname.

For the same network but having a server, one could have \masqmail\ running on the server and using simple forwarders (see \ref{subsec:relay-only}) to the server on the workstations. This setup does only support mail transfer to the server, but not back to a workstation; also sending mail to another user on the same workstation is not possible.

A better setup is to run \masqmail\ on every machine %FIXME



\section{What makes it special}

As main advantage, \masqmail\ makes it easy to set up an \MTA\ on workstations or notebooks without the need to do complex configuration or to be an mail server expert.

Workstations use %FIXME


\section{Alternatives?}
% http://anfi.homeunix.org/sendmail/dialup10.html


\section{Structure}
Like its anchestor \sendmail, \masqmail\ is a monolitic program. It consists of only one \emph{setuid root}\footnote{Runs as user root, no matter which user invoked it.}\index{setuid root} binary file, named \path{masqmail}. All functionality is included in it; of course some more comes from dynamic libraries linked.

The \masqmail\ executable can be called under various names for \name{sendmail-compatibility} reasons. This is commonly organized by creating symbolic links with with different names to the \masqmail\ executable. These are \path{/usr/lib/sendmail} and \path{/usr/sbin/sendmail} because many programs expect a \mta\ to be located there. Further more \sendmail\ provides shortcuts by calling it with a different name instead of supplying command line arguments. The best known of it is \path{mailq}, which is equivilent to calling the \MTA\ with the argument \verb+-bq+. \masqmail\ reacts to the names \path{mailq}, \path{smtpd}, \path{mailrm}, \path{runq}, \path{rmail}, and \path{in.smtpd}. The last four are an addition to \sendmail. Not implemented is the name \path{newaliases} because it is not relevant to \masqmail. To provide the command nonetheless, one may write a shell script located at \path{/usr/bin/newaliases}, that simply invokes \verb+masqmail -bi+.

%masqmail: mailq, mailrm, runq, rmail, smtpd/in.smtpd
%sendmail: hoststat, mailq, newaliases, purgestat, smtpd

\masqmail\ is written in the \NAME{C} programming language. The program, as of version 0.2.21, consists of 34 source code and eight header files, containing about 9,000 lines of code\footnote{Measured with \name{sloccount} by David A.\ Wheeler.}. Additionally, it includes a \name{base64} implementation (about 300 lines) and \name{md5} code (about 150 lines). For systems that do not provide \name{libident}, this library is distributed as well (circa 600 lines); an available shared library however has higher precedence in linking.

The only mandatory dependency is \name{glib}---a cross-platform software utility library, originated in the \NAME{GTK+} project. It provides safer replacements for many standard library functions. (The unsafe \verb+sprintf()+ is one example.) Also it offers handy data containers, easy-to-use implementations of data structures, and much more.

With \masqmail\ comes the small tool \path{mservdetect}; it helps setting up a configuration that uses the \name{mserver} system to detect the online state. Two other binaries get compiled for testing purposes: \path{readtest} and \path{smtpsend}. All three programms use \masqmail\ source code; they only add a file with a \verb+main()+ function each.

\masqmail\ does not provide an interface for modules with additional functionality. There exists no add-on or module system. But the code is separated by function to the various source files, and some functional parts can be included or excluded by defining symbols. This means adding some argument (like \verb+--enable-maildir+) to the \verb+configure+ call. Thus the concerning code gets not removed by the preprocessor.


\section{Features}
First of all \masqmail\ is an \MTA. Therefor it accepts mail on the command line and via \SMTP. Mail queueing and alias expansion is supported. \masqmail\ is able to deliver mail to local mailboxes (in \name{mbox} or \name{maildir} format) or pass it to a \name{mail delivery agent} (like \name{procmail}). Mail destinated to remote locations is sent via \SMTP. Outgoing \SMTP\ connections feature \name{SMTP-Auth} and \name{SMTP-after-POP} authentication, but incoming \SMTP\ does not.

As \masqmail\ is focused on non-permanent Internet connections, online state can be queried by three methods: reading from a file, reading the output of a command, or by asking an \name{mserver}. Each method may return a string indicating one of the available routes being online, or returning nothing to indicate offline state.

Delivery to recipients on the local host or in local nets is done at once; delivery to recipients on the Internet is only done when being online, and queued otherwise. Each online route may have a different mail server to which mail is relayed. Return address headers are modified appropriate if wished.

Additional to the \mta\ job, \masqmail\ also offers mail retrieval services with being a \NAME{POP3} client. Thus it can fetch mail from remote locations, dependent on the active online route.



\section{History}
%TODO: let oliver prove read it!
%FIXME: add references

The date of the first release (version 0.0.1) is unknown.
The only information available is, that it was packaged for \debian\ at 15\nth\ of September in 1999.
Further releases were made every few weeks or month during 2000, 2001 and 2002.
Development ended in mid-2003 in a hard stop.
The last ordinary release known to me is version 0.2.20, released on 4\nth\ of June in 2003.

During the time of development, Oliver released 53 versions.
That means a new release in less than every 20 days in average!

Mentionable are the four \emph{beta} releases of version 0.1.8 (named with the trailing letters `a' to `d') in winter 2000/2001 and the security-fix 0.1.15.1 in 2002.

One extra release (version 0.2.21) was made by him in November 2005.
This one is only available from the \debian\ pool.
Comparing it to version 0.2.20 shows, that no source code was altered.
Only building documents (like Makefiles) and \debian\ packageing documents were changed.
That leeds to the assumption that this last release was specificly created for the needs of \debian---to fix some errors in the package.

In May 2000 the minor version number increased to `1'.
Nothing special is mentioned in the documentation about that.
When it increased again to start the 0.2.x releases, Oliver titled them as the ``development branch'' of \masqmail.
At that second time, he started developing the 0.2.x ``development branch'', continuing to work on the 0.1.x series.
His parallel work on both branches lasted for four month, and one additional last release, numbered 0.1.17, one more year later.

