One Company for all your I.T. needs

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}
  • 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}
  • 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}, i.e. 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)){
        #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):

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.

Continue reading Post Office 2.0 Plugin for Movable Type…

Tags: , , , , , , , , , ,
Related tags: , , , , ,

Related Entries

  • Techmeme + Memo Plugin = Blogger Heaven!Jun 23, 2011
  • New CKEditor (FCKEditor) on Movable TypeMar 01, 2010
  • Upgraded to Movable Type 4.2Jun 13, 2008
  • uPhoneBlog enables Email to Blog PostsOct 22, 2007
  • WordPress 2.7 releasedDec 10, 2008
  • Facebook Connect for Movable Type pluginDec 05, 2008
  • Enabled Comments from AOL/AIM, Yahoo, Movable Type, WordPress, LiveJournal, OpenID, or Vox usersJun 27, 2008
  • Zemanta on Movable TypeMay 21, 2008
  • Email Subscribe to Blog postsJan 04, 2008
  • Outlook 2007 SucksJul 30, 2007
  • TrackBacks
    | Comments | Tag with | VoIP & Gadgets Blog Home | Permalink: Post Office 2.0 Plugin for Movable Type

    Copyright VoIP & Gadgets Blog

    Call Center Outsourcing Community Virtual Contact Center
    Sponsored by the Call Center Outsourcing Community & the Virtual Contact Center Outsourcing Community