2005-01-29 [paul] 1.0.0cvs23.2
[claws.git] / tools / kdeservicemenu / sylpheed-kdeservicemenu.pl
1 #!/usr/bin/perl
2
3 #  * Copyright 2004 Paul Mangan <claws@thewildbeast.co.uk>
4 #  *
5 #  * This file is free software; you can redistribute it and/or modify it
6 #  * under the terms of the GNU General Public License as published by
7 #  * the Free Software Foundation; either version 2 of the License, or
8 #  * (at your option) any later version.
9 #  *
10 #  * This program is distributed in the hope that it will be useful, but
11 #  * WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  * General Public License for more details.
14 #  *
15 #  * You should have received a copy of the GNU General Public License
16 #  * along with this program; if not, write to the Free Software
17 #  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 unless ($ARGV[0]) { exit; }
20
21 my $sylpheed = "sylpheed --compose --attach";
22 my $prefix = "/tmp/archive.";
23 my $command = find_command($ARGV[0]);
24 my ($sel,$att) = split_parts();
25
26 if ($ARGV[0] eq "gz" || $ARGV[0] eq "bz2") {
27         exec "$sel$sylpheed $att";
28 } elsif ($ARGV[0] eq "attachfile") {
29         exec "$sylpheed $sel";
30 } else {
31         exec "$command $prefix$ARGV[0] $sel;"
32             ."$sylpheed $prefix$ARGV[0]";
33 }
34
35 exit;
36
37 sub find_command {
38         local($s) = @_;
39         my $com;
40         
41         if ($s eq "gz")         { $com = "gzip -c"; }
42         elsif ($s eq "bz2")     { $com = "bzip2 -c"; }
43         elsif ($s eq "zip")     { $com = "$s -r"; }
44         elsif ($s eq "tar")     { $com = "$s -c -f"; }
45         elsif ($s eq "tar.bz2") { $com = "tar -cj -f"; }
46         elsif ($s eq "tar.gz")  { $com = "tar -cz -f"; }
47         
48         return $com;
49 }
50
51 sub split_parts {
52         my $selectedParts = "";
53         my $attachedParts = "";
54
55         for (my $count = $#ARGV; $count > 0; $count--) {
56                 my @s = split("/", $ARGV[$count]);
57                 my $p = pop(@s);
58                 if ($ARGV[0] eq "gz" || $ARGV[0] eq "bz2") {
59                         my $psub = $p;
60                         $psub =~ s/\s/_/g;
61                         my $output = "/tmp/$psub.$ARGV[0]";
62                         $selectedParts .= "$command \"$p\" > $output;";
63                         $attachedParts .= "$output ";
64                 } else {
65                         $selectedParts .= "\"$p\" ";
66                 }
67         }
68         return ($selectedParts,$attachedParts);
69 }