2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
2012-04-08 02:11:16 +02:00
|
|
|
|
2002-11-01 03:08:38 +01:00
|
|
|
# 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:;
|
|
|
|
|
2005-07-07 06:17:39 +02:00
|
|
|
sub hook_data_post {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $transaction) = @_;
|
2002-11-01 03:08:38 +01:00
|
|
|
|
2014-12-02 23:28:51 +01:00
|
|
|
open my $out, '>>', $self->content_log_file;
|
2014-09-18 03:28:51 +02:00
|
|
|
or return DECLINED, "Could not open log file.. continuing anyway";
|
2002-11-01 03:08:38 +01:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
$transaction->header->print($out);
|
|
|
|
$transaction->body_resetpos;
|
|
|
|
while (my $line = $transaction->body_getline) {
|
|
|
|
print $out $line;
|
|
|
|
}
|
2002-11-01 03:08:38 +01:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
close $out;
|
2002-11-01 03:08:38 +01:00
|
|
|
|
2014-09-18 03:28:51 +02:00
|
|
|
return DECLINED, "successfully saved message.. continuing";
|
2002-11-01 03:08:38 +01:00
|
|
|
}
|
2014-12-02 23:28:51 +01:00
|
|
|
|
|
|
|
sub content_log_file {
|
|
|
|
# as a decent default, log on a per-day-basis
|
|
|
|
my $date = strftime("%Y%m%d", localtime(time));
|
|
|
|
return "mail/$date";
|
|
|
|
}
|