2007-10-03 [colin] 3.0.2cvs6
[claws.git] / tools / claws-mail-compose-insert-files.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Getopt::Long;
6 use URI::Escape;
7
8 #  * This file is free software; you can redistribute it and/or modify it
9 #  * under the terms of the GNU General Public License as published by
10 #  * the Free Software Foundation; either version 3 of the License, or
11 #  * (at your option) any later version.
12 #  *
13 #  * This program is distributed in the hope that it will be useful, but
14 #  * WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 #  * General Public License for more details.
17 #  *
18 #  * You should have received a copy of the GNU General Public License
19 #  * along with this program; if not, write to the Free Software
20 #  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #  *
22 #  * Copyright 2007 Paul Mangan <paul@claws-mail.org>
23 #  *
24
25 # This script enables inserting files into the message body of a new Claws Mail
26 # Compose window from the command line. Additionally To, Cc, Subject and files
27 # to attach to the message can be specified 
28
29 my (@inserts,@attachments,@lines,@output) = ();
30 my $body = "";
31 my $attach_list = "";
32 my $to = "";
33 my $cc = "";
34 my $subject = "";
35 my $help = "";
36
37 GetOptions("to=s"      => \$to,
38            "cc=s"      => \$cc,
39            "subject=s" => \$subject,
40            "attach=s"  => \@attachments,
41            "insert=s"  => \@inserts,
42            "help|h"    => \$help);
43
44 if ($help) {
45         help_me();
46 }
47
48 @attachments = split(/,/, join(',', @attachments));
49 @inserts = split(/,/, join(',', @inserts));
50
51 foreach my $attach (@attachments) {
52         $attach_list .= "$attach ";
53 }
54
55 foreach my $insert (@inserts) {
56         open(FILE, "<$insert") || die("can't open file\n");
57                 @lines = <FILE>;
58                 push(@output, @lines);
59         close FILE;
60 }
61
62 foreach my $line (@output) {
63         $body .= "$line";
64 }
65
66 $body = uri_escape($body);
67
68 system("claws-mail --compose \"mailto:$to?subject=$subject&cc=$cc&body=$body\" --attach $attach_list");
69
70 exit;
71
72 sub help_me {
73         print<<'EOH';
74 Usage:  
75         claws-mail-compose-insert-files.pl [options]
76 Options:
77         --help -h
78         --to mail@address.net[,mail2@address.net]
79         --cc mail@address.net[,mail2@address.net]
80         --subject "My subject"
81         --attach FILE
82         --insert FILE
83
84 --attach and --insert can be used multiple times
85
86 EOH
87 exit;
88 }