Issue

ZF-1041: Zend_Mail splits up words in email body

Issue Type: Bug Created: 2007-03-12T14:25:03.000+0000 Last Updated: 2009-09-18T06:17:40.000+0000 Status: Resolved Fix version(s): Reporter: Véronique M. (vero) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Mail

Related issues: Attachments:

Description

Bonjour " . $fullName . ",

Merci de vous être enregistré avec " . SITE_NAME . ".

Votre compte " . $username . " est présentement inactif. Pour être activé, il doit d'abord être validé en deux étapes.
Pour la première étape de validation votre compte, veuillez tout simplement cliquer sur le URL ci-dessous (vous pouvez également le copier dans votre navigateur):

" . $url . "Une fois votre adresse email validée, votre compte sera revu par l'équipe " . SITE_NAME . " et activé.

Merci!

L'Équipe " . SITE_NAME . "

Comments

Posted by Véronique M. (vero) on 2007-03-13T12:20:42.000+0000

clarification

Posted by Simon Mundy (peptolab) on 2007-03-14T17:38:53.000+0000

Your example above looks like there are empty lines between each encoded line - is this how it is on your email source or is that just the way JIRA is displaying it? If there's extra linespaces it may be throwing the mail clients you mentioned.

Posted by Véronique M. (vero) on 2007-03-15T08:16:54.000+0000

Hello, Thanks for responding. In the above example, the first block is the email as it appears on Gmail. The last block with the full headers is the actual email source. Note that the broken words match the end of lines (=) in the source. Such as the words "e nregistré", "pré sentement", "votre co mpte", "Merc i", and of course the link.

It clearly has something to do with the maximum line length, but I'm not sure what I can do about it. Surely there is a way to use Zend_Mail without words being split like that (especially if it breaks important links), but I haven't been able to figure out how, so I reported it here.

Posted by Bill Karwin (bkarwin) on 2007-03-15T13:54:03.000+0000

Assigning to Nico.

Posted by thing2b (thing2b) on 2007-03-19T19:18:56.000+0000

I will just confirm that this happens for me as well. One thing that I will note is that this did not appear for me in any versions 0.7 and before. It started occurring when I moved to version 0.8 and continues to do it in version 0.9

Posted by Simon Mundy (peptolab) on 2007-03-19T19:29:58.000+0000

thing2b and Veronique, can you also please confirm which MTA is installed on your machines? Is it Postfix, QMail or Sendmail?

Could you also please send a test email to webmaster at peptolab dot com so I can see the source intact?

Posted by thing2b (thing2b) on 2007-03-19T19:54:59.000+0000

I have send a message to Simon Mundy and with the same code sent myself one. Using version 0.9.0 of Zend Framework. Sendmail is in my phpinfo(). Postfix, QMail and not in my phpinfo().

