note
dakkar
<p>You are <em>almost</em> doing it right. Your biggest problem is that [cpan://MIME::Words] does not work exactly as needed.</p>
<p>First of all, I assume you are dealing with character strings, not byte strings (read [perldoc://perluniintro] and [perldoc://perlunicode] for details). In that case, you should really use <tt>[cpan://Encode]::encode</tt> on your strings before passing them to <tt>[cpan://MIME::Words]::encode_mimeword</tt>.</p>
<p>The problem with the from and to fields (yes, they'll both get messed up) is that RFC-1522 poses some constraint on the encoding of the various parts. The easiest way to get near what the RFC requires is to use <tt>[cpan://MIME::Words]::encode_mimewords</tt>:</p>
<code>
$smtp->datasend( "To: " . MIME::Words::encode_mimewords(Encode::encode('utf-8',$self->to()), Encoding => 'Q', Charset=> 'utf-8') . "\n" );
</code>
<p>This way I was able to send myself a message with all headers containing japanese characters.</p>
<p>On a sidenote: the RFC requires each encoded "word" to be less than 75 octects. Keep this in mind when encoding long subject lines.</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-43471">
<pre>--
dakkar - Mobilis in mobile
</pre>
<p><font size="-2">Most of my code <em>is</em> tested...</font></p>
<p><font size="-2"><a href="http://www.sidhe.org/~dan/blog/archives/000151.html">Perl is strongly typed, it just has very few types</a> (Dan)</font></p>
</div></div>
413988
413988