1# GETHEADERINFO.RC
2#
3# EXTRACT EXTERNAL IP ADDRESSES AND DOMAINS FROM EMAIL HEADERS
4#
5# This section extracts the external IP addresses and domains found in the
6# headers of this email, information that later recipes use.
7#
8# Last updated: 5/30/2017
9
10# Extract the sending IP addresses from the Received: headers, first checking
11# each Received: header to be sure that the IP you're extracting is not from your
12# own system.  Examine only the first eight Received: headers, and extract only the
13# first four external IP addresses, since anything beyond that is probably
14# forged, and email with excessive Received: headers is dealt with later in the
15# SpamBouncer.
16
17# CHECK FIRST RECEIVED HEADER
18
19:0
20* H ?? ^(X-)?Received: from (.*$)
21{
22 LOCALIP="000.000.000.000"
23 LOCAL24="000.000.000"
24 LOCALIPREGEXP="NULL"
25 LOCALSENDER="host.example.com"
26 LOCALHELO="host.example.com"
27 LOCALNUMRCVDS=""
28 LOCALRCVD="NULL"
29 LOCALRECEIVER="host.example.com"
30
31 # Extract the header information.
32
33 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
34
35 # Check extracted info for local origin.
36
37 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
38
39 # Assign variable names.
40
41 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
42}
43
44
45# CHECK SECOND RECEIVED HEADER
46
47:0
48* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
49{
50 LOCALIP=000.000.000.000
51 LOCAL24="000.000.000"
52 LOCALIPREGEXP="NULL"
53 LOCALSENDER='host.example.com'
54 LOCALHELO='host.example.com'
55 LOCALNUMRCVDS='(X-)?Received: from (.*$)+'
56 LOCALRCVD=NULL
57 LOCALRECEIVER='host.example.com'
58
59 # Extract the header information.
60
61 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
62
63 # Check extracted info for local origin.
64
65 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
66
67 # Assign variable names.
68
69 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
70}
71
72
73# CHECK THIRD RECEIVED HEADER
74
75:0
76* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
77{
78 LOCALIP=000.000.000.000
79 LOCAL24="000.000.000"
80 LOCALIPREGEXP="NULL"
81 LOCALSENDER='host.example.com'
82 LOCALHELO='host.example.com'
83 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+'
84 LOCALRCVD=NULL
85 LOCALRECEIVER='host.example.com'
86
87 # Extract the header information.
88
89 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
90
91 # Check extracted info for local origin.
92
93 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
94
95 # Assign variable names.
96
97 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
98}
99
100
101# CHECK FOURTH RECEIVED HEADER
102
103:0
104* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
105{
106 LOCALIP=000.000.000.000
107 LOCAL24="000.000.000"
108 LOCALIPREGEXP="NULL"
109 LOCALSENDER='host.example.com'
110 LOCALHELO='host.example.com'
111 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+'
112 LOCALRCVD=NULL
113 LOCALRECEIVER='host.example.com'
114
115 # Extract the header information.
116
117  INCLUDERC=${SBDIR}/functions/extract-received-info.rc
118
119 # Check extracted info for local origin.
120
121  INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
122
123 # Assign variable names.
124
125  INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
126}
127
128
129# CHECK FIFTH RECEIVED HEADER
130
131:0
132* FOURTHEXIP ?? ^000\.000\.000\.000$
133* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
134{
135 LOCALIP=000.000.000.000
136 LOCAL24="000.000.000"
137 LOCALIPREGEXP="NULL"
138 LOCALSENDER='host.example.com'
139 LOCALHELO='host.example.com'
140 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+'
141 LOCALRCVD=NULL
142 LOCALRECEIVER='host.example.com'
143
144 # Extract the header information.
145
146 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
147
148 # Check extracted info for local origin.
149
150 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
151
152 # Assign variable names.
153
154 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
155}
156
157
158# CHECK SIXTH RECEIVED HEADER
159
160:0
161* FOURTHEXIP ?? ^000\.000\.000\.000$
162* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
163{
164 LOCALIP=000.000.000.000
165 LOCAL24="000.000.000"
166 LOCALIPREGEXP="NULL"
167 LOCALSENDER='host.example.com'
168 LOCALHELO='host.example.com'
169 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+'
170 LOCALRCVD=NULL
171 LOCALRECEIVER='host.example.com'
172
173 # Extract the header information.
174
175 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
176
177 # Check extracted info for local origin.
178
179 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
180
181 # Assign variable names.
182
183 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
184}
185
186
187# CHECK SEVENTH RECEIVED HEADER
188
189:0
190* FOURTHEXIP ?? ^000\.000\.000\.000$
191* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
192{
193 LOCALIP=000.000.000.000
194 LOCAL24="000.000.000"
195 LOCALIPREGEXP="NULL"
196 LOCALSENDER='host.example.com'
197 LOCALHELO='host.example.com'
198 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+'
199 LOCALRCVD=NULL
200 LOCALRECEIVER='host.example.com'
201
202 # Extract the header information.
203
204 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
205
206 # Check extracted info for local origin.
207
208 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
209
210 # Assign variable names.
211
212 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
213}
214
215
216# CHECK EIGHTH RECEIVED HEADER
217
218:0
219* FOURTHEXIP ?? ^000\.000\.000\.000$
220* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
221{
222 LOCALIP=000.000.000.000
223 LOCAL24="000.000.000"
224 LOCALIPREGEXP="NULL"
225 LOCALSENDER='host.example.com'
226 LOCALHELO='host.example.com'
227 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+'
228 LOCALRCVD=NULL
229 LOCALRECEIVER='host.example.com'
230
231 # Extract the header information.
232
233 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
234
235 # Check extracted info for local origin.
236
237 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
238
239 # Assign variable names.
240
241 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
242}
243
244# CHECK NINTH RECEIVED HEADER
245
246:0
247* FOURTHEXIP ?? ^000\.000\.000\.000$
248* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
249{
250 LOCALIP=000.000.000.000
251 LOCAL24="000.000.000"
252 LOCALIPREGEXP="NULL"
253 LOCALSENDER='host.example.com'
254 LOCALHELO='host.example.com'
255 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+'
256 LOCALRCVD=NULL
257 LOCALRECEIVER='host.example.com'
258
259 # Extract the header information.
260
261 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
262
263 # Check extracted info for local origin.
264
265 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
266
267 # Assign variable names.
268
269 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
270}
271
272# CHECK TENTH RECEIVED HEADER
273
274:0
275* FOURTHEXIP ?? ^000\.000\.000\.000$
276* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
277{
278 LOCALIP=000.000.000.000
279 LOCAL24="000.000.000"
280 LOCALIPREGEXP="NULL"
281 LOCALSENDER='host.example.com'
282 LOCALHELO='host.example.com'
283 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+'
284 LOCALRCVD=NULL
285 LOCALRECEIVER='host.example.com'
286
287 # Extract the header information.
288
289 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
290
291 # Check extracted info for local origin.
292
293 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
294
295 # Assign variable names.
296
297 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
298}
299
300# CHECK ELEVENTH RECEIVED HEADER
301
302:0
303* FOURTHEXIP ?? ^000\.000\.000\.000$
304* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
305{
306 LOCALIP=000.000.000.000
307 LOCAL24="000.000.000"
308 LOCALIPREGEXP="NULL"
309 LOCALSENDER='host.example.com'
310 LOCALHELO='host.example.com'
311 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+'
312 LOCALRCVD=NULL
313 LOCALRECEIVER='host.example.com'
314
315 # Extract the header information.
316
317 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
318
319 # Check extracted info for local origin.
320
321 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
322
323 # Assign variable names.
324
325 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
326}
327
328
329# CHECK TWELFTH RECEIVED HEADER
330
331:0
332* FOURTHEXIP ?? ^000\.000\.000\.000$
333* H ?? ^(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)
334{
335 LOCALIP=000.000.000.000
336 LOCAL24="000.000.000"
337 LOCALIPREGEXP="NULL"
338 LOCALSENDER='host.example.com'
339 LOCALHELO='host.example.com'
340 LOCALNUMRCVDS='(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from(.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+(X-)?Received: from (.*$)+'
341 LOCALRCVD=NULL
342 LOCALRECEIVER='host.example.com'
343
344 # Extract the header information.
345
346 INCLUDERC=${SBDIR}/functions/extract-received-info.rc
347
348 # Check extracted info for local origin.
349
350 INCLUDERC=${SBDIR}/functions/checklocalrcvd.rc
351
352 # Assign variable names.
353
354 INCLUDERC=${SBDIR}/functions/assign-local-vars.rc
355}
356
357# EXTRACT THE FROM:, REPLY-TO:, AND X-ORIGINAL-IP: OR X-ORIGIN: LINE, IF ANY.
358#
359
360:0
361* H ?? ^From:
362{
363 LOCALBUFFER='NULL'
364
365 :0
366 * H ?? ^From:.*\".*@.*\".*<\/([0-9a-z��������������������������������������]|\
367                     [0-9a-z��������������������������������������]\
368                     [-_+.0-9a-z��������������������������������������]*\
369                     [0-9a-z��������������������������������������])@\
370                     ([0-9a-z��������������������������������������]\
371                     [-_0-9a-z��������������������������������������]*\.)+\
372                     (xn--[0-9a-z][0-9a-z]*|\
373                      ([a-z��������������������������������������]|\?)\
374                      ([a-z��������������������������������������]|\?)\
375                      ([a-z��������������������������������������]|\?)*\
376                      (\.[a-z��������������������������������������]\
377                         [a-z��������������������������������������])?)
378 { LOCALBUFFER=${MATCH} }
379
380 :0
381 * LOCALBUFFER ?? ^NULL$
382 * H ?? ^From:(.*[^0-9a-z��������������������������������������"])?\
383                ()\/([0-9a-z��������������������������������������]|\
384                     [0-9a-z��������������������������������������]\
385                     [-_+.0-9a-z��������������������������������������]*\
386                     [0-9a-z��������������������������������������])@\
387                     ([0-9a-z��������������������������������������]\
388                     [-_0-9a-z��������������������������������������]*\.)+\
389                     (xn--[0-9a-z][0-9a-z]*|\
390                      ([a-z��������������������������������������]|\?)\
391                      ([a-z��������������������������������������]|\?)\
392                      ([a-z��������������������������������������]|\?)*\
393                      (\.[a-z��������������������������������������]\
394                         [a-z��������������������������������������])?)
395 { LOCALBUFFER=${MATCH} }
396
397 :0
398 * ! LOCALBUFFER ?? ^NULL$
399 {
400  LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${TR} '\n' ' '`
401  LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${TR} '\r' ' '`
402  LOCALEMAIL=`${ECHO} ${LOCALBUFFER} | ${SED} -e 's/[^0-9A-Z���������������������������،������ޟ�a-z��������������������������������������]*$//g'`
403
404  ## If email was successfully extracted, assign variables.
405  :0
406  * ! LOCALEMAIL ?? ^noemail@example\.com$
407  { FROMEMAIL=`${ECHO} -n ${LOCALEMAIL} | ${TR} '[:upper:]' '[:lower:]'` }
408
409  :0
410  * LOCALEMAIL ?? ^noemail@example\.com$
411  { FROMEMAIL=${LOCALEMAIL} }
412 }
413}
414
415## Extract login from the From email address.
416:0
417* ! FROMEMAIL ?? ^noemail@example\.com$
418{
419 :0
420 * FROMEMAIL ?? ^[0-9a-z��������������������������������������]\
421                 [-_+.0-9a-z��������������������������������������]*
422 {
423  FROMLOGIN=${MATCH}
424  FROMLOGIN=`${ECHO} ${FROMLOGIN} | ${SED} -e 's/@.*$//g'`
425 }
426}
427
428## Extract the host from the From email address.
429##
430:0
431* ! FROMEMAIL ?? ^noemail@example\.com$
432* FROMEMAIL ?? ^.*@\/([0-9a-z��������������������������������������]\
433                      [-_0-9a-z��������������������������������������]*\.)*\
434                      (xn--[0-9a-z][0-9a-z]*|\
435                      ([a-z��������������������������������������]|\?)\
436                      ([a-z��������������������������������������]|\?)\
437                      ([a-z��������������������������������������]|\?)*\
438                      (\.[a-z��������������������������������������]\
439                         [a-z��������������������������������������])?)$
440{
441 LOCALBUFFER=${MATCH}
442 LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${TR} '\n' ' '`
443 LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${TR} '\r' ' '`
444 FROMHOST=`${ECHO} ${LOCALBUFFER} | ${SED} -e 's/[^a-z��������������������������������������]*$//g'`
445}
446
447## Canonicalize and hash the email address.
448
449:0
450* ! FROMLOGIN ?? ^nologin$
451* ! FROMHOST ?? ^host\.example\.com$
452{
453 LOCALLOGIN=${FROMLOGIN}
454 LOCALHOST=${FROMHOST}
455 LOCALHASH='NULL'
456 INCLUDERC=${SBDIR}/functions/hash-email.rc
457 FROMHASH=${LOCALHASH}
458}
459
460## Extract the domain from the From host.
461
462:0
463* ! FROMEMAIL ?? ^noemail@example\.com$
464{
465 LOCALHOST=${FROMHOST}
466 INCLUDERC=${SBDIR}/functions/get-domain.rc
467 FROMDOMAIN=${LOCALDOMAIN}
468}
469
470:0
471* H ?? ^(From|Return-Path:)( )\/.*$
472{
473 LOCALBUFFER=${MATCH}
474
475 :0
476 { MAILFROMHOST=`${ECHO} "${LOCALBUFFER}" | ${SED} -e 's/^.*@//' -e 's/[^-_0-9a-zA-Z.].*$//'` }
477
478 :0
479 * MAILFROMHOST ?? ^$
480 { MAILFROMHOST=host.example.com }
481}
482
483LOCALDOMAIN='example.com'
484LOCALHOST=${MAILFROMHOST}
485INCLUDERC=${SBDIR}/functions/get-domain.rc
486MAILFROMDOMAIN=${LOCALDOMAIN}
487
488:0
489* H ?? ^Errors-To:
490{
491 LOCALBUFFER=`${FORMAIL} -xErrors-To:`
492
493 :0
494 { LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${SED} -e '/^[^@]*$/d' -e '/^[^@]*["][^"]*["][^@]*$/d'` }
495
496 :0
497 { ERRORHOST=`${ECHO} "${LOCALBUFFER}" | ${SED} -e 's/^.*@//' -e 's/[^-_0-9a-zA-Z.].*$//'` }
498
499 :0
500 * ERRORHOST ?? ^$
501 { ERRORHOST=host.example.com }
502}
503
504LOCALDOMAIN='example.com'
505LOCALHOST=${ERRORHOST}
506INCLUDERC=${SBDIR}/functions/get-domain.rc
507ERRORDOMAIN=${LOCALDOMAIN}
508
509:0
510* H ?? ^Reply-to:
511{
512 LOCALBUFFER='NULL'
513
514 :0
515 * H ?? ^Reply-to:.*<\/([0-9a-z��������������������������������������]|\
516                     [0-9a-z��������������������������������������]\
517                     [-_+.0-9a-z��������������������������������������]*\
518                     [0-9a-z��������������������������������������])@\
519                     ([0-9a-z��������������������������������������]\
520                     [-_0-9a-z��������������������������������������]*\.)+\
521                     (xn--[0-9a-z][0-9a-z]*|\
522                      ([a-z��������������������������������������]|\?)\
523                      ([a-z��������������������������������������]|\?)\
524                      ([a-z��������������������������������������]|\?)*\
525                      (\.[a-z��������������������������������������]\
526                         [a-z��������������������������������������])?)
527 { LOCALBUFFER=${MATCH} }
528
529 :0
530 * LOCALBUFFER ?? ^NULL$
531 * H ?? ^Reply-to: ([0-9a-z��������������������������������������]|\
532                     [0-9a-z��������������������������������������]\
533                     [-_+.0-9a-z��������������������������������������]*\
534                     [0-9a-z��������������������������������������])@\
535                     ([0-9a-z��������������������������������������]\
536                     [-_0-9a-z��������������������������������������]*\.)+\
537                     (xn--[0-9a-z][0-9a-z]*|\
538                      ([a-z��������������������������������������]|\?)\
539                      ([a-z��������������������������������������]|\?)\
540                      ([a-z��������������������������������������]|\?)*\
541                      (\.[a-z��������������������������������������]\
542                         [a-z��������������������������������������])?)
543 { LOCALBUFFER=${MATCH} }
544
545 :0
546 * ! LOCALBUFFER ?? ^NULL$
547 {
548  LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${TR} '\n' ' '`
549  LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${TR} '\r' ' '`
550  LOCALEMAIL=`${ECHO} ${LOCALBUFFER} | ${SED} -e 's/[^0-9A-Z���������������������������،������ޟ�a-z��������������������������������������]*$//g'`
551
552  ## If email was successfully extracted, assign variables.
553  :0
554  * ! LOCALEMAIL ?? ^noemail@example\.com$
555  { REPLYTOEMAIL=`${ECHO} -n ${LOCALEMAIL} | ${TR} '[:upper:]' '[:lower:]'` }
556
557  :0
558  * LOCALEMAIL ?? ^noemail@example\.com$
559  { REPLYTOEMAIL=${LOCALEMAIL} }
560 }
561}
562
563## Extract login from the Reply-to email address.
564:0
565* ! REPLYTOEMAIL ?? ^noemail@example\.com$
566{
567 :0
568 * REPLYTOEMAIL ?? ^[0-9a-z��������������������������������������]\
569                 [-_+.0-9a-z��������������������������������������]*
570 {
571  REPLYTOLOGIN=${MATCH}
572  REPLYTOLOGIN=`${ECHO} ${REPLYTOLOGIN} | ${SED} -e 's/@.*$//g'`
573 }
574}
575
576## Extract the host from the Reply-to email address.
577##
578:0
579* ! REPLYTOEMAIL ?? ^noemail@example\.com$
580* REPLYTOEMAIL ?? ^.*@\/([0-9a-z��������������������������������������]\
581                      [-_0-9a-z��������������������������������������]*\.)*\
582                      (xn--[0-9a-z][0-9a-z]*|\
583                      ([a-z��������������������������������������]|\?)\
584                      ([a-z��������������������������������������]|\?)\
585                      ([a-z��������������������������������������]|\?)*\
586                      (\.[a-z��������������������������������������]\
587                         [a-z��������������������������������������])?)$
588{
589 LOCALBUFFER=${MATCH}
590 LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${TR} '\n' ' '`
591 LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${TR} '\r' ' '`
592 REPLYTOHOST=`${ECHO} ${LOCALBUFFER} | ${SED} -e 's/[^a-z��������������������������������������]*$//g'`
593}
594
595## Canonicalize and hash the email address.
596
597:0
598* ! REPLYTOLOGIN ?? ^nologin$
599* ! REPLYTOHOST ?? ^host\.example\.com$
600{
601 LOCALLOGIN=${REPLYTOLOGIN}
602 LOCALHOST=${REPLYTOHOST}
603 LOCALHASH='NULL'
604 INCLUDERC=${SBDIR}/functions/hash-email.rc
605 REPLYTOHASH=${LOCALHASH}
606}
607
608## Extract the domain from the Reply-to host.
609
610:0
611* ! REPLYTOEMAIL ?? ^noemail@example\.com$
612{
613 LOCALHOST=${REPLYTOHOST}
614 INCLUDERC=${SBDIR}/functions/get-domain.rc
615 REPLYTODOMAIN=${LOCALDOMAIN}
616}
617
618# TO EMAIL
619:0
620* H ?? ^To:
621{
622 LOCALBUFFER=`${FORMAIL} -xTo:`
623
624 :0
625 { LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${SED} -e '/^[^@]*$/d' -e '/^[^@]*["][^"]*["][^@]*$/d'` }
626
627 :0
628 { LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${SED} -e 's/["][^"]*["][^������������������������������ޟ�������������������������������A-Za-z0-9]*//' -e 's/[ ]*\=\?[^?]*\?[^?]\?[^?]*\?\=[ ]*//' -e 's/^[^@]*[ ][^������������������������������ޟ�������������������������������A-Za-z0-9]*//' -e 's/\=\?[[^?]\?[������������������������������ޟ�������������������������������A-Za-z]\?[^?]*\=[cC][dD]\=[fF]8_[ ]*//' -e 's/^[^������������������������������ޟ�������������������������������A-Za-z0-9]*//' -e 's/, .*$//' -e 's/ (.*$//' -e 's/[^������������������������������ޟ�������������������������������A-Za-z]*$//' -e '2,$d'` }
629
630 :0
631 { TOEMAIL=`${ECHO} "${LOCALBUFFER}" | ${SED} -e 's/[^������������������������������ޟ�������������������������������A-Za-z0-9]*//'` }
632
633 :0
634 * TOEMAIL ?? ^$
635 { TOEMAIL=noemail@example.com }
636}
637
638:0
639* H ?? ^To:
640{
641 LOCALBUFFER=`${FORMAIL} -xTo:`
642
643 :0
644 { LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${SED} -e '/^[^@]*$/d' -e '/^[^@]*["][^"]*["][^@]*$/d'` }
645
646 :0
647 { LOCALBUFFER=`${ECHO} "${LOCALBUFFER}" | ${SED} -e 's/["][^"]*["][^������������������������������ޟ�������������������������������A-Za-z0-9]*//' -e 's/[ ]*\=\?[^?]*\?[^?]\?[^?]*\?\=[ ]*//' -e 's/^[^@]*[ ][^������������������������������ޟ�������������������������������A-Za-z0-9]*//' -e 's/\=\?[^?]\?[������������������������������ޟ�������������������������������A-Za-z]\?[^?]*\=[cC][dD]\=[fF]8_[ ]*//' -e 's/^[_������������������������������ޟ�������������������������������A-Za-z0-9-]*<//' -e 's/^[^������������������������������ޟ�������������������������������A-Za-z0-9]//' -e 's/@.*$//' -e '2,$d'` }
648
649 :0
650 { TOLOGON=`${ECHO} "${LOCALBUFFER}" | ${SED} -e 's/[^������������������������������ޟ�������������������������������A-Za-z0-9]*//'` }
651
652 :0
653 * TOLOGON ?? ^$
654 { TOLOGON=noemail }
655}
656
657:0
658* H ?? ^To:
659{
660 LOCALBUFFER=`${FORMAIL} -xTo:`
661
662 :0
663 { TOHOST=`${ECHO} "${LOCALBUFFER}" | ${SED} -e 's/^.*@//' -e 's/[^-_0-9a-zA-Z.].*$//'` }
664
665 :0
666 * TOHOST ?? ^$
667 { TOHOST=host.example.com }
668}
669
670LOCALDOMAIN='example.com'
671LOCALHOST=${TOHOST}
672INCLUDERC=${SBDIR}/functions/get-domain.rc
673TODOMAIN=${LOCALDOMAIN}
674
675:0
676* H ?? ^X-Original-IP:
677{ XORIGINALIP=`${FORMAIL} -xX-Original-IP:` }
678
679:0
680* H ?? ^X-Origin:
681{ XORIGINALIP=`${FORMAIL} -xX-Origin:` }
682
683:0
684* H ?? ^X-IP:
685{ XORIGINALIP=`${FORMAIL} -xX-IP:` }
686
687:0
688* H ?? ^X-OrignIP:
689{ XORIGINALIP=`${FORMAIL} -xX-OrignIP:` }
690
691:0
692* H ?? ^X-Originator-IP:
693{ XORIGINALIP=`${FORMAIL} -xX-Originator-IP:` }
694
695:0
696* H ?? ^X-IPAddress:
697{ XORIGINALIP=`${FORMAIL} -xX-IPAddress:` }
698
699:0
700* H ?? ^X-PHP-Script:
701{
702 LOCALBUFFER=`${FORMAIL} -xX-PHP-Script:`
703
704 :0
705 * LOCALBUFFER ?? ^.*\/[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?[^0-9].*$
706 { LOCALBUFFER=${MATCH} }
707
708 XORIGINALIP=`${ECHO} "${LOCALBUFFER}" | ${SED} -e 's/[^0-9.].*$//'`
709}
710
711
712# Now, generate the REVERSE IP equivalents of each extracted external IP, for
713# checking against DNS-based blocklists.
714
715:0
716* ! XORIGINALIP ?? ^000\.000\.000\.000$
717{
718 LOCALIP=${XORIGINALIP}
719 INCLUDERC=${SBDIR}/functions/reverseip.rc
720 XORIGINALREVIP=${LOCALREVIP}
721 INCLUDERC=${SBDIR}/functions/cidrmatch.rc
722 XORIGINALIPREGEXP=${LOCALIPREGEXP}
723}
724