#!/usr/bin/perl
$^W=1;
use strict;

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

use Getopt::Long;

Getopt::Long::Configure (

	# start with "sane", conservitive POSIX (compatible) defaults
	"posix_default",

	# then tweak as seems fitting
	"bundling"

);

my($quoted_printable,$unencode)=(undef,undef);

GetOptions (
		"q" => \$quoted_printable,
		"u" => \$unencode,
)
	or die	(	"$0: bad option(s), aborting"	);

if(defined($unencode)&&$unencode){
	# unencode
	if(defined($quoted_printable)&&$quoted_printable){
		# quoted printable
		while(<>){
			print(decode_qp($_));
		};
	}else{
		while(<>){
			print(decode_base64($_));
		};
	};
}else{
	# encode
	if(defined($quoted_printable)&&$quoted_printable){
		# quoted printable
		while(<>){
			print(encode_qp($_));
		};
	}else{
		{
			$/=undef;
			print(encode_base64(<>));
		};
	};
};
