~ubuntu-branches/ubuntu/hoary/courier/hoary

« back to all changes in this revision

Viewing changes to maildrop/maildropex.7

  • Committer: Bazaar Package Importer
  • Author(s): Thom May
  • Date: 2004-11-29 12:09:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041129120934-kkn0xj11j0n1n6lo
Tags: 0.47-3ubuntu1
* Nathaniel McCallum
 - debian/*.init: pretty initscripts
 - debian/control: version depends on lsb-base

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.\"  <!-- $Id: maildropex.sgml,v 1.5 2004/07/27 01:36:41 mrsam Exp $ -->
 
2
.\"  <!-- Copyright 1998 - 2001 Double Precision, Inc.  See COPYING for -->
 
3
.\"  <!-- distribution information. -->
 
4
.\" This manpage has been automatically generated by docbook2man 
 
5
.\" from a DocBook document.  This tool can be found at:
 
6
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/> 
 
7
.\" Please send any bug reports, improvements, comments, patches, 
 
8
.\" etc. to Steve Cheng <steve@ggi-project.org>.
 
9
.TH "MAILDROPEX" "7" "27 August 2004" "Double Precision, Inc." ""
 
10
 
 
11
.SH NAME
 
12
maildropex \- maildrop filtering language examples
 
13
.SH SYNOPSIS
 
14
.PP
 
15
.PP
 
16
\fI$HOME/.mailfilter\fR,
 
17
\fI$HOME/.mailfilters/*\fR
 
18
.SH "DESCRIPTION"
 
19
.PP
 
20
If \fI$HOME/.mailfilter\fR exists, filtering instructions in
 
21
this file will be carried out prior to delivering the message. The filtering
 
22
instructions may
 
23
instruct \fBmaildrop\fR to discard the message, save the
 
24
message in a
 
25
different mailbox, or forward the message to another address. If
 
26
\fI$HOME/.mailfilter\fR does not exist,
 
27
or does not provide explicit delivery
 
28
instructions, \fBmaildrop\fR delivers the message to the
 
29
user's system mailbox.
 
30
.PP
 
31
The files in \fI$HOME/.mailfilters\fR
 
32
are used when \fBmaildrop\fR is
 
33
invoked in embedded mode.
 
34
.SH "EXAMPLES"
 
35
.PP
 
36
Take all mail that's sent to the 'auto' mailing list, and save it in
 
37
\fIMail/auto\fR\&. The 'auto' mailing list software adds a
 
38
"Delivered-To: auto@domain.com" header to all messages:
 
39
.sp
 
40
.RS
 
41
.PP
 
42
 
 
43
.nf
 
44
if (/^Delivered-To: *auto@domain\\.com$/)
 
45
    to Mail/auto
 
46
.fi
 
47
.RE
 
48
After the \fBto\fR command delivers the message,
 
49
\fBmaildrop\fR automatically
 
50
stops filtering and terminates without executing the subsequent instructions
 
51
in the
 
52
\fBfilter file\fR\&.
 
53
.PP
 
54
Take all mail from <boss@domain.com> about the current project
 
55
status, save it in \fIMail/project\fR, then forward a copy to
 
56
John:
 
57
.sp
 
58
.RS
 
59
.PP
 
60
 
 
61
.nf
 
62
if (/^From: *boss@domain\\.com/ \\ 
 
63
    && /^Subject:.*[:wbreak:]project status[:wbreak:]/)
 
64
{
 
65
    cc "!john"
 
66
    to Mail/project
 
67
}
 
68
.fi
 
69
.RE
 
70
Note that it is necessary to use a backslash in order to continue the
 
71
\fBif\fR statement on the next line.
 
72
.PP
 
73
Keep copies of the last 50 messages that you received in the
 
74
\fImaildir\fR
 
75
directory 'backup'. NOTE: 'backup' must be a \fImaildir\fR
 
76
directory, not a
 
77
mailbox. You can create a \fImaildir\fR using the
 
78
\fBmaildirmake\fR
 
79
command.
 
80
.sp
 
81
.RS
 
82
.PP
 
83
 
 
84
.nf
 
85
cc backup
 
86
`cd backup/new && rm -f dummy \\`ls -t | sed -e 1,50d\\``
 
87
.fi
 
88
.RE
 
89
Put this at the beginning of your filter file, before any other filtering
 
90
instructions. This is a good idea to have when you are learning
 
91
\fBmaildrop\fR\&. If you make a mistake and accidentally delete a
 
92
message, you
 
93
can recover it from the backup/new subdirectory.
 
94
.PP
 
95
Save messages that are at least 100 lines long (approximately) into
 
96
\fIMail/IN.Large:\fR:
 
97
.sp
 
98
.RS
 
99
.PP
 
100
 
 
101
.nf
 
102
     if ( $LINES > 100 )
 
103
        to Mail/IN.Large
 
104
.fi
 
105
.RE
 
106
.PP
 
107
Send messages from the auto mailing list to the program 'archive', using a
 
108
lock file to make sure that only one instance of the archive program will be
 
109
running at the same time:
 
110
.sp
 
111
.RS
 
112
.PP
 
113
 
 
114
.nf
 
115
     if (/^Delivered-To: *auto@domain\\.com$/)
 
116
        dotlock "auto.lock" {
 
117
 
 
118
               to "|archive"
 
119
        }
 
120
.fi
 
121
.RE
 
122
.PP
 
123
Check if the Message-ID: header in the message is identical
 
124
to the same header
 
125
that was recently seen. Discard the message if it is, otherwise continue to
 
126
filter the message:
 
127
.sp
 
128
.RS
 
129
.PP
 
130
 
 
131
.nf
 
132
`reformail -D 8000 duplicate.cache`
 
133
if ( $RETURNCODE == 0 )
 
134
    exit
 
135
.fi
 
136
.RE
 
137
The reformail command maintains a list of
 
138
recently seen Message-IDs in the file
 
139
\fIduplicate.cache\fR\&.
 
140
.PP
 
141
Here's a more complicated example. This fragment is intended to go right
 
142
after the message has been filtered according to your regular rules, and just
 
143
before the message should be saved in your mailbox:
 
144
.sp
 
145
.RS
 
146
.PP
 
147
 
 
148
.nf
 
149
cc $DEFAULT
 
150
xfilter "reformail -r -t"
 
151
/^To:.*/
 
