sylpheed-kdeservicemenu.pl 2.0 KB

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