WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#5204 closed defect (bug) (fixed)

wp_mail Does Not Detect Custom Boundaries in "Multipart/Mixed" Email Headers

Reported by: Ghidra99 Owned by: westi
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.3
Component: Mail Keywords: has-patch wp_mail headers attachments
Focuses: Cc:

Description

There is a problem with the new wp_mail function.

If an email is sent to wp_mail() with a custom header of "Content-Type: multipart/mixed; boundary="frontier"", wp_mail() is a) not recognizing that a custom boundary has been set and b) using that custom boundary (in this case, "frontier") as the email character set (charset). This is producing malformed subject lines and messages in emails with non-western characters.

For example, PluginX sends an email to wp_mail(). The email's headers are formed correctly:

To: xxx@xxx.org
Subject: =?UTF-8?B?0KHRgNC/0YHQutC4INCa0YPQu9GC?=
Date: Mon, 15 Oct 2007 10:04:34 -0500
From: "xxx@xxx.org" <xxx@xxx.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="frontier"

--frontier
Content-Type: text/plain; charset = "UTF-8"
Content-Transfer-Encoding: 8bit

Attached to this email is
   xxx.sql.gz
   Size:82 kilobytes

--frontier
Content-Type: application/octet-stream; name="xxx.sql.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="xxx.sql.gz"

H4sIAAAAAAAAA5yMQQrCMBRE9znFQNdKWhQhWwu6sKgouLQ/yYeCNSn5UentzcITOLt585gKt5j8
--frontier

wp_mail() explodes and parses the email headers, incorrectly ascribing "frontier" as the Charset while assigning its own boundary:

To: xxx@xxx.org
Subject: =?frontier?B?0KHR?=  =?frontier?B?gNC/?=  =?frontier?B?0YHQ?=  =?frontier?B?utC4?=  =?frontier?B?INCa?=  =?frontier?B?0YPQ?=  =?frontier?B?u9GC?=
Date: Mon, 15 Oct 2007 10:04:34 -0500
From: "xxx@xxx.org" <xxx@xxx.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="b1_49700ab183d95dd1680e0898d750b958"

--b1_49700ab183d95dd1680e0898d750b958
Content-Type: text/plain; charset = "frontier"
Content-Transfer-Encoding: 8bit

Attached to this email is
   xxx.sql.gz
   Size:82 kilobytes

--b1_49700ab183d95dd1680e0898d750b958
Content-Type: application/octet-stream; name="xxx.sql.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="xxx.sql.gz"

H4sIAAAAAAAAA5yMQQrCMBRE9znFQNdKWhQhWwu6sKgouLQ/yYeCNSn5UentzcITOLt585gKt5j8
--b1_49700ab183d95dd1680e0898d750b958

PluginX's once correctly-formed email is now severely broken, using PluginX's custom boundary as a charset.

Attachments (3)

test_email.txt (2.4 KB) - added by filosofo 7 years ago.
email_fix.diff (2.2 KB) - added by filosofo 7 years ago.
email_fix_refreshed.5204.diff (2.1 KB) - added by filosofo 5 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 filosofo7 years ago

The problem is that wp_mail assumes the content-type is text, and it ends up thinking the boundary is the text encoding, or it ignores the boundary altogether.

My patch fixes wp_mail so that one can send attachments using custom headers.

I've also attached a test email message. Send it to yourself using sendmail, e.g.
sendmail [name]@[domain].com < test_email.txt

and it works.

Try to send it using wp_mail, with the 2-4 lines as custom headers, and it currently fails.

Apply my patch, then try sending it via wp_mail, and it works.

filosofo7 years ago

filosofo7 years ago

comment:2 westi7 years ago

  • Milestone changed from 2.3.1 to 2.4

Not a candidate for 2.3.1 moving to 2.4 for now.

comment:3 Denis-de-Bernardy5 years ago

  • Keywords reporter-feedback added; wp_mail email multipart mixed header boundary removed

is this still current in trunk?

comment:4 filosofo5 years ago

  • Component changed from General to Mail
  • Keywords has-patch wp_mail headers attachments added; reporter-feedback removed
  • Milestone changed from 2.9 to 2.8
  • Owner anonymous deleted
  • Severity changed from major to normal

The same problem occurs with the test email in trunk. Apply my refreshed patch, attached above, and it's fixed.

comment:5 westi5 years ago

  • Owner set to westi
  • Status changed from new to assigned

Patch looks good.

Will give this a whirl and then get it in.

Thanks for the example!

comment:6 Denis-de-Bernardy5 years ago

any traction?

comment:7 westi5 years ago

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

(In [11136]) Fix wp_mails handling of custom boundaries. Fixes #5204 props filosofo.

comment:8 westi5 years ago

I've also added a test case for this to wordpress-tests

Note: See TracTickets for help on using tickets.