| 1 | <?xml version='1.0' encoding='utf-8'?> |
1 | <?xml version='1.0' encoding='utf-8'?> |
| 2 | <!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> |
2 | <!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> |
| 3 | <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/mailfilter-guide.xml,v 1.25 2011/06/19 03:54:12 nightmorph Exp $ --> |
3 | <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/mailfilter-guide.xml,v 1.26 2011/06/19 09:12:09 nightmorph Exp $ --> |
| 4 | |
4 | |
| 5 | <guide> |
5 | <guide> |
| 6 | <title>Gentoo mailfiltering gateway guide</title> |
6 | <title>Gentoo mailfiltering gateway guide</title> |
| 7 | |
7 | |
| 8 | <author title="Author"> |
8 | <author title="Author"> |
| … | |
… | |
| 23 | |
23 | |
| 24 | <!-- The content of this document is licensed under the CC-BY-SA license --> |
24 | <!-- The content of this document is licensed under the CC-BY-SA license --> |
| 25 | <!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
25 | <!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
| 26 | <license/> |
26 | <license/> |
| 27 | |
27 | |
| 28 | <version>4</version> |
28 | <version>5</version> |
| 29 | <date>2011-06-18</date> |
29 | <date>2011-06-19</date> |
| 30 | |
30 | |
| 31 | <chapter> |
31 | <chapter> |
| 32 | <title>Introduction</title> |
32 | <title>Introduction</title> |
| 33 | <section> |
33 | <section> |
| 34 | <body> |
34 | <body> |
| … | |
… | |
| 1088 | $spam_quarantine_to = "spamtrap\@$myhostname"; |
1088 | $spam_quarantine_to = "spamtrap\@$myhostname"; |
| 1089 | </pre> |
1089 | </pre> |
| 1090 | |
1090 | |
| 1091 | </body> |
1091 | </body> |
| 1092 | </section> |
1092 | </section> |
| 1093 | |
|
|
| 1094 | <!-- 2011-06-18: smtpclient last-rited; needs to be rewritten to use ssmtp, |
|
|
| 1095 | mailx, postfix, nail, etc. |
|
|
| 1096 | <section> |
|
|
| 1097 | <title>Redelivering false positives</title> |
|
|
| 1098 | <body> |
|
|
| 1099 | |
|
|
| 1100 | <p> |
|
|
| 1101 | If you set the spam score very low like we do you will probably have some false |
|
|
| 1102 | positives. These are filtered into the folder <path>likely-spam</path>. These |
|
|
| 1103 | are manually reviewed and any false positive is moved to the |
|
|
| 1104 | <path>redeliver</path> mailfolder. From there it is first fed through |
|
|
| 1105 | <c>sa-learn \-\-ham</c> and then redelivered with all headers intact using <uri |
|
|
| 1106 | link="http://www.engelschall.com/sw/smtpclient/">smtpclient</uri>. |
|
|
| 1107 | </p> |
|
|
| 1108 | |
|
|
| 1109 | <pre caption="Installing smtpclient"> |
|
|
| 1110 | # <i>echo "mail-client/smtpclient" >> /etc/portage/package.accept_keywords</i> |
|
|
| 1111 | # <i>emerge smtpclient</i> |
|
|
| 1112 | </pre> |
|
|
| 1113 | |
|
|
| 1114 | <p> |
|
|
| 1115 | Check for mails in the <path>redeliver</path> folder every minute using cron. |
|
|
| 1116 | </p> |
|
|
| 1117 | |
|
|
| 1118 | <pre caption="amavis crontab"> |
|
|
| 1119 | <comment>#Redeliver false positives</comment> |
|
|
| 1120 | * * * * * find /var/amavis/.maildir/Bayes/.redeliver/cur/ -type f -name \ |
|
|
| 1121 | "[0-9]*" -exec cp {} /var/amavis/.maildir/Bayes/.ham/cur/ \; \ |
|
|
| 1122 | && find /var/amavis/.maildir/Bayes/.redeliver/cur/ -type f \ |
|
|
| 1123 | -name "[0-9]*" -exec /usr/local/bin/redeliver.pl {} \; |
|
|
| 1124 | </pre> |
|
|
| 1125 | |
|
|
| 1126 | <p> |
|
|
| 1127 | Now we only have to copy the <c>redeliver.pl</c> file to |
|
|
| 1128 | <path>/usr/local/bin/</path>. <uri |
|
|
| 1129 | link="http://home.coming.dk/files/redeliver.pl">Download it</uri> or use |
|
|
| 1130 | the version below. |
|
|
| 1131 | </p> |
|
|
| 1132 | |
|
|
| 1133 | <pre caption="redeliver.pl"> |
|
|
| 1134 | <comment>#!/usr/bin/perl -w |
|
|
| 1135 | |
|
|
| 1136 | # Redelivers mail using a modified version of smtpclient |
|
|
| 1137 | # By: Jens Hilligsoe <gentoo@hilli.dk></comment> |
|
|
| 1138 | |
|
|
| 1139 | use strict; |
|
|
| 1140 | |
|
|
| 1141 | if(!($#ARGV == 0)) { |
|
|
| 1142 | die "Usage:\n$0 maildir_mail\n"; |
|
|
| 1143 | } |
|
|
| 1144 | |
|
|
| 1145 | my $mail = $ARGV[0]; |
|
|
| 1146 | my $to = ""; |
|
|
| 1147 | my $from = ""; |
|
|
| 1148 | |
|
|
| 1149 | sub prunefile ( $ ); |
|
|
| 1150 | |
|
|
| 1151 | <comment># Retrieve To and From envelope adresses</comment> |
|
|
| 1152 | open (MAIL, $mail) or die "Could not open $mail: $?\n"; |
|
|
| 1153 | while(<MAIL>) { |
|
|
| 1154 | if(($to eq "") || ($from eq "")) { |
|
|
| 1155 | chop; |
|
|
| 1156 | (my $key, my $value) = split (/:/); |
|
|
| 1157 | if($key eq "X-Envelope-To") { |
|
|
| 1158 | $to = $value; |
|
|
| 1159 | $to =~ s/[\<\>,]//g; # Remove "<", ">" and "," |
|
|
| 1160 | $to =~ s/^\s+|\s+$//g; #Remove whitespace before and after |
|
|
| 1161 | } |
|
|
| 1162 | if($key eq "X-Envelope-From") { |
|
|
| 1163 | $from = $value; |
|
|
| 1164 | $from =~ s/[\<\>,]//g; |
|
|
| 1165 | $from =~ s/^\s+|\s+$//g; |
|
|
| 1166 | if($from eq "") { |
|
|
| 1167 | $from = "postmaster"; |
|
|
| 1168 | } |
|
|
| 1169 | } |
|
|
| 1170 | } |
|
|
| 1171 | } |
|
|
| 1172 | |
|
|
| 1173 | if($to eq "") { |
|
|
| 1174 | prunefile($ARGV[0]); # Just nuke it if to is empty |
|
|
| 1175 | } else { |
|
|
| 1176 | my $redelivercmd = "cat $ARGV[0] | smtpclient -w -S 127.0.0.1 -P 10025 -f $from $to"; |
|
|
| 1177 | unless (system($redelivercmd) == 0 ) { |
|
|
| 1178 | die "Unable to redeliver: $?"; |
|
|
| 1179 | } |
|
|
| 1180 | prunefile($ARGV[0]); # Clean up |
|
|
| 1181 | } |
|
|
| 1182 | |
|
|
| 1183 | sub prunefile ( $ ) { |
|
|
| 1184 | my ($file) = @_; |
|
|
| 1185 | unless (unlink $file) { |
|
|
| 1186 | die "Unable to remove mail: $?"; |
|
|
| 1187 | } |
|
|
| 1188 | } |
|
|
| 1189 | </pre> |
|
|
| 1190 | |
|
|
| 1191 | </body> |
|
|
| 1192 | </section> |
|
|
| 1193 | --> |
|
|
| 1194 | |
|
|
| 1195 | <section> |
1093 | <section> |
| 1196 | <title>Cleaning up</title> |
1094 | <title>Cleaning up</title> |
| 1197 | <body> |
1095 | <body> |
| 1198 | |
1096 | |
| 1199 | <p> |
1097 | <p> |