File: postfix-queue

package info (click to toggle)
qpsmtpd 0.32-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 860 kB
  • ctags: 237
  • sloc: perl: 4,219; sh: 592; makefile: 54
file content (96 lines) | stat: -rw-r--r-- 2,679 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

=head1 NAME

postfix-queue

=head1 DESCRIPTION

This plugin passes mails on to the postfix cleanup daemon.

=head1 CONFIG

The first optional parameter is the location of the cleanup socket. If it does
not start with a ``/'', it is treated as a flag for cleanup (see below).
If set, the environment variable POSTFIXQUEUE overrides this setting.

All other parameters are flags for cleanup, no flags are enabled by default.
Known flags are:

=over 3

=item FLAG_FILTER

Set the CLEANUP_FLAG_FILTER for cleanup. This enables the use of 
I<header_filter>, I<body_filter> or I<content_filter> in postfix' main.cf.

=item FLAG_BCC_OK

Setting this flag enables (for example) the I<recipient_bcc_maps> parameter

=item FLAG_MAP_OK

This flag enables the use of other recipient mappings (e.g. 
I<virtual_alias_maps>) in postfix' cleanup.

=back

=cut

use Qpsmtpd::Postfix;

#
# postfix' cleanup flags:
use constant CLEANUP_FLAG_FILTER => (1 << 1);    # /* Enable content filter */
use constant CLEANUP_FLAG_BCC_OK => (1 << 4);    # /* Ok to add auto-BCC addresses */
use constant CLEANUP_FLAG_MAP_OK => (1 << 5);    # /* Ok to map addresses */

sub register {
    my ($self, $qp, @args) = @_;

    $self->{_queue_flags} = 0;
    if (@args > 0) {
        if ($args[0] =~ m#^/#) {
            $self->{_queue_socket} = shift @args;
        }
        else {
            $self->{_queue_socket} = "/var/spool/postfix/public/cleanup";
        }

        foreach (@args) {
            if ($_ eq 'FLAG_FILTER') {
                $self->{_queue_flags} |= CLEANUP_FLAG_FILTER;
            }
            elsif ($_ eq 'FLAG_BCC_OK') {
                $self->{_queue_flags} |= CLEANUP_FLAG_BCC_OK;
            }
            elsif ($_ eq 'FLAG_MAP_OK') {
                $self->{_queue_flags} |= CLEANUP_FLAG_MAP_OK;
            }

            else {
                $self->log(LOGWARN, "Ignoring unkown cleanup flag $_");
            }
        }
    }
    else {
        $self->{_queue_socket} = "/var/spool/postfix/public/cleanup";
    }

    $self->{_queue_socket} = $ENV{POSTFIXQUEUE} if $ENV{POSTFIXQUEUE};

}

sub hook_queue {
    my ($self, $transaction) = @_;
    $transaction->notes('postfix-queue-flags', $self->{_queue_flags});

# $self->log(LOGDEBUG, "queue-flags=".$transaction->notes('postfix-queue-flags'));
    my ($status, $qid, $reason) = Qpsmtpd::Postfix->inject_mail($transaction);
    $status and return (DECLINED, "Unable to queue message ($status, $reason)");

    my $msg_id = $transaction->header->get('Message-Id') || '';
    $msg_id =~ s/[\r\n].*//s;    # don't allow newlines in the Message-Id here
    return (OK, "Queued! $msg_id (Queue-Id: $qid)");
}

#vim: sw=2 ts=8