procmail
[Top] [All Lists]

Re: Procmail question

1996-09-23 04:58:13
J. Daniel Smith writes:
Alan K. Stebbens writes on 22 September 1996 at 15:27:01
Is there any reasonable way to write a procmail script so that it
looks in a file, call it, losers.txt, say, for the ^From: line in the
header, and then sends matching messages to /dev/null?

This has been discussed before, many times.  Please review the procmail
archive, for messages, from me even, within the last two or three

Yes indeed; and if you do so, you'll note that recipes like the one from 

  ...

are not a particuarlly good idea.  It's best to just send such
messages straight to /dev/null; if you feel you must respond in some
way, then manually send a message to the user's postmaster and/or ISP.


Might try something like:

    # ${SENDER} is the address of whoever sent the message, the formail
    # command extracts it
    #
    SENDER=`${HOME}/.bin/formail -rtzx To:`
    #
    # if ${SENDER} is in the ${HOME}/.mailrc, then file the message in
    # your home file-messages from someone you have an alias for are 
    # assumed to be trusted friends, and the message is authentic
    #
    :0 h
    * ? test -f ${HOME}/.mailrc
    * ? fgrep -i -s "$SENDER" ${HOME}/.mailrc
    myhomefile
    #
    # if ${SENDER} is in the reject list, file the message in the
    # trash-note that entire domain names can be rejected by placing
    # only the domain name in the reject list-in case the ISP's are
    # not responsive.
    #
    :0 h
    * ? test -f ${HOME}/.procmail.reject
    * ? echo "${SENDER}" | fgrep -i -s -f ${HOME}/.procmail.reject
    /dev/null

where ${HOME}/.procmail.reject is of the form:

    mother(_at_)home(_dot_)com

to reject only letters from your mother, and

    home.com

would reject all letters from home-note that if you have an alias for
sis(_at_)home(_dot_)com in your ~/.mailrc file, then messages from her would not
be rejected. In addition, you may want to try:

    #
    # Then, if there is no "^To:" record in the message, then the message is,
    # almost certainly junk mail.
    #
    :0
    * !^To:.*
    junk

Because folks write stuff that scans the usenet news directories for
email addresses, and then hammer sendmail(1) with get rich schemes,
which get sent to you. If the messages are sent individually, this
won't work, but most are sent with enough addresses where sendmail
omits the "To: " record, (sometimes you will see an "address list
suppressed" in the "^To: " record.)  So, if it does not have a "To: "
record, put it in the junk mailbox, or perhaps /dev/null would be
better.

You can also do something like:

    # Finally, if not specifically addressed to at least this machine, the
    # message is to be considered junk mail. This will correctly file
    # messages that are .forward'ed from other accounts, bang addresses,
    # etc. Note that the "* !^TOmymachine" will correctly read header records
    # of the form "Resent-To:.*mymachine" and not file the message in "junk"
    # if resent to an address that contains at least this machine name. The
    # "^TO" will match "Original-To:", "Original-Cc:", "Original-Bcc:",
    # "To:", "Cc:", "Bcc:", "Xenvelope-To:", "Apparently-To",
    # "Apparently-Resent-To:", "Resent-To:", "Resent-Cc:", and
    # "Resent-Bcc:".
    #
    :0
    * !^TOmymachine
    junk

Or, you might want to use me(_at_)mymachine(_dot_)domain(_dot_)com(_dot_) This 
will work
pretty well unless someone bounces an email to you-which they
shouldn't be doing anyhow, because when you hit the reply button, you
could inadvertently reply to the wrong address, which could be
embarrassing, (like if sis bounced one of mother's messages to you.)
(The formal way of doing such things is with RFC 934 encapsulation, or
with digests, if mother is long winded.) You might want to try
!^To: +me(_at_)mymachine(_dot_)domain(_dot_)com to only let messages that are 
specifically
addressed to you through.

These should be at the end of your ~/.procmailrc, after any, and all,
stuff from mailing lists, etc., have been handled.

        John

-- 

John Conover, 631 Lamont Ct., Campbell, CA., 95008, USA.
VOX 408.370.2688, FAX 408.379.9602
john(_at_)johncon(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>