1MAILDROPEX(7)               Double Precision, Inc.               MAILDROPEX(7)
2
3
4

NAME

6       maildropex - maildrop filtering language examples
7

SYNOPSIS

9       $HOME/.mailfilter, $HOME/.mailfilters/*
10

DESCRIPTION

12       If $HOME/.mailfilter exists, filtering instructions in this file will
13       be carried out prior to delivering the message. The filtering
14       instructions may instruct maildrop to discard the message, save the
15       message in a different mailbox, or forward the message to another
16       address. If $HOME/.mailfilter does not exist, or does not provide
17       explicit delivery instructions, maildrop delivers the message to the
18       user's system mailbox.
19
20       The files in $HOME/.mailfilters are used when maildrop is invoked in
21       embedded mode.
22

EXAMPLES

24       Take all mail that's sent to the 'auto' mailing list, and save it in
25       Mail/auto. The 'auto' mailing list software adds a "Delivered-To:
26       auto@domain.com" header to all messages:
27
28           if (/^Delivered-To: *auto@domain\.com$/)
29               to Mail/auto
30
31       After the to command delivers the message, maildrop automatically stops
32       filtering and terminates without executing the subsequent instructions
33       in the filter file.
34
35       Take all mail from <boss@domain.com> about the current project status,
36       save it in Mail/project, then forward a copy to John:
37
38           if (/^From: *boss@domain\.com/ \
39               && /^Subject:.*[:wbreak:]project status[:wbreak:]/)
40           {
41               cc "!john"
42               to Mail/project
43           }
44
45       Note that it is necessary to use a backslash in order to continue the
46       if statement on the next line.
47
48       Keep copies of the last 50 messages that you received in the maildir
49       directory 'backup'. NOTE: 'backup' must be a maildir directory, not a
50       mailbox. You can create a maildir using the maildirmake command.
51
52           cc backup
53           `cd backup/new && rm -f dummy \`ls -t | sed -e 1,50d\``
54
55       Put this at the beginning of your filter file, before any other
56       filtering instructions. This is a good idea to have when you are
57       learning maildrop. If you make a mistake and accidentally delete a
58       message, you can recover it from the backup/new subdirectory.
59
60       Save messages that are at least 100 lines long (approximately) into
61       Mail/IN.Large::
62
63                if ( $LINES > 100 )
64                   to Mail/IN.Large
65
66       Send messages from the auto mailing list to the program 'archive',
67       using a lock file to make sure that only one instance of the archive
68       program will be running at the same time:
69
70                if (/^Delivered-To: *auto@domain\.com$/)
71                   dotlock "auto.lock" {
72
73                          to "|archive"
74                   }
75
76       Check if the Message-ID: header in the message is identical to the same
77       header that was recently seen. Discard the message if it is, otherwise
78       continue to filter the message:
79
80           `reformail -D 8000 duplicate.cache`
81           if ( $RETURNCODE == 0 )
82               exit
83
84       The reformail[1] command maintains a list of recently seen Message-IDs
85       in the file duplicate.cache.
86
87           Note
88           Unlike a similar feature in the formail command, reformail[1] takes
89           care of locking the file, so it's not necessary to implement your
90           own locking mechanism for this option.
91
92       Here's a more complicated example. This fragment is intended to go
93       right after the message has been filtered according to your regular
94       rules, and just before the message should be saved in your mailbox:
95
96           cc $DEFAULT
97           xfilter "reformail -r -t"
98           /^To:.*/
99           getaddr($MATCH) =~ /^.*/;
100
101           MATCH=tolower($MATCH)
102           flock "vacation.lock" {
103                   `fgrep -iqx "$MATCH" vacation.lst 2>/dev/null || { \
104                             echo "$MATCH" >>vacation.lst ; \
105                             exit 1 ; \
106                         } `
107           }
108           if ( $RETURNCODE == 0 )
109              exit
110           to "| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL"
111
112       This code maintains a list of everyone who sent you mail in the file
113       called vacation.lst. When a message is received from anyone that is not
114       already on the list, the address is added to the list, and the contents
115       of the file vacation.msg are mailed back to the sender. This is
116       intended to reply notify people that you will not be answering mail for
117       a short period of time.
118
119       The first statement saves the original message in your regular mailbox.
120       Then, xfilter[2] is used to generate an autoreply header to the sender.
121       The To: header in the autoreply - which was the sender of the original
122       message - is extracted, and the getaddr[3] function is used to strip
123       the person's name, leaving the address only. The file vacation.lst is
124       checked, using a lock file to guarantee atomic access and update
125       (overkill, probably). Note that the backslashes are required.
126
127       If the address is already in the file, maildrop exits, otherwise the
128       contents of vacation.msg are appended to the autoreply header, and
129       mailed out.
130
131           Note
132           An easier to make a vacation script is with mailbot(1)[4].
133
134       Here's a version of the vacation script that uses a GDBM database file
135       instead. The difference between this script and the previous script is
136       that the previous script will send a vacation message to a given E-mail
137       address only once. The following script will store the time that the
138       vacation message was sent in the GDBM file. If it's been at least a
139       week since the vacation message has been sent to the given address,
140       another vacation message will be sent.
141
142       Even though a GDBM database file is used, locking is still necessary
143       because the GDBM library does not allow more than one process to open
144       the same database file for writing:
145
146           cc $DEFAULT
147           xfilter "reformail -r -t"
148           /^To:.*/
149           getaddr($MATCH) =~ /^.*/;
150           MATCH=tolower($MATCH)
151           flock "vacation.lock" {
152               current_time=time;
153               if (gdbmopen("vacation.dat", "C") == 0)
154               {
155                  if ( (prev_time=gdbmfetch($MATCH)) ne "" && \
156                        $prev_time >= $current_time - 60 * 60 * 24 * 7)
157                  {
158                      exit
159                  }
160                  gdbmstore($MATCH, $current_time)
161                  gdbmclose
162               }
163           }
164           to "| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL"
165
166       This script requires that maildrop must be compiled with GDBM support
167       enabled, which is done by default if GDBM libraries are present.
168
169       After you return from vacation, you can use a simple Perl script to
170       obtain a list of everyone who sent you mail (of course, that can also
171       be determined by examining your mailbox).
172

SEE ALSO

174       maildrop(1)[5], maildropfilter(7)[6], reformail(1)[1], mailbot(1)[4],
175       egrep(1), grep(1), sendmail(8).
176

AUTHOR

178       Sam Varshavchik
179           Author
180

NOTES

182        1. reformail
183           http://www.courier-mta.org/maildrop/reformail.html
184
185        2. xfilter
186           http://www.courier-mta.org/maildrop/maildropfilter.html#xfilter
187
188        3. getaddr
189           http://www.courier-mta.org/maildrop/maildropfilter.html#getaddr
190
191        4. mailbot(1)
192           http://www.courier-mta.org/maildrop/mailbot.html
193
194        5. maildrop(1)
195           http://www.courier-mta.org/maildrop/maildrop.html
196
197        6. maildropfilter(7)
198           http://www.courier-mta.org/maildrop/maildropfilter.html
199
200
201
202Courier Mail Server               11/04/2020                     MAILDROPEX(7)
Impressum