Okay, so i decided to investigated the issue and found the problem.
Its not Zend_Mail alone but also Zend_Mime and the problem consists of two bugs. 
It is a bit complicated and not so easy to explain so this became a fairly long read.
Also please feel free to correct me or ask questions if something is incorret or unclear!
Ill start with the RFC definitions that will be usede for referencing when pointing out the issues and that help to understand the problem a bit better.
And just for clarification a encoded header-value =?ISO-8859-1?Q?aaaaaa?= is referred as encoded-word.
The string "aaaaaa" is referred as encoded-text and "=?ISO-8859-1?Q?" and "?=" as delimiters, charset and encoding, i refer to this three as DCE.
RFC definitions:
- The key and value needs to be composed of printable US-ASCII characters, to accomplish this you have to encode the header value either with quoted-printable or base64.
- An 'encoded-word' may not be more than 75 characters long, including 'charset', 'encoding', 'encoded-text', and delimiters. If it is desirable to encode more text than will fit in an 'encoded-word' of 75 characters, multiple 'encoded-word's (separated by CRLF SPACE) may be used.
- While there is no limit to the length of a multiple-line header field, each line of a header field that contains one or more 'encoded-word's is limited to 76 characters. It doesnt have to be exactly 76 chars long but should be about that length, some chars more or less dont hurt.
- The 'encoded-text' may not be continued in the next 'encoded-word'.
- Each value MUST represent an integral number of characters. A multi-octet character may not be split across adjacent 'encoded-word's.
Phew, in words that everyone understand this means:
- Take the Header-line, encode its value.
- Calculate how long a line would be when it includes the current DCE.
- Split the encoded-value to chunks with a newline at the calculated length WITHOUT breaking an encoded-char.
- Place the DCE at the start and end of every line.
- ???
- PROFIT!
Lets take the following example subject:
This is än germän multiline sübject with randöm ümläuts.
After doing all four steps from above the header value should look like this (i used the method mb_encode_mimeheader for this result):
This is =?UTF-8?Q?=C3=A4n=20germ=C3=A4n=20multiline=20s=C3=BCbject=20with?=
=?UTF-8?Q?=20rand=C3=B6m=20=C3=BCml=C3=A4uts=2E?=
This is how it looks like after the string has been encoded with Zend_Mime::encodeQuotedPrintable, notice the length and the missing space at the start of the second line which is required by point 2 of the definition list. The string gets splitted into to big chunks because the method does not take into account the DCE length.
This is =C3=A4n germ=C3=A4n multiline s=C3=BCbject with rand=C3=B6m =C3=BC=
ml=C3=A4uts.
And this is the final result after Zend_Mail::_encodeHeader has done its job.
=?UTF-8?Q?This=20is=20=C3=A4n=20germ=C3=A4n=20multiline=20s=C3=BCbject=20with=20rand=C3=B6m=20=C3=BC=
ml=C3=A4uts.?=
Besides the not so tragical error of the length, you will see that the DCE is missing at the end of the first line (?=) and the start of the second ( =?UTF-8?Q?)!
As also stated above all encoded-words need to be incased by the delimiters, charset and encoding syntax, this also means encoded-words on new lines! _encodeHeader simply concats the corresponding DCE at the start and end of the string. This would be the first major problem.
A not-so-good solution would be to replace every newline char with the DCE and a newline to get the desired result.
When using an iso charset this could work but not with utf8 or so called multibytechars and here comes the second issue into play.
When looking at the Zend_Mime code you will see that the code for splitting only checks if it found an equalsign, if yes it starts a newline.
Now take a look at the first umlaut we have, the "ä" that got encoded into "=C3=A4" because it consists of two bytes, now imagine that umlaut would start exactly at the 73 position of a string, Zend_Mime would break the char apart ....=C3= \n A4 and thus breaking our encoded string, resulting in a borked email.
This is the second major issue because point 5 from above states that a multi-octet char may not be splited accross adjacent encoded-words.
Lets recap the errors:
- When an encoded value gets splitted onto mulitple lines the DCE params are missing.
- Zend_Mime::encodeQuotedPrintable is not multibyte compatible.
- Zend_Mime is not build for encoding email headers!
It would take alof of effort to fix both the issues but i think its possible. It definitively would need an own encoding method which is build for mail header encoding.
A pass-by solution, as long as the iconv method is broken, would be to use the much better mbstring methods. Please note that you need to explicitly activate the mbstring extension! This is the replace method we use at work, right now:
protected function _encodeHeader($value)
{
if (!Zend_Mime::isPrintable($value)) {
$value = mb_encode_mimeheader($value, $this->_charset, 'Q', "\n", 74);
}
return $value;
}
To be honest i encourage everyone to use the above method because there can be other issues with Zend_Mime and the way email headers get encoded. Also note that Zend_Mime works perfectly fine for the body encoding!
I really hope i explained the issue so we can start to discuss further steps.
After digging a bit, I'd like to suggest having a look into Pear::Mail_Mime, and how RFC2047 conformance is ensured there. Using the same method for encoding header lines and body parts might not be sufficient since the requirements are different.