Re: 'Content-Type' problem

Mark Overmeer <[email protected]> Fri, 23 Apr 2004 11:30:37 +0200
Newsgroups gmane.comp.lang.perl.modules.mail-box
Organization MARKOV Solutions
Message-ID <[email protected]>
* [email protected] ([email protected]) [040422 04:24]:
> In the following code:
> 
>     $body = Mail::Message::Body::Lines->new( 'data' => @lines ) ;
>     $msg->body( $body->encode( 'mime_type' => 'text/html',
>                                                  'charset' => 'UTF-8',
>                                                  'transfer_encoding' => 'quoted-printable' ) ) ;

> the 'mime_type' and 'charset' attribute seemed to be ignored:
> Whatever I write, the mail always contains:
>     Content-Type: text/plain; charset="us-ascii"
> 
> Did I overlook something?


Two things: one is a bug, and the other an user's mistake.
To start with the latter: when you create a body object, you start with
all the knowledge you have about the data.  So: if the data is text/html,
then say it immediately:

  my $body = Mail::Message::Body->new
    ( data      => \@lines          # don't forget the \backslash!
    , charset   => 'UTF-8'
    , mime_type => 'text/html'
    );
  my $enc = $body->encode(transfer_encoding => 'quoted_printable');

So: with encode() you only specify the changes you want to make.  When
you create a body say:
  $body = Mail::Message::Body->new(data => \@lines);
then you do not specify the (type, charset, transfenc), which means that
the body is a  (text/plain, us-ascii, none).  With $body->encode() you
can change the content of the body.  So, in design, you can say:

  my $enc = $body->encode(mime_type => 'text/html', charset => 'UTF-8'
     , transfer_encoding => 'base64');

which means that the original body is converted from text/plain into
text/html, at the same time the charset is converted from us-ascii into
UTF-8, and the transfer-encoding is applied.  So
  (text/plain, us-ascii, none) --> (text/html, UTF-8, base64)

HOWEVER: encode() is only partially implemented.  On the moment, it
totally ignores the mime_type and charset conversion requests.  Sorry,
but it is quite a lot of work to add this, and I currently lack time
to do this.

The second thing is a bug you hit. A mistake in $body->new overrules
the specified charset in some circumstances: where one body is created
"based on" an other body.  That will be fixed in the next release.  I
have quite a list of fixes, so that release may arrive soon.  As a
quick work-around, you may consider to add a
 $msg->get('Content-Type')->attribute(charset => 'UTF-8');
after your message is constructed.

Thanks for the report,
-- 
               MarkOv

------------------------------------------------------------------------
drs Mark A.C.J. Overmeer                                MARKOV Solutions
       [email protected]                          [email protected]
http://Mark.Overmeer.net                   http://solutions.overmeer.net