From b6777d1ef8c2f5d346de6442d9a3eeeeacfc8e39 Mon Sep 17 00:00:00 2001 From: Robert Spier Date: Fri, 1 Nov 2002 02:08:38 +0000 Subject: [PATCH] A simple example of a plugin that logs all incoming mail to a file. git-svn-id: https://svn.perl.org/qpsmtpd/trunk@93 958fd67b-6ff1-0310-b445-bb7760255be9 --- plugins/content_log | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 plugins/content_log diff --git a/plugins/content_log b/plugins/content_log new file mode 100644 index 0000000..0198105 --- /dev/null +++ b/plugins/content_log @@ -0,0 +1,31 @@ +# -*- perl -*- +# $Id$ +# +# A simple example of a plugin that logs all incoming mail to a file. +# Useful for debugging other plugins or keeping an archive of things. + +use POSIX qw:strftime:; + +sub register { + my ($self, $qp) = @_; + $self->register_hook("data_post", "mail_handler"); +} + +sub mail_handler { + my ($self, $transaction) = @_; + + # as a decent default, log on a per-day-basis + my $date = strftime("%Y%m%d",localtime(time)); + open(my $out,">>mail/$date") + or return(DECLINED,"Could not open log file.. continuing anyway"); + + $transaction->header->print($out); + $transaction->body_resetpos; + while (my $line = $transaction->body_getline) { + print $out $line; + } + + close $out; + + return (DECLINED, "successfully saved message.. continuing"); +}