Forum Moderators: coopster
[snip]
When emailing posts from Gmail, or my email client, I have no problems and the post comes out fine. When sending from my phone, however, the post comes out garbled.
[snip]
The process of saving a copy of the site seems to have mucked up the special characters in the rest of the site, but it's just the first post that is actually the problem.
I checked, and it appears that my phone sends emails encoded in UTF-8, so I think this is the problem. I have tried using utf8_decode in the script, but have had no success. I'm a novice with PHP, and would appreciate any advice on a possible solution to the problem.
Thanks!
PS I tried the Wordpress support forum first, but without luck.
PPS If a copy of an email from my phone would be helpful, contact me at fyse [at] floatingface [dot] com
[edited by: ergophobe at 7:05 pm (utc) on July 9, 2005]
[edit reason] no personal URLs please - see site Usage Agreement [/edit]
I was thinking about the problem, but I'm having trouble figuring out where the conversion is happening. In other words, something is clearly happening when you send from your phone. Can you figure out at which point along the trail it is getting garbled? If you send it to a regular email address, what happens? What if you then take something sent from your phone to your regular email and forward it to your script?
It seems like maybe at some point it's a multi-byte encoding getting interpreted as single-byte or vice versa, or perhaps it's a different Unicode encoding. If you get some funny characters right at the beginning, like a left angle double quote (<< character) and a question mark, that's usually an indication that a byte-order mark is getting sent (which wouldn't be the case with UTF-8, but woudl with other Unicode encodings).
I changed the settings in my email client (Thunderbird) to send emails encoded in UTF-8 (default was ISO-8859-1), and these were still posted fine onto the blog. I also copied it back to myself, and the last few lines of the source are...
Subject: Just a test...
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bitYet another test post. I'll get this bloody posting via email working
properly in the end!
Yet another test post. I'll get this bloody posting via email working
properly in the end!
I sent an identically worded email from my phone, and viewed the source in my email client. The last few lines were...
Subject: =?utf-8?B?SnVzdCBhIHRlc3QuLi4=?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64WWV0IGFub3RoZXIgdGVzdCBwb3N0LiBJJ2xsIGdldCB0aGlzIGJsb29keSBwb3N0aW5nIHZpYSBl
bWFpbCB3b3JraW5nIHByb3Blcmx5IGluIHRoZSBlbmQhCgpZZXQgYW5vdGhlciB0ZXN0IHBvc3Qu
IEknbGwgZ2V0IHRoaXMgYmxvb2R5IHBvc3RpbmcgdmlhIGVtYWlsIHdvcmtpbmcgcHJvcGVybHkg
aW4gdGhlIGVuZCE=
Thunderbird is smart enough to display the email ungarbled when I view it, however, and reads exactly as it should. The garbled version I observe in the source code of the email (through Thunderbird) is exactly what appears on the blog when I email directly from my phone. I assume this indicates they are both mis-interpreting them in the same way?
You mentioned a possible problem with multi-byte encoding, so would it be right in guessing that the base64 encoding in the email from my phone is the problem? Thunderbird sophisticated enough to deal with the difference, where Wordpress is not?
(I wasn't sure of the conventions when posting script/source to the forum. I put it between code tags, but it seem to have come out strangely. Any pointers?)
You probably need to intercept the messages, check for the base64 header, and if present decode them before sending them on to your blog.
Sure enough, if you run the sample text you gave through a base64 decoder [makcoder.sourceforge.net], you get your text message exactly as it looks when sent from an email client.
See
[us3.php.net...]
Some other reading that may help
[en.wikipedia.org...]
[fourmilab.ch...]
[ietf.org...]
$email['body'] = base64_decode(imap_fetchbody($serverHandler,$msgNum,'1'));
For the subject I had to take a substring...
$email['subject'] = base64_decode(substr($email['subject'], 10, strlen($email['subject'])-3));
I haven't yet written it to automatically discern between emails that need base64 decoding and those that don't, but at least I have a script that'll work from my phone now.
Thanks very much for your help!