Ticket #6904 (closed defect: worksforme)

Opened 2 months ago

Last modified 1 month ago

Blog by email posts blank in 2.5.1 w/ HTML email

Reported by: geodanny Assigned to: anonymous
Priority: high Milestone:
Component: General Version: 2.5.1
Severity: normal Keywords: wp-mail.php has-patch needs-testing
Cc: nrackliffe

Description

My blog by email posts are blank. WP is able to access the email account I have set up for blog by email purposes, along with the messages I send. The subject line becomes the title of the post; however the text within my email is redacted.

It appears that this happens during the sequence in which WP gets the contents of my email to post. Here is a copy of the confirmation email I receive from WP.

*********

Author = *********@yahoo.com Content-type: multipart/alternative, boundary: 0-79868778-1200130438=:79225 Raw content:

Author: 3 Posted title: test Posted content:

Mission complete, message 1 deleted.

********

As you can see, it says that there is no content to post.

Here are all the things I think might help in diagnosing this problem: - I send email from my Yahoo! account (HTML) email account. - I tested the bug and it only happens with HTML formatted email from Outlook, Yahoo!, or GMail accounts. Email sent as text only don't appear to have a problem. - I use WP 2.5.1. I had a similar problem with 2.1 and 2.2 and fixed it according to the fix on Bug 4337 - http://trac.wordpress.org/ticket/4337. It reappeared when I installed 2.3.1. I have been very good at installing updates and it still occurs with 2.5.1. The same fix does not correct my problems now.

Any ideas on how I can fix this? Are there any debugging logs I should turn on to further help diagnose the source of my problem?

I posted this to the forums without realizing I could make a bug report. http://wordpress.org/support/topic/152039?replies=25

Change History

05/15/08 16:15:38 changed by nrackliffe

  • keywords set to wp-mail.php has-patch.
  • priority changed from normal to high.

I suspect that the problem lies in this section of wp-mail.php:

139    if ($content_type == 'multipart/alternative') {
140 	        $content = explode('--'.$boundary, $content);
141 	        $content = $content[2];
142 	        $content = explode('Content-Transfer-Encoding: quoted-printable', $content);
143 	        $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div>');

Gmail sends out HTML mail as a multipart/alternative, however it doesn't have the 'Content-Transfer-Encoding: quoted-printable' header. This leaves $content[1] empty, which results in a post with a title, but no body.

A different solution is needed to remove the headers from the multipart message. I tried doing the following and it seems to be working, but there is probably a better way to detect this.

142 	        $content = explode('\n\n', $content);

A fix to this section of code will probably help most people that are having problems with blank posts coming from email.

05/15/08 16:23:14 changed by nrackliffe

  • cc set to nrackliffe.
  • keywords changed from wp-mail.php has-patch to wp-mail.php has-patch needs-testing.

05/25/08 13:07:55 changed by MyLifeIsADanceFloor

Hi,

i changed the line in wp-mail.php, but still the post show up blank.

greetz

05/30/08 21:13:13 changed by MyLifeIsADanceFloor

  • status changed from new to closed.
  • resolution set to worksforme.

Maybe this can help ..

Go to line 139, and paste this above it.

function rheaders($string) {
	$headers = array(
		"/Content\-Type\: text\/html\; charset\=UTF\-8/i",
		"/Content\-Transfer\-Encoding\: 7bit/i",
		"/Content\-Disposition\: inline/i"
		);
	return preg_replace($headers, '', $string);
}

Now edit this line

$content = explode('Content-Transfer-Encoding: quoted-printable', $content);

By:

$content = rheaders($content);

Maybe you need to change the rheaders function to whatever the headers of the email are.

greetz

05/30/08 21:13:59 changed by MyLifeIsADanceFloor

  • status changed from closed to reopened.
  • resolution deleted.

05/31/08 03:14:39 changed by nrackliffe

  • status changed from reopened to closed.
  • resolution set to worksforme.

This helped me get my issues fixed with a couple of caveats. If multiple messages are waiting to be processed, the rheaders function gets redeclared. I moved the function outside the message loop and fixed that problem.

Also, the line following the call to rheaders needs to be changed because rheaders returns a single string and not an array. Here's what worked for me; I took the original strip_tags line:

  $content = strip_tags($content[1],'<img><p><br><i><b><u><em><strong><strike><font><span><div>');

and changed it to:

  $content = strip_tags($content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>');

I did need to add the following line to the headers array in order to handle Gmail's rich formatting.

  "/Content\-Type\: text\/html\; charset\=ISO\-8859\-1/i",

AOL mail comes in with yet another encoding, which I think can be fixed by adding:

  "/Content\-Type\: text\/html\; charset\=us\"\-ascii\"/i",

I suppose a more robust regexp would be helpful here; something that accepts text\html regardless of the encoding. I think there is a newline that could be matched at the end of the line, but I'm not sure how to go about that in PHP.

05/31/08 03:23:04 changed by thee17

  • milestone deleted.