<pre class="literal">
$mail = new Zend_Mail();
$mail->setBodyText('Simon Mundy [19/Mar/07 07:29 PM]
thing2b and Veronique, can you also please confirm which MTA is installed on your machines? Is it Postfix, QMail or Sendmail?
Could you also please send a test email to webmaster at peptolab dot com so I can see the source intact?
');
$mail->setFrom( 'test@example.com'  );
$mail->setReturnPath( 'test@example.com'  );
$mail->addTo('cencored@gmail.com', 'Cencored');
$mail->setSubject( '[#ZF-1041] Zend_Mail splits up words in email body - Zend Framework Issue Tracker' );
$mail->send();

And the mail I received at gmail was:

<pre class="literal">
Delivered-To: cencored@gmail.com
Received: by 10.100.111.13 with SMTP id j13cs581656anc;
        Mon, 19 Mar 2007 17:40:55 -0700 (PDT)
Received: by 10.35.41.12 with SMTP id t12mr11603001pyj.1174351255333;
        Mon, 19 Mar 2007 17:40:55 -0700 (PDT)
Return-Path: 
Received: from luke.cencored.com.au (luke.cencored.com.au [64.49.254.38])
        by mx.google.com with ESMTP id w67si69927pyg.2007.03.19.17.40.54;
        Mon, 19 Mar 2007 17:40:55 -0700 (PDT)
Received-SPF: neutral (google.com: 64.49.254.38 is neither permitted nor denied by best guess record for domain of test@example.com)
Received: (qmail 30589 invoked by uid 80); 20 Mar 2007 11:40:53 +1100
Date: 20 Mar 2007 11:40:53 +1100
Message-ID: <20070320004053.30588.qmail@luke.cencored.com.au>
To: "cencored" 
Subject: [#ZF-1041] Zend_Mail splits up words in email body - Zend Framework Issue Tracker
From: "" 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline


Simon Mundy [19/Mar/07 07:29 PM]=0D=0Athing2b and Veronique, can you also=

 please confirm which MTA is installed on your machines? Is it Postfix, QM=

ail or Sendmail?=0D=0ACould you also please send a test email to webmaster=

 at peptolab dot com so I can see the source intact?=0D=0A

Shown on screen through gmail is:

<pre class="literal">
Simon Mundy [19/Mar/07 07:29 PM]
thing2b and Veronique, can you also
 please confirm which MTA is installed on your machines? Is it Postfix, QM
ail or Sendmail?
Could you also please send a test email to webmaster
 at peptolab dot com so I can see the source intact?

Note the break in the word "QMail"

Posted by Véronique M. (vero) on 2007-03-20T08:16:47.000+0000

I have sent the same email, with the same code posted earlier (in my first post) but with a CC to Simon and "[#ZF-1041]" prefixing the mail subject.

The email shown in Gmail is the same as I posted before. I tried also with Thunderbird, same thing. On the other hand, the email displayed fine in Yahoo. But I haven't been able to find a way to print the original source in Yahoo mail, though. :(

According to our sysadmin, we use postfix 2.2.10.

Posted by thing2b (thing2b) on 2007-03-22T19:25:07.000+0000

I have found a few resources that may help in the solving of this bug. The website: http://nabble.com/Zend_Mail-problem-with-special-c… has an interesting note about something that sounds the same.

The problem was:

<pre class="literal"> 
> Second, a long line with a link gets an automatic line break in the
> middle of the link which makes the link invalid. Also I would like to
> add a couple of empty lines but Zend_Mail always gets rid of them. I
> would rather prefer to handle the line breaks myself to prevent
> Zend_Mail from splitting up words and links in the middle. 

And the bug was stated as:

<pre class="literal"> 
- Finally, the bug: When using the Zend_Mail default transport --  
PHP's own mail() function (sendmail) -- all of the CRLF end-of-line  
sequences that Zend_Mime::encodeQuotedPrintable() correctly generates  
are silently duplicated in the resulting message body. This results  
in the correct 'soft line break' to continue a line, followed by an  
additional CRLF by itself which mail clients interpret as a genuine  
line break. 

And the temporary fix that I am thinking about using in the mean time is:

<pre class="literal"> 
2. If you're only ever going to use the default sendmail transport  
with Zend_Mail, you can change Zend_Mime::encodeQuotedPrintable() so  
that it only generates a single LF end-of-line sequence which will  
not be duplicated by PHP's mail() function (this is the solution  
proposed by Kevin in ZF-264). Change line 74 of Zend_Mime from this:

   const LINEEND = "\r\n";

to this:

   const LINEEND = "\n";

This change will cause problems if you attempt to use the SMTP  
transport because now the end-of-line sequence is wrong. Your  
messages will likely be rejected at some point in the delivery chain. 

Posted by Simon Mundy (peptolab) on 2007-03-24T04:55:56.000+0000

Why thankyou thing! (Couldn't resist)

Thanks for following up the bugs. Problem is, Zend_Db_Transport_Sendmail does use the default PHP lineending instead of "\r\n". So UNIX defaults to "\n".

It's not an easy one to track insofar as we're seeing different results using the same MTA so I'd like to find some more common threads before we start committing changes.

This bug is still a priority but a fix will only be on the way once we're 100% sure!

Cheers

Posted by Tony Brady (tbrady) on 2007-03-29T06:53:35.000+0000

I have the same problem using the Postfix MTA 2.2.10 on RHEL 4. My work-around for now is not to use the quoted-printable encoding. This is easily done by extending the Zend_Mail class and has the advantage that you don't need to edit the ZF files (e.g. Zend_Mime LINEEND work-around above). All you need to do is change the

$mp->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE;

line in setBodyText() and setBodyHtml() methods. E.g. (based on ZF-0.7):

<pre class="highlight">
/**
 * Fix to Zend_Mail so that mail is not sent out with quoted printable encoding
*/
class MyApp_Mail extends Zend_Mail
{

    /**
     * Sets the text body for the message.
     *
     * @param string $txt
     * @param string $charset
     * @return Zend_Mime_Part
    */
    public function setBodyText($txt, $charset=null)
    {
        if ($charset === null) {
            $charset = $this->_charset;
        }

        $mp = new Zend_Mime_Part($txt);
        $mp->encoding = Zend_Mime::ENCODING_8BIT;
        $mp->type = Zend_Mime::TYPE_TEXT;
        $mp->disposition = Zend_Mime::DISPOSITION_INLINE;
        $mp->charset = $charset;

        $this->_bodyText = $mp;
        return $mp;
    }

    /**
     * Sets the HTML body for the message
     *
     * @param string $html
     * @param string $charset
     * @return Zend_Mime_Part
     */
    public function setBodyHtml($html, $charset=null)
    {
        if ($charset === null) {
            $charset = $this->_charset;
        }

        $mp = new Zend_Mime_Part($html);
        $mp->encoding = Zend_Mime::ENCODING_8BIT;
        $mp->type = Zend_Mime::TYPE_HTML;
        $mp->disposition = Zend_Mime::DISPOSITION_INLINE;
        $mp->charset = $charset;

        $this->_bodyHtml = $mp;
        return $mp;
    }

}

Posted by Véronique M. (vero) on 2007-04-09T12:35:32.000+0000

For the record, I am using the workaround posted above and so far I have not had any problems.

Is there any update from the devteam about this? I wonder if there's any reason to use the quoted-printable encoding instead of the 8bit one...

Posted by Nico Edtinger (nico) on 2007-06-01T14:48:46.000+0000

As Simon has written this bug is not easy to track down. Newlines are handled differently depending on the platform and MTA. As Tony has written one workaround is a different encoding. With the fix to ZF-980 the encoding can be changed with the third parameter in setBodyText() and setBodyHtml().

Posted by Benjamin Eberlei (beberlei) on 2009-01-11T01:18:42.000+0000

Since the bug does not depend on Zend_Mail, but on lower layers of Mail transport shouldn't the workaround possiblity through the API just be documented and the bug be closed?

Posted by Véronique M. (vero) on 2009-02-20T11:23:56.000+0000

Sorry for the delay in responding. I have no problem with documenting the use of the third parameter and closing the bug, myself.

Posted by Benjamin Eberlei (beberlei) on 2009-09-18T06:17:39.000+0000

Close as bug/problem in the lower MTA layers, which can be circumvented with using base64 instead of quoted printable encoding.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2020 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts