| 1 |
'\" t |
| 2 |
.\"<!-- Copyright 1998 - 2010 Double Precision, Inc. See COPYING for --> |
| 3 |
.\"<!-- distribution information. --> |
| 4 |
.\" Title: maildropex |
| 5 |
.\" Author: Sam Varshavchik |
| 6 |
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/> |
| 7 |
.\" Date: 11/04/2020 |
| 8 |
.\" Manual: Double Precision, Inc. |
| 9 |
.\" Source: Courier Mail Server |
| 10 |
.\" Language: English |
| 11 |
.\" |
| 12 |
.TH "MAILDROPEX" "7" "11/04/2020" "Courier Mail Server" "Double Precision, Inc\&." |
| 13 |
.\" ----------------------------------------------------------------- |
| 14 |
.\" * Define some portability stuff |
| 15 |
.\" ----------------------------------------------------------------- |
| 16 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 17 |
.\" http://bugs.debian.org/507673 |
| 18 |
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 19 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 20 |
.ie \n(.g .ds Aq \(aq |
| 21 |
.el .ds Aq ' |
| 22 |
.\" ----------------------------------------------------------------- |
| 23 |
.\" * set default formatting |
| 24 |
.\" ----------------------------------------------------------------- |
| 25 |
.\" disable hyphenation |
| 26 |
.nh |
| 27 |
.\" disable justification (adjust text to left margin only) |
| 28 |
.ad l |
| 29 |
.\" ----------------------------------------------------------------- |
| 30 |
.\" * MAIN CONTENT STARTS HERE * |
| 31 |
.\" ----------------------------------------------------------------- |
| 32 |
.SH "NAME" |
| 33 |
maildropex \- maildrop filtering language examples |
| 34 |
.SH "SYNOPSIS" |
| 35 |
.sp |
| 36 |
$HOME/\&.mailfilter, $HOME/\&.mailfilters/* |
| 37 |
.SH "DESCRIPTION" |
| 38 |
.PP |
| 39 |
If |
| 40 |
$HOME/\&.mailfilter |
| 41 |
exists, filtering instructions in this file will be carried out prior to delivering the message\&. The filtering instructions may instruct |
| 42 |
\fBmaildrop\fR |
| 43 |
to discard the message, save the message in a different mailbox, or forward the message to another address\&. If |
| 44 |
$HOME/\&.mailfilter |
| 45 |
does not exist, or does not provide explicit delivery instructions, |
| 46 |
\fBmaildrop\fR |
| 47 |
delivers the message to the user\*(Aqs system mailbox\&. |
| 48 |
.PP |
| 49 |
The files in |
| 50 |
$HOME/\&.mailfilters |
| 51 |
are used when |
| 52 |
\fBmaildrop\fR |
| 53 |
is invoked in embedded mode\&. |
| 54 |
.SH "EXAMPLES" |
| 55 |
.PP |
| 56 |
Take all mail that\*(Aqs sent to the \*(Aqauto\*(Aq mailing list, and save it in |
| 57 |
Mail/auto\&. The \*(Aqauto\*(Aq mailing list software adds a "Delivered\-To: auto@domain\&.com" header to all messages: |
| 58 |
.sp |
| 59 |
.if n \{\ |
| 60 |
.RS 4 |
| 61 |
.\} |
| 62 |
.nf |
| 63 |
if (/^Delivered\-To: *auto@domain\e\&.com$/) |
| 64 |
to Mail/auto |
| 65 |
.fi |
| 66 |
.if n \{\ |
| 67 |
.RE |
| 68 |
.\} |
| 69 |
.PP |
| 70 |
After the |
| 71 |
\fBto\fR |
| 72 |
command delivers the message, |
| 73 |
\fBmaildrop\fR |
| 74 |
automatically stops filtering and terminates without executing the subsequent instructions in the |
| 75 |
filter file\&. |
| 76 |
.PP |
| 77 |
Take all mail from |
| 78 |
<boss@domain\&.com> |
| 79 |
about the current project status, save it in |
| 80 |
Mail/project, then forward a copy to John: |
| 81 |
.sp |
| 82 |
.if n \{\ |
| 83 |
.RS 4 |
| 84 |
.\} |
| 85 |
.nf |
| 86 |
if (/^From: *boss@domain\e\&.com/ \e |
| 87 |
&& /^Subject:\&.*[:wbreak:]project status[:wbreak:]/) |
| 88 |
{ |
| 89 |
cc "!john" |
| 90 |
to Mail/project |
| 91 |
} |
| 92 |
.fi |
| 93 |
.if n \{\ |
| 94 |
.RE |
| 95 |
.\} |
| 96 |
.PP |
| 97 |
Note that it is necessary to use a backslash in order to continue the |
| 98 |
\fBif\fR |
| 99 |
statement on the next line\&. |
| 100 |
.PP |
| 101 |
Keep copies of the last 50 messages that you received in the |
| 102 |
maildir |
| 103 |
directory \*(Aqbackup\*(Aq\&. NOTE: \*(Aqbackup\*(Aq must be a |
| 104 |
maildir |
| 105 |
directory, not a mailbox\&. You can create a |
| 106 |
maildir |
| 107 |
using the |
| 108 |
\fBmaildirmake\fR |
| 109 |
command\&. |
| 110 |
.sp |
| 111 |
.if n \{\ |
| 112 |
.RS 4 |
| 113 |
.\} |
| 114 |
.nf |
| 115 |
cc backup |
| 116 |
`cd backup/new && rm \-f dummy \e`ls \-t | sed \-e 1,50d\e`` |
| 117 |
.fi |
| 118 |
.if n \{\ |
| 119 |
.RE |
| 120 |
.\} |
| 121 |
.PP |
| 122 |
Put this at the beginning of your filter file, before any other filtering instructions\&. This is a good idea to have when you are learning |
| 123 |
\fBmaildrop\fR\&. If you make a mistake and accidentally delete a message, you can recover it from the backup/new subdirectory\&. |
| 124 |
.PP |
| 125 |
Save messages that are at least 100 lines long (approximately) into |
| 126 |
Mail/IN\&.Large:: |
| 127 |
.sp |
| 128 |
.if n \{\ |
| 129 |
.RS 4 |
| 130 |
.\} |
| 131 |
.nf |
| 132 |
if ( $LINES > 100 ) |
| 133 |
to Mail/IN\&.Large |
| 134 |
.fi |
| 135 |
.if n \{\ |
| 136 |
.RE |
| 137 |
.\} |
| 138 |
.PP |
| 139 |
Send messages from the auto mailing list to the program \*(Aqarchive\*(Aq, using a lock file to make sure that only one instance of the archive program will be running at the same time: |
| 140 |
.sp |
| 141 |
.if n \{\ |
| 142 |
.RS 4 |
| 143 |
.\} |
| 144 |
.nf |
| 145 |
if (/^Delivered\-To: *auto@domain\e\&.com$/) |
| 146 |
dotlock "auto\&.lock" { |
| 147 |
|
| 148 |
to "|archive" |
| 149 |
} |
| 150 |
.fi |
| 151 |
.if n \{\ |
| 152 |
.RE |
| 153 |
.\} |
| 154 |
.PP |
| 155 |
Check if the |
| 156 |
Message\-ID: |
| 157 |
header in the message is identical to the same header that was recently seen\&. Discard the message if it is, otherwise continue to filter the message: |
| 158 |
.sp |
| 159 |
.if n \{\ |
| 160 |
.RS 4 |
| 161 |
.\} |
| 162 |
.nf |
| 163 |
`reformail \-D 8000 duplicate\&.cache` |
| 164 |
if ( $RETURNCODE == 0 ) |
| 165 |
exit |
| 166 |
.fi |
| 167 |
.if n \{\ |
| 168 |
.RE |
| 169 |
.\} |
| 170 |
.PP |
| 171 |
The |
| 172 |
\m[blue]\fBreformail\fR\m[]\&\s-2\u[1]\d\s+2 |
| 173 |
command maintains a list of recently seen Message\-IDs in the file |
| 174 |
duplicate\&.cache\&. |
| 175 |
.if n \{\ |
| 176 |
.sp |
| 177 |
.\} |
| 178 |
.RS 4 |
| 179 |
.nr an-no-space-flag 1 |
| 180 |
.nr an-break-flag 1 |
| 181 |
.br |
| 182 |
.ps +1 |
| 183 |
\fBNote\fR |
| 184 |
.ps -1 |
| 185 |
.br |
| 186 |
.PP |
| 187 |
Unlike a similar feature in the |
| 188 |
\fBformail\fR |
| 189 |
command, |
| 190 |
\m[blue]\fBreformail\fR\m[]\&\s-2\u[1]\d\s+2 |
| 191 |
takes care of locking the file, so it\*(Aqs not necessary to implement your own locking mechanism for this option\&. |
| 192 |
.sp .5v |
| 193 |
.RE |
| 194 |
.PP |
| 195 |
Here\*(Aqs a more complicated example\&. This fragment is intended to go right after the message has been filtered according to your regular rules, and just before the message should be saved in your mailbox: |
| 196 |
.sp |
| 197 |
.if n \{\ |
| 198 |
.RS 4 |
| 199 |
.\} |
| 200 |
.nf |
| 201 |
cc $DEFAULT |
| 202 |
xfilter "reformail \-r \-t" |
| 203 |
/^To:\&.*/ |
| 204 |
getaddr($MATCH) =~ /^\&.*/; |
| 205 |
|
| 206 |
MATCH=tolower($MATCH) |
| 207 |
flock "vacation\&.lock" { |
| 208 |
`fgrep \-iqx "$MATCH" vacation\&.lst 2>/dev/null || { \e |
| 209 |
echo "$MATCH" >>vacation\&.lst ; \e |
| 210 |
exit 1 ; \e |
| 211 |
} ` |
| 212 |
} |
| 213 |
if ( $RETURNCODE == 0 ) |
| 214 |
exit |
| 215 |
to "| ( cat \- ; echo \*(Aq\*(Aq; cat vacation\&.msg) | $SENDMAIL" |
| 216 |
.fi |
| 217 |
.if n \{\ |
| 218 |
.RE |
| 219 |
.\} |
| 220 |
.PP |
| 221 |
This code maintains a list of everyone who sent you mail in the file called |
| 222 |
vacation\&.lst\&. When a message is received from anyone that is not already on the list, the address is added to the list, and the contents of the file |
| 223 |
vacation\&.msg |
| 224 |
are mailed back to the sender\&. This is intended to reply notify people that you will not be answering mail for a short period of time\&. |
| 225 |
.PP |
| 226 |
The first statement saves the original message in your regular mailbox\&. Then, |
| 227 |
\m[blue]\fB\fBxfilter\fR\fR\m[]\&\s-2\u[2]\d\s+2 |
| 228 |
is used to generate an autoreply header to the sender\&. The |
| 229 |
To: |
| 230 |
header in the autoreply \- which was the sender of the original message \- is extracted, and the |
| 231 |
\m[blue]\fB\fBgetaddr\fR\fR\m[]\&\s-2\u[3]\d\s+2 |
| 232 |
function is used to strip the person\*(Aqs name, leaving the address only\&. The file |
| 233 |
vacation\&.lst |
| 234 |
is checked, using a lock file to guarantee atomic access and update (overkill, probably)\&. Note that the backslashes are required\&. |
| 235 |
.PP |
| 236 |
If the address is already in the file, |
| 237 |
\fBmaildrop\fR |
| 238 |
exits, otherwise the contents of |
| 239 |
vacation\&.msg |
| 240 |
are appended to the autoreply header, and mailed out\&. |
| 241 |
.if n \{\ |
| 242 |
.sp |
| 243 |
.\} |
| 244 |
.RS 4 |
| 245 |
.nr an-no-space-flag 1 |
| 246 |
.nr an-break-flag 1 |
| 247 |
.br |
| 248 |
.ps +1 |
| 249 |
\fBNote\fR |
| 250 |
.ps -1 |
| 251 |
.br |
| 252 |
.PP |
| 253 |
An easier to make a vacation script is with |
| 254 |
\m[blue]\fB\fBmailbot\fR(1)\fR\m[]\&\s-2\u[4]\d\s+2\&. |
| 255 |
.sp .5v |
| 256 |
.RE |
| 257 |
.PP |
| 258 |
Here\*(Aqs a version of the vacation script that uses a GDBM database file instead\&. The difference between this script and the previous script is that the previous script will send a vacation message to a given E\-mail address only once\&. The following script will store the time that the vacation message was sent in the GDBM file\&. If it\*(Aqs been at least a week since the vacation message has been sent to the given address, another vacation message will be sent\&. |
| 259 |
.PP |
| 260 |
Even though a GDBM database file is used, locking is still necessary because the GDBM library does not allow more than one process to open the same database file for writing: |
| 261 |
.sp |
| 262 |
.if n \{\ |
| 263 |
.RS 4 |
| 264 |
.\} |
| 265 |
.nf |
| 266 |
cc $DEFAULT |
| 267 |
xfilter "reformail \-r \-t" |
| 268 |
/^To:\&.*/ |
| 269 |
getaddr($MATCH) =~ /^\&.*/; |
| 270 |
MATCH=tolower($MATCH) |
| 271 |
flock "vacation\&.lock" { |
| 272 |
current_time=time; |
| 273 |
if (gdbmopen("vacation\&.dat", "C") == 0) |
| 274 |
{ |
| 275 |
if ( (prev_time=gdbmfetch($MATCH)) ne "" && \e |
| 276 |
$prev_time >= $current_time \- 60 * 60 * 24 * 7) |
| 277 |
{ |
| 278 |
exit |
| 279 |
} |
| 280 |
gdbmstore($MATCH, $current_time) |
| 281 |
gdbmclose |
| 282 |
} |
| 283 |
} |
| 284 |
to "| ( cat \- ; echo \*(Aq\*(Aq; cat vacation\&.msg) | $SENDMAIL" |
| 285 |
.fi |
| 286 |
.if n \{\ |
| 287 |
.RE |
| 288 |
.\} |
| 289 |
.PP |
| 290 |
This script requires that |
| 291 |
\fBmaildrop\fR |
| 292 |
must be compiled with GDBM support enabled, which is done by default if GDBM libraries are present\&. |
| 293 |
.PP |
| 294 |
After you return from vacation, you can use a simple Perl script to obtain a list of everyone who sent you mail (of course, that can also be determined by examining your mailbox)\&. |
| 295 |
.SH "SEE ALSO" |
| 296 |
.PP |
| 297 |
\m[blue]\fB\fBmaildrop\fR(1)\fR\m[]\&\s-2\u[5]\d\s+2, |
| 298 |
\m[blue]\fB\fBmaildropfilter\fR(7)\fR\m[]\&\s-2\u[6]\d\s+2, |
| 299 |
\m[blue]\fB\fBreformail\fR(1)\fR\m[]\&\s-2\u[1]\d\s+2, |
| 300 |
\m[blue]\fB\fBmailbot\fR(1)\fR\m[]\&\s-2\u[4]\d\s+2, |
| 301 |
\fBegrep\fR(1), |
| 302 |
\fBgrep\fR(1), |
| 303 |
\fBsendmail\fR(8)\&. |
| 304 |
.SH "AUTHOR" |
| 305 |
.PP |
| 306 |
\fBSam Varshavchik\fR |
| 307 |
.RS 4 |
| 308 |
Author |
| 309 |
.RE |
| 310 |
.SH "NOTES" |
| 311 |
.IP " 1." 4 |
| 312 |
reformail |
| 313 |
.RS 4 |
| 314 |
\%http://www.courier-mta.org/maildrop/reformail.html |
| 315 |
.RE |
| 316 |
.IP " 2." 4 |
| 317 |
\fBxfilter\fR |
| 318 |
.RS 4 |
| 319 |
\%http://www.courier-mta.org/maildrop/maildropfilter.html#xfilter |
| 320 |
.RE |
| 321 |
.IP " 3." 4 |
| 322 |
\fBgetaddr\fR |
| 323 |
.RS 4 |
| 324 |
\%http://www.courier-mta.org/maildrop/maildropfilter.html#getaddr |
| 325 |
.RE |
| 326 |
.IP " 4." 4 |
| 327 |
\fBmailbot\fR(1) |
| 328 |
.RS 4 |
| 329 |
\%http://www.courier-mta.org/maildrop/mailbot.html |
| 330 |
.RE |
| 331 |
.IP " 5." 4 |
| 332 |
\fBmaildrop\fR(1) |
| 333 |
.RS 4 |
| 334 |
\%http://www.courier-mta.org/maildrop/maildrop.html |
| 335 |
.RE |
| 336 |
.IP " 6." 4 |
| 337 |
\fBmaildropfilter\fR(7) |
| 338 |
.RS 4 |
| 339 |
\%http://www.courier-mta.org/maildrop/maildropfilter.html |
| 340 |
.RE |