Opened 5 years ago

Closed 5 years ago

#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: git-master
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&nbsp;=D0=B4=D0=B5=D0=BB=D0=B0&nbsp;?
</p>
<p>
=D0=9F=D0=BE=D0=BA=D0=B0&nbsp;!&nbsp;
</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&nbsp;=D0=B4=D0=B5=D0=BB=D0=B0&nbsp;?
</p>
<p>
=D0=9F=D0=BE=D0=BA=D0=B0&nbsp;!&nbsp;
</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).

Change History (3)

comment:1 Changed 5 years ago by seansan

  • Milestone set to 0.1.1
  • Summary changed from Main and nested MIME-parts have same boundary on some systems to Main and nested MIME-parts have same boundary - patch available

Review in 0.1.1

comment:3 Changed 5 years ago by alec

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in1323. Srand call removed as we require php5.

Note: See TracTickets for help on using tickets.