BUG: Quoted-Printable

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
apexa
Forum Newbie
Posts: 8
Joined: Tue Dec 04, 2007 8:50 am

BUG: Quoted-Printable

Post by apexa »

Hi Chris & everyone

First off, thanks for Swift - it's awesome!

I've come across a bug (PHP5, latest build, using SMTP) with Quoted-Printable encoding.

It seems like you already know about it - it's related to the last changeset:
http://swiftmailer.svn.sourceforge.net/ ... 462&r2=466

Re: the changeset above: from what I can tell, this was just a quick fix as it is essentially halting the second part of QP-encoding (line length stuff) from that point of the string on. This is one part of my problem as this is happening a short way into a much longer string (e.g. below)

The other problem is that with this fix, the resulting output contains an extra hard break at the point where it skipped.

Less of a bug but still not ideal, I noticed how Swift inserts hard breaks (with " =\r\n") at the end of *every* line, not just when required. This is giving rather messy output encoding, even if it is valid. I see you mentioned that QP needs a rethink in your announcement about v4, so added to the fact that it seems like you know about my first problem I wanted to know if you had any specific plans in store for updating the encoding?


Example text causing the bug (note that this contains intentional hard line breaks):

Code: Select all

Dear OxHub members,

We're just too good to you. In case you have any free time amongst all the
ice-skating and shopping this December, we've put together a **summary list
of events** going on in Oxford, London and elsewhere. I'd be happy to send
out information about things we've missed off next week if people send them
to me.

Finally, in an unashamed rip off of an Independent front page of a while
back: No Oxhub news today. 'Just 6,500 Africans died today as a result of a
preventable, treatable disease.' Our **call to action for World AIDS Week**
is listed below. ...(continues)
Resultant QP output from Swift:

Code: Select all

Dear OxHub members,

=
We're just too good to you. In case you have any free time amongst all th=
e
ic=
e-skating and shopping this December, we've put together a **summary list=

of=
 events** going on in Oxford, London and elsewhere. I'd be happy to send
=

out information about things we've missed off next week if people send them
to me.

Finally, in an unashamed rip off of an Independent front page of a while
back: No Oxhub news today. 'Just 6,500 Africans died today as a result of a
preventable, treatable disease.' Our **call to action for World AIDS Week**
is listed below. ...(continues)
Note that in this example the desired QP output (e.g. given correctly by http://www.motobit.com/util/quoted-prin ... ncoder.asp) is actually the same as the input since it contains no non-printable chars and i've already word-wrapped it.

So, in summary(!), the code inserted in the last changeset is being activated just after the last "=" inserted, when the remaining string starts with a newline - at this point neither of the preg's match and the remaining QP encoding to be done is being abandoned, and also gives an erroneous hard break at this point.


As a workaround for now, I've stolen the QP encoding function from http://pear.php.net/package/Mail_Mime (_quotedPrintableEncode() on http://cvs.php.net/viewvc.cgi/pear/Mail ... iew=markup) and inserted this at the top of QPEncode:

Code: Select all

public function QPEncode($data, $chunk=76, $init_chunk=0, $headers=false, $le="\r\n")
  { 
  	if (!$headers) {
  		return $this->_quotedPrintableEncode($data, $chunk, $le);
  	}
Obviously this hack smells bad - I was wondering if you'd looked into this function before when working out the method to do the QP encoding, and whether there's any reason why it may not be a good solution?

Thanks a lot, and I hope this helps make Swift even better!

-- Andy
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

QP encoding is the first thing I've redeveloped in version 4. It's a couple of months from being released but I have the QP encoding down to a T and more solid than other preg_replace() implementations I've seen.
apexa
Forum Newbie
Posts: 8
Joined: Tue Dec 04, 2007 8:50 am

Post by apexa »

Cheers Chris, that's great to hear.

Is your implementation of the QP-encoding routine something that you'd be prepared to make public/send me a copy of in the interim, while v4 is still in the works?

As I said previously I've wired my own workaround based on the Pear Code, but I'd feel more confident with yours! If it's not directly compatible with the rest of the v3 code in the form that you have it I'd be prepared to try and integrate it and contribute the patch back if that would help you and other current v3 users..
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

apexa wrote:Cheers Chris, that's great to hear.

Is your implementation of the QP-encoding routine something that you'd be prepared to make public/send me a copy of in the interim, while v4 is still in the works?

As I said previously I've wired my own workaround based on the Pear Code, but I'd feel more confident with yours! If it's not directly compatible with the rest of the v3 code in the form that you have it I'd be prepared to try and integrate it and contribute the patch back if that would help you and other current v3 users..
If you have mb_*() functions installed I could send you a patched-together version within a few days, if not it will be a matter of checking to subversion logs until you see a log entry starting with [COMPLETE] and referencing the Encoder package. The Encoder is done and fully tested, but the encoder itself has dependencies which are not yet implemented.
apexa
Forum Newbie
Posts: 8
Joined: Tue Dec 04, 2007 8:50 am

Post by apexa »

Yup I have the mb_* functions.. that'd be a big help, cheers!

I'll PM you my email address in case you need that.

Thanks, good luck, and happy holidays!

-- A
Post Reply