WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#6904 closed defect (bug) (worksforme)

Blog by email posts blank in 2.5.1 w/ HTML email

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

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 (8)

comment:1 nrackliffe6 years ago

  • Keywords wp-mail.php has-patch added
  • 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.

comment:2 nrackliffe6 years ago

  • Cc nrackliffe added
  • Keywords needs-testing added

comment:3 MyLifeIsADanceFloor6 years ago

Hi,

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

greetz

comment:4 MyLifeIsADanceFloor6 years ago

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

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

comment:5 MyLifeIsADanceFloor6 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

comment:6 nrackliffe6 years ago

  • Resolution set to worksforme
  • Status changed from reopened to closed

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.

comment:7 thee176 years ago

  • Milestone 2.7 deleted

comment:8 geodanny6 years ago

This still remains an issue with WP 2.6.1; however I won't re-open this bug.

I get blank posts when using Yahoo! or Gmail. I think that blog-by-email ultimately needs to accept text\html regardless of encoding, as nracklife stated.

I'm not a coder so my quick fix was to remove the following from wp-mail.php. It sounds as if my problems all lie with that part of the php code.

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

That leaves me with a post with unnecessary info about the content type, encoding, etc. but at least my content isn't stripped and I can edit at a later time to remove the unnecessary info.

With that portion of the code removed, here is what my post content looks like when sent from Yahoo! Mail:

--0-945523328-1219549749=:79650
Content-Type: text/plain; charset=us-ascii

testing blog by email 8
test
test
test

and here is what my post content now looks like when sent from Gmail:

------=_Part_45000_2317808.1219549399420
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

testing blog by email 7---
Note: See TracTickets for help on using tickets.