Ticket #1484728 (closed Bugs: fixed)
Main and nested MIME-parts have same boundary - patch available
| Reported by: | Javer | Owned by: | |
|---|---|---|---|
| Priority: | 5 | Milestone: | 0.2-alpha |
| Component: | MIME parsing | Version: | svn-trunk |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Problem
On some fast servers when creating e-mail with html and attachments and/or images, which have main and nested MIME-parts, generated message have same MIME-boundary for all parts and subparts. After sending this e-mail by Mail Server he close all unclosed Mime subparts, and because boundary is the same, message finally damaged. Therefore, generated message cannot be correctly recognized by any e-mail client, all attachments have been lost, but message physically contains attachments (detected on size of message).
Sample
User-Agent: RoundCube Webmail/0.1
Content-Type: multipart/mixed;
boundary="=_74fb39420296c4aaca07a0fa81d22c40"
--=_74fb39420296c4aaca07a0fa81d22c40
Content-Type: multipart/alternative;
boundary="=_74fb39420296c4aaca07a0fa81d22c40"
--=_74fb39420296c4aaca07a0fa81d22c40
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82! =20
=D0=9A=D0=B0=D0=BA =D0=B4=D0=B5=D0=BB=D0=B0 ? =20
=D0=9F=D0=BE=D0=BA=D0=B0 ! =20
--=_74fb39420296c4aaca07a0fa81d22c40
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<p>
=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82!
</p>
<p>
=D0=9A=D0=B0=D0=BA =D0=B4=D0=B5=D0=BB=D0=B0 ?
</p>
<p>
=D0=9F=D0=BE=D0=BA=D0=B0 !
</p>
--=_74fb39420296c4aaca07a0fa81d22c40--
--=_74fb39420296c4aaca07a0fa81d22c40--
After sending by Mail Server:
User-Agent: RoundCube Webmail/0.1
Content-Type: multipart/mixed;
boundary="=_74fb39420296c4aaca07a0fa81d22c40"
--=_74fb39420296c4aaca07a0fa81d22c40
Content-Type: multipart/alternative;
boundary="=_74fb39420296c4aaca07a0fa81d22c40"
--=_74fb39420296c4aaca07a0fa81d22c40--
--=_74fb39420296c4aaca07a0fa81d22c40
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82! =20
=D0=9A=D0=B0=D0=BA =D0=B4=D0=B5=D0=BB=D0=B0 ? =20
=D0=9F=D0=BE=D0=BA=D0=B0 ! =20
--=_74fb39420296c4aaca07a0fa81d22c40
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<p>
=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82!
</p>
<p>
=D0=9A=D0=B0=D0=BA =D0=B4=D0=B5=D0=BB=D0=B0 ?
</p>
<p>
=D0=9F=D0=BE=D0=BA=D0=B0 !
</p>
--=_74fb39420296c4aaca07a0fa81d22c40--
Solution
It occurs because between recursive calls of encode() method microtime() value has not been changed, and the generator of random numbers is initialized by the same number.
You should patch program/lib/Mail/mimePart.php:211
< srand((double)microtime()*1000000); --- > // srand((double)microtime()*1000000);
In PHP documentation specified:
As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically
Or for backward compatibility with older PHP you should move this line to program/lib/Mail/mime.php before calling $message->encode() (line 712 in revision 955).
