From 746e683bd12005337be464cbd1b21a73de78e8f7 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Wed, 15 Jun 2005 10:41:53 +0000 Subject: [PATCH] cscvs to tla changeset 5 Author: noodles Date: 2005/03/21 15:11:01 Add support for MIME signed mails from Simon Huggins. git-archimport-id: noodles@earth.li--pie/autodns--mainline--1.0--patch-4 --- HISTORY | 4 +++ autodns.pl | 79 +++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/HISTORY b/HISTORY index 6a845ae..206261c 100644 --- a/HISTORY +++ b/HISTORY @@ -42,3 +42,7 @@ * Fix for problems with gpg flushing & lots of domains. (James Harrison) * Fix bug with writing filenames with /s in them - we convert them to :s now. + +0.0.8 + +* Add support for MIME signed mails. (Simon Huggins) diff --git a/autodns.pl b/autodns.pl index 2b973ee..67377a3 100755 --- a/autodns.pl +++ b/autodns.pl @@ -5,12 +5,14 @@ # http://www.earth.li/projectpurple/progs/autodns.html # Released under the GPL. # -# $Id: autodns.pl,v 1.4 2004/04/08 10:48:35 noodles Exp $ +# $Id: autodns.pl,v 1.5 2005/03/21 15:11:01 noodles Exp $ # use strict; -use IPC::Open3; use Fcntl qw(:flock); +use File::Temp qw(tempfile); +use IPC::Open3; +use MIME::Parser; $ENV{'PATH'}="/usr/local/bin:/usr/bin:/bin:/usr/sbin"; @@ -211,21 +213,72 @@ Released under the GPL. EOF # -# Now run GPG against our incoming mail, first making sure that our locale is -# set to C so that we get the messages in English as we expect. +# Throw the mail at MIME::Parser and see if it accepts it. +# +my $parser = new MIME::Parser; +$parser->output_to_core(1); # No temporary files +my $entity = $parser->parse_data(\@MAIL); + +# +# Make sure locale is set to C so we get messages in English as we expect. # $ENV{'LC_ALL'}="C"; -open3(\*GPGIN, \*GPGOUT, \*GPGERR, "gpg --batch"); -# Feed it the mail. -print GPGIN @MAIL; -close GPGIN; +if ($entity->parts) { + # MIME + + my ($got_sig, $got_text) = (0, 0); + my ($sig_name,$sig_fh,$text_name,$text_fh); + ($sig_fh, $sig_name) = tempfile(); + ($text_fh, $text_name) = tempfile(); + + foreach my $subent ($entity->parts) { + if ($subent->effective_type eq "text/plain") { + @COMMANDS = split /\n/,$subent->bodyhandle->as_string; + + my $str = $subent->as_string; + $str =~ s/=\n$//; + $str =~ s/\n/\r\n/g; + print $text_fh $str; + close($text_fh); + $got_text++; + } elsif ($subent->effective_type eq + "application/pgp-signature") { + print $sig_fh $subent->as_string; + close($sig_fh); + $got_sig++; + } + } + + if ($got_sig && $got_text) { + open3(\*GPGIN, \*GPGOUT, \*GPGERR, "gpg --batch --verify ". + $sig_name." ".$text_name); -# And grab what it has to say. -@GPGERROR=; -@COMMANDS=; -close GPGERR; -close GPGOUT; + close GPGIN; + + @GPGERROR=; + my @GPGOUTPUT=; + close GPGERR; + close GPGOUT; + + unlink($text_name); + unlink($sig_name); + } +} else { + # Clear text. + + open3(\*GPGIN, \*GPGOUT, \*GPGERR, "gpg --batch"); + + # Feed it the mail. + print GPGIN @MAIL; + close GPGIN; + + # And grab what it has to say. + @GPGERROR=; + @COMMANDS=; + close GPGERR; + close GPGOUT; +} # Check who it's from and if the signature was a good one. $gpggood=1; -- 2.39.5