> The encoded format is called "quoted-printable", and there should be
> utilities for it.  I've seen algorithms in Perl for it, as well as
> native functions in PHP (though it'd be a little hackish to use a PHP
> shell script).  Just search for 'quoted-printable decode' and I'm sure
> something will turn up :-)

Thanks a lot for the hint!  I searched, found and programmed.  Here is the
result in case that anyone else needs that:

------------------8<--------<8------------------------
#!/usr/bin/perl
#
# mime_base64-decode  --  decodes strings that are mime or base64 encoded
#
# Andy Spiegl, [EMAIL PROTECTED]
# Created:     12. Dezember 2001
# Last change: 12. Dezember 2001
#

use strict;

use MIME::QuotedPrint;
use MIME::Base64;

my ($text,$result);
my ($head,$charset,$encoding,$encoded_text,$tail);

# read string from command line
$text = join " ", @ARGV;

# decode all the encoded parts
$result = "";
while ( ($head,$charset,$encoding,$encoded_text,$tail) =
  ($text =~ /^(.*?)=\?([^?]+)\?([^?]+)\?(.+?)\?=(.*)$/i) )
{
# rfc1522 says format is: "=?" charset "?" encoding "?" encoded-text "?="
  $result .= $head . &decode($charset,$encoding,$encoded_text);
  $text = $tail;
}

print $result . $text;
exit;


sub decode
{
  my ($c,$e,$t) = @_;

  if ($e =~ /Q/i)
  {
        $t =~ s/_/ /g;
        $t = decode_qp($t);
  }
  elsif ($e =~ /B/i)
  {
        $t = decode_base64($t);
  }
  else
  {
        print "---ERROR: unknown encoding $e---\n";
  }

  return $t;
}
------------------8<--------<8------------------------


Thanks again,
 Andy.

-- 
 Dr. Andy Spiegl, Radio Marañón, Jaén, Perú
 E-Mail: [EMAIL PROTECTED], [EMAIL PROTECTED]
 URL: http://spiegl.de, http://radiomaranon.org.pe
 PGP/GPG: see headers
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Your food stamps will be stopped effective March 1992 because we received
 notice that you passed away.  May God bless you.  You may re-apply if there is
 a change in your circumstances.  (Dept. of Social Services, Greenville, SC)

Attachment: msg21545/pgp00000.pgp
Description: PGP signature

Reply via email to