]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - barnowl/zcrypt.pl
zcrypt.pl: No need to replace BarnOwl’s builtin zcrypt anymore
[Scripts/git/.git] / barnowl / zcrypt.pl
CommitLineData
e34d1a28
AK
1# This perl module adds a :decrypt command that uses barnowl's zcrypt
2# binary via Perl to decrypt zcrypt'd zephyrs after they have been
3# received.
cb96a5e1
GT
4#
5# To use this code, type
e51766d3 6# :perl do '/mit/snippets/barnowl/zcrypt.pl'
cb96a5e1 7#
cb96a5e1
GT
8
9use IPC::Open2;
10BarnOwl::new_command(decrypt => sub {
11 my $msg = BarnOwl::getcurmsg();
12 my $cmd = shift;
13 my @args = @_;
14 if (scalar @args == 0) {
15 @args = ('-c', $msg->class, '-i', $msg->instance);
16 }
17 my ($zo, $zi);
3c2ef01d 18 my $pid = open2($zo, $zi, 'athrun', 'barnowl', 'zcrypt', '-D', @args) or die "Couldn't launch zcrypt\n";
cb96a5e1 19 my $decrypted;
e34d1a28 20 print $zi $msg->fields->[1] . "\n";
cb96a5e1
GT
21 close $zi;
22 while (<$zo>) {
23 chomp;
24 last if $_ eq "**END**";
25 $decrypted .= "$_\n";
26 }
27 BarnOwl::popless_ztext($decrypted);
28 waitpid $pid, 0;
29 },
30 {summary => "Decrypt a zcrypted message once",
31 usage => "decrypt [args]",
3c2ef01d 32 description => "Invokes athrun barnowl zcrypt on the current message,\n
cb96a5e1
GT
33using the class and instance to find the crypt key, and pops up the\n
34decrypted output. If args are specified, they are passed to zcrypt and the\n
35class and instance are ignored.\n\n
36SEE ALSO: zcrypt(1)"});
37
e34d1a28 381;