636 Commits

Author SHA1 Message Date
Alberto Bertogli
69222284e0 test: Rename test directories to use an explicit order
For convenience, rename the directories so the order is explicit in the name.
Make the simple test run first, to save time if it's not working.
2016-09-12 04:06:56 +01:00
Alberto Bertogli
2c90281c11 test: Add top-level README and run script 2016-09-12 04:06:56 +01:00
Alberto Bertogli
905161c537 test: Add a test for Exim interactions
This patch adds a new test which makes chasquid send and receive email to/from
Exim.

To make it work we need to add two testing flags to the SMTP courier, which is
not ideal but doesn't muddle the code much.

The test is not very portable, and assumes an exim binary is available, but
does not have to be installed in the system. It includes a helper script to
fetch one from the Debian archives.
2016-09-12 04:06:56 +01:00
Alberto Bertogli
aac2d3c061 Minor style and simplification cleanups
This patch does various minor style and simplification cleanups, fixing things
detected by tools such as go vet, gofmt -s, and golint.

There are no functional changes, this change is purely cosmetic, but will
enable us to run those tools more regularly now that their output is clean.
2016-09-12 04:06:56 +01:00
Alberto Bertogli
92a88bd06f test: Add a new local end-to-end test
This patch introduces a new directory, test/, which contains a simple local
end-to-end test which runs a chasquid binary and uses msmtp to send an email,
which is delivered locally.

As it's the first one, it adds a bunch of common infrastructure to simplify
writing these kinds of tests.

More end-to-end tests will follow, and it's expected that the common
infrastructure will also change significantly to accomodate their needs.
2016-09-12 04:06:56 +01:00
Alberto Bertogli
92d16a0ca9 Add a new "chasquid-userdb" command line tool
This patch adds a "chasquid-userdb" command line tool to check and add users
to chasquid's userdb files.

It's not pretty or very friendly, as it's meant to be used for testing for
now.
2016-08-01 22:56:57 +01:00
Alberto Bertogli
7eba9bb4f7 chasquid: Flush logs periodically and before exiting
This patch makes chasquid flush logs periodically, and also before exiting,
even if it gets killed via the usual signals (including Ctrl-C).

Both things help troubleshooting when there is not much traffic, or we kill
the server manually (including during automated tests).
2016-08-01 22:56:57 +01:00
Alberto Bertogli
ae1c246bde chasquid: Make "MAIL FROM" ignore extra parameters
MAIL FROM commands usually come in the form of:

  MAIL FROM:<from@from> BODY=8BITMIME

Note that there's extra parameters after the address, which for now we want to
ignore.

The current parser doesn't ignore them, and relies on mail.ParseAddress doing
so (that is, on mail.ParseAddress("<from> BODY=8BITMIME") working).
However, in go 1.7, the parser will get more strict and start to fail these
cases.

To fix this, we change the way we parse the line to use fmt.Sprintf, which is
much nicer than splitting by hand, and is more readable as well.
2016-07-22 01:44:45 +01:00
Alberto Bertogli
9d172a6ea0 Make the queue aware of local and remote couriers
The routing courier is a nice idea in theory, but at least for now, we want
the queue to be aware of when a destination is local so we can implement
differentiated logic.

This may change in the future, though, but at the moment it's not clear that
the abstractions will be worth it.

So this patch removes it, and makes the queue do the routing. There is no
difference in how the two are handled yet, those will come in subsequent
patches.
2016-07-22 01:44:45 +01:00
Alberto Bertogli
362ef6f6d0 Introduce an "envelope" package
This patch introduces an "envelope" package which, for now, provides simple
utilities for getting the user and domain of an address.

It also changes the couriers to use it (but other implementations remain, will
be moved over in subsequent patches).
2016-07-22 01:44:45 +01:00
Alberto Bertogli
831ef13132 queue: Add a mutex to protect item's results
The item results get accessed in various places concurrently, so this patch
adds a mutex to protect it.
2016-07-22 01:44:45 +01:00
Alberto Bertogli
21e69aa42f Implement AUTH
This patch implements the AUTH SMTP command, using per-domain user databases.

Note that we don't really use or check the validation for anything, this is
just implementing the command itself.
2016-07-22 01:44:45 +01:00
Alberto Bertogli
ff103c18c3 courier: Let the users configure the mail delivery agent
This patch adds configuration options for the MDA binary and command line
arguments, and changes the (soon to be renamed) procmail courier to make use
of them.
2016-07-16 12:33:51 +01:00
Alberto Bertogli
bb08be4023 .gitignore: Exclude *.pem files 2016-07-16 12:33:50 +01:00
Alberto Bertogli
9015e97ae1 Implement a simple user database (internal/userdb)
This patch adds a package implementing a simple user database, called userdb.
It has a human readable space-separated extensible format, and uses scrypt for
password storage (but supports plain as well, for debugging and testing).

chasquid is not using it yet, that will come in later patches.
2016-07-16 12:33:50 +01:00
Alberto Bertogli
c12fa0eed7 Add a new internal/safeio package for safer I/O functions
This patch adds a new internal/safeio package, which is meant to implement
safer version of some I/O related functions.

