1 #!/usr/bin/perl -wT
 2 # http://www.0x11.net/notify-remote/unmarshal.pl
 3 #
 4 # see also my blog post on
 5 # http://blog.foosion.org/2008/02/15/libnotify-over-ssh/
 6 #
 7 # based and inspired on
 8 # http://jaredquinn.info/it-related/technical/unix/2007.09.25/libnotify-with-irssi-over-ssh/
 9 
10 use strict;
11 $ENV{PATH} = '/bin:/usr/bin';
12 
13 my $icon = "gtk-dialog-info";
14 my $timeout = 5000;
15 my $urgency = "normal";
16 my $content = "";
17 my $category = "Message";
18 my $subject = "";
19 
20 sub unmarshall(\$)
21 {
22   my $foo = shift;
23 
24   ${$foo} =~ s/\\\\/\\/g;
25   ${$foo} =~ s/\\n/\n/g;
26 
27   # escape it as well
28   ${$foo} =~ s/&/&/g;
29   ${$foo} =~ s/'/'/g;
30   ${$foo} =~ s/"/"/g;
31   ${$foo} =~ s/>/>/g;
32   ${$foo} =~ s/</&lt;/g;
33 }
34 
35 while (<STDIN>)
36 {
37   if (/^([A-Z]+)\s+(.+?)\s*$/)
38   {
39     $category = $2 if ($1 eq 'CATEGORY');
40     $icon     = $2 if ($1 eq 'ICON');
41     $content  = $2 if ($1 eq 'CONTENT');
42     $timeout  = $2 if ($1 eq 'TIMEOUT');
43     $subject  = $2 if ($1 eq 'SUBJECT');
44     $urgency  = $2 if ($1 eq 'URGENCY');
45   }
46 }
47 
48 exit unless ($content or $subject);
49 
50 unmarshall($category);
51 unmarshall($icon);
52 unmarshall($content);
53 unmarshall($timeout);
54 unmarshall($subject);
55 unmarshall($urgency);
56 
57 system('notify-send', '-i', $icon, '-c', $category, '-u', $urgency, '-t', $timeout, '--', $subject, $content);