File: maildropex.html

package info (click to toggle)
maildrop 0.75-2.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,760 kB
  • ctags: 1,588
  • sloc: cpp: 9,269; ansic: 6,018; perl: 786; sh: 467; makefile: 398
file content (187 lines) | stat: -rw-r--r-- 9,090 bytes parent folder | download | duplicates (2)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!-- DSTART                                                                -->
<!--                                                                       -->
<!--           maildrop - mail delivery agent with filtering abilities     -->
<!--                                                                       -->
<!--  Copyright 1998-1999, Double Precision Inc.                           -->
<!--                                                                       -->
<!--  This program is distributed under the terms of the GNU General Publi -->
<!--  License. See COPYING for additional information.                     -->
<!-- DEND                                                                  -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
   "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.06 [en] (X11; I; Linux 2.0.35 i586)
[Netscape]">
<title>maildropex - examples of maildrop filtering language</title>
<!-- $Id: maildropex.html 1.4 1999/02/18 01:02:01 mrsam Exp $ -->
<!-- SECTION 5 -->
</head>
<body>

<h1>maildropex - examples of maildrop filtering language</h1>

<h2>SYNOPSIS</h2>

<tt>$HOME/.mailfilter, $HOME/.mailfilters/*</tt>

<h2>DESCRIPTION</h2>

If <i>$HOME/.mailfilter</i> exists, filtering instructions in this file will
be carried out prior to delivering the message. The filtering instructions may
instruct <I>maildrop</I> to discard the message, save the message in a different
mailbox, or forward the message to another address. If
<i>$HOME/.mailfilter</i> does not exist, or does not provide explicit delivery
instructions, <I>maildrop</I> delivers the message to the user's system mailbox.
<p>
The files in <i>$HOME/.mailfilters</i> are used when <I>maildrop</I> is invoked in
embedded mode.</p>

<h2>EXAMPLES</h2>

Take all mail that's sent to the 'auto' mailing list, and save it in
<tt>Mail/auto</tt>. The 'auto' mailing list software adds a "Delivered-To:
auto@domain.com" header to all messages:
<pre>&nbsp;&nbsp;&nbsp;&nbsp; if (/^Delivered-To: *auto@domain\.com$/)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to Mail/auto</pre>

After the to commands delivers the message, <I>maildrop</I> automatically stops
filtering and terminates without executing the subsequent instructions in the
<i>filter file</i>.
<p>
Take all mail from <tt>boss@domain.com</tt> about the current project status,
save it in <tt>Mail/project</tt>, then forward a copy to John.</p>
<pre>&nbsp;&nbsp;&nbsp;&nbsp; if (/^From: *boss@domain\.com/ \&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;&amp; /^Subject:.*[:wbreak:]project status[:wbreak:]/)
&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cc "!john"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to Mail/project
&nbsp;&nbsp;&nbsp;&nbsp; }</pre>

Note that it is necessary to use a backslash in order to continue the
<tt>if</tt> statement on the next line.
<p>
Keep copies of the last 50 messages that you received in the <i>maildir</i>
directory 'backup'. NOTE: 'backup' must be a <i>maildir</i> directory, not a
mailbox. You can create a <i>maildir</i> using the <tt>maildirmake</tt>
command. <tt>maildirmake</tt> comes with <a
href="http://www.qmail.org/">qmail</a>. If Qmail is not installed, a
substitute <tt>maildirmake</tt> is provided as part of the <I>maildrop</I>
package.</p>
<pre>&nbsp;&nbsp;&nbsp;&nbsp; cc backup
&nbsp;&nbsp;&nbsp;&nbsp; `cd backup/new &amp;&amp; rm -f dummy \`ls -t | sed -e 1,50\``</pre>

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 <I>maildrop</I>. If
you make a mistake and accidentally delete a message, you can recover it from
the backup/new subdirectory.
<p>
Save messages that are at least 100 lines long (approximately) into
Mail/IN.Large:</p>
<pre>&nbsp;&nbsp;&nbsp;&nbsp; if ( $LINES > 100 )
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to Mail/IN.Large</pre>

Send messages from the auto mailing list to the program 'archive', using a
lock file to make sure that only one instance of the archive program will be
running at the same time:
<pre>&nbsp;&nbsp;&nbsp;&nbsp; if (/^Delivered-To: *auto@domain\.com$/)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dotlock "auto.lock" {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to "|archive"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</pre>

Check if the Message-ID: 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:
<pre>&nbsp;&nbsp;&nbsp;&nbsp; `reformail -D 8000 duplicate.cache`
&nbsp;&nbsp;&nbsp;&nbsp; if ( $RETURNCODE == 0 )
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit</pre>

The <a href="reformail.html">reformail</a> command maintains a list of
recently seen Message-IDs in the file "duplicate.cache".
<p>
Here's 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:</p>
<pre>&nbsp;&nbsp;&nbsp; cc $DEFAULT
&nbsp;&nbsp;&nbsp; xfilter "reformail -r -t"
&nbsp;&nbsp;&nbsp; /^To:.*/
&nbsp;&nbsp;&nbsp; getaddr($MATCH) =~ /^.*/;<br>

    MATCH=tolower($MATCH)
