Make WordPress Core

Opened 13 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:

Description

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] ) ) {

...is replaced by...

if ( ! empty( $content_type[1] ) && stripos( $content_type[1], 'charset' ) !== FALSE ) {

...in 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
13 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://pop.gmail.com port 995, and have the correct ssl settings enabled in php within MAMP, as described here: https://wordpress.org/extend/ideas/topic/pop3-over-ssl-support-enables-post-via-mail-from-gmail

#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://pop.gmail.com. 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)mydomain.com. Then WordPress fetches those messages from the server mail.mydomain.com (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
12 years ago

  • Cc kat@… added

#7 @codebykat
12 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: http://make.wordpress.org/core/2013/07/12/post-by-email-weekly-update-3/

#8 @nacin
11 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.