[Mimedefang] mimedefang send a copy of all mails to a directory

Dianne Skoll dfs at roaringpenguin.com
Mon Jun 27 10:17:55 EDT 2016


On Mon, 27 Jun 2016 15:01:22 +0200
Shaun Megaw <shaun.megaw at cartrack.com> wrote:

> sub filter_begin
> {
> system('cp', 'INPUTMSG', '/home/shaun');
> }

> This created a file called /home/shaun/INPUTMSG which is over written
> by each new mail

Well, yes.  It's doing what you told it to do.

> Is there a way to send a copy of all mails in individual files to a 
> directory?

You need to give each message a unique name.  The global variable
$QueueID holds the Sendmail queue ID which is guaranteed unique
for a given host, so something like:

system('cp', 'INPUTMSG', "/home/shaun/$QueueID.eml");

would probably fit the bill.

Note that in production code, you want to check whether or not the cp
succeeded.  You also need to watch out for race conditions whereby
you're taking files out of the directory at the same time as
MIMEDefang is putting them in.  You probably want to copy the
file to a temporary file such as "$QueueID.eml.tmp" and then
atomically rename to "$QueueID.eml" so your archiver is never
fed half a message.

Regards,

Dianne.



More information about the MIMEDefang mailing list