Support » Fixing WordPress » Fix for wp-mail.php

  • I believe I’ve come up with a fix for wp-mail.php. In addition to adding the trim() funtion to the statement gathering the password (I am not responsible for finding this), I have fixed the problem of the category not getting set – email would not get assigned a category.
    Below is the code to place in wp-mail.php; below that is the instructions for using it, as you need to enter the category into the email message.

    if ($user_level > 0) {
    $blah = explode("\n", $content);
    $firstline = $blah[0];
    $secondline = $blah[1];
    $blah = explode(':', $firstline);
    $t = $blah[0];
    $post_categories[] = trim($blah[1]);
    echo "<b>Post category:</b> $post_categories[0]";
    $content = $contentfirstline.str_replace($firstline, '', $content);
    $content = trim($content);
    //$post_title = xmlrpc_getposttitle($content);
    //$post_categories[] = xmlrpc_getpostcategory($content);
    if ($post_title == '') {

    I commented out the calls to the xmlrpc functions, as these were the problems – the category is not being sent in with the email in this format, so seems irrelevant.
    I added a few statements which will parse the category from the email message. To use this, simply enter the category on the line directly beneath the username:password. Example:
    ... the body of the message..
    The above would be proecessed and message placed in category #1. You need to use the category number, not the category name.
    I’ve done some testing here, and this seems to work reliably now.
    Note: Be sure to also change the following line:
    $user_pass = md5($blah[1]);
    .. to ..
    $user_pass = md5(trim($blah[1]));

Viewing 10 replies - 1 through 10 (of 10 total)
  • Looks reasonable, I will give it a shot…

    You can check out a message I posted on my WP blog using this setup. I posted it using Eudora on Windows XP. I’ll try from another mailer and see what happens.

    I posted two additions emailed blog entries. One was from a web-front end to Outlook, the other from a normal webmail application. Both posted and posted to the correct categories.
    I did notice that the Outlook message has what looks like a linebreak character (it represents a LF as an ‘=’ character.) Not certain what to do about that at this point.
    Honestly, I won’t be using a blog by email feature much, if at all. For remote posting, I use w.bloggar.

    Which version of WP have you guys tested this on?

    Beel Your solution is much more elegant than mine. Using one additional argument, rather than several statements, as my example used, is simpler.
    I’ve modified my version here based on your suggestions.

    I’m using the current CVS.

    Now all we need is to use the default category if none is submitted in the e-mail. Shouldn’t be difficult but I have to run to a meeting – if you go ahead and do it please let me know so I don’t spend time on it.

    Well, I guess the meeting was cancelled. If no category is set in the e-mail, changing to this will give you the default category set in admin:
    if (empty($post_categories[0])) {
    $post_categories[0] = get_settings(‘default_category’);
    But in testing this I realized in the “Writing by Email” settings one selects by category name, not ID. To maintain consistency, I think that is the next thing I will change in wp-mail.

    Instead of
    $blah = explode("\n", $content);
    $firstline = $blah[0];
    $secondline = $blah[1];

    why not
    list($firstline, $secondline) = explode("\n", $content);

    I made the changes and now everything works except the body of my post does not show up. The title only.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Fix for wp-mail.php’ is closed to new replies.