#!/usr/bin/perl
 
use warnings;
use strict;
use MailIdentity 'ReadID';
##use Locale::TextDomain ('tb-att', './locale/');
use Locale::TextDomain ('tb-att', '/usr/share/thunderbird-attachment/locale');
use POSIX;
use File::Spec;
setlocale( LC_MESSAGES, '' );

die __":: no input file(s) specified!\n"  unless @ARGV;
##convert relative path into absolute path
##useful when launching from command line
my @ABS;
for my $f(@ARGV)
	{
		if (!File::Spec->file_name_is_absolute($f)) 
			{
				my $abs_path = File::Spec->rel2abs($f);
				push @ABS, $abs_path;
			}
		else { push @ABS, $f }
	}
				 
my $ATT = join (',', @ABS);
my @FILES = map {$_ =~ /([^\/]+)$/; $1} @ABS;
my $SUBJECT;
if ( $#FILES == 0 )
	{$SUBJECT = __x ("Emailing: {att}", att => $FILES[0])}
else 
        {my $s = join (',', @FILES);
	$SUBJECT = __x ("Emailing: {att}", att => $s)}

my $files_body = join("\n",@FILES);
my $b1 = __"Your message is ready to be sent with the following file or link attachments:\n\n";
my $b2 = __"\n\nNote: To protect against computer viruses e-mail programs may prevent sending or receiving certain types of file attachments.";
my $b3 = __ " Check your e-mail security settings to determine how attachments are handled.\n";

my $BODY = $b1 . $files_body . $b2 . $b3; 
my $FROM = 'preselectid=' . ReadID;
(system qq{thunderbird -Compose "attachment=\'$ATT\'","subject=\'$SUBJECT\'","body"=\"$BODY\",$FROM}) == 0 or 
print __x(":: thunderbird exited with status {status}\n", status => $? >> 8);

