Score:0

Postfix After-Queue Content Filter full example

de flag

i'm trying the Simple content filter example: i followed the steps mentioned here http://www.postfix.org/FILTER_README.html#simple_filter

but in line 24 of the content filter that can be a simple shell script like this

you need to specify your content filter

my question is :

is there any full example with a content filter ( line 24) that i can work with ?

 1 #!/bin/sh
 2 
 3 # Simple shell-based filter. It is meant to be invoked as follows:
 4 #       /path/to/script -f sender recipients...
 5 
 6 # Localize these. The -G option does nothing before Postfix 2.3.
 7 INSPECT_DIR=/var/spool/filter
 8 SENDMAIL="/usr/sbin/sendmail -G -i" # NEVER NEVER NEVER use "-t" here.
 9 
10 # Exit codes from <sysexits.h>
11 EX_TEMPFAIL=75
12 EX_UNAVAILABLE=69
13 
14 # Clean up when done or when aborting.
15 trap "rm -f in.$$" 0 1 2 3 15
16 
17 # Start processing.
18 cd $INSPECT_DIR || {
19     echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
20 
21 cat >in.$$ || { 
22     echo Cannot save mail to file; exit $EX_TEMPFAIL; }
23 
24 # Specify your content filter here.
25 # filter <in.$$ || {
26 #   echo Message content rejected; exit $EX_UNAVAILABLE; }**
27 
28 $SENDMAIL "$@" <in.$$
29 
30 exit $?
anx avatar
fr flag
anx
Even just `grep -F sesame` is a valid filter. The whole point of this mechanism is that *its up to what you want* what sort of program you use to filter the mail. **Explain the criteria by which you want to decide which mail to treat differently**, only then it becomes clear whether a dead-simple search suffices, or whether you need a MIME-aware parser - or whether *after-queue* is even a suitable point to plug in your filter!
Score:0
in flag

I use my own filter. I used Perl script instead of shell.

#!/usr/bin/perl
use 5.010;
use strict;
use warnings;

my $str = do { local $/; <STDIN> };
my $recipient   = $ARGV[0];
my $filename = '/etc/postfix/myfilters/data.txt';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
print $fh  $str;
close $fh;

=========================

Use exec to sendmail

exec(" SENDMAIL $toemail > $bodyfile ");

If your filter doesn't match do nothing it gets quarantined.

cn flag
Can you add some more explanation on how this actually runs the filter? Thanks!
djdomi avatar
za flag
it needs a hell more information how it supports the question to be solved?!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.