1#!/usr/local/bin/perl -w
2
3use strict;
4
5use Getopt::Long;
6use 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, Bcc, Subject and
27# files to attach to the message can be specified
28
29my (@inserts,@attachments,@lines,@output) = ();
30my $body = "";
31my $attach_list = "";
32my $to = "";
33my $cc = "";
34my $bcc = "";
35my $subject = "";
36my $help = "";
37
38GetOptions("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);
45
46if ($help) {
47	help_me();
48}
49
50@attachments = split(/,/, join(',', @attachments));
51@inserts = split(/,/, join(',', @inserts));
52
53foreach my $attach (@attachments) {
54	$attach_list .= "$attach ";
55}
56
57foreach my $insert (@inserts) {
58	open(FILE, "<$insert") || die("can't open file\n");
59		@lines = <FILE>;
60		push(@output, @lines);
61	close FILE;
62}
63
64foreach my $line (@output) {
65	$body .= "$line";
66}
67
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);
73
74system("claws-mail --compose \"mailto:$to?subject=$subject&cc=$cc&bcc=$bcc&body=$body\" --attach $attach_list");
75
76exit;
77
78sub help_me {
79	print<<'EOH';
80Usage:
81	claws-mail-compose-insert-files.pl [options]
82Options:
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
90
91For multiple recipients separate the addresses with ','
92e.g. --to "Person One <mail@address.net>,Person Two <mail2@address.net>"
93--attach and --insert can be used multiple times
94
95EOH
96exit;
97}
98