# pm-jafrom.rc -- get message's best FROM field without calling `formail'
#
#   File id
#
#       Copyright (C) 1997-2010 Jari Aalto
#
#       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 at
#       <http://www.gnu.org/copyleft/gpl.html>.
#
#   Description
#
#	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
#
#	PMSRC must point to source directory 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)
#
#       (none)
#
#   Usage example
#
#	INCLUDERC = $PMSRC/pm-jafrom.rc
#	FROM      = $OUTPUT   # now we have the 'best' FROM field
#
#   Change Log (none)

# .................................................... &initialising ...

id    = "pm-jafrom.rc"
dummy = "
========================================================================
$id: init:
"

:0
* !  WSPC ?? [ ]
{
    INCLUDERC = $PMSRC/pm-javar.rc
}

# ..................................................... &output-vars ...
# output variables

OUTPUT

# ........................................................... &do-it ...
#	Check that input is something like: Thu, 13 Nov 1997

dummy = "$id: Get message's FROM field."

:0
*$ ! ^Reply-to: *\/$NSPC.*
*$ ! ^From: *\/$NSPC.*
*$ ! ^Sender: *\/$NSPC.*
*$ ! ^From *\/$NSPC+
{
    OUTPUT = `formail -zxFrom:`
}
:0 E
{
    OUTPUT = $MATCH
}


dummy = "$id: end:"

# end of file pm-jafrom.rc
