Re: multilanguage e-mails, something I would like to share
Dj YB <[email protected]>
| Newsgroups | gmane.comp.kde.users.pim |
|---|---|
| Message-ID | <[email protected]> |
Sorry, I didn't attach the latest version of the script. YB. _______________________________________________ KDE PIM users mailing list [email protected] https://mail.kde.org/mailman/listinfo/kdepim-users
mail_translate.pl
(application/x-perl, 1.3 KB)
#!/usr/bin/perl
use Email::MIME;
use Encode;
my $translation_command = 'tw translate.google.com.en-he';
my $line;
my $message='';
while ($line=<>)
{
$message.=$line;
}
my $email = Email::MIME->new($message);
my @parts = $email->parts; # These will be Email::MIME objects, too.
my $decoded = $email->body;
my $content_type = $email->content_type;
if (@parts > 1)
{
for $parsed(@parts)
{
my @parts = $parsed->parts; # These will be Email::MIME objects, too.
my $decoded = $parsed->body;
my $non_decoded = $parsed->body_raw;
if ( $parsed->content_type =~ m[text/plain] )
{
my $text_body=$decoded;
my $text_raw=$non_decoded;
my $text_body=`$translation_command "$decoded"`;
my $single = Email::MIME->create(
body => "$text_body",
);
$single->content_type_set( 'text/plain' );
$single->charset_set( 'utf8' );
my @list;
$list[@list]=$single;
$email->parts_add( \@list );
}
}
}
else
{
my $translated=`$translation_command "$decoded"`;
if (($translated ne $decoded) && ($translated ne ''))
{
my $separator = `$translation_command "TRANSLATION"`;
chop $separator;
$email->body_set($decoded."\n\n--".$separator."--\n\n".$translated );
$email->charset_set( 'utf8' );
}
}
print $email->as_string;