# @(#) pm-jamime-decode.rc -- decode MIME body contents; quoted-printable, base64
# @(#) $Id: pm-jamime-decode.rc,v 2.0 2001/07/27 22:45:50 jaalto Exp $
#
#   File id
#
#       .Copyright (C)  1998-2001 Jari Aalto
#       .$Maintainer:   Jari Aalto <jari.aalto@poboxes.com> $
#       .$Created:      1998-01 $
#       .$Keywords:     procmail, subroutine, mime $
#
#       This code is free software in terms of GNU Gen. pub. Lic. v2 or later
#	Refer to http://www.gnu.org/copyleft/gpl.html
#
#   Documentation
#
#	The original father of the decoding scheme used here was
#	presented by Peter Galbraith <galbraith@mixing.qc.dfo.ca> in
#	procmail mailing list somewhere at the end of 1997.
#
#       This includerc supposes that the header has MIME header
#       Content-Type: text/plain and performs qp or base64 decoding
#       on the whole message. Note, that if you receive messages that
#       have many mime attachements, then this recipe is not suitable
#       for it.
#
#       Procmail is not designed to handle mime attachements and this
#       recipe only applies to whole _body_.
#
#   Required settings
#
#       PMSRC must point to source direcry of procmail code. This subroutine
#       will include
#
#       o   pm-javar.rc
#
#   Call arguments (variables to set before calling)
#
#       (none)
#
#   Return values
#
#	(none)
#
#   Examples
#
#	Instead of testing the existense of text/plain in the body,
#	you can force decoding by settings JA_MIME_DECODE_REGEXP to
#	".*".
#
#	    RC_MIME_DECODE = $PMSRC/pm-jamime-decode.rc
#
#	    :0
#	    * condition
#	    { JA_MIME_DECODE_REGEXP = ".*" }
#
#	    INCLUDERC = $RC_MIME_DECODE	    # call subroutine.
#
#
#   Change Log (none)

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


id    = "pm-jamime-decode.rc"
dummy = "
========================================================================
$id: init:
"

# :0
# * !  WSPC ?? ( )
# { INCLUDERC = $PMSRC/pm-javar.rc }

# .......................................................... &public ...
# User configurable sections

JA_MIME_DECODE_REGEXP = ${JA_MIME_DECODE_REGEXP:-\
"^Content-Type: *text/plain"}

# ........................................................... &do-it ...
#   Run conversion if it was quoted printable.
#   Also reflect correct MIME header

dummy = "$id: handle quoted printable"

#   Prevent calling sh -c here. This speeds up procmail
#
jaMimeDecodeShellmetas = $SHELLMETAS
SHELLMETAS


:0
*$ $JA_MIME_DECODE_REGEXP
{
    :0 fbw
    * ^Content-Transfer-Encoding: *quoted-printable
    | $MIME_BIN_QP

        :0 Afhw
        | $FORMAIL -I "Content-Transfer-Encoding: 8bit"

    :0 fbw
    * ^Content-Transfer-Encoding: *base64
    | $MIME_BIN_64

        :0 Afhw
        | $FORMAIL -I "Content-Transfer-Encoding: 8bit"
}


SHELLMETAS  = $jaMimeKillShellmetas

dummy = "$id: end:"

# End of file pm-jamime-decode.rc
