JB's Blog

/au/SysAdmin

wp-mail mod update! Now 0.2!

with 100 comments

Thanks for all the feedback for my last wp-mail mod. I’ve done a lot of bug fixing in this release, and added a few features. Still working on improving though, so let me know how you guys go with this version!

Here’s the new version: Thanks for all the feedback for my last wp-mail mod. I’ve done a lot
of bug fixing in this release, and added a few features. Still
working on improving though, so let me know how you guys go with this
version!

Here’s the new version:wp-mail-0.2.zip

<rip from README-wp-mail.php>
Wordpress 1.2 – wp-mail hack
Released 2004-08-26 – Version 0.2
By John B. Hewitt – blade@lansmash.com
Blog: http://blade.lansmash.com

License
-=-=-=-=-=–
It’s GPL! Credits are in the wp-mail.php code.

Introduction
-=-=-=-=-=-=-
This hack is a ‘drop in’ replacement for the current wp-mail.php. It uses pear as a mime compliant email ‘decoder’. What’s cool is that you can attach images inline in your email messages and they’ll be shown as an image in your wordpress article. It does this by decoding the image attachments and writing them to ‘wp-photos’ directory (not in default wp install).

History
-=-=-=-
* Version 0.2 – 2004-08-26
* – Stopped using pear body decoding in favour of own decoding (may be slower but more modifiable) because of enriched text decoding
* – Added base64_decode checking (may help mobile phone users)
* – Fixed Subject line for non-english users (htmlentities instead of just trim)
* – Fixed error in some pop hanging -> more graceful exit on event on no emails in inbox ($pop3->quit)
* – Added work around for email addresses with exta <> in field (ie: <blade@lansmash.com> instead of blade@lasmash.com
* – Added some ===basic=== enriched text support
* – Updated readme file for easier install
* – Easy modify of globals (such as photosdir and filesdir)
* – Cleaned up some pear stuff in install
*
* Version 0.1 – 2004-06-20
* First release (was released under version 1.0 initially, oh boy was I silly)

Features
-=-=-=-=-
It has all the abilities of the current wp-mail.php plus:
- Allows image attachments (posts inline! Main reason I built this mod!!)
- Checks if user email address is in the database (otherwise discards message)
- Allows other file attachments (zip’s, exe’s, etc)
- You can post to various categories (ie, 1 = General)
- Fairly good cleaner for removing excessive line breaks

Would love to see it in the wordpress core
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I’m planning on more updates, but would love to see this update included in future wordpress releases. Would be happy to maintain it to, I’m fairly sure it complies with most of the coding guidelines I’ve read on
the wordpress coding standard.

Install
-=-=-=-=-
To install you grab the zip file.
- – Drop the two files (wp-mail.php & mailmimedecode.php & PEAR.php) into your wordpress 1.2 root directory
- – Create the directories ‘wp-photos’ and ‘wp-filez’ in the wordpress root directory (with writing permissions (probably 0777).

That’s it. You should now be able to post email to wordpress.

Features to come
-=-=-=-=-=-=-=-=-
Immediate features to come:
- Direct email script that parses email as it comes in (so removes cronjobs)
- GPG/PGP signature verification
- Better enriched text support (only basic stuff at the moment)
- Better security for file attachments (no .php stuff, less l33t hax0rs)
- Look ups for Category posting

Usage
-=-=-=-
You can use the wp-mail hack just like the old wp-mail.

Make sure you change your email client to use HTML encoded messages, that way you’ll get a better looking post that is similar to what you emailed.

When emailing to your blog you can also change the category the post is going to. To do so change the subject line to include [1] at the beginning where one is the number of the category you want to post to.
1 is usually General’s category, so if I want my email to go to the General board I type:
Subject: [1] This is a test

FAQ
-=-
- If you are using Mozilla (thunderbird,etc), use HTML mail! Not HTML/TEXT combined! (One day this script will be able to decode both at the same time, just not today)
- If you are using Outook/Outlook express, use HTML mail!
- If you are using Mac OS X email, you’re sweet
- You can change the default photos and files directories. The variables are on the top of the wp-mail.php code.

Written by JB Hewitt

August 26th, 2004 at 8:50 am

Posted in Code

  • http://tomihagman.net/wordpress/index.php?p=18 Hiilihappoa » Kotisivut

    [...] vaviesteillä päivitys onnistui muutaman tunnin puurtamisen jälkeen kun olin ensin löytänyt wp-mail.php ohjelman muokatun version. WWW-palvelimen ja blogin ylläpitoon pitäisi löytyä vielä jotai [...]

  • http://www.project222.com/nate/index.php?p=50 Nate Ritter: Web Chef » Posting via Email + Update Notify

    [...] the site had been updated. To solve this, I installed the Update Notify plugin and use a modified wp-mail.php to allow him to post into different categories as well as add photos to his posts v [...]

  • http://indi.ca/index.php?p=360 indi.ca » Email Posting, Radix, DNA, Molecules, and Religion

    [...] trying to hack a hack of WordPress into the website they want. There’s a really excellent email-to-blog plugin for WordPress that I’ve been experimenting with. The most popular application on t [...]

  • http://graham.doel.org/2004/12/29// Graham Doel’s Blog » 2004 » December » 29

    [...] I have been struggling with the WordPress e.mail to blog hack of wp-mail.php from John Blade . The problems I had with his hack were: # It didn’t interpret the HTML properly fro [...]

  • http://graham.doel.org/2004/12/29// Graham Doel’s Blog » 2004 » December » 29

    [...] I have been struggling with the WordPress e.mail to blog hack of wp-mail.php from John Blade . The problems I had with his hack were: # It didn’t interpret the HTML properly from [...]

  • http://graham.doel.org/2004/12/29// Graham Doel’s Blog » 2004 » December » 29

    [...] I have been struggling with the WordPress e.mail to blog hack of wp-mail.php from John Blade . The problems I had with his hack were: # It didn’t interpret the HTML properly from [...]

  • http://briandonovan.info/self-assembly/index.php?p=17 Brian Donovan’s Self-Assembly » Moblogging update

    [...] to “draft” mode, then back to “publish”. At the moment, I’m using John Blade’s replacement wp-mail and it’s pretty swell (can post attached photos and posts a [...]

  • http://janolin.phpnet.org/blog/index.php?p=36 L’Espace Eauxigènes – blog » email plugin

    [...] is, pour l’instant, il n’y a pas de redimensionnement automatique des images. Le plugin utilisé Comments » The URI to TrackBa [...]

  • http://www.bloggie.com/wp/index.php?p=9 BSL/ESL » WP/MT/PM

    [...] nt release. The new photo email plug-in (0.3) doesn’t work for me so I am using the older one (0.2). ————————— I always love MT an [...]

  • http://blog.weblars.de/wp Lars

    Good work! Now I am able to use my SE T610 for moblogging. Thank you, John.

  • http://blog.weblars.de/wp/archives/2004/08/26/moblogging-mit-worpdress/ weblars.de / blog

    Moblogging mit Worpdress
    John Blade hat eine neue Version seines wp-mail-Hacks veröffentlicht. Der Hack erweitert die Fähigkeiten von WordPress, die das Veröffentlichen von Artikeln per Email ermöglichen. Mit einem geeigneten Mobiltelefon ist es damit auch möglich, Bilder und …

  • http://domovolcanico.com/felixe Felixe

    Thank you for this terrific mod. It worked first time and now with v.0.2 still works. One little problem I have is when I use yahoo for posting, it sends plain text and html (don’t know how to override this behaviour) and what I get on my blog is a nice post with the same info appended only in html.

    I guess it’s the same as your recommendation for Mozilla Thunderbird and Outlook to just use HTML, so I think I’ll be hand-editing for some time.

    And one last question: how do I post to other categories?

  • Jim Levin

    A also very much appreciate your hack, however from Mozilla mail, when sending as HTML only I see raw HTML in the blog (see http://thelevins.net/wp/ ). Also, the posting doesn’t trigger an outgoing email notification (using a modified verison of this script: http://www.briangroce.com/software/wp-email-notification.html ). Please let me know if you have any thoughts or would like me to do any testing. Thanks again.

  • http://holosite.servepics.com/baby/ John Arnold

    Thanks for the work, I need to check out this new version. I modified your older one for my site to work with my phone. The problem I had with the mime and base64 decode was my phone sends the information in all caps, so I tweaked the mimedecode and wp-mail.php to be strtolower the content types and encodeing, that fixed my phone sending mail.

    Thanks for all the work.

  • Jim Levin

    One additional question: The code that strips signatures (after –) also seems to strip off my photo attachment. Any suggestions?

  • http://www.heymelby.com/wordpress erik hodson

    It’s not working, I get all the html coding and no image, i added the files and crated the directories. If i send outlook mail as plain text its fine- but no image! help!

  • http://www.project222.com/nate nate

    I am installing this for a friend of mine and found that it works great by sending plain text with an attachment in MS Outlook. What I also found was that it ignores the “Allow Comments” and “Allow Pings” default settings. So, even though I don’t want to allow comments on this blog, if I use this plugin, I have to go back in and reset it for each post anyway.

    I’ll try to hack it to make it work and then give you what I used, if I get that far. But, if you do it first, please be so kind as to let me/us know.

    Thanks.

  • http://www.project222.com/nate nate

    To fix the above situation, I added these two lines after line 35:

    //default comment/ping status
    $comment_status = get_settings('default_comment_status');
    $ping_status = get_settings('default_ping_status');

    I also added two lines to the array used for the sql string. It now looks like this:

    $details = array(
    'post_author' => $poster,
    'post_date' => $post_date,
    'post_date_gmt' => $post_date_gmt,
    'post_content' => $content,
    'post_title' => $subject,
    'post_modified' => $post_date,
    'post_modified_gmt' => $post_date_gmt,
    'comment_status' => $comment_status,
    'ping_status' => $ping_status,
    'post_name' => $post_name
    );

    However, I am having problems now with it in combination with the plugin called update_notify(). It seems that your code is missing something in it’s posting action that triggers the update_notify plugin whereas if I post through the admin UI, the update_notify plugin does work. It may not be your problem, but I just throught I’d mention it.

    Again, if I find a solution, I’ll let ya know.

  • http://www.project222.com/nate nate

    As for my last post, after removing the update_notify() plugin and using the default Post by Email that comes with WP, I’ve found that it doesn’t work either. So, it must not be your plugin’s problem. Just thought I’d let ya know.

  • John

    Everything seems to be working great except posting a picture via email. I can post via my cell phone fine but when I try to post with a picture, I get an error message from the plug-in that says “invalid sender.” What gives?

  • JohnBlade

    John, you need to have a user in your wordpress user list that has an email address of your mobile phone’s. My hack checks to see if the user is valid before it allows it in.

    So just add a user with a valid email address.

  • http://www.tchansen.org Chris Hansen

    Sweet! Now I can post from my camera phone! Great job, great code.

  • http://www.spreeblick.de johnny

    my old wp-mail.php did work, yours doesn’t up to now. it seems to check for mail correctly but returns the “There does not seem to be any new mail.” message. my install has got a user with the mail address I am sending from, so that should work. any more hints on where to look for a problem? TIA!

  • http://www.spreeblick.de johnny

    I re-installed. And it works. Sorry for the mess-up, thanks for a great script!

  • http://bekit.net Brint

    Great hack. I’m writing a Sprint Picture Share plugin, and it was much easier to use your script instead of the basic wp-mail. I did find some things I needed to change though to make it work the way I needed/wanted. I think they are things that everyone could benifit from, and they integrate nicely into your existing code. I’m cleaning up/commenting now – when I finish it up I will post the code here. I’d rather not maintain a fork of the code, so I’m hoping you will like my modifications and incorporate them into future releases :)

  • Dan

    I’m very new with WordPress and with weblogging/hosting in general, so pardon my stupid questions… I am able to post via mail after installing this nice plug-in but I still see HTML formatting although I’ve selected HTML mail in Outlook – is this expected?. Do you mean to not use Outlook at all to send mail? Also, when sending a URL via email (even text format in Outlook), I do not get the actual reference to the link, just text. Is this expected? Finally, when sending mail from my phone (I do have the phone’s email address added as a user), I still get the “this user is not allowed to post” when exec wp-mail.php. Any suggestions for troubleshooting this problem?

    Thanks.

  • http://bekit.net Brint

    Okay, I have completed my code and released a new version of my SprintPhoto script. The new copy of wp-mail.php can be found here, and a commented page listing the differences can be found here. As I said, I think that these changes/additions would benifit the script and I would love it if you could incorporate them into future releases. If not, I will do what I can to maintain my fork of the code, though I doubt I will do much to modify the pure email side of things. Dan, you may want to check out my copy – it has a bug fix to the address checking and also has the ability to dissable the email address checking completely if needed. The changes I have made were mostly created to better utilize my SprintPhoto v0.2 plugin.

    Please feel free to get in touch with me about the changes I have made. Thanks again for the great work!

  • http://www.iblog.dk/nldk Ingrid

    I have the same problem as Dan. I send with Outlook, the picture and text get posted on my weblog, but so does the mail in HTML format.
    Is there any solution for that ?

  • Hugo

    I’ve added image resizing and pop-ups to the script. This will scale the largest dimension of the image to a pre-set size, and maintain the aspect ratio. It’ll then save a .JPG of the scaled image, and make the image a link to a full-sized version which comes up in a pop-up window:

    $filename = $photosdir . rand() . '.' . $part->ctype_secondary;
    $fp = fopen($filename, 'w');
    fwrite($fp, $part->body);
    fclose($fp);

    $maxdim = 200; // maximum height
    $size = getimagesize($filename);
    if ((1 < = $size[2]) && ($size[2] <= 3) || ($size[2] == 15)) { // handles JPG, GIF, PNG, and WBMP

    if ($size[0] > $size[1]) {
    $sizemin[0]=$maxdim;
    $sizemin[1]=$maxdim * $size[1] / $size[0];
    }
    if ($size[1] > $size[0]) {
    $sizemin[0] = $maxdim * $size[0] / $size[1];
    $sizemin[1] = $maxdim;
    }
    switch ($size[2]) {
    case 1:
    $im = @imagecreatefromgif($filename);
    break;
    case 2:
    $im = @imagecreatefromjpeg($filename);
    break;
    case 3:
    $im = @imagecreatefrompng($filename);
    break;
    case 15:
    $im = @imagecreatefromwbmp($filename);
    break;
    }

    $small = imagecreatetruecolor($sizemin[0], $sizemin[1]); // new image
    ImageCopyResampled($small, $im, 0, 0, 0, 0, $sizemin[0], $sizemin[1], $size[0], $size[1]);

    $small_filename = $photosdir . rand() . '.' . "jpg";
    ImageDestroy($im); // free memory

    if (ImageJPEG($small,$small_filename,100)) // try to save image
    {
    echo "File $path has been written
    \n"; // success
    echo "size: ".$sizemin[0]."x".$sizemin[1] ."
    \n";
    }
    else
    {
    echo ""; // failed to write file
    echo "Error ! File has not been written.";
    echo "

    \n";
    }

    $meta_return .= '' . $part-/>ctype_parameters['name'] . '' . "\n";
    }
    else
    {
    $meta_return .= '"' . $part-/>ctype_parameters['name'] . '' . "\n";
    }
    break;

    You also need to add this javascript code to index.php:

    popUp(sURL,sName,iWidth,iHeight) {
    window.open(sURL,sName,'width='+iWidth+',height='+iHeight+',scrollbars=no,noresize');
    }

  • http://mud.vienna360.net Mudhenn

    this must be an error:
    if ((1 $size[1]) {

    how do I insert the script in index.php?

  • http://mud.vienna360.net Mudhenn

    hmmm… the whole resizing-code seems to be full of bugs, at least if I copy & paste it in the wp-mail.php (replacing the right parts, of course)

  • http://mud.vienna360.net Mudhenn

    so finally I have it working :-)
    thanks to hugo! most of the problems occured because of the formating done by wordpress in the comments, so I have posted my working version here .
    at next I want to find out how to get the german letters like ä working…

  • Tina

    wow! this mod kicks ass! Works perfectly from Outlook. I’m having a problem using G Mail to post pictures, but I’m not sure if it’s a local problem on my end. I get this error:

    Warning: Invalid argument supplied for foreach() in /public_html/blog/wp-includes/template-functions-category.php on line 70

    Only happens when attaching pictures. Emailing a regular post works just fine. I can live with this, but was just curious.

    Again – thanks for all your hard work!

  • http://www.cynikalsam.com Sam

    I’ve noticed more then one person having problems with their picture posts displaying raw HTML code. Has anybody found a fix for this yet? Im using mozilla thunderbird, and im sending the picture post as HTML. You can see the problem here; http://www.cynikalsam.com/blog

    Im new to wordpress, so could this be a problem with my wordpress settings?

  • http://gnbi.com Otis Riggins

    //Hack for wp-mail.php plugin
    //Author: J. Otis Riggins; otis@gnbi.com
    //Use as you like!
    //What does it do? It creates a smaller .jpg image scaled to your specs while maintaining the aspect ratio of
    //the original image. The function was created to support image uploading using wp-mail for users who upload
    //large images but could be used for other image scaling task as well.
    //
    //By replacing a line in the wp-mail.php file and adding the function to the end of wp-mail.php it will cause
    //the thumbnail image to be displayed in the blog message and linked so that when a user clicks on it the larger
    //original image will be displayed in a seperate window. The method I chose was to append “tn_” to the begining
    //of the image name and saving both files into the wp-photos directory.
    //
    //To use replace the following line in wp-mail.php with the five lines after it and include the function in wp-mail.php

    $meta_return .= ‘' . $part-/>ctype_parameters['name'] . ‘”/>’ . “\n”;</p>
<p>$thumb = dirname($filename) . “/tn_” . basename($filename);//append “tn_” to begining of filename for thumbnail<br />
$pos = strrpos($thumb, “.”);<br />
$thumbfile = substr($thumb, 0, $pos + 1) . “jpg”;<br />
$strsize = sizeit($filename, $thumbfile, 400, 300);// Adjust width & Height to suit I like 400X300<br />
$meta_return .= ‘<a href=' . $part-/>ctype_parameters['name'] . ‘” ‘ . $strsize . ‘ border=”0″/></a>‘ . “\n”;</p>
<p>function sizeit($filename, $thumbfile, $maxwidth, $maxheight) {<br />
         set_time_limit(1000);// just to be safe<br />
         $array = GetImageSize($filename);<br />
         switch ($array[2]) {<br />
         case 1:<br />
              $im = @imagecreatefromgif($filename);<br />
              break;<br />
         case 2:<br />
              $im = @imagecreatefromjpeg($filename);<br />
              break;<br />
         case 3:<br />
              $im = @imagecreatefrompng($filename);<br />
              break;<br />
         case 15:<br />
              $im = @imagecreatefromwbmp($filename);<br />
              break;<br />
         }<br />
         $cwidth = $array[0];<br />
         $cheight = $array[1];<br />
         if ($cwidth > $maxwidth) {<br />
            $pdivisor = $maxwidth / $array[0];<br />
            $cwidth = round($array[0] * $pdivisor);<br />
            $cheight = round($array[1] * $pdivisor);<br />
         };<br />
         if ($cheight > $maxheight) {<br />
            $pdivisor = $maxheight / $cheight;<br />
            $cwidth = round($cwidth * $pdivisor);<br />
            $cheight = round($cheight * $pdivisor);<br />
         };<br />
         $resize = imagecreatetruecolor($cwidth, $cheight); // Create a blank image of the propersize<br />
         imagecopyresampled($resize, $im, 0, 0, 0, 0, $cwidth, $cheight, $array[0], $array[1]); // Resample the original JPEG<br />
         imagejpeg($resize, $thumbfile, 100);// save the thumbnail file – quality set here to 100% which is max<br />
         $picsize = ‘width=”‘ . $cwidth . ‘” height=”‘ . $cheight . ‘”‘;<br />
         imagedestroy($im);// to free memory<br />
         imagedestroy($resize);// to free memory<br />
         return $picsize;// return the new thumbnail pic size formatted for image tag<br />
      }</p>
</div>
                    </div>
                </li>
                    <li id=

    Brian

    Something I noticed that I wanted to mention. When I first setup the script, I tried creating 2 posts from my Palm Pilot, and they failed due to the email address not being in the WP database, which was fine, once I changed the email I was able to post without a problem, but when I looked at the wp-photos directory I noticed that the original two photos were sitting in there, even though the script denied the posting to unauthorized poster. Shouldn’t it remove/or not even save the files from any invalid posts?

  • Agnete

    I would love to use your great hack. But I have one small problem. When I post something with Danish characters in the CONTENT, the characters don’t get translated correctly. The Danish characters show as =E6, =F8, and =E5 in my blog. Can anyone help me solve this problem?

  • Brian

    Another concern I had was:
    Since I know going to http:////wp-email.php will process any waiting emails, Since the script outputs the post to the web browser as it makes the post, I could attempt to run it on sites not my own and read their incoming posts regardless of the security level (if using viewlevel plugins, etc).

  • http://maneblog.mgate.com.br oculos

    I just loved your hack!

    However, I have two issues:

    1 – it won’t delete the e-mail from the server, resulting on posting the same thing over and over;

    2 – it is conflicting with my Show Categories plugin:

    Warning: Invalid argument supplied for foreach() in /home/mgateco/public_html/maneblog/wp-includes/template-functions-category.php on line 9 (displayed at the Posts tab of the WordPress admin page, and

    Warning: Invalid argument supplied for foreach() in /home/mgateco/public_html/maneblog/wp-content/plugins/showcategories.php on line 254, displayed at the front page of my blog.

    What can I do to fix this?

    Yours,

    oculos

  • http://www.grass-net.de Sebastian

    Hi John!

    Thanks a lot for this nice hack! I like it! But one question, is there a solution how to handle the raw html code output? I saw here in the comments more questions and ih have the problem too. Has anyone got that working with HTML-Emails?

    Thank you John for these hack!

    Sebastian

  • http://blog.81tz.net JHH

    Very cool hack. Keep up the good work. I had some problems with posts showing up with the wrong time. Two hours added. Easily fixed by removing some of the stuff after character 54 line 93 in wp-mail.php. (” + ($time_difference * 3600)”) Also while posting from my t630 local characters like æ ø and å doesn’t show up correctly in the body (it’s shows up correctly in the title btw), but it seems to work very well when posting from Mail.app on my comp. I’ll mainly use it for posting pictures from my mobile on the go, so it’s not a big concern, but I would prefer not to use html codes for æøå when I accidently feel like adding comments to a picture or whatever. :D
    Very useful utility.

  • http://tinylens.com Brad

    Mostly I wanted the geourl by email feature that is supposed to already work, but doesn’t.
    So, I added the functionality to the wp-mail.php file.

    Modifications to John B. Hewitt’s hacked wp-mail.php version 2.0 – http://blade.lansmash.com/index.php?cat=5
    Adds coordinate parsing, which according to the wiki was working at some point.
    I borrowed the coordinate parsing from http://drbacchus.com/wordpress/index.php?p=631
    This hack extracts the first set of coordinates from the body of the email and inserts them into the database

    Coordinates must be in the format: 33d39.452,-117d42.315
    That’s “Degrees” then “d” then “Minutes” then “.” then “Minutes”
    Note that the last is in minutes, not seconds.

    Coordinates can be anyplace in the message body.

    Comments and improvements welcome.

    Brad Wilson – bwilson@b-photo.com

    After this:—————————————————————–
    //date reformating
    $post_date = date(‘Y-m-d H:i:s’, time($ddate) + ($time_difference * 3600));
    $post_date_gmt = gmdate(‘Y-m-d H:i:s’, time($ddate) );
    Add this:—————————————————————–
    //get Latitude
    $latitude = getLat($content);
    //get Longitude
    $longitude = getLon($content);

    After this:—————————————————————–
    print ‘Subject: ‘ . $subject . ‘
    ‘ . “\n”;
    Add this:—————————————————————–
    print ‘Coordinates: ‘ . $latitude . ‘x’ . $longitude . ‘
    ‘ . “\n”;

    After this:—————————————————————–
    ‘post_title’ => $subject,
    Add this:—————————————————————–
    ‘post_lat’ => $latitude,
    ‘post_lon’ => $longitude,

    After this:—————————————————————–

    function charsetcheck ( $part )
    {
    if ( strtolower($part->ctype_parameters['charset'] == ‘utf-8′) )
    {
    $part->body = utf8_decode($part->body);
    }
    return $part;
    }

    Add this:—————————————————————–

    /**
    * Grab Latitude from message body
    * Coordinates must be in the form: 34d13.345,-123d45.234
    * That’s degrees, then ‘d’ and then minutes.minutes
    */
    function getLat ( $data )
    {

    $coords = ‘((-?)(\d+)d(\d+\.\d+)),((-?)(\d+)d(\d+\.\d+))’;

    preg_match(“/$coords/mx”,$data,$matches);
    //$lat=$matches[1];

    /* Convert to Decimal */
    $latd = $matches[3];
    $latm = $matches[4];
    $lat_sign = $matches[2];
    $lat_dec = $latd + $latm / 60;
    $lat_dec = $lat_sign . $lat_dec;

    return $lat_dec;
    }

    /**
    * Grab Longitude from message body
    * Coordinates must be in the form: 34d13.345,-123d45.234
    * That’s degrees, then ‘d’ and then minutes.minutes
    */
    function getLon ( $data )
    {

    $coords = ‘((-?)(\d+)d(\d+\.\d+)),((-?)(\d+)d(\d+\.\d+))’;

    preg_match(“/$coords/mx”,$data,$matches);
    //$lon=$matches[5];

    /* Convert to Decimal */
    $lond = $matches[7];
    $lonm = $matches[8];
    $lon_sign = $matches[6];
    $lon_dec = $lond + $lonm / 60;
    $lon_dec = $lon_sign . $lon_dec;

    return $lon_dec;
    }

  • Cory

    I’d like to say this mod rocks! Just one question, anyone know how to modify the script so I can use the mail filter option rather than using cron jobs?

  • http://th80.de/blog/index.php?p=10 tomblog

    Mobile Blogging!
    Es ist soweit. Nachdem ich lange auf der Suche nach einem geeigneten Webspace-Provider war, starte ich heute mein Weblog. Dieses wird mit Hilfe von WordPress realisiert. Beim einrichten des Blogs ist mir dabei ein wunderbares Feature aufgefallen, welch…

  • daniel

    does any one have a fix for the html problem? when I email a post using thunderbird it shows the raw html coding.

  • http://www.itst.org/linkdump.php?id=658 Sascha Carlins Linkdump

    This page has been linkdumped
    Sascha Carlin thought this page could be useful, so he sent it to his linkdump.

  • http://123456 ahmadreza_soroush

    pass send for me

  • http://123456 ahmadreza_soroush

    salam

  • cyril

    when i post with or without picture i have:

    ok–> essai sans image
    ok–> cat 2

    but i have this displayed also. How can i do for remove this?
    < !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    charset=3Dus-ascii">


    rial size=3D2>essai =
    sans=20
    image

    cat=20
    2

  • cyril

    sorry this is the problem:
    essai sans image
    cat 2

    < !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    charset=3Dus-ascii">


    rial size=3D2>essai =
    sans=20
    image

    cat=20
    2


  • cyril

    my problem here http://www.cdprod.org/pb.JPG
    because i can’t display code here. sorry for my multi posts!

  • http://west4me.com/ipw-web/gallery/index.php Will

    I am running WP and Gallery and I have been looking for a mod like this everywhere. I just installed it on my blog and trying to get it to work. The main reason I was looking at this it to see if it can be used on my gallery intalation. I am a complete php idiot so I don’t know how to do it. I was wondering if someone might want to take a crack at it. It is something that is asked for on the Gallery forum but I havn’t been able to find a good working solution. I you would like to give it a try let me know. Thanks.

  • http://www.harrysufehmi.com Harry Sufehmi

    It seems that this script will always have problem with email sent from Thunderbird. I checked, and Thunderbird always send email as full HTML document, and the ContentType is of course text/html instead of text/enriched.

    It seems the solution is:

    # Send email as text
    # Any images attached to that email
    # If you need to embed HTML codes, then make sure that line 193 is as follows:

    $meta_return = $part->body;
    (instead of filtered by htmlentities)

    Hope it helps.

  • Brian

    I’m a moron. I’m a PHP and WordPress noob and I installed this plugin and have NO idea how to manually go in and give WordPress a “whitellist” of email addresses I can send messages from. Right now, every time I write an email to my blog it gets rejected because it’s not approved. Help!

    -Brian

  • http://www.landrysplace.com Adalan

    This hack works wonderfully. My only problem is thatI use Verizon Wireless and when I use the “–”, it not only blocks the crap they attach…but also block the image from coming through…any ideas?

  • misery152

    jg chcuycıhvjblkj

  • Cryptik

    Anyone got a working version of the image resize hack …
    I have tried both the Hugo… Mudhen download
    and the Otis hack

    With the mudhen download the thumbnail never gets dumped into the wp-photos folder and so it never shows up,

    the otis hack gives me a parce error “;” unexpected at 204 and I cant seem to figure it out.

    It sounds like its working for some…anyone have a hacked and working wp-mail that they could email my way.

    My wife would most appreciate it LOL

    Thanks

    Cryptik

  • Cryptik

    Anyone know why I would get an error writing the picture using the hugo hack .. mudhenn file.

    I just doenst want to write the thumbnail.

    Thanks
    Cryptik

  • Cryptik

    Ok figured it out… Iam lower than the required GD 2.0 and had to change
    iamgecreatetrue to imagecreate and
    imagecopyresampled to imagecopyresized

    works perfect now… GREAT HACKS YOU GUYS keep them coming!!!

  • http://www.mrmule.com mrmule

    Is there something I am doing wrong here?

    I get a cron error when running
    ERROR:

    /home/mysite/public_html/wp-mail.php: line 1: ?php: No such file or directory
    /home/mysite/public_html/wp-mail.php: line 3: /aquota.user: Permission denied
    /home/mysite/public_html/wp-mail.php: line 4: etc: command not found
    /home/mysite/public_html/wp-mail.php: line 5: etc: command not found
    /home/mysite/public_html/wp-mail.php: line 6: syntax error near unexpected token `(‘
    /home/mysite/public_html/wp-mail.php: line 6: `* Copyright (c) 2003-2004 The WordPress Team’

    if i open the file in the browser it will post.
    UH?

    any help would be super, i just upgraded from MT.

  • http://imnotsoho.net geensleutel

    Hey John,

    I love this hack. My PHP skills are sucky-sucky-5-dollah so I’m glad you’re sharing this with us…

    One thing though:

    Immediate features to come:
    - Direct email script that parses email as it comes in (so removes cronjobs)

    Any idea when you will have this going? Thanks!!!

  • http://www.thebestbuy.net best-buy-boy

    I am having problems with the posts via email not having filenames (the re-written, post slug type).

    I have set up the emailing properly. However, I have found that when I post, there is no actual post slug or file name. So, the links on the blog are /24/11/2004// for example … instead of /24/11/2004/post-name-here.

    Posting regularly is fine, however this is a problem only when posing by email. I have tested it multiple times, even using the hack from the wiki (new wp-mail).

    Any suggestions?

  • http://gumia.de/geniessen/2004/11/28/mobil-bloggen-mit-wordpress-12-mingus/ Notizen fuer Geniesser

    Mobil bloggen mit WordPress 1.2 Mingus
    Bloggen macht Spass! Mobiles Bloggen per E-Mail und über ein Foto-Handy bringt erst richtig Spaß! Ich habe das MoBlogging für diesen Blog realisiert und möchte kurz die Möglichkeiten in Verbindung mit WordPress beschreiben.

  • http://thepete.com ThePete

    Wow, this sounds like a great thing, but I can’t get it to work worth a damn. I keep getting the “There does not seem to be any new mail.” message. I’ve reinstalled the files, made sure that the email came from an address that WP recognized and still the same results. Whenever I call wp-mail.php, I get “There does not seem to be any new mail.” Is there something I might be forgetting to do? All three files are in the WP root directory.

    It does seem to check the mailbox, but it fails to see the emails that I know are there. (I checked the mailbox with mail syphon for OSX.) Any advice would be muchly appreciated. Thanks!

  • sharfuddeensk@yahoo.com
  • Allan

    The problem with the post names appears to be in the original wp-mail.php and John’s. I hunted about in the PHP and the problem is that the post_name field is not being populated when the message is parsed. Open wp-mail.php (John’s) and find the block of code that reads:

    $details = array(
    ‘post_author’ => $poster,
    ‘post_date’ => $post_date,
    ‘post_date_gmt’ => $post_date_gmt,
    ‘post_content’ => $content,
    ‘post_title’ => $subject,
    ‘post_modified’ => $post_date,
    ‘post_modified_gmt’ => $post_date_gmt
    );

    and change it by adding the post_name field:

    $details = array(
    ‘post_author’ => $poster,
    ‘post_date’ => $post_date,
    ‘post_date_gmt’ => $post_date_gmt,
    ‘post_content’ => $content,
    ‘post_title’ => $subject,
    ‘post_modified’ => $post_date,
    ‘post_modified_gmt’ => $post_date_gmt,
    ‘post_name’ => sanitize($subject)
    );

    Tested and seems to work.

    Allan

  • http://www.texas-holdem-p.com texas holdem

    I think there is nothing to be commnented
    texas holdem
    here :)  right free 
    online texas holdem
    here. But right away here
    http://www.texas-holdem-p.com you can find the right info for play texas holdem
    now.

  • http://www.online-poker-888.us online poker

    I think there is nothing to be commnented
    online poker
    here :)  right free 
    online poker
    here. But right away here
    http://www.online-poker-888.us you can find the right info for play online poker
    now.

  • http://www.primedirectiveonline.com/blog Se˜or Pez

    Another tweak I made was to the posting time… right now, if you use a cron job to process the email, any posts that get processed appear at the time the cron job runs, not when they were actually submitted.

    To fix this, change the following two lines:
    $post_date = date('Y-m-d H:i:s', time($ddate) + ($time_difference * 3600));
    $post_date_gmt = gmdate('Y-m-d H:i:s', time($ddate) );

    to (changes in bold):
    $post_date = date('Y-m-d H:i:s', strtotime($ddate) + ($time_difference * 3600));
    $post_date_gmt = gmdate('Y-m-d H:i:s', strtotime($ddate) );

    Enjoy!

  • http://www.primedirectiveonline.com/blog Señor Pez

    Oops… changes didn’t show up bold.

    Just change the call to the “time” function to “strtotime” instead.

  • http://www.radicalgeorgiamoderate.org/ Rusty

    One thing this script doesn’t do is add a slug, which is necessary for those of us who have mucked around with our permalink structure via Mod.rewrite. Here’s how I modified this script to add a slug:

    After this code…


    if (empty($post_categories))
    $post_categories[] = get_settings('default_category');

    Add this code:


    // creates a variable to be used as the post's slug
    $array_post_name = explode(" ", strtolower($subject));
    $string_post_name = implode("-", $array_post_name);

    Then add a line to your $details array like this:


    $details = array(
    'post_author' => $poster,
    'post_date' => $post_date,
    'post_date_gmt' => $post_date_gmt,
    'post_content' => $content,
    'post_title' => $subject,
    'post_modified' => $post_date,
    'post_modified_gmt' => $post_date_gmt,
    'post_name' => $string_post_name
    );

    I also hacked mine to use the free Audioblogger system with WordPress. It’s pretty easy, since you can get Audioblogger to send an HTML formatted email to a specified address whenever you post. Then you just write a function to strip out some of the code from that email. If anyone wants me to post a tutorial here or on my site, I will.

    Thanks for this cool hack. I love using it with cell phone photos too.

  • http://jystewart.net James Stewart

    I’ve been setting up wordpress for some friends, including adding this plugin and they’re also having the problem mentioned above that emails aren’t being deleted from the server, and the ‘foreach’ message shows up for some of them. I’m happy to have a go at debugging the plugin myself, but wanted to check whether a patch was available?

  • http://www.online-poker-888.us online poker

    Here are many reasons I post here , thanks for posts before but I really
    recommen this website online poker . Please refer to our
    friends and play online poker also free
    online poker
    http://www.online-poker-888.us to our best greetings.

  • http://www.online-poker-888.us online poker

    Here are many reasons I post here , thanks for posts before but I really
    recommen this website online poker . Please refer to our
    friends and play online poker also free
    online poker
    http://www.online-poker-888.us to our best greetings.

  • Hazza

    I have everything working perfectly except since my mail server is 8 hours behind GMT all my emails post at the time the mail server receives them. Any suggestions to change it?
    I have tried the strto fix, but didn’t know where to “just change the call to the ‘time’ function to ‘strtotime’ instead”.

  • http://www.online-poker-888.info online poker
  • http://www.blackjack-a.com blackjack

    play blackjack online http://www.blackjack-a.com blackjack

  • http://www.gamb-info.com online gambling
  • http://www.online-blackjack-i.com online blackjack
  • http://www.online-blackjack-i.us online blackjack
  • http://www.texas-hold--em.biz texas hold em
  • http://www.texas-hold--em.us texas hold em
  • http://www.texas-holdem-p.com texas holdem
  • http://www.texas-hold-em-a.com texas hold em
  • http://www.texas-holdem-i.com texas holdem
  • http://eiaüaaıie ahmet

    aeiıücıotğddddddddddddddddddddddddd

  • par

    Just made a clean install of WP 1.2.2 and configged original Writing-by-email, which worked like a charm. Dropped the three files of wp-mail mod 0.2 and created directories, and sending email (HTML) with picture attachment, all I get is “Mission complete, message 1 deleted.” and no action (email not even deleted as reported).

  • Hans

    I have the same problem as comment #84. Using WP 1.2.2 (PHP 5.0.3, Apache 2.0.52/Win2K). Original wp-mail working. Did some quick debugging, seems to stop at first if-statement in mimedecode ‘decode’, removed these static checks and changed to non-static call to ‘decode’ from wp-mail which made it able to post with correct subject/time but no content. Help? Have tried mailing from different clients, setting HTML where possible.

  • John Blade

    Ok – thanks for everyone’s commments and patches. I’ve been pretty slack on the coding front lately but I’m going to remedy that with a new version of wpmail this week.

    For everyone running PHP5 (Han’s, etc) wp-mail ver 0.2 won’t work. This is because of a problem with Pear’s mimedecode objective stuff being messed up. I’ve fixed it and submitted the bugs to Pear, so basically it’s fixed in wp-mail ver 0.3.

    I’m just testing 0.3 now and if it passes by the end of the week I’ll post it up. Stay tuned…

  • Jim Munroe

    Excited to see the new version! I’m having a problem with the current .2. I’m trying to post .wav files sent as email attachments, but it just disappears. A zip file I attached as a test worked fine, linked and posted in the wp-filez dir, so I suspect there’s something weird about a .wav file being a MIME file…? Anyway, thanks for your work on this.

  • http://www.inkietos.com Inkietos

    anyone know how to fix the thunderbird html format?. i would like to use this hack, but not change my favorite email client. ;)

  • Jeff

    Please, John! I crave your code! ;^)

  • http://www.easy-application-credit-cards.com/ credit cards

    Please check the sites dedicated to credit cards

  • http://l-s.em-pathy.net/wp Grace

    Yes! It’s working it’s working! Thanks so much for the script, though I had to modify it to match my GMT settings.

    Just modify $time_difference * 3600 in:

    $post_date = date(‘Y-m-d H:i:s’, time($ddate) + ($time_difference * 3600));
    $post_date_gmt = gmdate(‘Y-m-d H:i:s’, time($ddate) );

    Change the numbers to match the timeserver of your cron job. It’ll be different for each server.

    Sent out using PLAIN text. Tried to modify with the suggestions given above for HTML, but it still did not turn out well. Plus, if I posted with picture in HTML via email, I’ll still get the error thing about the $post_categories.

    Mobile-blogging OK. Just make sure you have your mobile-email stored as an email under users in wp inself to work. Formatting still lacking though (sadly).

    Otherwise, I’ll say this works just fine for me! :D

  • Jeff

    John, you are a star, and I really appreciate your work…but if I could get ahold of your mimecode upgrade, man would I look good here in the belly of the military industrial complex! And you could have the satisfaction of contributing in a small but real way to the defense of our nation! (Aircraft documentation, not bombs!) whaddaya say, pal? :)

  • http://wsop.tecrep-inc.net/ wsop

    You may find it interesting to visit some information about poker games
    - Tons of interesdting stuff!!!

  • Cryptik

    I just updated gd and php to 4.3.10 now the image resize hack as shown above gives me a file not found error (*NOTE only when there is a image attached, it works perfect without an image)

    Any Ideas?

    Cryptik

  • http://www.buyzoloft.us Propecia
  • http://www.buycheapcelebrex.biz Celebrex
  • sumit

    Has anybody fixed the HTML problem? It suspect it shouldn’t be to hard? (php has built in strip functions, doesn’t it)?

    I am keen to hear if somebody has some idea’s or working hacks!