[Mimedefang] MIMEDefang drop mails into Maildir mailbox

Jan-Pieter Cornet johnpc at xs4all.nl
Mon Apr 14 18:24:05 EDT 2008

On Sat, Apr 12, 2008 at 05:57:22AM +0100, Jon Rowlan wrote:
> Hi all, I am desperately trying to find a way to drop copies of sendmail
> queue items into a maildir so that customers can review their emails
> (using something like Squirrelmail) when their server is down and cannot
> receive their mail. Also as an archive backup.

<commercial plug>This is exactly the "batched SMTP" setup that we
provide, in the Netherlands.</commercial>

This depends on a pretty hefty amount of hand-hackery, though, and
it doesn't involve MIMEDefang (although we do use mimedefang for
filtering, it is not linked to batched SMTP).

There are a couple of rather limiting restrictions. Foremost is that
the maildir format leaves you no way to store the envelope recipient
information. Second, you probably don't want to store the mail of
customers that DO get it delivered to your server, so you want to
delete the mail from the maildir as soon as it's actually delivered.

What we do these days is this:

- we define a custom mailer, very similar to the local mailer, but with
  a few tweaks, that stores mail in a maildir folder like the original
  local mailer, but adds a header containing the original envelope
- customers/domains who have batched SMTP get a mailertable entry
  pointing to this special mailer, with the dropoff account as a
- A custom program is designed to look up the original delivery address
  for a specific dropbox in the system, and deliver the maildir messages,
  stripping the extra header, and adding a Received header. As a result,
  mails that come in via SMTP look like ordinary mails.
- various radius daemons are keyed to these customers, and fire trigger
  events that start the queue runner for a customer.

The upshot of all this is that customers who run their own SMTP server
get their mail delivered to their server like nothing happened. However,
if the customer's mail server is down, they can use whatever email program
they like, or even webmail, to browse the "queue" which just sits in a
special inbox. And as soon as a customer comes online again after being
offline for a while, the radius coupling makes sure the email delivery
starts within a few seconds.

Since this is rather tightly integrated with our radius daemons, I'm afraid
I cannot release the code, and I'm not aware of any open source programs
that provide this functionality.

However, if you drop the requirement of not storing delivered mail,
and you want to keep the original sendmail queue intact with all its
limitations (eg on retry periods), and you can afford to, say, keep a
backlog of last week's email for a specific customer, then MIMEDefang
could help you by allowing you to duplicate incoming mails.

Easiest, in that case, would be to add a recipient for each domain
that you would offer this service to. Eg:

# NOTE: untested code
# you'll have to provide %ARCHIVE_FOR_DOMAIN specifying the archive
# mailboxes for each domain, like this:
# ( 'example.com' => 'examplebox at my.tld',
#   'example.org' => 'orgbox at my.tld',
# );
sub filter_begin {
    # get recipient domains from @Recipients array
    my @recip_domains = map { /\@([^>]*)>?$/ } @Recipients;
    my %seen_domain;
    for my $domain ( @recip_domains ) {
	# skip if we've already processed this domain
	next if $seen_domain{$domain}++;
	my $dropbox = $ARCHIVE_FOR_DOMAIN{$domain};
	# skip unless a dropbox is defined for this domain
	next unless defined $dropbox;

... then setup a cronjob that deletes mail older than a week in the
specified maildirs, eg: find /path/to/maildirs -atime +7 -exec rm {} \;

But please review this code as I haven't tested it at all, and I might
have even introduced a deliverate bug to force you to read the
mimedefang-filter manpage :)

Also note that if $LAW_ENFORCEMENT_TLA discovers you are keeping backup
copies of old emails, they might force you to do that for all customers,
and then request all archived emails in case one of your customers is
ever suspected of having pondered to conspire in a jaywalking-instigating
scheme. But your mileage, and your local BigBrother, might vary.

Jan-Pieter Cornet <johnpc at xs4all.nl>
!! Disclamer: The addressee of this email is not the intended recipient. !!
!! This is only a test of the echelon and data retention systems. Please !!
!! archive this message indefinitely to allow verification of the logs.  !!

More information about the MIMEDefang mailing list