zendframework / zend-mail

Mail component from Zend Framework
BSD 3-Clause "New" or "Revised" License
96 stars 111 forks source link

Zend\Mail: setEncoding broken #102

Open GeeH opened 8 years ago

GeeH commented 8 years ago

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7324 User: @echampet Created On: 2015-03-13T13:57:58Z Updated At: 2015-10-25T07:09:02Z Body Hi,

I'm using Zend\Mail\Message::fromString() to parse an existing mail, modify/check some stuff in the headers, and after send it via smtp.

In my headers everything is in ascii, except the subject which is utf8 (encoded in quoted printable) parsing is fine (Mime\Decode::splitMessage here https://github.com/zendframework/zf2/blob/67f098af070b29d5042e89e936604df3193d2212/library/Zend/Mail/Message.php#L546) and all headers in $headers have ->encoding == ascii except the subject ->encoding == utf-8

now when calling $message->setHeaders($headers); (https://github.com/zendframework/zf2/blob/67f098af070b29d5042e89e936604df3193d2212/library/Zend/Mail/Message.php#L550), there is a call to $headers->setEncoding('ascii') (https://github.com/zendframework/zf2/blob/67f098af070b29d5042e89e936604df3193d2212/library/Zend/Mail/Message.php#L86), but it's doing nothing except breaking encoding.

When you call setEncoding, you are only changing the 'declared' encoding, but you are not converting the data, so this can only break stuff.

For now i've just commented out //$headers->setEncoding($this->getEncoding()); (ligne 86)

I think encoding should only be stored at header (singular) level, or even better store everything in utf8, and at encoding time detect if encoding is needed (mb_detect_encoding !== 'ascii'?)

Cullprit is 9f70feb81b5fccd7259d97971084c1d455525ae3 (December 2011)


Comment

User: @weierophinney Created On: 2015-03-23T18:57:15Z Updated At: 2015-03-23T18:57:15Z Body Could you provide a message that fails for us? We can then use that for a test case in order to correct the issue.

Thanks!


Comment

User: @echampet Created On: 2015-03-24T08:01:24Z Updated At: 2015-03-24T08:01:24Z Body hi @weierophinney endline are CRLF

Content-Type: text/plain;
    charset=us-ascii
Content-Transfer-Encoding: 7bit
Subject: =?utf-8?Q?Test_for_zend_=28=C3=A9=C3=A0=C3=B9=29?=
From: aaa@aaa.com
Message-Id: <1087914B-7A28-4CF9-B590-2A0FD320CE76@aaa.com>
Date: Tue, 24 Mar 2015 08:56:07 +0100
To: "aaa" <aaa@aaa.com>
Mime-Version: 1.0 (1.0)

Test for zend

Comment

User: @croensch Created On: 2015-08-31T09:53:58Z Updated At: 2015-08-31T09:53:58Z Body I got this one too, outlook server has attachments like:

Content-Type: application/pdf;
    name="test.pdf"

That is always \r\n\t, maybe we can add this as special case without breaking security?


michalbundyra commented 4 years ago

This repository has been closed and moved to laminas/laminas-mail; a new issue has been opened at https://github.com/laminas/laminas-mail/issues/54.