]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - barnowl/zcrypt.pl
barnowl/zcrypt.pl: BarnOwl::quote the editwin prompt.
[Scripts/git/.git] / barnowl / zcrypt.pl
CommitLineData
cb96a5e1
GT
1# BarnOwls older than late September 2008 will segfault on short zcrypt messages.
2# Besides, the code is sketchy and doesn't belong in core. This perl module
3c2ef01d 3# will add :zcrypt and :decrypt commands that use barnowl's zcrypt binary via
cb96a5e1
GT
4# Perl, so a bug in zcrypt can't possibly affect BarnOwl proper. The :zcrypt
5# command replaces the built-in one.
6#
7# To use this code, type
e51766d3 8# :perl do '/mit/snippets/barnowl/zcrypt.pl'
cb96a5e1
GT
9#
10# This first line will disable BarnOwl's own zcrypt code, so messages are
11# encrypted onscreen. Use :decrypt to display them. (Security bugs were later
12# found in the decryption code, although these probably affect locker zcrypt
13# too.)
14
15BarnOwl::command("unset zcrypt");
16
17use IPC::Open2;
18BarnOwl::new_command(decrypt => sub {
19 my $msg = BarnOwl::getcurmsg();
20 my $cmd = shift;
21 my @args = @_;
22 if (scalar @args == 0) {
23 @args = ('-c', $msg->class, '-i', $msg->instance);
24 }
25 my ($zo, $zi);
3c2ef01d 26 my $pid = open2($zo, $zi, 'athrun', 'barnowl', 'zcrypt', '-D', @args) or die "Couldn't launch zcrypt\n";
cb96a5e1 27 my $decrypted;
d58b13ca 28 print $zi @{$msg->fields}[1] . "\n";
cb96a5e1
GT
29 close $zi;
30 while (<$zo>) {
31 chomp;
32 last if $_ eq "**END**";
33 $decrypted .= "$_\n";
34 }
35 BarnOwl::popless_ztext($decrypted);
36 waitpid $pid, 0;
37 },
38 {summary => "Decrypt a zcrypted message once",
39 usage => "decrypt [args]",
3c2ef01d 40 description => "Invokes athrun barnowl zcrypt on the current message,\n
cb96a5e1
GT
41using the class and instance to find the crypt key, and pops up the\n
42decrypted output. If args are specified, they are passed to zcrypt and the\n
43class and instance are ignored.\n\n
44SEE ALSO: zcrypt(1)"});
45
46BarnOwl::new_command(zcrypt => sub {
47 my $cmd = shift;
48 my @args = @_;
36b8f5a7
AK
49 #my $argstring = BarnOwl::quote(@args); # requires BarnOwl 1.4
50 my $argstring = join ' ', map { BarnOwl::quote($_) } @args;
3c2ef01d 51 BarnOwl::start_edit_win("athrun barnowl zcrypt $argstring", sub {
cb96a5e1
GT
52 my $msg = shift;
53 my ($zo, $zi);
3c2ef01d 54 my $pid = open2($zo, $zi, 'athrun', 'barnowl', 'zcrypt', @args);
cb96a5e1
GT
55 print $zi "$msg\n";
56 close $zi;
57 local $/;
58 BarnOwl::message(<$zo>);
59 waitpid $pid, 0;
60 });
61 },
3c2ef01d 62 {summary => "Run athrun barnowl zcrypt",
cb96a5e1 63 usage => "zcrypt -c [class] -i [instance]",
3c2ef01d 64 description => "Calls athrun barnowl zcrypt on a message you type in.\n\n
cb96a5e1 65SEE ALSO: zcrypt(1)"});