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