fix check for mail at start-up
[claws.git] / tools / claws-mail-compose-insert-files.pl
blobee99641c28a58c1759488fb17843d89502b5494e
1 #!/usr/bin/perl -w
3 use strict;
5 use Getopt::Long;
6 use URI::Escape;
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 # *
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, Bcc, Subject and
27 # files to attach to the message can be specified
29 my (@inserts,@attachments,@lines,@output) = ();
30 my $body = "";
31 my $attach_list = "";
32 my $to = "";
33 my $cc = "";
34 my $bcc = "";
35 my $subject = "";
36 my $help = "";
38 GetOptions("to=s" => \$to,
39 "cc=s" => \$cc,
40 "bcc=s" => \$bcc,
41 "subject=s" => \$subject,
42 "attach=s" => \@attachments,
43 "insert=s" => \@inserts,
44 "help|h" => \$help);
46 if ($help) {
47 help_me();
50 @attachments = split(/,/, join(',', @attachments));
51 @inserts = split(/,/, join(',', @inserts));
53 foreach my $attach (@attachments) {
54 $attach_list .= "$attach ";
57 foreach my $insert (@inserts) {
58 open(FILE, "<$insert") || die("can't open file\n");
59 @lines = <FILE>;
60 push(@output, @lines);
61 close FILE;
64 foreach my $line (@output) {
65 $body .= "$line";
68 $to = uri_escape($to);
69 $cc = uri_escape($cc);
70 $bcc = uri_escape($bcc);
71 $subject = uri_escape($subject);
72 $body = uri_escape($body);
74 system("claws-mail --compose \"mailto:$to?subject=$subject&cc=$cc&bcc=$bcc&body=$body\" --attach $attach_list");
76 exit;
78 sub help_me {
79 print<<'EOH';
80 Usage:
81 claws-mail-compose-insert-files.pl [options]
82 Options:
83 --help -h
84 --to "Person One <mail@address.net>"
85 --cc "Person One <mail@address.net>"
86 --bcc "Person One <mail@address.net>"
87 --subject "My subject"
88 --attach FILE
89 --insert FILE
91 For multiple recipients separate the addresses with ','
92 e.g. --to "Person One <mail@address.net>,Person Two <mail2@address.net>"
93 --attach and --insert can be used multiple times
95 EOH
96 exit;