#!/usr/bin/perl # # mail-gnupg-encrypt.pl - encrypt received mail with # your GnuPG/PGP key. Use with # procmail. # # Developed by Lubomir Host 'rajo' # Copyright (c) 2005 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # Changelog: # 2005-01-13 - created # # $Platon$ use strict; use warnings; use English; use AppConfig qw/:expand :argcount/; use GnuPG::Tie::Encrypt; use vars qw ( $VERSION %conf $conf $recipient $cfgfile ); sub help($;); $| = 1; $VERSION = do { my @r = (q$Revision: 1.1 $=~/\d+/g); sprintf "%d." . "%02d" x $#r, @r }; $conf = AppConfig->new( # {{{ { CASE => 1, DEBUG => 0, CREATE => 0, GLOBAL => { ARGCOUNT => ARGCOUNT_NONE, } }, # ALIAS =>, so imperfect and universe-breaking, and we still need it. "config|cfg=s", { }, "recipient|r=s", { }, "version", { ACTION => sub { print "$0 version $VERSION"; exit 0 } }, ) or die "Can't initialize the AppConfig object\n"; $conf->getopt; # parse command line $cfgfile = $conf->cfg(); if (defined($cfgfile) and $cfgfile ne '') { unless (-r $cfgfile) { help("Config file '$cfgfile' not found\n"); } else { $conf->file($conf->cfg) } } $recipient = $conf->recipient(); if (!defined($recipient) or $recipient eq '') { help("You need specify at least recipient parameter\n"); exit 1; } # }}} tie *CIPHER, 'GnuPG::Tie::Encrypt', armor => 1, recipient => $recipient; if (my $pid = fork) { # parent close (STDOUT); while () { print CIPHER $_; } } else { # child die("Fork failed!: $!") unless defined $pid; close (STDIN); while () { print; } } close CIPHER; untie *CIPHER; sub help($;) { # {{{ my ($err) = @_; print STDERR "\nError: $err\n"; print STDERR <