Issues with D5, ZF1.5.2 and zend_mail.inc

frega - July 24, 2008 - 18:12
Project:Zend Framework
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,

when trying to enable the zend_mail.inc in order to use the SMTP functionality I ran into two small obstacles ...
a) the same issue that's been reported here http://drupal.org/node/243120 (which is a ZF 1.5 issue)
b) the function declaration for drupal_mail_wrapper might have changed b/w D5 and D6
please find a patch attached ...

best regards,

fredrik

AttachmentSize
patch_zend_mail_inc_d5_zf152.patch2.53 KB

#1

Rob Loach - July 25, 2008 - 15:41
Status:needs review» fixed

Thanks a lot for the patch, frega! Committed.... http://drupal.org/cvs?commit=129777

#2

frega - July 25, 2008 - 17:03

thanks for committing!

i ran into, one more significant issue. but i am not entirely certain whether this is due to the configuration of the mailserver we use in the project or whether it is a more general ZF this ...
drupal likes to send everything in UTF-8 charset (good thingTM), but ZF defaults to sending its own Content-Type header, if you don't specify anything when calling

setBodyText($txt, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE)

so i forced charset to be 'UTF-8' in setBodyText() - one could also parse the $headers['Content-Type'] string which drupal_mail() sets, but I don't know how other contrib modules muck w/ the headers ... if you think a patch would be needed (this could also apply to the D6-version), i'll post it here :)

best regards,
f.

#3

Rob Loach - July 25, 2008 - 19:18
Status:fixed» active

What change would have to happen?

#4

frega - July 27, 2008 - 14:22

Hi,

it's could be as simple as explicitly telling Zend_Mail to use UTF-8:

Pseudo-Patch:
- $mail = new Zend_Mail()
+$mail = new Zend_Mail('UTF-8');

Or could be a bit more complicated - parsing the Content-Type header set by Drupal (and/or contrib modules) like this:

// Content-Type
if (isset($headers['Content-Type'])) {
// see includes/common.inc
// 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed',
// we could regex or just split ...
list($type, $charset, $format) = expode(';', $headers['Content-Type']);
// we can skip the type, because Zend_Mail::setBodyText implies text/plain
// figure out charset ...
if ($charset) {
list($c, $charset) = explode('=', $charset);
if (strtolower($c)=='charset' && $charset) {
$charset = trim($charset);
}
else {
$charset = 'UTF-8';
}
}
else {
$charset = 'UTF-8';
}
// what to do about format, what to do about $headers['Content-Transfer-Encoding'] => '8Bit',
// maps to e.g. $mail->setBodyText($body, $charset, $encoding)
// should we force 8Bit like the $headers value suggests, works fine w/o for me
}
else {
$charset = 'UTF-8';
}
$mail = new Zend_Mail($charset);

or one could do mb_detect_encoding on the body and subject ... and skip the header altogether ...

But the simple first options works just fine for me :)

Best regards,
f.

 
 

Drupal is a registered trademark of Dries Buytaert.