claws-mail-compose-insert-files.pl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Getopt::Long;
  4. use URI::Escape;
  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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. # *
  19. # * Copyright 2007 Paul Mangan <paul@claws-mail.org>
  20. # *
  21. # This script enables inserting files into the message body of a new Claws Mail
  22. # Compose window from the command line. Additionally To, Cc, Bcc, Subject and
  23. # files to attach to the message can be specified
  24. my (@inserts,@attachments,@lines,@output) = ();
  25. my $body = "";
  26. my $attach_list = "";
  27. my $to = "";
  28. my $cc = "";
  29. my $bcc = "";
  30. my $subject = "";
  31. my $help = "";
  32. GetOptions("to=s" => \$to,
  33. "cc=s" => \$cc,
  34. "bcc=s" => \$bcc,
  35. "subject=s" => \$subject,
  36. "attach=s" => \@attachments,
  37. "insert=s" => \@inserts,
  38. "help|h" => \$help);
  39. if ($help) {
  40. help_me();
  41. }
  42. @attachments = split(/,/, join(',', @attachments));
  43. @inserts = split(/,/, join(',', @inserts));
  44. foreach my $attach (@attachments) {
  45. $attach_list .= "$attach ";
  46. }
  47. foreach my $insert (@inserts) {
  48. open(FILE, "<$insert") || die("can't open file\n");
  49. @lines = <FILE>;
  50. push(@output, @lines);
  51. close FILE;
  52. }
  53. foreach my $line (@output) {
  54. $body .= "$line";
  55. }
  56. $to = uri_escape($to);
  57. $cc = uri_escape($cc);
  58. $bcc = uri_escape($bcc);
  59. $subject = uri_escape($subject);
  60. $body = uri_escape($body);
  61. system("claws-mail --compose \"mailto:$to?subject=$subject&cc=$cc&bcc=$bcc&body=$body\" --attach $attach_list");
  62. exit;
  63. sub help_me {
  64. print<<'EOH';
  65. Usage:
  66. claws-mail-compose-insert-files.pl [options]
  67. Options:
  68. --help -h
  69. --to "Person One <mail@address.net>"
  70. --cc "Person One <mail@address.net>"
  71. --bcc "Person One <mail@address.net>"
  72. --subject "My subject"
  73. --attach FILE
  74. --insert FILE
  75. For multiple recipients separate the addresses with ','
  76. e.g. --to "Person One <mail@address.net>,Person Two <mail2@address.net>"
  77. --attach and --insert can be used multiple times
  78. EOH
  79. exit;
  80. }