---> UTA - Jari's Procmail module description [Previous]

Table of contents ftp://cs.uta.fi/pub/ssjaaa/pm-code.html

Document id
Pm-jaaddr.rc -- extract 'foo@some.com' email address from variable INPUT
Pm-jabup.rc -- Keeep N arriving message backup in separate directory
Pm-jacookie.rc -- Handle cookie (unique id) confirmations
Pm-jacookie1.rc -- Generate unique id from INPUT variable.
Pm-jalint.rc -- Procmail: Run cron once a day
Pm-jadaemon.rc -- Handle DAEMON messages by changing subject
Pm-jadate.rc -- Read date from the message hdrs: From_, Receved:
Pm-jadate1.rc -- 'Tue, 31 Dec 1997' date parser from variable INPUT
Pm-jadate2.rc -- 'YYYY-MM-DD' ISO date parser from variable INPUT
Pm-jadate3.rc -- 'Tue Nov 25 19:32:57' date parser from variable INPUT
Pm-jadate4.rc -- make RFC 'Mon, 1 Dec 1997 17:41:09' and parse values
Pm-jadup.rc -- Procmail: Handle duplicates; store to separate folder
Pm-jaempty.rc -- check if message body is empty (nothing relevant)
Pm-jafrom.rc -- get message's best FROM field without calling `formail'
Pm-jafwd.rc -- Controlling forwarding remotedly, procmail 3.11pre7
Pm-jamime-kill.rc -- Kill MS Explorer/Lotus notes attachement
Pm-jamime.rc -- subroutine to read mime boundary etc. variables
Pm-janetmind.rc -- handle http://minder.netmind.com/ messages
Pm-janslookup.rc -- run nslookup on variable INPUT
Pm-japing.rc -- reply shortly to message "Subject: ping"; account ok
Pm-japop3.rc -- Subject field cleaner and canonilizer (Re:)
Pm-jarandf.rc -- pick (rand)om line from (f)ile
Pm-jasrv-check.rc -- check FILE validity, subroutine for File Server
Pm-jasrv-err.rc -- send message, subroutine for File Server
Pm-jasrv-from.rc -- compose reply, subroutine for File Server
Pm-jasrv-msg.rc -- send message, subroutine for File Server
Pm-jasrv-req.rc -- server request check, subroutine for File Server
Pm-jasrv-send.rc -- server request check, subroutine for File Server
Pm-jasrv.rc -- Jari's MPFS (Mime Procmail 3.11+ File server)
Pm-jasrv1.rc -- Jari's TPFS (Tiny Procmail 3.03+ file server)
Pm-jastore.rc -- Store messagee to inbox or gzip inbox
Pm-jasubject.rc -- Subject field cleaner and canonilizer (Re:)
Pm-jatime.rc -- "hh:mm:ss" time parser from variable INPUT
Pm-jaube.rc -- Jari's Unsolicited Bulk Email (UBE) filter.
Pm-jaube1.rc -- Jari's UBE filter. Subroutine 1
Pm-javac.rc -- Procmail: Vacation framework recipe (id-cache)
Pm-javar.rc -- Jari's global variable definitions
End

Document id [toc]