For now, only an atomic version of ioutil.WriteFile is implemented. More may
be added later if there's a need for them.
2016-07-16 12:33:50 +01:00
Alberto Bertogli
7e7c8073c4 Implement VRFY and EXPN commands
We implement the VRFY and EXPN commands, but as no-ops. The RFC allows this,
and most implementations seem to do it this way too.

While at it, merge the tests for simple commands like these into one.
2016-07-16 12:33:50 +01:00
Alberto Bertogli
e32ba1ee86 courier: Make procmail's sanitize be more unicode friendly
Sanitize only lets some ascii characters go through, which is very unfriendly
to non-ascii usernames.

This patch changes it to be more inclusive, and filter out only selected
characters that may be problematic for the subprocesses, specially considering
UNIX shell environments. It's not meant to catch all possible problems, just
help prevent some common ones.
2016-07-16 12:33:34 +01:00
Alberto Bertogli
724d915e95 Implement a string set data type
We will need a few string sets in different places, create it as a separate
package for convenience.

For now, it only implements strings, but it may be extended to other data
types in the future.
2016-05-06 23:00:55 +01:00
Alberto Bertogli
17c536f5e3 queue: Incremental delays
This patch introduces incremental delays in the queue, so retries are not all
done with the same delay.

The table is static; we could perturb it but there's not that much benefit
anyway, at least for now.
2015-11-13 03:41:06 +00:00
Alberto Bertogli
4de805ab34 queue: Send mails in parallel
This patch makes queue items deliver mail in parallel to all recipients.
2015-11-13 03:41:06 +00:00
Alberto Bertogli
77d547288f Implement couriers
This patch introduces the couriers, which the queue uses to deliver mail.

We have a local courier (using procmail), a remote courier (uses SMTP), and a
router courier that decides which of the two to use based on a list of local
domains.

There are still a few things pending, but they all have their basic
functionality working and tested.
2015-11-13 03:41:06 +00:00
Alberto Bertogli
e5c2676f83 Convert addresses to lower case
This patch makes the MAIL FROM and RCPT TO commands convert addresses to lower
case. It also makes the commands themselves case-flexible as a side effect.
2015-11-06 10:27:11 +00:00
Alberto Bertogli
fbf1060b71 Introduce a trace wrapper
This patch introduces a wrapper to golang.org/x/net/trace with a new method
that will be useful later on, making logging and tracing less verbose.
2015-11-06 10:27:11 +00:00
Alberto Bertogli
58de5a6200 Add a skeleton queue
This patch introduces a basic, in-memory queue that only holds emails for now.

This slows down the benchmarks because we don't yet have a way to wait for
delivery (even if fake), that will come in later patches.
2015-11-06 10:27:05 +00:00
Alberto Bertogli
701f359634 Support getting listeners from systemd
Add a new module for getting listener sockets via systemd's file descriptor
passing (see sd_listen_fds(3) for more details), and make the main daemon use
it when "systemd" is given an address.
2015-11-01 02:19:23 +00:00
Alberto Bertogli
a809a3caa9 Basic configuration
This patch introduces a basic on disk configuration, comprised of a main
configuration file and per-domain directories.

It's still not complete, but will be extended in subsequent patches.
2015-11-01 02:19:12 +00:00
Alberto Bertogli
f055a3460e Do not allow repeated STARTTLS commands
Clients should only be able to do STARTTLS once.
2015-10-26 13:40:44 +00:00
Alberto Bertogli
8c22b3beef Add timeouts for the connection and individual commands
This patch introduces a general connection timeout (20m); and a shorter one
(1m) for individual command round-trips.

DATA is excluded from the latter, because it is expected that it takes more
time; we use the general connection timeout for it.
2015-10-26 04:06:40 +00:00
Alberto Bertogli
a5510607e8 Add some tests
This patch adds some tests that cover the SMTP commands, including STARTTLS
and various correctness checks.

There are also two simple benchmarks, that are not optimized and are more
useful for stress testing and profiling than anything else.
2015-10-26 03:40:33 +00:00
Alberto Bertogli
ca9c366087 Handle null reverse paths ("MAIL FROM:<>")
Null reverse paths are explicitly allowed, and used when sending delivery
notifications (https://tools.ietf.org/html/rfc2821#section-4.5.5).
2015-10-26 03:40:32 +00:00
Alberto Bertogli
5978c96fd6 Create a Server structure and start organizing its configuration
This is in preparation for the tests, which will come soon.
2015-10-26 03:40:32 +00:00
Alberto Bertogli
f5cab62c1e Implement STARTTLS 2015-10-26 03:40:32 +00:00
Alberto Bertogli
2c612002a9 Implement DATA receiving
This patch implements the receiving of DATA from the client.
We still don't do anything with it, though.
2015-10-26 03:40:32 +00:00
Alberto Bertogli
d92860c1de Implement more basic commands
Implement NOOP, RSET, MAIL FROM, RCPT TO, and the skeleton for DATA.
2015-10-26 03:40:32 +00:00
Alberto Bertogli
1ee6bf563e Initial commit
Extremely basic and hacky chasquid.go.
Hard-codes ports and hostname.

"Implements" EHLO, HELO, HELP and QUIT.
2015-10-26 03:40:26 +00:00