File: content_log

package info (click to toggle)
qpsmtpd 0.40-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,024 kB
  • ctags: 393
  • sloc: perl: 6,462; sh: 383; makefile: 54
file content (26 lines) | stat: -rw-r--r-- 714 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# -*- perl -*-
# $Id: content_log 573 2005-11-18 09:42:45Z ask $
#
# 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 hook_data_post {
  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");
}