email encrypted form

Anthony E. Greene agreene@pobox.com
Fri Nov 30 08:23:01 2001


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, 29 Nov 2001, Brandon Rasler wrote:

>I am trying to email an encrypted form using this script.
>
>open(MAIL, "|/home/menno/bin/gpg --homedir /home/menno/.gnupg -a -r
>'0x8ED34D6B' -e --no-secmem-warning -|/usr/sbin/sendmail -t
>user\@domain.com") || die ("can't open sendmail");
>print MAIL "You Said: $FORM{ 'line' }\n";
>close(MAIL);
>
>It is working fine but I have several forms and I would like to add headders
>so I know which form it is from.
>
>How would I add headders before running gpg?

You could write the headers to a temp file, then append the GPG data and
call sendmail to send the whole thing. 

You could put the whole plaintext message into a single string variable,
then use backticks to pipe the data to gpg and capture the output into
another string. Then open a pipe to sendmail and send the headers, then
the encrypted string.

$scriptname = `basename $0`;
chomp($scriptname);
$recipient = '"Full Name" <user@domain.tld>';
$keyid = '0xNNNNNNNN';
$plainmessage = "You said blah, blah, blah.\n";
$ecnryptedmessage = `echo "$plainmessage" |/home/menno/bin/gpg \
 --homedir /home/menno/.gnupg -a -r $keyid -e --no-secmem-warning`;
open(MAIL,"|/usr/sbin/sendmail -oi -t");
print MAIL "From: $scriptname <nobody>\n";
print MAIL "To: $recipient\n";
print MAIL "Subject: Web form data\n\n";
print MAIL "$encryptedmessage\n";
close(MAIL);


Or you could just specify an appropriate subject on the command line:

$scriptname = `basename $0`;
chomp($scriptname);
$recipient = 'user@domain.com';
$keyid = '0xNNNNNNNN';
$subject = "Web form data ($scriptname)";
$gpgcmd = "/path/to/gpg --homedir /path/to/.gnupg -a -r $keyid\ 
 -e --no-secmem-warning";
$mailcmd = "/bin/mail -s \"$subject\" $recipient ";
open(MAIL,"| $gpgcmd | $mailcmd");
print MAIL "You said blah, blah, blah.\n";
close(MAIL);

>
>I tried the following with no luck.
>
>{
>open(MAIL, "|/usr/sbin/sendmail -t user\@domain.com") || die ("can't open
>sendmail");
>print MAIL "From: Secure_Form_1\n";
>print MAIL "To: user\@domain.com\n";
>print MAIL "Subject: Results from Secure Form 1\n";
>print MAIL "Content-type:text/plain\n";
>{
>open(OUT, "|/home/menno/bin/gpg --homedir /home/menno/.gnupg -a -r
>'0x8ED34D6B' -e --no-secmem-warning -");
>print OUT "You Said: $FORM{ 'line' }\n";
>close(OUT);
>}
>close(MAIL);
>}

You specified the email recipient on the sendmail command line and in the
"To:" header. Also, you cannot redirect the output of gpg into the
existing pipe to sendmail. The closest thing you can do to this is to
write a tempfile and pipe the tempfile to sendmail.

Tony
- -- 
Anthony E. Greene <agreene@pobox.com> <http://www.pobox.com/~agreene/>
PGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26 C484 A42A 60DD 6C94 239D
Chat: AOL/Yahoo: TonyG05
Linux. The choice of a GNU generation <http://www.linux.org/>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Anthony E. Greene <agreene@pobox.com> 0x6C94239D

iD8DBQE8BzNEpCpg3WyUI50RAhhtAJ9xb5ms7k3+FPKbAPEyxS3gbGPVowCg8CMH
cg40NQIRgI8cKsmlsUArFIU=
=mHr4
-----END PGP SIGNATURE-----