&nbsp;&nbsp;&nbsp; flock "vacation.lock" {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `fgrep -iqx "$MATCH" vacation.lst 2>/dev/null || { \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "$MATCH" >>vacation.lst ; \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit 1 ; \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } `
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; if ( $RETURNCODE == 0 )
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit
&nbsp;&nbsp;&nbsp; to "| ( cat - ; echo ""; cat vacation.msg) | $SENDMAIL"</pre>

This code maintains a list of everyone who sent you mail in the file called
"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
"vacation.msg" 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.
<p>
The first statement saves the original message in your regular mailbox. Then,
<a href="maildropfilter.html#xfilter">xfilter</a> is used to generate an
autoreply header to the sender. The "To:" header in the autoreply - which was
the sender of the original message - is extracted, and the <a
href="maildropfilter.html#getaddr">getaddr</a> function is used to strip the
person's name, leaving the address only. The file "vacation.lst" is checked,
using a lock file to guarantee atomic access and update (overkill, probably).
Note that the backslashes are required.</p>
<p>
If the address is already in the file, <I>maildrop</I> exits, otherwise the
contents of vacation.msg are appended to the autoreply header, and mailed
out.</p>
<p>
Here's 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's been at least a week since the vacation
message has been sent to the given address, another vacation message will be
sent.</p>
<p>
Even though GDBM database files are using, locking is still necessary because
the GDBM library does not allow more than one process to open the same
database file for writing.</p>
<pre>    cc $DEFAULT
    xfilter "reformail -r -t"
    /^To:.*/
    getaddr($MATCH) =~ /^.*/;
    MATCH=tolower($MATCH)
    flock "vacation.lock" {
        current_time=time;
        if (gdbmopen("vacation.dat", "C") == 0)
        {
           if ( (prev_time=gdbmfetch($MATCH)) ne "" &amp;&amp; \
                  $prev_time >= $current_time - 60 * 60 * 24 * 7)
           {
               exit
           }
           gdbmstore($MATCH, $current_time)
           gdbmclose
        }
    }
    to "| ( cat - ; echo ""; cat vacation.msg) | $SENDMAIL"</pre>
<p>
This script requires that <I>maildrop</I> must be compiled with GDBM support
enabled, which is done by default if GDBM libraries are present.</p>
<p>
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).</p>

<h2>SEE ALSO</h2>

<a href="maildrop.html">maildrop(1),</a> <a
href="maildropfilter.html">maildropfilter(1),</a> <a
href="reformail.html">reformail(1),</a> egrep(1), grep(1), sendmail(8), <a
href="http://www.qmail.org">http://www.qmail.org</a>
</body>
</html>