LOGFILE="${HOME}/PROCMAIL.LOG" VERBOSE="on" LOGABSTRACT="all" # # Find the valid recipient address of an e-mail. # # The construct is, if a valid address is found, to fall through with # VALID_ADDRESS set, (i.e., its value is true,) and with DELIVERED_TO # containing the valid recipient e-mail address, and with an # "X-Delivered-To: " record inserted into the e-mail headers containing # the valid e-mail address. All "Delivered-To: " headers will be # removed. # # Else, VALID_ADDRESS is reset, (i.e., its value is false,) if no # valid recipient address was found, and the e-mail headers will # have no "X-Delivered-To: " record added; if a recipient address was # found that matched any domain in the database, then DELIVERED_TO # will contain that address, (and so will the "X-Delivered-To: " # record inserted in the e-mail's headers, and the "Delivered-To: " # records removed from the e-mail headers,) else, DELIVERED_TO will be # null, (i.e., "", and there will be no "X-Delivered-To: " header # inserted, and the "Delivered-To: " records will not be removed.). # # Assume the e-mail has a valid recipient that can be found in the # databases, (which are lower case sorted lists of all valid e-mail # addresses for a machine or domain, e.g., tolower | sort -u,) and # search for the recipient address: # VALID_ADDRESS=true # # E-mail message already have a valid recipient address, (i.e., has # this routine already be run on the message-the "X-Delivered-To: " # header is its "signature"): # # Upstream providers, for which messages are processed here: # usp='(upstream1\.net|upstream2\.com)' # :0 * !^x-delivered-to: { # # Find all RFC 821 paragraph 4.1.2 "Received: ... for ..." # e-mail addresses, and query the database for any matches: # :0 Wh DELIVERED_TO=| /usr/local/bin/receivedAddressdb -r n -e localhost "${HOME}/.procmail.user" # :0 wfha | formail -I "X-Delivered-To: ${DELIVERED_TO}" -I "Delivered-To:" # :0 E { # # No envelope to address found; find the e-mail addresses in all # "Delivered-To: " records, and query the database for any # matches-excluding local addresses, (e.g., external addresses # have precedence): # :0 Wh DELIVERED_TO=| /usr/local/bin/receivedTodb -r n -D -e localhost -e thedomain.com "${HOME}/.procmail.user" # :0 wfha | formail -I "X-Delivered-To: ${DELIVERED_TO}" -I "Delivered-To:" # :0 E { # # No envelope to, or, external Delivered-To: address found; # find the e-mail addresses in all "Delivered-To: " records, # and query the database for any matches-including local # addresses: # :0 Wh DELIVERED_TO=| /usr/local/bin/receivedTodb -r n -D -e localhost "${HOME}/.procmail.user" # :0 wfha | formail -I "X-Delivered-To: ${DELIVERED_TO}" -I "Delivered-To:" # :0 E { # # No envelope to, or, Delivered-To: address found; find # the e-mail addresses in the To: and Cc: records, and # query the database for any matches: # :0 Wh DELIVERED_TO=| /usr/local/bin/receivedTodb -r n -e localhost "${HOME}/.procmail.user" # :0 wfha | formail -I "X-Delivered-To: ${DELIVERED_TO}" -I "Delivered-To:" # :0 E { # # Apparently-To: addresses: # :0 Wh DELIVERED_TO=| /usr/local/bin/receivedTodb -r n -A -e localhost "${HOME}/.procmail.user" # :0 wfha | formail -I "X-Delivered-To: ${DELIVERED_TO}" -I "Delivered-To:" # :0 E { VALID_ADDRESS=false # # Address to someone in this domain, but not valid? # :0 * ^delivered-to:[ ]+(.*[^-0-9a-z._+=?])*\/[-0-9a-z._+=?]+@([-0-9a-z._+=]+\.)*thedomain\.com * ? /usr/local/bin/bsearchtext -r n -f "${HOME}/.procmail.addresses" "# ${MATCH}" { DELIVERED_TO="${MATCH}" # :0 wfh | formail -I "X-Delivered-To: ${DELIVERED_TO}" } # :0 E { # # Address to any upstream provider's domain, but # not valid? # :0 * $ ^delivered-to:[ ]+(.*[^-0-9a-z._+=?])*\/[-0-9a-z._+=?]+@([-0-9a-z._+=]+\.)*${usp} { DELIVERED_TO="${MATCH}" # :0 wfh | formail -I "X-Delivered-To: ${DELIVERED_TO}" -I "Delivered-To:" } # :0 E { # # No envelope to, Delivered-To:, To:, or, Cc: e-mail # address found; the e-mail does not have any valid # addresses-look for any address matching a domain in # any "Received: ... for ..." record: # :0 WhE DELIVERED_TO=| /usr/local/bin/receivedAddressdb -r n -d -e localhost "${HOME}/.procmail.domains" # :0 wfha | formail -I "X-Delivered-To: ${DELIVERED_TO}" -I "Delivered-To:" # :0 E { # # No address found, use user's address, and # prohibit retaliation: # :0 wfh | formail -I "X-Delivered-To: user@thedomain.com" -A "Log: spam no bounce" -I "Log: no envelope to address" } } } } } } } } } # :0 E { # # E-mail message already has a valid recipient address, get it: # :0 wh DELIVERED_TO=| formail -zx "X-Delivered-To:" # # Query the database for a match of the valid recipient address: # :0 * 1^0 !? /usr/local/bin/bsearchtext -r n -f "${HOME}/.procmail.user" "${DELIVERED_TO}" * 1^0 ^log:[ ]+no[ ]+envelope[ ]+to[ ]+address { VALID_ADDRESS=false } # # Found a valid recipient address in the database, remove any # "Delivered-To: " headers: # :0 wfhE * ^delivered-to: | formail -I "Delivered-To:" } # ###################################################################### # # A license is hereby granted to reproduce this software for personal, # non-commercial use. # # THIS PROGRAM IS PROVIDED "AS IS". THE AUTHOR PROVIDES NO WARRANTIES # WHATSOEVER, EXPRESSED OR IMPLIED, INCLUDING WARRANTIES OF # MERCHANTABILITY, TITLE, OR FITNESS FOR ANY PARTICULAR PURPOSE. THE # AUTHOR DOES NOT WARRANT THAT USE OF THIS PROGRAM DOES NOT INFRINGE THE # INTELLECTUAL PROPERTY RIGHTS OF ANY THIRD PARTY IN ANY COUNTRY. # # So there. # # Copyright (c) 1992-2005, John Conover, , All # Rights Reserved. # # $Revision: 1.0 $ # $Date: 2005/03/11 08:33:13 $ # $Id: howto-to.txt,v 1.0 2005/03/11 08:33:13 conover Exp $ # $Log: howto-to.txt,v $ # Revision 1.0 2005/03/11 08:33:13 conover # Initial revision #