# pm-jamime-decode.rc -- decode MIME body contents; quoted-printable, base64 # $Id: pm-jamime-decode.rc,v 2.6 2004/04/04 16:59:05 jaalto Exp $ # # File id # # .Copyright (C) 1998-2004 Jari Aalto # .$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 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 attachments, then this recipe is not suitable # for it. # # Procmail is *not* designed to handle mime attachments and this # recipe only applies to whole _body_. # # The pm-jamime-kill.rc is really stretching the limits and any # serious works hould be delegated to appropriate Perl MIME modules. # There is a Perl MIME module which will allow you to manipulate MIME # body parts rather elegantly. See # http://www.perl.com/CPAN-local/authors/Eryq/ for MIME-tools. # # Se also mimedecode at ftp://ftp.dde.dk/pub/mimedecode.c which # in included in Debian Linux. # # Notes # # Perl and it's modules are not used, because Perl is so CPU intensive. # If we can do it with Procmail, let's do it. When we can't, we must give # the task to outside processes and pay the penalty. Consider this # seriously if you get hundreds of mails per day from mailing # lists. # # Required settings # # PMSRC must point to source directory 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 existence 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 } :0 * ! MIME_VER ?? [0-9] { INCLUDERC = $PMSRC/pm-jamime.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 handledSubject = "no" :0 D * ^Subject:\/.*=?(iso|ISO)-8859.*?=.* { SUBJECT = $MATCH clean_subject = `echo "$SUBJECT" | tee /tmp/subj | \ $SED 's/=?iso-\{0,1\}8859-[1-9]?Q?\([^?]*\)?=/\1/g' \ -e 's/=0D//g' -e 's/=0A//g' | \ $MIME_BIN_QP ` handledSubject = "yes" :0E fhw | $FORMAIL \ -i "Subject: $clean_subject" \ -I "X-Mime-Header-Decoded: $MIME_TYPE" } handledFrom = "no" :0 D * ^From:\/.*=?(iso|ISO)-8859.* { FROM = $MATCH clean_from = `echo "$FROM" | tee /tmp/from | \ $SED -e 's/=?ISO-\{0,1\}8859-[1-9]?Q?\([^?]*\)?=/\1/g' \ -e 's/=0D//g' -e 's/=0A//g' | \ $MIME_BIN_QP ` handledFrom = "yes" :0E fhw | $FORMAIL \ -i "From: $clean_from" \ -I "X-Mime-Header-Decoded: $MIME_TYPE" } # Touch only real mime messages and text/plain :0 * ! JA_MIME_TYPE ?? ^^^^ *$ $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 = $jaMimeDecodeShellmetas dummy = "$id: end:" # End of file pm-jamime-decode.rc