[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] sending MIME encoded EMail



Below you'll find an example MacPerl program which uses a MIME
scheme to safely transfer european language characters through email.

It uses the CPAN available module MIME::Lite.
Replace the addresses according to your configuration.
Use your fantasy to find useful ways to input the message text
and other parameters. In the moment it's some silly test text
hardwired into the script.

The translation tables are taken from an article written by
Scott Hanson <shanson@mail.hh.provi.de> Asendorf, Germany
on this mailing list.

I'd like to hear about problems and possible improvements.


Have fun


Axel

P.S.: I'm not quite sure whether MIME encoding is the right term.
Actually it is the quoted-printable scheme which converts e.g. an
"ö" to "=E4". To learn more read RFC2045, 2046 and the MIME::Lite
documentation.

============================================================================
#!perl -w

use MIME::Lite;
use vars @trans;

&init();

$message = "äöü ÄÖÜß, Umlaute im Mail Text";
$message = &mac2iso( $message );

$msg = new MIME::Lite
	From		=> 'me@mydomain.tld',
	To		=> 'you@yourdomain.tld',
	Subject		=> 'A MIME::Lite test message ...',
	Type		=> 'TEXT',
	Encoding	=> 'quoted-printable',
	Data		=> $message;

# DEBUG
# $msg->print_header( \*STDOUT );
# $msg->print_body( \*STDOUT );

MIME::Lite->send('smtp', "mailhost.mydomain.net", Timeout=>60);

$msg->send;

exit 0;

sub mac2iso()
{
	my( $string ) = $_[0];
	$string =~ s/[\x80-\xff]/$trans[ord($&)-(128)]/ge ;
	return $string;
}

sub init()
{
@trans = (

"\304", "\305", "\307", "\311",  "\321",  "\326", "\334", "\341",  
# Mac \200 - \207
# &Auml; &Aring; &Ccedil; &Eacute; &Ntilde; &Ouml; &Uuml; &aacute;

"\340", "\342", "\344", "\343", "\345", "\347", "\351", "\350", 
# Mac \210 - \217
#  &agrave; &acirc; &auml; &atilde; &aring; &ccedil; &eacute; &egrave; 

"\352", "\344", "\355", "\354", "\356", "\357", "\361", "\363", 
# Mac \220 - \227
# &ecirc; &euml; &iacute; &igrave; &icirc; &iuml; &ntilde; &oacute;

"\362", "\364", "\366", "\365", "\372", "\371", "\373", "\374",
# Mac \230 - \237
# &ograve; &ocirc; &ouml; &otilde; &uacute; &ugrave; &ucirc; &uuml; 

"*", "\260", "\242", "\243", "\247", "*", "\266", "\337", 
# MAC \240 - \247
# dagger &deg; &cent; &pound; &sect; bullet &para; &szlig;

"\256", "\251", "(TM)", "\264", "\250", "<>", "\306", "\330", 
# Mac \250 - \257
# &reg; &copy; trademark &acute; &uml; not_eq  &AElig;  &Oslash;

"infinity", "\261", "<=", ">=", "\245", "\265", "delta", "Sigma",
# Mac \260 -267
# infinity &plusmn; less/eq great/eq &yen; &micro; delta Sigma 

"pi",  "Pi", "integral", "\252", "\272", "Omega", "\346", "\370",
# Mac \270 - \277
# pi Pi integral &ordf; &ordm; Omega &aelig; &oslash;

"\277", "\241", "\254", "sqrt", "f", "~=", "Delta", "\253",
# Mac \300 - \307
# &iquest; &iexcl; &not; radical florin apeq Delta &laqot;

"\273", "...", "\240", "\300", "\303", "\325", "OE", "oe", 
# MAC \310 - \317
# &raqot; ellipsis &nbsp; &Agrave; &Atilde; &Otilde; OE oe 

"-", "--", '"', '"', '"', '"', "\367", "*", 
# Mac \320 - \327
# endash emdash open_qt clos_qt open_qt clos_qt &divide; diamond

"\377", "Y", "/", "*", '"', '"', "fi", "fl", 
# Mac \330 - \337
# &yuml; Y.umlaut fraction circ.x open_qt clos qt fi.lig fl.lig

"*", "\267", "'", '"', "o/oo", "\305", "\312", "\301",  
# Mac \340 - 341
# dbldagger &middot; under_qt under_dqt per_mil &Acirc; &Ecirc; &Aacute;

"\313", "\310", "\315", "\316", "\317", "\314", "\323", "\324", 
# Mac \350 - \357
# &Euml; &Egrave; &Iacute; &Icirc; &Iuml; &Igrave; &Oacute; &Ocirc;  

"*", "\322", "\332", "\333", "\331", "i", "", "", 
# Mac \360 - \367
# apple &Ograve &Uacute; &Ucirc; &Ugrave; dotless_i circumflex tilde

"\257", "", "", "", "", "", "", "" );
# Mac \370 - \377
# &macr; breve dot ring_above cedilia hung_umlaut ogonek caron 
}

__END__

----------------------------------------------------------------------
Axel Rose, Springer & Jacoby Digital GmbH & Co. KG, mailto:rose@sj.com
  pub PGP key 1024/A21CB825 E0E4 BC69 E001 96E9  2EFD 86CA 9CA1 AAC5
  "... denn alles, was entsteht, ist wert, daß es zugrunde geht ..."

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org