Page 1 of 1

Set header charset automaticaly

Posted: Thu Dec 06, 2007 9:28 am
by finwe
Based on what I've tried, Swift does not set other than default charset to headers automaticaly. It is necessary to form a conctruction like

Code: Select all

   $message = new Swift_Message($subject, $body, 'text/plain', null, 'ISO-8859-2');
    $message->headers->setCharset('ISO-8859-2');
Instead of setting headers charset directly in constructor of Swift_Message or in Swift_Message::setCharset.

What is the reason for this behavior? Is there some technical difficulty in this or is it good feature request :wink: ?

Posted: Tue Dec 11, 2007 9:14 pm
by Chris Corbyn
Swift should set your charset in the headers automatically. What it won't do however is set the same charset across all sub-parts since it's perfectly viable for each sub-part to have a different charset. Can you post the script you're having issues with?

Re: Set header charset automaticaly

Posted: Wed Feb 06, 2008 3:20 am
by finwe
Sorry for the rather long pause between replies.

It is somethig like

Code: Select all

 
    $message = new Swift_Message('PF 2008', null, 'text/plain', null, 'iso-8859-2');
    // without this, the message header is in iso...1 and therefore malformed
    $message->headers->setCharset('iso-8859-2');
        
    $message->attach(new Swift_Message_Part(
        iconv('UTF-8', 'ISO-8859-2', "Some text with diak?i?i?š"), // this is OK
        'text/plain', 
        null, 
        'iso-8859-2'
    ));
        
    $message->attach(new Swift_Message_Attachment(...));
        
    $from = new Swift_Address('finwe@finwe.info', iconv('UTF-8', 'ISO-8859-2', 'Mat?j Finwe Humpál'));
    $swift->send($message, $email, $from);
I'd expect, when creating an instance of Swift_Message with Charset set to 'iso-8859-2', that headers will have that charset, the same way as all other parts unless stated differently.

I've now tried, that even a message with one part has the headers the wrong way (encoded to ISO-8859-1), unless headers charset is set explicitly.

Code: Select all

 
    $message = new Swift_Message(
        'PF 2008', 
        iconv('UTF-8', 'ISO-8859-2', "Some text with diak?i?i?š"), 
        'text/plain', 
        null, 
        'iso-8859-2'
    );
        
    $from = new Swift_Address('finwe@finwe.info', iconv('UTF-8', 'ISO-8859-2', 'Mat?j Finwe Humpál')); 
    // From  will result in =?iso-8859-1?B?TWF07GogRmlud2UgSHVtcOFsIA==?=
    $swift->send($message, $email, $from);