Oct 8

Postie Mod!

Category: Coding

Postie is a WordPress plugin developed by Dirk Elmendorf which provides extended blog-by-email capabilities to WordPress, such as allow lists, image scaling and rotation, 3gp videos, and the ability to specify categories.  When I stumbled across it, I thought “That would be great for writing posts from my phone!”  Unfortunately, having just set up my blog, I was running WordPress 2.3, which changes SQL tables around and broke Postie’s ability to recognize categories.  I checked the original site and saw no update, so I decided to fix it myself.

I did some poking around, and managed to find the problem.  It turns out that categories used to exist in their own table, so Postie just needed to look one place.  In 2.3 however, categories, tags and link categories have all been rearranged and lumped into three new tables.  Names are in one (wp_terms), Type (tag, category, etc…) and description in another (wp_term_taxonomy), and the third one (wp_term_relationships) that… uhh… does something.  The problem then wasn’t just pointing Postie at a different table; it had to query two tables to make sure the term it found was the right kind of term.  The old SQL strings looked something like this (without the PHP around it, category is the category we are looking for):

SELECT cat_ID
FROM wp_categories
WHERE cat_name=’category

While the new strings are more like this:

SELECT wp_terms.term_id
FROM wp_terms
INNER JOIN wp_term_taxonomy
ON wp_terms.term_id=wp_term_taxonomy.term_id
WHERE wp_terms.name=’category
AND wp_term_taxonomy.taxonomy=’category’

There was also a change in the Postie options page so that the categories will list in the drop-down box.  Any other change I made were cosmetic changes (like how 3gp videos are inserted into posts).

I think it would be easy to add tag support by just changing that last line so that it looks for tags, but I don’t have the time to go beyond what I’ve done for right now.

So, now for the thing you probably skipped everything else looking for: Click here to download!

DISCLAIMER: I have no experience with PHP, but I have worked with many similar languages, and I’ve never had to write a SQL query either.  I managed (after some trial and error) to figure out how to make this work right.  I’ve used it myself and it works fine, but if it breaks something, I won’t know how to fix it.

Disclaimer: I make no guarantee that this will work properly. It has worked for me so far, but everybody’s server is different, so problems may arise. If you need help, you can check the comments on the original site or leave a comment here, however please remember that your question may not be answered immediately.

EDIT (10/15/07): Added disclaimer and link to original site (I forgot to link back since I was writing this for people coming from there…)

Tags: , ,

