Post Office 2.0 Plugin for Movable Type

Tom Keating : VoIP & Gadgets Blog
Tom Keating
CTO
| VoIP & Gadgets blog - Latest news in VoIP & gadgets, wireless, mobile phones, reviews, & opinions

Post Office 2.0 Plugin for Movable Type

Movable Type has a plugin called Post Office (now maintained on Github by Endevver) which is a cool email-to-blog (moblogging) Perl-based plugin. I wrote my own email-to-blog Perl script years ago, which has some advanced features like support for both images and videos in your email attachments. However, the script would run via a Linux bash shell and executed via a scheduled cron job. Because of that, for each Movable Type user that needed this feature I need to copy the Perl script to a new .pl Perl file and change the 'static' variables (email address, MT XML-RPC password, etc.). It was becoming a pain to maintain, since any new features or code I added had to be manually done to each Perl script.

Enter Post Office! I tested this plugin about a year ago, but it didn't do everything I wanted, including lack of support for video attachments, which my Perl code did support. But PostOffice did have some cool features and it directly integrated into the Movable Type platform, so it is multi-user friendly. I decided to integrate my Perl code into Post Office 1.1 -- and since it truly is a forked version I'm calling it Post Office 2.0 to avoid any confusion.

My original Perl code had a ton of regular expressions (regex) to strip out Word gobblygook that gets added to Word-based email. I also had to strip some stuff out of HTML-based emails as well. The code wasn't pretty, but it did the job. Post Office handles Word- and HTML-based emails automatically, thus negating all my man hours of regex programming work. cry_smile All via a simple Perl module (Email::MIME) too.

In any event, here's what's new in Post Office 2.0. over Post Office 1.0/1.1.

New Features:

  • Images are now imported into MT Asset Management database, so they can be used in a slideshow, search results, etc. {Note: PostOffice v1.1 added this feature too}
  • Videos are also now imported into MT Asset Management database.
  • Both images and videos are now stored in /images/YYYY/MM dated folders instead of a single directory like PostOffice 1.0 & 1.1.
  • Ability for each blogger to set a maximum image width so they don't 'blow' out their blog layout with an image that is too wide.
  • Images are resized automatically if larger than maximum width
  • Detect html or text email format and set the line breaks for the entry automatically. {Credit: Alex Teslik www.acatysmoof.com}
  • Process message parts in a single loop (instead of two loops as in 1.1) while still replacing cid and loc links with the correct asset. The structure allows for future modifications, such as the automatic embedding of videos, audio files, etc. {Credit: Alex Teslik www.acatysmoof.com}
  • Auto-rotate email images based on EXIF tags. Originally I was running this cron job to auto-rotate all images based on EXIF data:
    /usr/bin/jhead -autorot -ft /var/www/html/blog/tom-keating/images/*
    But the code above has to process every image each time even if it has been rotated already. Now I can rotate images with PostOffice using Image::ExifTool. This allows iPhone and iPad users to mail images to their blog and have them appear correctly. The EXIF tag is updated after rotation so that Mobile Safari and some other browsers do not rotate the image again based on the EXIF orientation tag.
  • Disabled plus style email addressing used by PostOffice 1.0 and 1.1, which expects email addresses using the format emailaddress+{blogid}@domain.com, i.e. [email protected]. However, since most email servers DO NOT support plus-style addressing, this was preventing me from getting this plugin to work with Exchange Server 2010. I commented out the code, so you can re-enable it if you wish, though I suspect most will prefer it disabled.

Probably the most interesting modification I made was allowing each blog to specify the maximum image width within the PostOffice plugin settings. My code then resizes it accordingly. Here's the code snippet:

#Get Dimensions
my ($globe_x, $globe_y) = imgsize($file->{path});
## added this to debug a divide by zero, but problem is the globe vars 'sometimes' can't figure out image size.
$globe_y=$globe_y+1; # so don't get divide by zero error.
my $ratio = 0;
# Now set ratio = to the width you want
$ratio=$cfgglobal->{max_image_width}; #TK Get blog-level max image width

my $ratio2 = ($ratio / $globe_x) * $globe_y;
if (($globe_x < $ratio)){
  }else{
        #Above leaves image alone - no resize. Else does resize here:
        $img2->Resize(width=>$ratio, height=>$ratio2);
        #Here is where it writes the resized image
        $img2->Write(filename=>$file->{path}, compression=>'JPEG', quality=>75);
       }
         } #End If image

How to set it up

First, let's take a look at the PostOffice plugin settings (per-blog):
post-office-20-plugin-settings.jpg

Put in your POP3 or IMAP accounts settings and credentials. Then choose whether posts are Draft or Published. Make sure to put in the maximum width. I don't test for a null value in the plugin, so if you send an email-to-blog without the max image size defined, it most likely won't post.

Now all you have to do is send an email using this format:

Format for Subject:
[Category name] Headline #tag1 #tag2 #tag3 #tag(etc)

Example:
[Skype] Skype spun off from Microsoft #skype #voip #microsoft #p2p

If you leave the brackets / category name blank, NO category will be assigned.

Format for body:
Plain text or HTML should work. You can use Word-formatted HTML Outlook emails, iPad emails, iPhone emails, Android emails, or whatever email client you use.

You can even embed images in the Outlook message body OR attach as files. The benefit of embedding in the HTML email within Outlook is you can place / position images where you want them. Attached images always appear at the bottom.

Essentially, Outlook COULD become your WYSIWYG editor since it’s essentially running Word. I do strip <div> tags, but other stuff like bullets and tables *should* work.

Any email client should work, but a special note about attaching multiple images when using an iPhone or iPad. You can use iOS's multiple select photos feature and Copy/Paste into an email. Screenshot of multiple select / Copy:
iphone-multiple-select-photos.PNG

The only small caveat is you cannot put text captions in-between the photos after you paste photos in the message body. Any text you add is placed at the TOP of the blog entry when published. This is because the images are ATTACHED and not embedded (cid) into the message body.

Thus, if you want to caption each photo or have full paragraphs of body text in-between each photo, you simply have to copy/paste one photo at a time from the iPhone/iPad Camera Library into a draft email. Then the image is truly embedded and not an attachment. You can write an entire blog post with multiple images and use your iPhone/iPad as your editor. But if you simply want to post a lot of photos quickly with no text, you can use the multiple select option.

Future features:

  • Support for spaces tags in Subject line, i.e.: #ip communications, #windows 8 [will likely require comma as tag separator]
  • Support for default category if unassigned
  • If using IMAP I may specify a specific folder to monitor, i.e. BlogEmails. This way, you don't have to setup a separate 'dummy' email account to use. You can use your regular email account. Then you just setup an email (Outlook) rule that moves an inbound email with certain email-to-blog characteristics to this BlogEmails folder.

Download my forked PostOffice 2.0 plugin. (Note: I may upload this to Github eventually) - Update - my latest PostOffice version is now on Github.

Hope you enjoy my version of the Post Office moblogging plugin for Movable Type. If you're using my version, have feedback or issues, just post a comment.



Related Articles to 'Post Office 2.0 Plugin for Movable Type'
movable-type-logo.jpg
memo-plugin-movable-type-setting.jpg
ckeditor-movabletype.jpg
wordpress-auto-update.jpg
Featured Events