#!/usr/bin/perl # $version = 'pgpmimeify 0.06 - Report bugs to '; # # This code is in the public domain. Please send cookies if you like it. # # This is a simple script to encrypt any multipart/mime message using # PGP/MIME. # # Author: Bjarni R. Einarsson, http://bre.klaki.net/ use FileHandle; use IPC::Open2; $username = $ARGV[0]; $seperator = 'fNord' . time() . 'fnORD'; $mimestuff = "Mime-Version: 1.0\n" . "Content-Type: multipart/encrypted; protocol=\"application/pgp-encrypted\";\n" . " boundary=$seperator;\n" . "X-MIME-Autoencrypted: by $version\n"; $| = 1; $mimeset = 0; $lastline = ''; $header{"Content-Transfer-Encoding"} = "Content-Transfer-Encoding: 8bit\n"; while (($line = ) !~ /^\s*$/) { $line =~ s/charset=us-ascii/charset=iso-8895-1/; # Yahoomail hack if ($line =~ /^\s+/) { $t = $lastline . $line; $lastline = $line = $t; } if ($lastline ne $line) { if ((!$mimeset) && ($lastline =~ /^(To|From|Subject):/i)) { print $mimestuff; $mimeset = 1; } if ($lastline =~ /^(Lines|Mime-Version|Content.*?):/i) { $header{$1} = $lastline; } else { print $lastline; } $lastline = $line; } } if ($lastline ne $line) { if ($lastline =~ /^(Lines|Mime-Version|Content.*?):/i) { $header{$1} = $lastline; } else { print $lastline; $lastline = $line; } } print $mimestuff if (!$mimeset); print " --$seperator Content-Type: application/pgp-encrypted Version: 1 --$seperator Content-Type: application/octet-stream "; $username =~ s/\'//g; $sleep_count = 0; do { $pid = open2(\*FromPGP, \*ToPGP, "pgp +verbose=0 -fea -- '$username'"); unless (defined $pid) { warn "cannot fork: $!"; die "ugh!" if $sleep_count++ > 6; sleep 10; } } until defined $pid; printf ToPGP "%s%s\n", $header{"Content-Type"}, $header{"Content-Transfer-Encoding"}; while () { print ToPGP; } close(ToPGP); while () { print STDOUT; } print "\n--$seperator\n";