29 Comments so far

  1. Roger October 15th, 2007 4:48 pm

    Hello,

    I’m trying to use your plugin on my website to retrieve email with attachments, but I cannot open the plugins page after i upload postie to contents directory.

    I’m using version 2.3 of wordpress, do you think this has anything to do with it?

    Many thanks.
    Roger

  2. Greg Medding October 15th, 2007 5:22 pm

    That is odd… I don’t have that problem (I’m running 2.3). You could try removing the Postie folder from your plugins and see if that fixes it. I’m assuming you have ftp access or something similar. If removing the plugin doesn’t fix it, the problem might be caused by something else.

    You might also try looking in the comments here: http://www.economysizegeek.com/?page_id=395. Someone might have had the same problem.

    That is the site for the original plugin. I just updated (rather hastily) it for 2.3.

  3. Benjamin October 16th, 2007 11:44 am

    I’ve added “addslashes” in a few places and am working on allowing javascript confirmation of posts before they are posted to the database. Check here for the latest working version. http://benjaminfleischer.com/code I’ll probably do it by the weekend (if possible)

  4. Greg Medding October 16th, 2007 12:52 pm

    I would also recommend looking at this: http://wordpress.org/support/topic/136967?replies=1

    It has been pointed out that it is best to avoid SQL if at all possible. You may also want to skim through the recent comments at http://www.economysizegeek.com/?page_id=395 (some additional fixes have been posted there, search for Oliver)

    Hope some of that helps (and that it is new information…)

  5. Benjamin October 17th, 2007 6:09 am

    I added an option to use ajax to confirm posts. This is useful for me because I bounce emails to my site, and some are sent mistakenly. Now I can approve them. This process is optional, in the settings. Approved posts disappear when posted. I might make some more changes tonight, to change the checkbox to a button and have it change text and colors. http://benjaminfleischer.com/code I haven’t checked out Oliver’s stuff yet, but mine works fine

  6. Benjamin October 17th, 2007 7:34 am

    Okay, I made Olivier’s changes and updated my zip

  7. Greg Medding October 17th, 2007 9:29 am

    That all sounds good. I probably won’t use the option to approve posts (I can’t access it from my cell phone), but it does sound like a useful feature.

  8. Kydd November 1st, 2007 8:24 am

    Couple apparent bugs:
    -”Default post by mail category” dropdown in “Message Settings” of “Postie Options” does not save when changed.
    -when clicking on the Quick read me, all of the nav links change to have wp-content (in the URL) rather than wp-admin.

  9. Greg Medding November 1st, 2007 12:40 pm

    I checked on my server and it looks like Postie is saving the “Default post by mail category” setting. Are you using the version from my site, the original from Economy Sized Geek, or the updated and improved version on Benjamin’s site (see above)? I’m still using mine, but when I have time, I will probably take a look at Benjamin’s version of the plugin.

    Yes, it does seem odd that the Quick Read Me has all broken links. I haven’t looked at it, but my guess would be that wp-admin is the real culprit: the readme is probably calling functions from the admin files to maintain the correct look and links (I see ones that are not there on a stock wp install, but are there in my normal admin page). The wp-admin functions probably know where they are being run from and would then use links based on that location, so that the admin section can be relocated and not require that the entire script be re-written. However, without examining the code, I cannot be sure, so this is just speculation.

  10. Kydd November 1st, 2007 1:17 pm

    Hi Greg,

    I’m using Ben’s. Any idea which file(s) are different to perhaps try yours?

  11. Greg Medding November 2nd, 2007 12:14 am

    Not off the top of my head. I think you might need the config_form.php file from mine, but I’m not sure.

  12. Kydd November 14th, 2007 7:10 am

    I also noticed that if an article has an apostrophe the backslash (\) (which I’m assuming is used to escape it) still appears in the article heading.

    Also, if an article is forwarded and HTML is turned on the formatting of the page goes awry and for example, the article will block navigation elements.

  13. Greg Medding November 14th, 2007 6:12 pm

    I did a test myself, and got none of the problems you had. You can see mine at http://greg.medding.net/blog/2007/11/14/im-doin-a-postie-test.

    Would you be able to provide more information? A link to your site (with the broken post) would help. Also, are you using the most current version of WordPress? Are you using the version of Postie from my site? Have you made any changes to Postie? Maybe a plugin or your theme are causing your problems. (Just making random guesses).

    It could also be your web host. Every web host is different, so there may be an issue there with different software versions.

  14. Benjamin November 14th, 2007 9:11 pm

    I’ve noticed that the version I uploaded doesn’t deal well with addslashes (things with quotes and stuff in them), so, I’ve use the off option till I figure it out. But, I did go into the code and where it says post_status = publish, I changed it to draft, so that nothing is posted automatically and I can review them.

    If you want to compare code, a quick and dirty way is to paste one into word and save it, then paste the other code in and compare documents

  15. Kydd November 16th, 2007 8:00 am

    Hi Greg,

    Have a look at http://www.cae-nyc.org/intranet/2007/11/16/no-child-left-behind-the-money-was-left-behind/. This is with “Prefered Text Type (HTML/plain):” set to HTML. Notice how it’s not centered properly, not at least on PC/IE7.

    I also replaced Benjamin’s config_form.php file with yours and I still have the “Default post by mail category” dropdown in “Message Settings” of “Postie Options” does not save when changed problem.

  16. Greg Medding November 17th, 2007 12:04 am

    I can’t access that site. It requires a username and password.

    As for the problems, I still haven’t been able to reproduce either of them. It may be that I am running Safari on Mac OS X 10.4.10, but I have also tried Firefox on Mac OS, as well as IE7 on Windows Vista, both of which work fine for me.

    Just to clarify, I am running the latest version of WordPress, and I am using MY VERSION OF POSTIE. None of the components I am using at this time are from any other version. I just haven’t taken the time to try out any other versions (busy college student).

    Also, I have nothing to do with the actual development of any other version, and as such I cannot provide support for those versions.

  17. Lee November 17th, 2007 4:21 pm

    Dude, you ruuule!!! Thanks man!

  18. Kydd November 19th, 2007 6:47 am

    We’ll be changing the username/password next week but for the moment you can use blog / blogreader as we only PW protect it from the search engines.

  19. Greg Medding November 19th, 2007 10:01 am

    Alright, now that I can see it, I’m pretty sure what is wrong. (I still don’t see any problems with the quotes). The table (or div) that creates the box is too big, and probably has a padding size set (or whatever property is outside spacing). It doesn’t fit because it’s too big.

    Postie doesn’t fix html so that it will fit right. If you send it something that won’t work or look right, it won’t work or look right.

    HTML in Postie works fine if you want to include a picture, format some text (maybe… it strips it out for me), or provide a link, but forwarding in complex HTML messages will result in your problem.

    Here’s how to fix it: Delete the post. Go back to your email and copy the content you want. Paste that into a new email.

    I’ve done it in MS Word, if you want, I can post a link to the file so you can see what I mean.

    As for the category problem, I don’t know what is wrong (as I’ve said). If you need to change it, and won’t be changing it again, you could probably edit postie_functions.php to change it. While there, you could also change the default tag from “mobile” to something that suits your site better.

    Anyway, good luck with your site. I hope it all works out for you.

  20. Greg Medding November 19th, 2007 10:07 am

    @Lee

    You’re welcome! I notice you have a post on changing your header image when you send a picture from your phone. How did you do that? Is it some sort of special plugin (or something you wrote yourself), or is it something unique to your theme implementation? That sounds like it would be really cool to use.

  21. Kydd November 26th, 2007 10:06 am

    The fix by Tommaso Baldovino at Entropy in the Stairway blog takes care of all of these bugs.

  22. Greg Medding November 28th, 2007 11:15 am

    I’m glad that has resolved your issues.

  23. jj January 4th, 2008 9:54 pm

    i can’t thank you enough for doing this….. i hack around with php and mysql and never would of gotten this to work without your help!

    may you have the most successful year of your life 2008 thank you for helping!

  24. Greg Medding January 6th, 2008 9:10 pm

    Great to hear this works for you!

  25. jeremy April 14th, 2008 1:33 pm

    great fix - i installed it and it worked well.

  26. jj April 17th, 2008 2:16 pm

    hello i really need your help fixing another problem with this amazing plugin POSTIE

    it keeps removing the javascript from images that makes them popup and display the full size …all it does is link to the larger image so you click and it goes to the image file (no popup ..no blank window even just a plain direct a href link to the full size image)

    it is basically stripping that code can you help me get it to stop doing that …its like black magic to me cause in some cases on mutiple installations of wordpress even 2.3 and 2.5 it worked then it wouldn’t work??

    thanks for all your help ! i am willing to pay anything you’d charge within reason just let me know please its an urgent matter

    thanks!
    JJ

  27. Greg Medding April 17th, 2008 8:14 pm

    JJ-

    I’ve looked through the message handling code and don’t see anything that indicates postie is removing javascript. I’m not the original author, and I am not familiar with all parts of the code, but I don’t think that is the source of your problem.

    In my experience, WordPress is extremely hostile to javascript (it tries to strip it from everything). I don’t remember how I got around it. You can check this by going to the blogs that are having trouble and trying to post the javascript code in question using both postie and the online forms. If the code is only stripped when postie is used, I recommend getting in contact with the original author (it is probably too deep in the code for my understanding of php).

    Hopefully that helps.

  28. Brazilian Don May 10th, 2008 8:29 am

    Thanks for your report.

    I can finally post from my BlackBerry.

  29. clyde July 7th, 2008 1:43 pm

    after having postie working for almost a year, (Wp 2.3 and postie 1.1) my isp changed to php 5
    and then the category and “body part” of an email was getting neglected by postie.

    meaning postie was not posting to the correct category and missing the body part of a mail.

    switching to gregs version again cured all!

    Thanks greg

Leave a comment