wp-gallery-mail for Wordpress

By Ian Tomey. For the latest information see this page. Help/support/queries to the forum.

This code based on the wp-mail code by By John B. Hewitt - http://blade.lansmash.com and the original from the Wordpress team.

Overview

wp-gallery-mail is a script to allow you to post entries to your Wordpress blog. This script differs from one supplied with Wordpress as it supports images and files. If an image is found in the email, it is posted to a Gallery album, and a linked thumbnail placed in the blog. Attached files of other types are saved on the server and a link is placed at the bottom of your blog post.

Version History

13 April 2005 0.02

7 April 2005 0.01

Installation

Usage/Features

Supports images that are placed inline or added as attachments, and files as attachments. Files are added to /wp-filez/ directory under /wp-content/ by default, however this can be changed in the configuration file.

Post to different categories in your blog by placing either the name of the category or its number in the subject line, for example "General: This post will go in the General category"

Mail Commands

Mail commands allow you to control things about how the blog entry is posted. These appear on the very first line of the mail and must be in the format #(command: parameters). A newline is optional afterwards, it will be discarded.

Currently supported mail commands:

Command Description Example/Notes
album: xxxxx Change the Gallery album that images will be posted to.

#(album: holiday)
If the album cannot be found or there is an error loading it, the default album will be used instead.

Image Meta Information

Inline images (i.e. images inserted directly into the email) may now have some meta information associated with them. This allows some control over the image and a title to be added. To achieve this, place the meta information in brackets immediately after the image. In the following example we use *image* to represent an image in the post:

*image*(left|border: 2px solid red|A picture of Eric Balls, a retired plumbers mate and his dog called Nuts) This is the text of the post....

Inside the brackets, the various information is broken up by vertical bars, and the final piece of text is the image title (if no image title or meta text is present, then the filename will be used). If you do not wish to specify a different image title to the filename, simply omit any description from the end, but you must be sure to have added the final vertical bar. For example (left|).

Currently supported meta items:

Item Description Example/Notes
left Float the image to the left place the image for floating at the very start of the line of text
right Float the image to the right place the image for floating at the very start of the line of text

border: xxx

Add CSS border style

(border: 2px solid green|This has a 2 pixel solid green border)
See CSS documentation for more information

description: xxx Add a description in the gallery album (description: this is a description|this is the image title)

Example Emails

Example 1

So in the above email we are saying this should be posted in the 'General' category, the Gallery album that the image should be posted in is 'stuff'. The image should be floated to the left, and it's description in the album is going to be "A Roberts 9962". The title of the image is "My worldband radio".

Here is how the image was posted into the blog. Note that the text is rammed up right next to the thumbnail image. See the section on Styles to fix this.

And this is how the image appears inside the Gallery album. 'A Test Post' is a link back to the blog entry.

Styles

As you have seen in the above example, the text surrounding the image is too close. To fix this, you will need to modify your Wordpress theme's stylesheet. Go to the Wordpress site admin > 'Presentation' > 'Theme Editor' and add the following to the stylesheet:

.thumbFromGallery {
padding: 1px;
margin: 2px;
border: 1px solid black;
}

Note that depending on your Wordpress installation and server setup the themes may not be editable from inside Wordpress. Either make the file writable (change the permissions on style.css to 0777) or edit it outside of Wordpress.

Issue/Problems/Notes

A very large chunk of the code for processing has been rewritten from the original wp-mail hack and so may cause formatting or recognition problems with email formats I have not seen. However, it has been tested with posts from Outlook 2003 and Thunderbird 1.02 and a Sony Ericsson T610, all of these work as planned and validate correctly as XHTML 1.0 Transitional through the Kubrick theme.

This script is very memory hungry having to load Wordpress & Gallery plus process potentially large emails. If you are finding the script seems to die, check the error log and see if it ran out of memory. I would suggest a minimum of 16M being available to PHP (which can be set with the php.ini file). I have tweaked some of the code inside mimedecode and the script itself to reduce value copying. Probably using the PECL mail decode functions would be easier on memory (and faster) but it does not seem to be deployed that much so I have avoided using it.

For the latest information on this code see this page. Help/support/queries/suggestions to the forum.