152
getaddr($MATCH) =~ /^.*/;
 
153
 
 
154
MATCH=tolower($MATCH)
 
155
flock "vacation.lock" {
 
156
        `fgrep -iqx "$MATCH" vacation.lst 2>/dev/null || { \\
 
157
                  echo "$MATCH" >>vacation.lst ; \\
 
158
                  exit 1 ; \\
 
159
              } `
 
160
}
 
161
if ( $RETURNCODE == 0 )
 
162
   exit
 
163
to "| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL"
 
164
.fi
 
165
.RE
 
166
.PP
 
167
This code maintains a list of everyone who sent you mail in the file called
 
168
\fIvacation.lst\fR\&.
 
169
When a message is received from anyone that is not already on
 
170
the list, the address is added to the list, and the contents of the file
 
171
\fIvacation.msg\fR are mailed back to the sender.
 
172
This is intended to reply notify
 
173
people that you will not be answering mail for a short period of time.
 
174
.PP
 
175
The first statement saves the original message in your regular mailbox.
 
176
Then,
 
177
\fBxfilter<\fR
 
178
is used to generate an
 
179
autoreply header to the sender. The To: header in the
 
180
autoreply - which was
 
181
the sender of the original message - is extracted, and the \fBgetaddr\fR
 
182
function is used to strip the
 
183
person's name, leaving the address only. The file 
 
184
\fIvacation.lst\fR is checked,
 
185
using a lock file to guarantee atomic access and update (overkill, probably).
 
186
Note that the backslashes are required.
 
187
.PP
 
188
If the address is already in the file, \fBmaildrop\fR exits,
 
189
otherwise the
 
190
contents of \fIvacation.msg\fR are appended to the autoreply
 
191
header, and mailed out.
 
192
.PP
 
193
Here's a version of the vacation script that uses a GDBM database file
 
194
instead. The difference between this script and the previous script is that
 
195
the previous script will send a vacation message to a given E-mail address
 
196
only once. The following script will store the time that the vacation message
 
197
was sent in the GDBM file. If it's been at least a week since the vacation
 
198
message has been sent to the given address, another vacation message will be
 
199
sent.
 
200
.PP
 
201
Even though a GDBM database file is used, locking is still necessary
 
202
because the GDBM library does not allow more than one process to open the same
 
203
database file for writing:
 
204
.sp
 
205
.RS
 
206
.PP
 
207
 
 
208
.nf
 
209
cc $DEFAULT
 
210
xfilter "reformail -r -t"
 
211
/^To:.*/
 
212
getaddr($MATCH) =~ /^.*/;
 
213
MATCH=tolower($MATCH)
 
214
flock "vacation.lock" {
 
215
    current_time=time;
 
216
    if (gdbmopen("vacation.dat", "C") == 0)
 
217
    {
 
218
       if ( (prev_time=gdbmfetch($MATCH)) ne "" && \\
 
219
             $prev_time >= $current_time - 60 * 60 * 24 * 7)
 
220
       {
 
221
           exit
 
222
       }
 
223
       gdbmstore($MATCH, $current_time)
 
224
       gdbmclose
 
225
    }
 
226
}
 
227
to "| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL"
 
228
.fi
 
229
.RE
 
230
.PP
 
231
This script requires that \fBmaildrop\fR must be compiled with
 
232
GDBM
 
233
support enabled, which is done by default if GDBM libraries are present.
 
234
.PP
 
235
After you return from vacation, you can use a simple Perl script to obtain
 
236
a list of everyone who sent you mail (of course, that can also be determined
 
237
by examining your mailbox).
 
238
.SH "SEE ALSO"
 
239
.PP
 
240
\fBmaildrop\fR(1),
 
241
\fBmaildropfilter\fR(7),
 
242
\fBreformail\fR(1),
 
243
\fBegrep\fR(1),
 
244
\fBgrep\fR(1),
 
245
\fBsendmail\fR(8)\&.