#!/usr/bin/perl -w # Copyright: Guido Socher # $Revision: $, last changed: $Date: $ # use strict; use vars qw($opt_h); use Getopt::Std; # &getopts("h")||exit 1; &help if ($opt_h); &help unless ($ARGV[0]); &help if ($ARGV[2]); my $encoded=""; my $outfile = pop; if (-f "$outfile"){ die "ERROR: output-file $outfile does already exist\n"; } $encoded=join('',<>); open(OFILE,">$outfile")||die "ERROR: can not write output file $outfile\n"; print OFILE decodebase64($encoded); close OFILE; # sub decodebase64 ($) { local($^W) = 0; # unpack("u",...) gives bogus warning in 5.001m, 5.002beta2 my $str = shift; my $res = ""; $str =~ tr|A-Za-z0-9+/||cd; # remove non-base64 chars (padding) $str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format while ($str =~ /(.{1,60})/gs) { my $len = chr(32 + length($1)*3/4); # compute length byte $res .= unpack("u", $len . $1 ); # uudecode } $res; } # sub help{ print "base64decode -- decode mail attachments in base64 format. The base64 encoding is a popular encoder for binary files used by MIME compliant mailers. EXAMPLE: If you receive a mail that looks like: --------------2D586AC36159 Content-Type: application/x-gzip; name=\"myfile.gz\" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename=\"myfile.gz\" H4sIAFGbXzQAA+1bDXBc1XU24Ezwa5NAUtImg8O1DPautPtWu1pZWGKdyrEsC2RJSDKJbQnz tHt390Vv31vee6vV2niGEkNcAm0oTUJSSvhpEgoz9eDEGZKW0mTaMZiY0KEDhYSGkkkKNKmT QGIYl9Jzzn3/WtnxjDFTunfMavfdc+8995xzz/nOeZd6Wc2XK4qeTMudqSVvTWPZzp7ubraE c3ctfbuPRKu1Wqu1Wqu1Wqu1Wqu1Wqu1Wqu1Wqu12juq/S/PxSuyAFAAAA== --------------2D586AC36159-- Then you have either the option to load the mail into Netscape or use this little decoder. Cut out the middle part: H4sI.. until...AAAA== and save this into a file called input.file After that you just run: base64decode input.file myfile.gz which will restore the original myfile.gz file. USAGE: base64decode [-h] [input.file] output.file \n"; exit; } __END__