Debian Codegraph @

plugins/content_log

raw
1 #!perl -w
2
3 # A simple example of a plugin that logs all incoming mail to a file.
4 # Useful for debugging other plugins or keeping an archive of things.
5
6 use POSIX qw:strftime:;
7
8 sub hook_data_post {
9 my ($self, $transaction) = @_;
10
11 # as a decent default, log on a per-day-basis
12 my $date = strftime("%Y%m%d", localtime(time));
13 open(my $out, ">>mail/$date")
14 or return (DECLINED, "Could not open log file.. continuing anyway");
15
16 $transaction->header->print($out);
17 $transaction->body_resetpos;
18 while (my $line = $transaction->body_getline) {
19 print $out $line;
20 }
21
22 close $out;
23
24 return (DECLINED, "successfully saved message.. continuing");
25 }