* pgp-clean:
[pgp-tools.git] / caff / caff
index 47c4ec89802c7211bfe5f46f18ab63d951fc3dd9..8c6e7e6a663186e481de4c4bb8402d4491de55fa 100755 (executable)
--- a/caff/caff
+++ b/caff/caff
@@ -4,7 +4,7 @@
 # $Id$
 #
 # Copyright (c) 2004, 2005 Peter Palfrader <peter@palfrader.org>
-# Copyright (c) 2005 Christoph Berg <cb@df7cb.de>
+# Copyright (c) 2005, 2006 Christoph Berg <cb@df7cb.de>
 #
 # All rights reserved.
 #
@@ -245,6 +245,23 @@ Add a Reply-To: header to messages sent. Default: none.
 Address to send blind carbon copies to when sending mail.
 Default: none.
 
+=item B<mailer-send> [array]
+
+Parameters to pass to Mail::Mailer.
+This could for example be
+
+       $CONFIG{mailer-send} =  [ 'smtp', Server => 'mail.server', Auth => ['user', 'pass'] ]
+
+to use the perl SMTP client or
+
+       $CONFIG{mailer-send} =  [ 'sendmail', '-o8' ]
+
+to pass arguments to the sendmail program.
+For more information run C<< perldoc Mail::Mailer >>.
+Setting this option is strongly discouraged.  Fix your local MTA
+instead.
+Default: none.
+
 =back
 
 =head1 AUTHORS
@@ -286,6 +303,10 @@ my $VERSION = "0.0.0.$REVISION_NUMER";
 
 
 
+sub mywarn($) {
+       my ($line) = @_;
+       print "[WARN] $line\n";
+};
 sub notice($) {
        my ($line) = @_;
        print "[NOTICE] $line\n";
@@ -313,9 +334,12 @@ sub generate_config() {
        my $gecos = defined $ENV{'LOGNAME'} ? (getpwnam($ENV{LOGNAME}))[6] : undef;
        my $email;
        my @keys;
-       my $hostname = `hostname -f`;
+       # BSD does not have hostname -f, so we try without -f first
+       my $hostname = `hostname`;
+       $hostname = `hostname -f` unless $hostname =~ /\./;
        chomp $hostname;
        my ($Cgecos,$Cemail,$Ckeys) = ('','','');
+
        if (defined $gecos) {
                $gecos =~ s/,.*//;
 
@@ -426,6 +450,8 @@ sub load_config() {
        $CONFIG{'no-download'} = 0 unless defined $CONFIG{'no-download'};
        $CONFIG{'no-sign'} = 0 unless defined $CONFIG{'no-sign'};
        $CONFIG{'key-files'} = () unless defined $CONFIG{'key-files'};
+       $CONFIG{'mailer-send'} = [] unless defined $CONFIG{'mailer-send'};
+       die ("$PROGRAM_NAME: mailer-send is not an array ref in $config.\n") unless (ref $CONFIG{'mailer-send'} eq 'ARRAY');
        $CONFIG{'mail-template'} = <<'EOM' unless defined $CONFIG{'mail-template'};
 Hi,
 
@@ -609,7 +635,7 @@ my $KEYEDIT_KEYEDIT_OR_DELSIG_PROMPT = '^\[GNUPG:\] (GET_BOOL keyedit.delsig|GET
 my $KEYEDIT_DELSUBKEY_PROMPT = '^\[GNUPG:\] GET_BOOL keyedit.remove.subkey';
 
 load_config;
-my $USER_AGENT = "caff $VERSION - (c) 2004, 2005 Peter Palfrader et al.";
+my $USER_AGENT = "caff $VERSION - http://pgp-tools.alioth.debian.org/";
 
 my $KEYSBASE =  $CONFIG{'caffhome'}.'/keys';
 my $GNUPGHOME = $CONFIG{'caffhome'}.'/gnupghome';
@@ -624,7 +650,7 @@ my $DATE_STRING = sprintf("%04d-%02d-%02d", $year+1900, $mon+1, $mday);
 
 sub version($) {
        my ($fd) = @_;
-       print $fd "caff $VERSION - (c) 2004, 2005 Peter Palfrader et al.\n";
+       print $fd "caff $VERSION - (c) 2004, 2005, 2006 Peter Palfrader et al.\n";
 };
 
 sub usage($$) {
@@ -770,7 +796,8 @@ sub send_mail($$$@) {
        $message_entity->head->add("Reply-To", $CONFIG{'reply-to'}) if defined $CONFIG{'reply-to'};
        $message_entity->head->add("Bcc", $CONFIG{'bcc'}) if defined $CONFIG{'bcc'};
        $message_entity->head->add("User-Agent", $USER_AGENT);
-       $message_entity->send();
+       mywarn("You have set arguments to pass to Mail::Mailer.  Better fix your MTA.  (Also, Mail::Mailer's error reporting is non existant, so it won't tell you when it doesn't work.)") if (scalar @{$CONFIG{'mailer-send'}} > 0);
+       $message_entity->send(@{$CONFIG{'mailer-send'}});
        $message_entity->stringify();
 };
 
@@ -1002,6 +1029,12 @@ if ($CONFIG{'no-download'}) {
        if (scalar %local_keyids) {
                notice ("Import failed for: ". (join ' ', keys %local_keyids)."." . ($had_v3_keys ? " (Or maybe it's one of those ugly v3 keys?)" :  ""));
                exit 1 unless ask ("Some keys could not be imported - continue anyway?", 0);
+               if (scalar %local_keyids == 1) {
+                       mywarn("Assuming ". (join ' ', keys %local_keyids)." is a fine keyid.");
+               } else {
+                       mywarn("Assuming ". (join ' ', keys %local_keyids)." are fine keyids.");
+               };
+               push @keyids_ok, keys %local_keyids;
        }
 };