Make WordPress Core

Opened 12 years ago

Closed 9 years ago

#21554 closed defect (bug) (wontfix)

Problem with determining e-mail charset in wp-mail.php

Reported by: mighty_mt's profile mighty_mt Owned by: lizhenry's profile lizhenry
Milestone: Priority: normal
Severity: normal Version: 3.4.1
Component: Mail Keywords:
Focuses: Cc:


In wp-mail.php the charset of the incoming e-mail message is determined on line 77 by taking the string between the second "=" in the line and the end of line/second ";" respectively.

The problem

If the header line in question looks like any of the following that method is perfectly fine:

Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes
Content-Type: multipart/alternative;

However in messages sent from e.g. Gmail or Goolge Reader this header line usually looks like this:

Content-Type: multipart/alternative; boundary=f46d044516dd9cd71f04c70e55e8

I this case "f46d044516dd9cd71f04c70e55e8" is determined as the charset and the iconv function further down on line 187 returns false which causes the post content to be emptied.

Suggested solution

I personally think that it is better to have the post published with an "incorrect" charset than with no content at all.

Therefore I suggest that on line 76 in wp-mail.php...

if ( ! empty( $content_type[1] ) ) { replaced by...

if ( ! empty( $content_type[1] ) && stripos( $content_type[1], 'charset' ) !== FALSE ) { order to check if there is actually a charset definded.

Alternatively/additionally the return value of the iconv function on line 187 should be checked and the $content variable only modified if the return value doesn't equal FALSE.

Attachments (1)

wp-email.php.diff (1.0 KB) - added by lizhenry 12 years ago.

Download all attachments as: .zip

Change History (10)

#1 @knutsp
12 years ago

  • Cc knut@… added

#2 @lizhenry
12 years ago

For WordPress running from MAMP to work to test this for Gmail, you need to connect to ssl:// port 995, and have the correct ssl settings enabled in php within MAMP, as described here:

#3 follow-up: @lizhenry
12 years ago

  • Keywords has-patch dev-feedback added; needs-patch removed

I made both changes suggested by mighty_mt and tested it with MAMP and WordPress version 3.5-alpha-21589, downloaded from Gmail using POP and ssl:// Before the patch, posts showed up with no text from Gmail and after the patch, all posts contained content. So, now, as long as a charset is defined, and there is content returned from iconv, the content gets posted.

#4 in reply to: ↑ 3 @mighty_mt
12 years ago

@lizhenry: Thanks for the patch!

Just to clarify: In my case I send e-mail messages from Google Reader or Gmail to an address like something(at) Then WordPress fetches those messages from the server (port 110). So there is neither SSL involved nor does WordPress fetch messages from Gmail's servers.

#5 @lizhenry
12 years ago

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

#6 @codebykat
11 years ago

  • Cc kat@… added

#7 @codebykat
11 years ago

This is going into the new Post By Email plugin; I don't know that it will ever get merged back into Core at this point. I will update this ticket when the plugin is ready for testing.

See also:

#8 @nacin
10 years ago

  • Component changed from Blog by Email to Mail

#9 @chriscct7
9 years ago

  • Keywords has-patch dev-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from assigned to closed

This entire feature is leaving core in #22942

Note: See TracTickets for help on using tickets.