@(#) This page contains man pages from the Procmail modules
@(#) I have written and that can be used as includerc plug-ins:
@(#) some can be used as subroutines to your own programs and
@(#) some are self containing recipes. There is no user or site
@(#) specific settings in these modules.

@(#) I have tried to minimize the use of external processes and
@(#) use the procmail way as much as possible (eg. to get date and
@(#) directly from message without calling expensive shell date).
@(#) It is important that you concentrate on this performance factor
@(#) too; remember that procmail is run on every incoming message and
@(#) every tick you spend counts.

@(#) $Id: pm-code.txt,v 1.8 1998/03/08 21:33:07 jaalto Exp $
$Contactid: jari.aalto@poboxes.com $
$URL: http://www.netforward.com/poboxes/?jari.aalto $
$Keywords: Emacs elisp package documentation $

This document is automatically generated from the procmail rc files with 2 small perl scripts in the following manner

      % ripdoc.pls `ls pm-ja*.rc|sort`|t2html.pls -name-uniq>pm-code.html

The perl program assume that the documentation sections have been written in Technical Text Format (you are looking at TF layout in this file) An Emacs minor mode for writing TF files is available: tinytf.el. It's installation suite supplies both Perl scripts.

You can get the procmail code and perl scripts form file server

          To: jari.aalto@poboxes.com
          Subject: send help

Also use "Subject: send ls-l.txt" to get listing and description of available files.

If you add link to the absolute address of this site/page, please also mention/include this link:

      http://www.netforward.com/poboxes/?jari.aalto

The above permanent www link points to main from which this document canb be accessed even if this account ceases to exist or of this page is renamed or moved to another site.

If you want to have automatic notification whenever my page changes, please visit this link and register any ULR in your reminder list:

      http://www.netmind.com/URL-minder/new/register.html

Pm-jaaddr.rc -- extract 'foo@some.com' email address from variable INPUT [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-11 $
$keywords: procmail extractEmailAddress subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This includerc extracts the various components of email address from variable INPUT.

Example input

      "From: foo+procmail@this.site.com (Mr. foo)"

Returned values

      ADDRESS     "foo+procmail@this.site.com"
                  containing the email address without <>
      ACCOUNT     "foo+procmail"
                  all characters before @
      ACCOUNT1    "foo"
                  characters before plus: account1+account2@site
                  Note, if there is no "+", this is same as ACCOUNT.
      ACCOUNT2    "procmail"
                  _only_ set if plus found: account1+account2@site
      SITE        "this.site.com"
                  all characters after @
      DOMAIN      "site.com"
                  the main domain, preceding words in site are
                  considered subdomain (local) addresses.
                      sub.sub.domain.net
                  "com"
      NET         last characters after last period ( net,com,edu ...)

Additionally there is variables DOT1 DOT2, which behave like ACCOUNT1 and ACCOUNT2, but in respect to dotted firstname.surname type address:

          john.doe@site.com
          ACCOUNT1    = john.doe
          ACCOUNT2    = <empty>
          DOT1        = john
          DOT2        = doe

If there is plus, the ACCOUNT2 is defined

          john.doe+foo@site.com
          ACCOUNT1    = john.doe
          ACCOUNT2    = foo
          DOT1        = john          (in respect to ACCOUNT1)
          DOT2        = doe           (in respect to ACCOUNT1)

Variable ERROR is set to "yes" if INPUT wasn't recognized or parsing the address failed.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include pm-javar.rc from there.

Call arguments (variables to set before calling) [toc]

      INPUT = string-to-parse

Usage example [toc]

Read From field and address from it. This is lot faster than using external formail call.
      PMSRC   = $HOME/pm
      RC_ADDR = $PMSRC/pm-jaaddr.rc
      :0
      *  ^From:\/.*@.*
      {
          INPUT = $MATCH
          #  Turn off the logging while executing this part
          VERBOSE="off"   INCLUDERC = $RC_ADDR  VERBOSE="on"
          :0
          * ERROR ?? yes
          {
             # Hmm, no std email address found. Any other ideas?
          }
      }

Pm-jabup.rc -- Keeep N arriving message backup in separate directory [toc]

File id [toc]

Copyright (C) 1997-98 John Gianni, Jari Aalto
IdeaBy 1995-01 John Gianni jjg@cadence.com
Maintainer: Jari Aalto
Created: 1997-12
Contactid: jari.aalto@poboxes.com
$Keywords: procmail backup recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

Preserve last N arriving messages in a separate sub-directory. This should be your safety-belt recipe that you put to the beginning of your .procmailrc.

Procmail saves the backup files with names like: msg.rcG msg.scG msg.3YS1, msg.4YS1, msg.VYS1, msg.fYS1 to the backup directory.

Note: this recipe will alawys call shell commands for each message you recive. That is needed because cleaning of the backup directory. If you receive only small number of messages per day, the performance drop of your .procmailrc is not crucial. But if you store many messages per day, then the shell calls may be a performance problem.

In that case, consider moving the cleanup to the pm-jacron.rc module (The cleanup is run only once a day, not for every message)

John Gianni send his simple bsckup script to Jari, who packaged and generalized the code. The code is reused with John's permission and maintaining responsibility was transferred to Jari

Required settings [toc]

(none)

Call arguments (variables to set before calling) [toc]

Usage example [toc]

You only want to keep backup of messages that are not from mailing lists. You may want to use TO_ macro to detect addresses better, this example matches against all headers
      LISTS          = "(procmail|list-1|list-2)"
      JA_BUP_DIR     = $HOME/Mail/backup/.        # Create the path too
      JA_BUP_MAX     = 42                         # this should be enough
      :0 c:
      *$ ! $LISTS
      {
          INCLUDERC = $PMSRC/pm-jabup.rc
      }

If you get many messages, please don't use this module. Instead see pm-jacron.rc where similar backup work is done better.


Pm-jacookie.rc -- Handle cookie (unique id) confirmations [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-12 $
$keywords: procmail cookieConfirm recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Overview of features [toc]

Description [toc]

This recipe handles generating the cookie to new users, comparing the returned cookie against the original one and passing known users through if they already had returned their cookie.

When you run automatised scripts, eg. to manage mailing lists where users can subscribe and unsubscribe, you have better to install safety measure so that someone can not subscribe his enemy to 30 mailing lists.

The cookie is any continuous block of random characters that is sent to person who wanted to use the service. He must send back the cookie before the service starts or action, like subscribe will take in effect. If someone forges the From address to pretend to be someone else and then subscribes as-beeing-someone-else to a mailing list, the cookie protects this from happening.

The cookie is sent to someone-else, and he must return the cookie before the "subscribe" service is activated. Obviously this someone-else will not be interested in sending back the cookie and thus the forgery fails. Isn't that simple, but efective protection against misuse?

And nowadays when UBE (aka Spam) is crawling from every possible domain thinkable, you can also start requesting that people "join" to your white list, before you start discussing with them. Bulk email shotguns do not reply to you, so you won't get cookies back from them, but individual peoples that want to talk with you, may want to return the cookie. For start you should add your friends to your cookie database by hand, so that they don't get upset when you activate "cookie-shield".

It's burden, I admit, to have to response to the cookies, but if that is the best way so far after the spam filters, to keep out uninvited people. Think this as a "doorbell", you don't usually let people in to your house without invitation or your approval.

If you have strong spam shield already, then you may not want to install cookie confirmation for your mates. But it's possible with this module.

How it works [toc]

By default, the cookie generated uses CRC 32 cksum, but if you have md5, you should use it. The cookie is generated from the reply address and immediately stored to cookie database file with entry
      DATE FROM-a COOKIE-a
      DATE FROM-b COOKIE-b

If this was a new user or an old user, who has not registered his cookie yet, then original message is sent back to the sender with instructions: "please place the magic string to Subject line and resent the message."

When cookie is returned back, a new line to the database is added, simply by adding a duplicate entry. The file now looks like this:

      DATE FROM-a COOKIE-a
      DATE FROM-b COOKIE-b
      DATE FROM-a COOKIE-a

When there is two or more same entries, like FROM-a, the address is supposed to be known and person behind it "cleared".

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

Returned values [toc]

ERROR will contain the efective action when this recipe file ends

key is an internal variable in this recipe file and will hold the cookie id in case of "new-user" and "key-mismatch". You may want to use it if you generate your own reply.

Example usage for UBE shield [toc]

This is what I use to prevent unknown people from sending me UBE. It takes a bit extra, but they can easily return the message. Fill in the missing variables, this won't work out of the box for you.
       WORK = "(domain1|domain2|domain3)"
      LISTS = "(procmail|list-2|list-3|list-4)"
      VALID = "(postmaster|abuse|$LISTS|$WORK)"
      RC_COOKIE   = $PMSRC/pm-jacookie.rc
      :0
      *$ ! From:.*$VALID
      *  ! FROM_DAEMON
      {
          JA_COOKIE_SEND  = "no"   # Take over the resend control
          INCLUDERC       = $RC_COOKIE
          :0 wc: $RC_COOKIE.lock
          *    mail ?? yes
          * ! ^X-Loop: $JA_COOKIE_XLOOP
          *   ^Subject:\/.*
          | ( $FORMAIL -rkt -b                                        \
              -A "X-Authentication-key: $key [$ERROR]"                \
              -A "X-Loop: $JA_COOKIE_XLOOP";                          \
              -I "Subject: $MATCH $key"                               \
              echo "You Authentication key is: $key";                 \
              echo "$JA_COOKIE_MSG";                                  \
              ) | $SENDMAIL;                                          \
              echo "[my; cookie; $ERROR; $JA_COOKIE]" >> $HIN
          :0
          * mail ?? yes
          $COOKIE_SPOOL
      }

Example usage for subscriptions [toc]

      :0 c:        # keep backups, expired by cron
      $BACKUP
      $RC_COOKIE   = $PMSRC/pm-jacookie.rc
      ...Mailing lists handled here...
      ...Your work messages filed here..
      TO            = `formail -rt -zxTo:`  # We need this elswhere
      JA_COOKIE_TO  = $TO                   # Update this, it is known
      #   I run private List-X, and all subscribe requests must
      #   be confirmaed
      * ^TO_()list-x
      * ^Subject: +subscribe\>
      {
          JA_COOKIE_SEND  = "no"
          INCLUDERC = $RC_COOKIE
          :0
          * ERROR ?? known-user
          {
              #   User sent the subsribe request again, allow joining
              #   immediately.
          }
          :0 E
          {
              # Because the Send was set to "no"; we're in charge
              # to send a reply to the user.
              # ...generate suitable message with formail -rt
          }
      }
      #   Any other messages may be UBE
      JA_COOKIE_SEND  = "yes"
      INCLUDERC       = $RC_COOKIE

Pm-jacookie1.rc -- Generate unique id from INPUT variable. [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-12 $
$keywords: procmail cookieMake subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

When given a string, this subroutine returns a unique number representing a string, a cookie.

Required settings [toc]

(none)

Call arguments (variables to set before calling) [toc]

Return values [toc]

Example usage [toc]

      INPUT           = "foo@site.com"
      JA_COOKIE_CMD   = "md5"     # or chksum
      INCLUDERC       = $PMSRC/pm-jacookie1.rc
      cookie          = $OUTPUT

Pm-jalint.rc -- Procmail: Run cron once a day [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-12 $
$Keywords: procmail cron framework recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

Framework for all cron tasks that can be run once a day. This is a wrapper recipe to your cron task list: when the day changes, you cron includerc is called.

Required settings [toc]

PMSRC must point to source directory of procmail code. This recipe will include

Call arguments (variables to set before calling) [toc]

A file JA_CRON_RUN_FLAG, which defaults to ~/.yymmdd.run is created when your includerc, that contains list of cron tasks, is run. If new mail arrives while your cron recipes are still running, you should prevent invoking the cron again by checking if this file exists. When all the cron tasks have been run, this flag file is removed. Remember to use "w" flag in your cron recipes where necessary to serialize the work.

Return values [toc]

(none)

Usage example [toc]

Save backups to separate directory, but do cleaning only once a day We do not keep backups from mailing list messages
      LISTS          = "(procmail|list-1|list-2)"
      BACKUP_DIR     = "$HOME/Mail/backup/."
      #   Store backups: separate files to directory
      :0 c:
      *$ ! $LISTS
      $BACKUP_DIR
      #   Run JA_CRON_RC once a day. It contains all daily cron tasks
      #
      CRON_RC             = $PMSRC/pm-jacron.rc   # the framework
      JA_CRON_RC          = $PMSRC/pm-mycron.rc   # the tasks to do
      JA_CRON_RUN_FLAG    = $HOME/.cron-running   # define this!
      #   Do not enter here if message arrived at the same day when
      #   the cron is already running. The CRON_RC takes care
      #   of deleting the file when cron has finished.
      #
      :0
      *$ ! ? test -f $JA_CRON_RUN_FLAG
      { INCLUDERC = $CRON_RC }

The pm-mycron.rc file may contain anything. For example to clean the backup directory; you add these statements there

      #   rm dummy: if ls doesn't return files, make sure rm has
      #   at least one argument.
      #
      #   ls -t: list files; newest first
      #
      #   sed: chop $max newest files from the listing, leaving the
      #   old ones
      max = 32
      :0 hwic
      | cd $BACKUP_DIR && rm -f dummy `ls -t msg.* | sed -e 1,${max}d`
      # End of file pm-mycron.rc

Pm-jadaemon.rc -- Handle DAEMON messages by changing subject [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
Maintainer: Jari Aalto
Created: 1997-11
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail recipe daemon messages $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to Contactid with subject "send <FILENAME>"

Description [toc]

When you sent a message to a address that had delivery troubles, you get a DAEMON message back explaining the error problem. I usually want to save these daemon mesaages to a different folder and check the folder from time to time. A typical daemon message is like this (shortened)
      From: Mail Delivery Subsystem MAILER-DAEMON@my.domain.com
      Subject: Warning: could not send message for past 4 hours
      The original message was received at...
      ----- Transcript of session follows -----
      Deferred: Connection timed out
      ----- Original message follows -----
      [YOUR MESSAGE AS YOU SENT IT WITH HEADERS]

Well, when I read the subjects, I do not like the standard error messages, but I also like to know to which address the delivery failed and what was the original subject. This small recipe changes the daemon message's Subject to

      Subject BRIEF-ERROR-REASON, SENT-TO-ADDRESS, ORIGINAL-SUBJECT

and from that you can immediately tell if you should be worried Eg. if SENT-TO-ADDRESS was your friend's, then you want to take actions immediately, but if it were your complaint to UBE message to postmaster, you don't want to bother reading that daemon message. Here are some real examples:

      fatal errors,postmaster,ABUSE (Was: Super Cool Site!)
      Host unknown,postmaster,ABUSE (Was: A-Credit Information)
      undeliverable,postmaster,Could you investigate this spam
      Warning-Returned,friend,Have you looked at this

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine needs scrips

Call arguments (variables to set before calling) [toc]

Return values [toc]

Usage example [toc]

Just add this recipe somewhere in your .procmailrc
      PMSRC           = $HOME/pm
      RC_DAEMON       = $PMSRC/pm-jadaemon.rc
      DAEMON_MBOX     = $HOME/Mail/junk.daemon.mbox
      #  ...somewhere in the recipe pile
      INCLUDERC       = $RC_DAEMON
      #   If that was a daemon message, put it to folder
      :0 :
      * ERROR ?? yes
      $DAEMON_MBOX

Pm-jadate.rc -- Read date from the message hdrs: From_, Receved: [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-12 $
$keywords: procmail dateFromMessage recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This recipe will scan several headers to find the date string. When suitable header is found and the parsing has succeeded, the return variables are set. The Date values reflects the arrive time of the message; not the sending time. If nothing works, a shell call date is used as a last resort.

Returned values

      YYYY    = 4 digits
      YY      = 2 digits
      MON     = 3 characters
      MM      = 2 digits
      DAY     = 3 characters
      DD      = 2 digits
      hh      = 2 digits      if available
      mm      = 2 digits      if available
      ss      = 2 digits      if available

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

(none)

Usage example [toc]

      INCLUDERC = $PMSRC/pm-jadate.rc
      #   now we have all date variables that we need
      #
      $TODAY    = $YYYY-$MM-$DD

Pm-jadate1.rc -- 'Tue, 31 Dec 1997' date parser from variable INPUT [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
Maintainer: Jari Aalto
Created: 1997-11
$Contactid: jari.aalto@poboxes.com $
$URL: ftp://cs.uta.fi/pub/ssjaaa/ $
$Keywords: procmail subroutine date parsing $

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

You can get newest version by sending email to Contactid with subject "send <FILENAME>"

Description [toc]

This includerc parses date from variable INPUT which has string
      "Week, dayNbr Month Year"

Example input

      "Tue, 31 Dec 1997"      -- without comma
      "Tue 31 Dec 1997"       -- with comma

Returned values

      YYYY    = 4 digits
      YY      = 2 digits
      MON     = 3 characters
      MM      = 2 digits
      DAY     = 3 characters
      DD      = 2 digits
      hh      = 2 digits      If available
      mm      = 2 digits      If available
      ss      = 2 digits      If available
      TZ      = 5 characters  If available

Variable ERROR is set to "yes" if it couldn't recognize the INPUT and couldn't parse the basic YYYY,YY,MM,DD variables.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include pm-javar.rc from there.

Call arguments (variables to set before calling) [toc]

      INPUT = string-to-parse

The INPUT can have anything after "Week, dayNbr Month Year", or before it: you can pass a string like "Thu, 13 Nov 1997 11:43:23 +0200".

Usage example [toc]

The first Received header will tell when the message was received by your mailserver. We parse the date and avoid calling expensive date command.
      PMSRC           = $HOME/pm
      RC_DATE_WDMY    = $PMSRC/pm-jadate1.rc #Week-Day-Month-Year parser
      # Get time from first header, it ends like this:
      #
      #       Received: ... ; Thu, 13 Nov 1997 11:43:50 +0200
      :0 c
      *$ ^Received:.*;$s+\/...,$s+$d.*
      {
          INPUT = $MATCH
          #  Turn off the logging while executing this part
          VERBOSE=off   INCLUDERC = $RC_DATE_WDMY   VERBOSE=on
          :0
          * ERROR ?? yes
          {
             # Use some other way to get the time or shout loudly
          }
      }

Pm-jadate2.rc -- 'YYYY-MM-DD' ISO date parser from variable INPUT [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
Maintainer: Jari Aalto
Created: 1997-11
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail subroutine body-empty-test $

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

You can get newest version by sending email to Contactid with subject "send <FILENAME>"

Description [toc]

This includerc parses date in format "YYYY-MM-DD hh:mm:ss" like "1997-12-01" and sets following variables whenever called
          YYYY    = 4 digits
          YY      = 2 digits
          MON     = 3 characters
          MM      = 2 digits
          DD      = 2 digits
          hh      = 2 digits  If avaliable
          mm      = 2 digits  If avaliable
          ss      = 2 digits  If avaliable

Variable ERROR is set to "yes" if it couldn't recognize the INPUT and couldn't parse the basic YYYY,YY,MM,DD variables.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include pm-javar.rc from there.

Call arguments (variables to set before calling) [toc]

      INPUT = string-to-parse

Last string in INPUT that matches number sequence "NNNN-NN-NN" is parsed.

Usage example [toc]

      PMSRC          = $HOME/pm
      RC_DATE_ISO    = $PMSRC/pm-jadate2.rc # ISO date parser
      INPUT = "This is 1800-10-11, a very old date"
      #  Turn off the logging while executing this part
      VERBOSE="off"  INCLUDERC=$RC_DATE_ISO  VERBOSE="on"

Pm-jadate3.rc -- 'Tue Nov 25 19:32:57' date parser from variable INPUT [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
Maintainer: Jari Aalto
Created: 1997-11
$Contactid: jari.aalto@poboxes.com $
$URL: ftp://cs.uta.fi/pub/ssjaaa/ $
$Keywords: procmail subroutine date parsing $

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

You can get newest version by sending email to Contactid with subject "send <FILENAME>"

Description [toc]

This includerc parses date from variable INPUT which has string
      "Week, Month dayNbr hh:mm:ss yyyy",

Example

      Tue Nov 25 19:32:57 1997

Returned values

          YYYY    = 4 digits
          YY      = 2 digits
          MON     = 3 characters
          MM      = 2 digits
          DAY     = 3 characters
          DD      = 2 digits
          hh      = 2 digits
          mm      = 2 digits
          ss      = 2 sigits

Variable ERROR is set to "yes" if it couldn't recognize the INPUT.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include pm-javar.rc from there.

Call arguments (variables to set before calling) [toc]

      INPUT = string-to-parse

Usage example [toc]

The first Received header will tell when the message was received by the mailserver. Parse the date and avoid calling expensive date command.
      PMSRC           = $HOME/pm
      RC_DATE_WMDT    = $PMSRC/pm-jadate4.rc #Week-Month-Day-Time parser
      # Get time from X-From-Line: Which was added by my MDA
      #   X-From-Line: procmail-request@informatik.rwth-aachen.de \
      #    Tue Nov 25 19:32:57 1997
      #
      :0 c
      *$ ^X-From-Line:\/.*
      {
          INPUT = $MATCH
          #  Turn off the logging while executing subroutine
          VERBOSE=off   INCLUDERC = $RC_DATE_WMDT   VERBOSE=on
          :0
          * ERROR ?? yes
          {
             # Use some other way to get the time or shout loudly
          }
      }

Pm-jadate4.rc -- make RFC 'Mon, 1 Dec 1997 17:41:09' and parse values [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-12 $
$keywords: procmail dateFromSehll subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This subroutine calls shell command date once and prses the values. This should be your last resort if you haven't got the date values by any other means. This subroutine assumes that the DATE command knows the following % specifier formats (HP-UX)
      Y   NNNN    year
      h   MON     month
      d   NN      day
      a   WEEK    Like "Mon"
      H   NN      hour
      M   NN      min
      S   NN      sec

Returned values

      DATE    = RFC date in format "Mon, 1 Dec 1997 17:41:09"
                This is same as what you would see in From_
      YYYY    = 4 digits
      YY      = 2 digits
      MON     = 3 characters
      MM      = 2 digits
      DAY     = 3 characters
      DD      = 2 digits
      hh      = 2 digits
      mm      = 2 digits
      ss      = 2 sigits

Variable ERROR is set to "yes" if values couldn't be set

Required settings [toc]

PMSRC must point to source directory of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

(none)

Usage example [toc]

The First Received line will tell when the message was received by the MDA. If thata fails, then get date from the system. If you send test messages to # yourself, you don't usually put From_ header in it and thus there is # no date information in 'dry run' tests.

      # Get time from first eader, which is always same in my system
      # Received: ... ; Thu, 13 Nov 1997 11:43:50 +0200
      INCLUDERC   = $PMSRC/pm-javar.rc    # to get $s $d definitions
      TODAY       # Clear it
      :0
      *$ ^Received:.*;$s+\/...,$s+$d.*
      {
          INPUT     = $MATCH
          INCLUDERC = $PMSRC/pm-jadate1.rc
          TODAY     = "$YYYY-$MM-$DD"
      }
      #   Check that variable did get set, if not then we have to call
      #   another date subroutine: Call shell then to find out date
      #
      #   You could also do this with ':0 E', but this is more educational
      :0
      *$ ! $TODAY^0
      {
          INCLUDERC = $PMSRC/pm-jadate4.rc    # Get date from Shell then
          TODAY     = $YYYY-$MM-$DD
      }

Pm-jadup.rc -- Procmail: Handle duplicates; store to separate folder [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-11 $
$keywords: procmail filter duplicates recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This recipe stores duplicate messages to separate folder

Required settings [toc]

PMSRC must point to source directory of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

Usage Example [toc]

When you are testing messages, you send them over and over to procmailrc. You use procmail option "-a test" and define flag IGNORE
to say "yes" in these cases. The duplicate check is then not performed.
      ARG        = $1
      :0
      * ARG ?? test
      { JA_ID_IGNORE = "yes"  }
      #   Some microsoft product is known to send same message ids
      #   over and over. If we detect one, tunr off the duplicate test,
      #   because it would trash every message.
      #   MAPI.Id.0016.00666479202020203030303430303034@MAPI.to.RFC822
      :0
      * ! ^X-msmail
      * ! ^Message-ID: *MAPI.*@MAPI.to.RFC822
      { JA_ID_IGNORE = "yes"  }
      #   Run this command every time a duplicate message is found.
      #   It writes a small log entry to MY_LOG
      #
      JA_ID_SH_CMD = "echo '    [my; duplicate; $SUBJ]' >> $MY_LOG"
      INCLUDERC    = $PMSRC/pm-jadup.rc


Pm-jaempty.rc -- check if message body is empty (nothing relevant) [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-11 $
$keywords: procmail filter duplicates recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This simple includerc will define variable BODY_EMPTY to "yes" or "no" when called like this
      INCLUDERC = $PMSRC/pm-jaempty.rc

Required settings [toc]

(none)

Pm-jafrom.rc -- get message's best FROM field without calling formail [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto $Contactid: jari.aalto@poboxes.com $ $Created: 1997-12 $ $keywords: procmail extracFROM subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This includerc extracts the most likely FROM address from the message. The order of the search is Reply-to, From_, Sender, From and if none found, then as a last resort, call formail. You would usually use the returned value for logging purposes.

Avoiding extra formail call could be usefull if you receive lot of messages per day.

Example input

      (none)

Returned values

      OUTPUT, containing the derived FROM field

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include pm-javar.rc from there. You nee procmail 3.11pre7 in order to use this subroutine. (due to formail -z switch)

Call arguments (variables to set before calling) [toc]

(none)

Usage example [toc]

INCLUDERC = $PMSRC/pm-jafrom.rc FROM = $OUTPUT # now we have the 'best' FROM field

Pm-jafwd.rc -- Controlling forwarding remotedly, procmail 3.11pre7 [toc]

File id [toc]

Copyright (C) 1997 Jari Aalto
$Created: 1997-10 (ISO yyyy-mm date) $
$Maintainer: Jari Aalto jari.aalto@poboxes.com $
$keywords: procmail forward mail $

@(#) $Id: pm-code.txt,v 1.8 1998/03/08 21:33:07 jaalto Exp $ This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Overview of features [toc]

Description [toc]

This includerc makes it possible to control your message forwarding via simple remote email message. Thanks to Era Eriksson and Timothy J Luoma who gave the initial idea to this forwarding module in the procmail mailing list 1997-10-07.

Activating the forwarding by hand [toc]

If you want to activate the forwarding from the local site where this module is, then you could simply write the forward address to the file pointed by JA_FWD_FILE which is ~/.forward-address by default.
      % echo Me@somewhere.com > ~/.forward-address

and when you no longer need forwarding, then remove that file. But really, this module is not used for that purpose, because it is lot easier to write

      :0
      ! Me@somewhere.com

as a first statement in your .procmailrc when you want to forward your mail to another account.

Activating the forwarding by remote email [toc]

Suppose you're on the road and suddenly realise that you want your mail forwarded to the current account, then you send following control message
      Subject: forward-on PASSWD onTheRoad@some.com
      To: procmail-account-listening@some.com
      From: onTheRoad-another-account@some.com

That message is is enough to get the mail forwarded to the address onTheRoad@here.is. This script will repond that the current forwarding is now using address "onTheRoad@some.com".

Deactivating forwarding by remote email [toc]

The message is very similar, but the Subject header says
      Subject: forward-off PASSWD

And no other fields are checked. Not even Reply-To. In this case the confirmation message is sent directly back to From address.

Restricting the control message aceptance [toc]

If you only have persistent accounts, then you should set the JA_FWD_FROM_MUST_MATCH to match those addresses that you have. The following setting says that only control messages sent from these addresses are accepted. Nobody else can't change your forwarding settings.
      JA_FWD_FROM_MUST_MATCH = "(acc1@a.com|acc2@b.com)"

Hm, that's not a bullet proof, because someone may in theory forge the From address. You propably should also set this variable to point to accounts where the mail can be legally forwarded to. Then, even if the imposter forges the From address; he can't get the email forwarded anywhere else than to the valid locations.

      JA_FWD_TO_MUST_MATCH = $JA_FWD_FROM_MUST_MATCH

Diagnostics [toc]

If you don't receive confirmation message, then your control message was ill formed or you're not in the JA_FWD_FROM_MUST_MATCH list. There is no notification sent on failure, so that no attacker can draw conclusions.

Installation [toc]

You should preset all necessary variables prior adding the includerc command to your .procmailrc. Here is one simple setup
      #JA_FWD_SENDMAIL = "tee $HOME/test.mail" # Uncomment if testing
      JA_FWD_COPY      = no       # no copies stored while forwarding
      JA_FWD_PASSWORD  = "MyMagicString"
      JA_FWD_FROM      = $FROM    # This is already known.
      INCLUDERC        = $PMSRC/pm-jafwd.rc

Comments from the author [toc]

Please realise that when you set the forwarding from a remote site, be very carefull when you type in the forward address or your mail ends up to somebody else's mailbox. Also I recommend that you keep JA_FWD_COPY to yes so that your local account always keep the copy of forwarded message.

A step furher would conventionally encrypt(1)'ing your forwarded messages. This way even your top secret messaes would be mostly safe even if they end up to someone else's mailbox.

File layout [toc]

tinybm.el/&tags and tinytab.el for the 4 tab text placement. See also unix what(1) and GNUS RCS ident(1).

Pm-jamime-kill.rc -- Kill MS Explorer/Lotus notes attachement [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-12 $
$keywords: procmail MIME killer recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

Microsoft Explorer has a bad habbit of including 7k application/ms-tnef attachement to the end of message. The sample message is described in next section. If you don't want to see that additional ms-tnef attachement, then plug in this module and you no longer see MS Explorer cruft.

This recipe works like this: If email's structure is

      --boundary
      message-text (maybe quoted-printable)
      --boundary
      some-unwanted-mime-attachement
      --boundary

then the attachement is killed from the body. The message-text part is also decoded if it was quoted printable. This leaves clean text; with no MIME anywhere. MIME headers have been modified as needed (due to conversion from multipart and possibly quoted printable to plain text):

      message

But if email's structure was anything else, like if there were 3 mime sections:

      --boundary
      message-text (maybe quoted-printable)
      --boundary
      some-attachement
      --boundary
      some-unwanted-mime-attachement
      --boundary

then the "unwanted" part is emptyed by replacing area with one empty line. The message structure stays the same, but the killed "unwanted" part is labelled as text/plain so that your MUA will decode the MIME message correctly.

Applications for other mime attachements [toc]

Lotus Notes sends similar extra attachement and you can use this same recipe to kill it. See example section. Microsoft Express sends a copy of message in html format in the attachement, you can kill that too, see example section.

Netscape's Mozilla sends a copy of message in html. See example. Also it sends vcards

Example of lotus notes attachement [toc]

      Subject: message
      From: foo@bar.com
      X-Lotus-FromDomain: XXX COMPANIES
      Mime-Version: 1.0
        Boundary="0__=cieg4oHxUNf2h3evyOXIsHTGDpFfaZilTDCFhpZSgsw"
      Content-Type: multipart/mixed;
        Boundary="0__=cieg4oHxUNf2h3evyOXIsHTGDpFfaZilTDCFhpZSgsw
      --0__=cieg4oHxUNf2h3evyOXIsHTGDpFfaZilTDCFhpZSgsw
      Content-type: application/octet-stream;
          name="PIC10898.PCX"
      Content-transfer-encoding: base64
      eJ8+IjsQAQaQCAAEAAAAAAABAAEAAQeQBgAIAAAA5AQAAAAAAADoAAEIgAcA
      b3NvZnQgTWFpbC5Ob3RlADEIAQ2ABAACAAAAAgACAAEEkAYAyAEAAAEAAAAQ
      <AND-THE-REST-OF-BASE64>
      --0__=cieg4oHxUNf2h3evyOXIsHTGDpFfaZilTDCFhpZSgsw--

Example of MS Explorer's ms-tnef message [toc]

      Subject: message
      From: foo@bar.com
      MIME-Version: 1.0
      Content-Type: multipart/mixed;
          boundary="---- =_NextPart_000_01BD04D4.A5AC6B00"
      Lines: 158
      ------ =_NextPart_000_01BD04D4.A5AC6B00
      Content-Type: text/plain; charset="iso-8859-1"
      Content-Transfer-Encoding: quoted-printable
      <MESSAGE ITSELF IS HERE>
      ------ =_NextPart_000_01BD04D4.A5AC6B00
      Content-Type: application/ms-tnef
      Content-Transfer-Encoding: base64
      eJ8+IjsQAQaQCAAEAAAAAAABAAEAAQeQBgAIAAAA5AQAAAAAAADoAAEIgAcA
      b3NvZnQgTWFpbC5Ob3RlADEIAQ2ABAACAAAAAgACAAEEkAYAyAEAAAEAAAAQ
      <AND-THE-REST-OF-BASE64>
      ------ =_NextPart_000_01BD04D4.A5AC6B00--

Example of MS Express's html message [toc]

      MIME-Version: 1.0
      Content-Type: multipart/alternative;
          boundary="----=_NextPart_000_003A_01BD16E2.C97E27B0"
      X-Mailer: Microsoft Outlook Express 4.72.2106.4
      X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
      This is a multi-part message in MIME format.
      ------=_NextPart_000_003A_01BD16E2.C97E27B0
      Content-Type: text/plain;
          charset="iso-8859-1"
      Content-Transfer-Encoding: quoted-printable
      <ACTUAL TEXT>
      ------=_NextPart_000_003A_01BD16E2.C97E27B0
      Content-Type: text/html;
          charset="iso-8859-1"
      Content-Transfer-Encoding: quoted-printable
      <SAME IN HTML>
      ------=_NextPart_000_003A_01BD16E2.C97E27B0--

Example of Netscape's html attachement [toc]

      X-Mailer: Mozilla 4.04 [en] (X11; U; Linux 2.0.33 i686)
      MIME-Version: 1.0
      Content-Type: multipart/alternative;
          boundary="------------69D9D579CF587DC8BB26C49C"

      --------------69D9D579CF587DC8BB26C49C
      Content-Type: text/plain; charset=us-ascii
      Content-Transfer-Encoding: 7bit
      <ACTUAL TEXT>
      --------------69D9D579CF587DC8BB26C49C
      Content-Type: text/html; charset=us-ascii
      Content-Transfer-Encoding: 7bit
      <SAME IN HTML>
      --------------69D9D579CF587DC8BB26C49C--

Example of Netscape's vcard attachement. [toc]

      Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
      Content-Transfer-Encoding: 7bit
      Content-Description: Card for Laird Nelson
      Content-Disposition: attachment; filename="vcard.vcf"
      begin:          vcard
      fn:             Laird Nelson
      n:              Nelson;Laird
      org:            Perot Systems Corporation
      email;internet: ljnelson@unix.amherst.edu
      title:          Software Engineer
      tel;work:       (617) 303-5059
      tel;fax:        (617) 303-5293
      tel;home:       (978) 741-3126
      note;quoted-printable:Information is for reference only;=0D=0A=
              please do not abuse it.
      x-mozilla-cpt:  ;0
      x-mozilla-html: TRUE
      version:        2.1
      end:            vcard

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

First of all, this is primarily a framework recipe to kill any kind of attachement. If you do not set JA_MIME_TYPE before calling this recipe, recipe will try to determine the right value by itself. See if the automatic detection works for you or preset the JA_MIME_TYPE beforehand if it fails (I'd like to hear about the failure and add the conditions as default)

It may be possible that some messages are malformed and that they do not contain preper "boundary" definition string in the header. I have seen messages that have text/html attachements, but no proper Mime headers. For those cases there is additional variable that will kill all text up till matching line regardless of message content.

That is your last resort if the standard MIME detection failed. (there must have been some problem in the sender's MUA that composed message)

Possible conflict with your awk [toc]

If you see an error message in the logfile saying that awk failed:
      procmail: Executing "awk,
      ...
      procmail: Error while writing to "awk"
      procmail: Rescue of unfiltered data succeeded

it means that the system's standard awk doesn't support the variable passing syntax: do following test

      % awk '{print VAR; exit}' VAR="value" /etc/passwd

And it should print "value". If not, then see if you have nawk or gawk is your system, which should understand the variable passing syntax. In HP 9 and 10 the standard awk will do fine. The only change you need is

      AWK = "nawk"        # if that works better than standard "awk"

Somewhere at the top of your .procmailrc

Warnings [toc]

You should know that the variable JA_MIME_KILL_RE is used to wipe any lines that match that regexp. This is due to MIME structure where continuing header lines exist in the body:
      ------=_NextPart_000_003A_01BD16E2.C97E27B0
      Content-Type: text/plain;
          charset="iso-8859-1"                << kill this line too

If you want to be absolutely sure that anything valuable won't be accidentally killed (like a code line in programming language scripts), you should set this variable to nonsense value that newer matches:

      JA_MIME_KILL_RE = "match_it_never_I_hope"

Usage example [toc]

If you want to do all by yourself, you can add all this to your ~/.procmailrc. This demonstrates the steps to call the includerc.
      #   1) Add following line if needed before this script
      #
      #   AWK = "nawk"
      # .....................................................

      #  2) Next set correct value for attachement killing
      # .....................................................
      #   If this is Lotus Notes message, it has extra .pcx attachement
      :0
      * ^X-Lotus-FromDomain:
      {  JA_MIME_TYPE = "application/octet-stream" }
      #   If this is MS Express's or Netscape's message with
      #   extra html attachement
      :0
      * ^X-Mailer:.*(Microsoft.*Express|Mozilla)
      {  JA_MIME_TYPE = "text/html" }
      #  3) And now handle the message
      # .....................................................
      #    by default kill MS Explorer's ms-tnef attachement.
      INCLUDERC = $PMSRC/pm-jamime-kill.rc

But, because all the type detection mentioned above are already included in the module, you onlye need to add conditions that it doesn't know by default. This one is exactly the same as above:

      :0
      * some-other-attachement-type
      { JA_MIME_TYPE = "some-new-type" }
      INCLUDERC = $PMSRC/pm-jamime-kill.rc

Pm-jamime.rc -- subroutine to read mime boundary etc. variables [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Maintainer: Jari Aalto jari.aalto@poboxes.com $
$Created: 1997-12 $
$Keywords: procmail MIME subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Documentation [toc]

This includerc reads MIME boundary string from the message if it exists. The boudary string is typically found from Content-Type header.
      Mime-Version: 1.0
      Content-Type: multipart/mixed; boundary=9i9nmIyA2yEADZbW

In addition it will define few other mime variables. See the returned values. You use these variables later in your MIME message processing.

Required settings [toc]

PMSRC must point to source directory of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

(none)

Return values [toc]

Usage example [toc]

INCLUDERC = $PMSRC/pm-jamime-tag.rc

Pm-janetmind.rc -- handle http://minder.netmind.com/ messages [toc]

File id [toc]

Copyright (C) 1998 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1998-01 $
$keywords: procmail netmind recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

http://minder.netmind.com/ http://www.netmind.com/URL-minder/new/register.html

...Netmind, or The URL-minder is a free, automatic Web-surfing robot that keeps track of changes to Web pages that are important to you. When the URL-minder detects changes in any of the Web pages you have registered, it sends you e-mail. an efective way to test if the address is known to internet. You could usethis information to see if some automated reply to a address can be sent.

In another words, if your're interested in some URL; say an FAQ page and any updates to them, you can tell Netmind to monitor the page changes for you and it send a message back every time page changes. This recipe "pretty formats" the announcement sent by Netmind by stripping the message to bare minimum. You usually aren't interested in 4k message which includes "Note from our sponsors", "Try the free online demo" etc. The things saved from the announcement message are:

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

(none)

Return values [toc]

(none)

Usage example [toc]

      INCLUDERC = $PMSRC/pm-janetmind.rc          # reformat the message
      :0:
      * netmind                                   # drop to folder
      url.mbox

Pm-janslookup.rc -- run nslookup on variable INPUT [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-11 $
$keywords: procmail nslookup subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This subroutine runs nslookup on given INPUT address. This may be an efective way to test if the address is known to internet. You could use this information to determine if some automated reply to a address can be sent. The know truth is that you can't validate whole email address
          to_someone@foo.com

but you can validate "foo.com"; that's the closest you get.

[Warning: If you don't use cache feature...]

Do not however use this module to regularly check all incoming from addresses with this subroutine for possible bogus UBE addresses, because calling nslookup

You can however check some messages that are likely UBE to verify your doubts.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

If the cache file can be read:

Return values [toc]

Usage example [toc]

If you are going to check some header field, like From:, please explode the content with pm-jaaddr.rc first. Suppose you have string:
      "From: foo@ingrid.sps.mot.com (Yoshiaki foo)"

You have to derive the address from string and pass the site name: Read From: field and address from it.

      PMSRC       = $HOME/pm
      RC_NSLOOKUP = $PMSRC/pm-janslookup.rc   # name the subroutine
      :0
      * MAYBE_UBE ?? yes
      * ^From:\/.*
      {
          INPUT       = $MATCH
          INCLUDERC   = $RC_NSLOOKUP  #   to nslookup
          :0
          * ERROR ?? yes
          {
              #   Hmm, nslookup failed, can't send anything back to this
              #   address
          }
      }

Second example, check if the address is reachable before sending reply

      INPUT       = `formail -rt -x To:`
      INCLUDERC   = $RC_NSLOOKUP
      :0
      *    ERROR ?? no
      {
          # okay, at least site address seems to be reachable
      }


Pm-japing.rc -- reply shortly to message "Subject: ping"; account ok [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-12 $
$Keywords: procmail ping auto-ack recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

When I'm on remote site and I don't seem to get throught with telnet or even with Unix "ping", I want to know if the at least the mailserver is up. I can send a "ping" message and the auto responder will reply immediately.

Sometimes, when you send a message to a person, it would be nice, if you could test that the destination address is valid, before sending a message to a "black hole". If the receiver had ping service running; like this, then you would know that you spelled the the right address. (after wondering two weeks; why you don't get response). Nowadays finger command seems to be blocked many times.

This recipe answers to simple ping message like this:

      To: you@site.com
      Subject: ping

Recipe sends a short message back to the sender.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

(see Usage)

Usage example [toc]

JA_PING_MBOX = $HOME/Mail/spool/ping.spool INCLUDERC = $PMSRC/pm-japing.rc

Pm-japop3.rc -- Subject field cleaner and canonilizer (Re:) [toc]

File id [toc]

Copyright (C) 1998 Jari Aalto
Maintainer: Jari Aalto
Created: 1998-01
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail pop3emulation recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

Ahem,t hat "pop3" is just to draw your attentions. This module has nothing to do with pop3. The idea may resemble it though. This recipe will listen "pop3" request, and when it gets one, it sends your whole mailbox as forwarded messages to the account from where you sent the request.

This is kinda "empty my mailbox in account X and send the messages to account Y"

You might have permanent forwarding on in account X, but if that is your socondary account, you can ask what messages has been arrived there with this recipe.

After you have configured your magic "pop3" command, simply sending message to account X, will initiate emptying your mailbox

      Subject: pOp3-send [mailbox] [kill]

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

Return value [toc]

STATUS will contain mailbox name if valid pop3 request was received. You may wish to save the request message to separate folder.

Example usage [toc]

You install this same setup for each site where you have account
      JA_POP3_SUBJECT_CMD = myPoPcmd
      INCLUDERC = $PMSRC/pm-japop3.rc
      #   Save all pop3 requests to folder
      #
      :0
      * STATUS ?? [a-z]
      mail.pop3-req.mbox

      #   in account Y, this recipe stores the moved messages to
      #   separate folder
      :0
      * X-Loop-Fwd:.*\.rc \/$NSPC+
      {
          #   The MATCH wil lhave the host name from where the messages
          #   were moved
          :0:
          mail.fwd.$MATCH.mbox
      }

Pm-jarandf.rc -- pick (rand)om line from (f)ile [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-12 $
$keywords: procmail subroutine random GetLine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

Return random line or a line from a file. This subroutine uses shell command awk and possily wc to be as small burden to the system as possible.

Required settings [toc]

You must have awk that supports VAR=value assignment syntax outside the code block: that is, in the input line. I know no awk that would not have this feature, but at least you know now what it takes.
      % awk '{}' VAR=value FILE

Call arguments (variables to set before calling) [toc]

If intend to call this subroutine many times, then please calculate the number of lines beforehand and pass it to this subroutine. If the MAX is not set, then wc is called every time to find your the line count.

Returned value [toc]

variable LINE

Example usage [toc]

      # Select random line from a file
      $RC_RANDF = $PMSRC/pm-jarand.rc
      $FILE     = $HOME/txt/cookie.lst
      $MAX      = 20
      INCLUDERC = $RC_RANDF
      #  LINE contains randomly read line

Pm-jasrv-check.rc -- check FILE validity, subroutine for File Server [toc]

File id [toc]

Copyright (C) 1998 Jari Aalto
Maintainer: Jari Aalto
Created: 1998-01
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail FileServer subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This subroutine is part of the TPFS or MPFS file server. Check FILE for nonvalid filenames or other access problems.

Input [toc]

Output [toc]


Pm-jasrv-err.rc -- send message, subroutine for File Server [toc]

File id [toc]

Copyright (C) 1998 Jari Aalto
Maintainer: Jari Aalto
Created: 1998-01
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail FileServer subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This subroutine is part of the TPFS or MPFS file server. Ssnd error notice that file didn't exist.

Input [toc]

Output [toc]


Pm-jasrv-from.rc -- compose reply, subroutine for File Server [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
Maintainer: Jari Aalto
Created: 1997-09
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail FileServer subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This subroutine is part of the TPFS or MPFS file server. Compose headers for reply message using formail -rt

Input [toc]

Output [toc]

(none)

Pm-jasrv-msg.rc -- send message, subroutine for File Server [toc]

File id [toc]

Copyright (C) 1998 Jari Aalto
Maintainer: Jari Aalto
Created: 1998-01
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail FileServer subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This subroutine is part of the TPFS or MPFS file server. Run $CODE and return resutls to to user. Subroutine is meant to be used for informational messages.

Input [toc]


Pm-jasrv-req.rc -- server request check, subroutine for File Server [toc]

File id [toc]

Copyright (C) 1998 Jari Aalto
Maintainer: Jari Aalto
Created: 1998-01
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail FileServer subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This subroutine is part of the TPFS or MPFS file server. Check if file server request is on the JA_SRV_SUBJECT and do case or incasensitive check.

Input [toc]

o JA_SRV_FORMAIL_FROM o

Output [toc]


Pm-jasrv-send.rc -- server request check, subroutine for File Server [toc]

File id [toc]

Copyright (C) 1998 Jari Aalto
Maintainer: Jari Aalto
Created: 1998-01
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail FileServer subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This subroutine is part of the TPFS or MPFS file server. Send the requested file.

Input [toc]

o FILE is the filename(chdir to directory is already done) file is _absolute_ filename WORD is next word from subject line after FILE word. o JA_SRV_CMD_STRING o JA_SRV_F_SUBJ_NOTIFY

Output [toc]


Pm-jasrv.rc -- Jari's MPFS (Mime Procmail 3.11+ File server) [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
Maintainer: Jari Aalto
Created: 1997-09
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail FileServer $

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

You can get newest version by sending email to Contactid with subject "send <FILENAME>"

Description [toc]

This is the MPFS (Mime procmail file server) and it can send MIME compliant messages with command
      "send <FILE> [WORD1] [WORD2]"

Usually only the FILE arg is used, and the rest of the words are for special use like password and preventing file encoding. A typical request looks like:

      Subject: send help              # ask for file named 'help'

Overview of features [toc]

Install: server file directory [toc]

You have to create directory for the server where the files are kept. Usually I don't copy the files there, but whenever I want to put a file available, I draw a hard or softlink to a file.
      % mkdir $HOME/pm-server
      % cd $HOME/pm-server
      # Repeat this as needed for files you want to put available
      #
      % cd $HOME/pm-server
      % ln $HOME/txt/interesting-file.txt interesting-file.txt

You define the server directory by changing

      JA_SRV_FILE_DIR = $HOME/pm-server

The short server log is written to file:

      JA_SRV_LOG = $HOME/pm-server.log

The incoming "send" request messages are stored here, which defaults to /dev/null, but you may want to set it to ~/Mail/spool/log.srv.spool and define In Emacs Gnus 5 group with `G` m nnml log.srv.

      JA_SRV_MSG_MBOX

Install: special files [toc]

Tweak this variable to commands you want to allow shell to execute in server's directory.
      JA_SRV_SH_COMMAND = "^(ls|what)$"

There are some special files that this server accepts. They are not actually files at all, but commands passed to shell. Be sure that the commands exist in your system. See man pages for more if you want to know what these commands do.

      ls      -- list directory
      file    -- print file type information.
      what    -- prints all @(#) tags from files
      ident   -- print all $ $ tags from files

Install: file help [toc]

Users want to get a help file with message "send help" and the help is just a file in your server directory. Be sure to supply it prior any other files. You can always draw a link to a file if you don't want to name it that way (eg. if you keep several server help files in RCS tree)
      #   draw symlink to help
      #
      % ln -s $HOME/txt/srv-public-hlp.txt $HOME/server/help

Basic usage in details [toc]

The server accepts command in format
      "send <FILE> [CMD|PASSWORD]"

Where FILE can be any name as long as it starts with [^ .]. The regexp says: Anything goes as long as FILE does not start with space or period. This gives you quite a much freedom to construct filenames. if you want to hand out file

      .procmailrc

you can't. Instead make a link to point to plain "procmailrc" without the leading period. There is also additional checks against possible security threat "../" like below; user can't request such file.

      ../../../gotcha  or  dir/../../gotcha

The filename cannot contain special charcters like [*?<>{}()].

Advanced usage [toc]

[conversions]

If some of your files are big, it makes sense to send them in compressed base64 format; which in MIME world is called content-type x-gzip64. You can set a regexp to enforce encoding for your big files before they are sent to user. The following setting will send all text files in compressed format to user.

      JA_SRV_XGZIP_REGEXP = "\.txt"

When the message is composed a header is inserted to message telling how the message is decoded, in case user doesn't have decent MUA that can handle the MIME type:

      X-comment: To decode, cat msg| mmencode -u| gzip -d > test.txt

The CMD parameter after the FILE is optional and user can override base64 encoding and request plain file if he uses word "noconv".

      Subject: send <FILE> noconv

[case sensitivity]

By default the request word("send") or file names are not case sensitive, unless you set

      JA_SRV_F_CMD_CASE_SENSITIVE  = "yes"
      JA_SRV_F_FILE_CASE_SENSITIVE = "yes"

In "no" case these are identical commands:

      Subject: Send Help
      Subject  SEND HELP

Stopping server [toc]

Sometimes you're making rearrangements in you file directory Or doing something else, and you are unable to respond to send requests. You can stop te server by setting
      JA_SRV_IN_USE = "no"

And when the you want to enable the server again; just comment out the statement or assign yes. [The default is yes]. When this variable is set to no, server sends message from following variable as a response to any "send" request.

      JA_SRV_IN_USE_NO_MSG

Using password to validate file requests [toc]

You should be aware that this file server's implementation is public in nature. Anyone who asks for a file is allowed to get it. But it would be good if you could limit the access to documents with some simple way, like if you set up two file servers (see next chapter) where one is public and the other is interesting only to group of people. You can define a string that must be found in Subject field by setting the following variable
      JA_SRV_PASSWORD = ".*"    # default

The default value will match anything in the subject, thus making the server public. But if you set it like this

      JA_SRV_PASSWORD ".*123"

Then string "123" must be there somewhere in the line, like here

      Subject: send <FILE> 123

Yes, "123" is actually a CMD definition, but it dosn't matter because there is no CMD 123. But the Subject now matches password and the server can be accessed. Of course the following is valid too.

      Subject: send <FILE> noconv 123

If the password was wrong, server won't tell it. The message just lands to your mailbox in that case and you can investigate who tried to access the restricted server.

Changing server's command string (multiple servers) [toc]

The default command string is "send", but you can change it and thus create multiple services. Here is one example, where you have set up two file servers, each has its own directory.
      #   The public server
      #
      JA_SRV_CMD_STRING   = "send"
      JA_SRV_FILE_DIR     = $HOME/server/public
      INCLUDERC           = $HOME/procmail/pm-jasrv.rc
      #   Company server, only interests fellow workers
      #   Here "xyz-send" is just magig server request string.
      #   Notice: case sensitive.
      #
      JA_SRV_F_CMD_CASE_SENSITIVE = "yes"
      JA_SRV_CMD_STRING           = "XYz-send"
      JA_SRV_PASSWORD             = ".*12qw"
      JA_SRV_FILE_DIR             = $HOME/server/public/xyz-dir
      INCLUDERC                   = $HOME/procmail/pm-jasrv.rc

Notes from the author [toc]

[basic Mime type note]

All basic files that you send must be US-ASCII, 7bit. At least that is the default mime type used. See JA_SRV_CONTENT_TYPE. I once received following message back

----- Transcript of session follows ----- 554 foo@bar... Cannot send 8-bit data to 7-bit destination 501 foo@bar... Data format error because in the previous releases, the MIME type headers were not in the message saying that the content really was plain 7bit ascii.

[Sendig the file as is]

Note, that the file is included "as is" without any extra start-of-file or end-of-file tags. This is possible, because the file file is sent in MIME format.

[Using one line log entry]

It may look very spartan to print a single line log entry. You see messages like above in the file server log. Using one line entry instead of multiline announcements makes it possible to write a small perl tool to parse information from a single line. If you get many file server messages per day, it it quiker to look at the single line entries too.

      [ja-srv1; sh file;  Foo Bar foo@site.com;]
      [ja-srv1; send xxx-file.txt; Foo Bar foo@site.com;]
                |
                Server's request keyword (you may have multiple servers)

[todo]

(1) I don't have a clear though right now how should I send out already compressed files "file.tar.gz". And how would I send multipart mime files in those cases.

(2) Also relying on simple regexp to send out base64 x-gzip64 is not the smartest idea. The natural extension would be to use file size threshold: if file is bigger than N bytes, send it out with x-gzip64. And further: if file is more than NN bytes, send it out as multipart MIME.

If you have suggestions or ideas, please drop mail to maintainer.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include many pm-jasrv-*.rc modules from there.

Please test the file Server in your environment before you start using it for every day. For example I had some weird local problem where PATH had /usr/contrib/bin/ where gzip was supposed to be, but in spite of my tries procmail didn't find it along the path. Don't ask why. I now use absolute binary name:

      GZIP = /usr/contrib/bin/gzip

In addition, if your messages are not sent to recipient, but you get daemon message:

      ... Recipient names must be specified

That's because you have setting SENDMAIL="sendmail"; which is not enough. It must be

      SENDMAIL = "sendmail -oi -t"

Usage example [toc]

This is my .procmailrc installation. Notice that the file server code is used only if you get "send" request. On the other hand, this double wrapping is not all necessary, you could as wee rely on the FSRV's capability to detect SEND request.

      PMSRC   = $HOME/pm      # directory where the procmail rc files are
      RC_FSRV = $PMSRC/pm-jasrv.rc
      mySavedLOGFILE = $LOGFILE   # record file server actions elswhere
      LOGFILE        = $PMSRC/pm-jasrv.log
      #   Listen "send" requests.
      :0
      *   ^Subject: +send\>
      {
          JA_SRV_FILE_DIR = $HOME/fsrv    # Where to get the files
          JA_SRV_LOG      = $HIN          # Write log here
          JA_SRV_FROM     = $FFROM        # I have defined this already
          JA_SRV_SUBJECT  = $FSUBJ        # ..and this
          #       Use File server now.
          #
          INCLUDERC       = $FSRV
      }
      LOGFILE = $mySavedLOGFILE

Pm-jasrv1.rc -- Jari's TPFS (Tiny Procmail 3.03+ file server) [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
Maintainer: Jari Aalto
Created: 1997-09
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail FileServer $

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

You can get newest version by sending email to Contactid with subject "send <FILENAME>"

Description [toc]

This is the simplest file server possible and this is a ripped down version of the MPFS pm-jasrv.rc. If you later decide to use pm-jasrv.rc, you can use the same variable names. You only need to change the INCLUDERC statement.

Overview of features [toc]

Mime type note [toc]

All files that you send must be US-ASCII, 7bit. At least that is the default mime type used. See JA_SRV_CONTENT_TYPE. I once received following message back

----- Transcript of session follows ----- 554 foo@bar... Cannot send 8-bit data to 7-bit destination 501 foo@bar... Data format error because in the previous releases, the MIME type headers were not in the message saying that the content really was plain 7bit ascii.

Installation example [toc]

This is how I have installed this Tiny Procmail File server (TPFS) into my .procmailrc. Notice that the file server code is used only if you get "send" request.
      PMSRC = $HOME/pm        # directory where the procmail rc files are
      #   Listen "send" requests.
      :0
      *   ^Subject: +send\>
      {
          JA_SRV_FILE_DIR = $HOME/fsrv    # Where to get the files
          JA_SRV_LOG      = $HIN          # Write log here
          JA_SRV_FROM     = $FFROM        # I have defined this already
          JA_SRV_SUBJECT  = $FSUBJ        # ..and this
          #       Use TPFS server now.
          #
          INCLUDERC       = $PMSRC/pm-jasrv1.rc
          #       This MPFS is temporarily out of use
          #
          #INCLUDERC      = $PMSRC/pm-jasrv.rc
      }

Notes from the author [toc]

[Sendig the file as is]

Note, that the file is included "as is" without any extra start-of-file or end-of-file tags. The philopsophy is that there must be no additional tags or cruft in the body of message; only the file itself. This way the receiver can just receive and drop the incoming file to his disk and even automate the procedure with some script, Mail user agent or procmail. If the tags were added, think what happens if dozen different file Servers add their own tags -- parsing the incoming email would be nightmare.

So, it's better to simply send the file. If you need tags, then the MIME is the right way to go and you should use MPFS server.

[Using one line log entry]

It may look very spartan to print a single line log entry. You see messages like above in the file server log. Using one line entry instead of multiline announcements makes it possible to write a small perl tool to parse information from a single line. If you get many file server messages per day, it it quiker to look at the single line entries too.

      [ja-srv1; sh file;  Foo Bar foo@site.com;]
      [ja-srv1; send xxx-file.txt; Foo Bar foo@site.com;]
                |
                Server request keyword (you may have server
                servers by changing the keyword)

Server command [toc]

This server accepts following request. The <ITEM> can be filename or shell command to execute in the file server directory.

      "send <ITEM>"

Please create file "help" to your server directory, so that user can request "send help" to get instructions. If you change the keyword, you can set up multiple file servers for different documents:

The ITEM cannot have any special characters, like <>{}()[]*?'$


Pm-jastore.rc -- Store messagee to inbox or gzip inbox [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-11 $
$keywords: procmail storeMessage subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This subroutine stores the message to file pointed by MBOX. This subroutine is meant to be used with the the other general purpose includerc files. This makes it possible to have a centralized file storage hanling for all your includercs.

Regular user doesn't get much of use of this unless he mixes both gz and regular files in his .procmailrc

Required settings [toc]

(none)

Call arguments (variables to set before calling) [toc]

if MBOX_MH is set to "yes"

otherwise

Example usage [toc]

      $RC_STORE   = $PMSRC/pm-jastore.rc
      :0
      * condition
      {
          MBOX = $HOME/Mail/spool/junk.mbox   INCLUDERC = $RC_STORE
      }

Pm-jasubject.rc -- Subject field cleaner and canonilizer (Re:) [toc]

File id [toc]

Copyright (C) 1998 Jari Aalto
Maintainer: Jari Aalto
Created: 1998-01
$Contactid: jari.aalto@poboxes.com $
$Keywords: procmail SubjectClean recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

There are many different Email programs out there that add their own "reply" characters to the subject field. The most sad programs come usually from PC platform. Eg. Microsoft has gained a lot of bad reputation due to it's own standards.

They all must mean well, but there already is a de facto standard where message should contain only single "Re:" if message has been replied to (no matter how many times). This makes it possible to do efficient message threading by only using Subject and date fields. And grepping same subjects is lot easier than from this horrible mess:

      Subject: Re^2: Re[32]: FW: Re: Re[15]: Sv: Re[9]: test message

This recipe standardizes any subject (like above) that has been replied to, to de facto format:

       Subject: Re: test message

Awk usage note [toc]

awk is a small, efective and much smaller than perl for little tasks. See the verbose log and make sure your awk understands VAR="value" passing syntax. Change it to nawk or gawk if they work better than your standard awk.
      AWK = "nawk"        # you may need this, try also gawk

Example usage [toc]

You need nothing special, just include this recipe before you save message to folder.
      INCLUDERC = $PMSRC/pm-jasubject.rc

Customizations: Let's say Polish M$Outlook uses "ODP:" instead of standard "re:" and you want to handle that too: Then set:

      JA_SUBJECT_KILL = "ODP:"
      INCLUDERC       = $PMSRC/pm-jasubject.rc

Pm-jatime.rc -- "hh:mm:ss" time parser from variable INPUT [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
Maintainer: Jari Aalto
Created: 1997-11
$Contactid: jari.aalto@poboxes.com $
$URL: ftp://cs.uta.fi/pub/ssjaaa/ $
$Keywords: procmail subroutine date parsing $

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

You can get newest version by sending email to Contactid with subject "send <FILENAME>"

Description [toc]

This includerc parses date from variable INPUT which has string
      "hh:mm:ss"

Example input

      "Thu, 13 Nov 1997 11:43:23 +0200"

Returned values

      hh      = 2 digits
      mm      = 2 digits
      ss      = 2 digits

Variable ERROR is set to "yes" if it couldn't recognize the INPUT and couldn't parse all hh, mm, ss variables.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This subroutine will include pm-javar.rc from there.

Call arguments (variables to set before calling) [toc]

      INPUT = string-to-parse

The INPUT can be anything as long as it contains NN:NN:NN

Usage example [toc]

Get the time of received message. The From_ header will always have the standard time stamp.
      PMSRC           = $HOME/pm
      RC_DATE_TIME    = $PMSRC/pm-jatime.rc
      :0 c
      *  ^From +\/.*
      {
          INPUT = $MATCH
          #  Turn off the logging while executing this part
          VERBOSE=off   INCLUDERC = $RC_DATE_TIME   VERBOSE=on
          :0
          * ERROR ?? yes
          {
             # Should not ever happen, you have broken From_
          }
      }

Pm-jaube.rc -- Jari's Unsolicited Bulk Email (UBE) filter. [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Created: 1997-09 $
$Maintainer: Jari Aalto jari.aalto@poboxes.com $
$Keywords: procmail UBE filter recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Warning [toc]

Put all your UBE (aka spam) filters towards the end of your .procmailrc. The idea is that valid messages are filed first(mailing lists, etc) and only rest of the messages are checked.

Overview of features [toc]

Remember: this is not 100%, there is always some mishits, so don't just junk messages to /dev/null. Instead set JA_UBE_MBOX to the appropriate mailbox where you want to store the messages.

Description [toc]

My life changed when Daniel smith posted his spam.rc, where he had gathered many tips and heuristics to filter UBE email. The filter expressed work of many Procmail usears including [phil] and [dan]. You can get the original file by sending subject "pm-dsspam.rc" to maintainer.

I modified the filtering rules a bit, took out some rules that catched false email messages and made the package look a bit more general so that it could be included via INCLUDERC in the standard way. Not all ideas here are mine; many of them are directly from Dan's original filter with slight modifications.

Thanks to Daniel and others, the UBE bomb days are gone, when this filter is active. Couple of UBE email may still lurk into my mailbox, but that's life; no shield is 100% proof.

Logging the events [toc]

The default subroutine pm-jaube1.rc does nothing fancy, but writes a short log to JA_UBE_LOG and stores the message into JA_UBE_MBOX. It is supposed that the JA_UBE_LOG is your brief "biff" log, where you store information about incoming mail and what happened to it. When message arrives, you write date, from and subject to the log and when message gets filed; you write the folder and reason to the file. The log looks like this:
      1997-12-08 Foo bar@x.com  send pm-tips.txt
          [ja-srv1; sent ema-keys.txt; Foo bar@x.com ;]
      1997-12-08 work@home.com  Extra Holiday $$$$$
          [jaube; Marketing-Big-ExitCode; LEGAL, MONEY-MAKING PHENOMENON]
      1997-12-09 Denizen logger@california.com  [RePol] hiding
      1997-12-09 david X dx@a.com  Re: Send list to incoming folder
      1997-12-09 david X dx@a.com  Re: Send list to incoming folder
      1997-12-09 OMC manager omcman@foo.fi "Environments updated"
          [my; work-localenv]
      1997-12-09 doodle@gruppe.org  Re: Gnus (Emacs Newsreader) FAQ
          [my; emacs;   Re: Gnus (Emacs Newsreader) FAQ ]

First, I got a message to my fileserver and it responded. Then came a UBE message that was identified and saved to UBE folder. Next 3 messages vere ones, that were filed to mailing-list folders and there was no [] action displayed for them (left out due to high volume of these messages). Second Last; that was internal work message, Lastly someone mailed me about Emacs and that message was files to emacs folder.

The basic log is written to "headers in" file with this recipe. Variable TODAY is $YYYY-$MM-$DD which you get from pm-jadate.rc. The LISTS Exclude some mailing list which have too high traffic. the F[FROM|SUBJ] are formail derived header contents.

      :0 hwic: ${HIN}.lock
      *$ ! $LISTS
      |echo "$TODAY $FFROM $FSUBJ" >> $HIN

About bouncing message back with exitcode 67 or 77 [toc]

The gneral concensus is, that you should not send bounches, the UBE sender is not there, because the address is usually forged. Do not increase the network traffic. Instead save the messages to folders and periodically send complaints to postmasters, that is much more efective. If you decide to bounce anyway, be sure to do FROM_DAEMON and mailing list tests before sending anything back. It's not nice to be forced to apologize about boounces to a wrong destination.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This recipe file will include

Call arguments (variables to set before calling) [toc]

Return values [toc]

If you use your own JA_UBE_RC. then you can use these values. They are also set after recipe if JA_UBE_MBOX is empty "".

The UBE reason ERROR is also seen in the separate header.

Usage example [toc]

It is best, that the UBE filterings are put last to your .procmailrc. handle all legimate messages at the beginning and save them to folders. Only messages that didn't fit to previous categories shgould be feed to to this recipe.
      # - All legimite messages already handled and saved before this
      # - Activate the filter only for messages that are not from
      #   daemon and not from valid senders: like from "my" domain
      #   and mailing lists and from soemwhere else. Define your
      #   favourite VALID_FROM regexp.
      VALID_FROM = "(my_domain|my_mailinglist)"
      :0
      *$ ! ^From:.*$VALID_FROM
      *  ! ^FROM_DAEMON
      {
          INCLUDERC = $PMSRC/pm-jaube.rc
      }

I have also received UBE messages that fool FROM_DAEMON test, so you could also consider using this condition. The standard daemon error message almost always has sentence "Transcript of session follows" in the body.

      *   -1^0    ^FROM_DAEMON
      * !  2^1  B ?? Transcript of session follows

Intead of simple daemon test:

      * ! ^FROM_DAEMON

File layout [toc]

tinybm.el/&tags and tinytab.el for the 4 tab text placement. See also unix what(1) and GNU RCS ident(1).

Bug reports [toc]

1998-02-27 bochmann@TUDURZ.urz.tu-dresden.de (Henryk Bochmann) reported that the ReceivedFrom test triggered all htmail messages. Fiexed.

Pm-jaube1.rc -- Jari's UBE filter. Subroutine 1 [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Maintainer: Jari Aalto jari.aalto@poboxes.com $
$Created: 1997-09 $
$Keywords: procmail UBE filter subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Documentation [toc]

This file is part of the "pm-jaube.rc". This subroutine is called when likely UBE message has been triggered.

Required settings [toc]

PMSRC must point to source direcry of procmail code. This recipe file will include


Pm-javac.rc -- Procmail: Vacation framework recipe (id-cache) [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-11 $
$keywords: procmail vacation framework recipe $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

Framework for all programs that need to reply to messages only once. Usually known as "vacation" feature. If you cahnge th cache file, you can attach this recipe to any messages that you want to deal with only once.

Required settings [toc]

PMSRC must point to source directory of procmail code. This subroutine will include

Call arguments (variables to set before calling) [toc]

Usage example [toc]

To turn on the vacation feature, create ~/.vac file and recipe below activates vacation. If the vacation is not active, then cache file is removed. (automatic cleanup). The VERBOSE is also turned off when you're on vacation; so that your procmail log will not get filled.

So when you go to vacation, you 'touch ~/.vac' and update ~/vacation.msg. When you come back, you 'rm ~/.vac'. That's it.

IMPORTANT: If you are subscribed to mailing lists, be sure to file messages from those services first and put the vacation recipe only after the list or bot messages. Also add sufficent "!" conditions in order not to reply to other "bot" service messages.

      JA_VAC_ID_CACHE = $HOME/.pm-vac.cache
      :0
      *$ ? test -e $HOME/.vac
      {
          VERBOSE     = off
          JA_VAC      = "yes"
          JA_VAC_RC   = $PMSRC/pm-myvac.rc        # my vacation recipe
          INCLUDERC   = $PMSRC/pm-javac.rc        # framework
      }
      :0 E
      * ? test -e $JA_VAC_ID_CACHE
      { dummy = `rm -f $JA_VAC_ID_CACHE` }

Here is example of pm-myvac.rc recipe

      #  Change subject
      #
      :0 fhw
      * ^Subject: *\/[^ ].*
      | formail -I "Subject: vacation (was: $MATCH)"
      :0 fb           # put message to body
      | cat $HOME/.vacation.msg
      :0              # Send it
      | $SENDMAIL

Pm-javar.rc -- Jari's global variable definitions [toc]

File id [toc]

Copyright (C) 1997-98 Jari Aalto
$Contactid: jari.aalto@poboxes.com $
$Created: 1997-12 $
$Keywords: procmail variableDEFS subroutine $

This code is free software in terms of GNU Gen. pub. Lic. v2 or later You can get newest version by sending email to maintainer with subject "send <FILENAME>"

Description [toc]

This file defines common varibles that you can use in the recipipes condition line. Because procmail does not know scape sequences like \t or \n, it is much more readable to use contruct
      :0
      *$ $s+something+$s+$d+$a+

Than the equivalent without variables

      :0
      #  Space + tab
      * [         ]something[     ][0-9]+[a-z]+

The standard set is also described in the pm-tips.txt file

Standard variables defined [toc]

See pm-tips.txt file for full explanation or look at the source code.
      SPC WSPC NSPC WSPCL      # Whitespace NonWhitespace + linefeed
      \s \d \D \w \W and \a \A # perl styled variables

Usage example [toc]

Put this as first lilne in you includerc. It makes ure that the file is loaded only if the variables are not already set.
      :0
      *$ ! $WSPC ?? ( )
      { INCLUDERC = $PMSRC/pm-javar.rc }

For your .procmailrc, you can simply put this, because you, that you don't have the variables available yet.

      INCLUDERC = $PMSRC/pm-javar.rc


End [toc]

End of document

This material can be publically distributed and copied with the permission of the Author, provided that you preserve the Author's name and that you distribute it in full and not partially. If you quote parts of this document, please always mention author's email address or http reference where to get the document you refered to.

This file has been automatically generated from plain text file with perl 4 script v1.51 t2html.pls
Document author: Jari Aalto
Url: ftp://cs.uta.fi/pub/ssjaaa/pm-code.txt
Contact: <jari.aalto@poboxes.com>
Html $Doc id: 1998-03-08 23:03 $