TMCNet:  Post Office 2.0 Plugin for Movable Type

[March 15, 2012]

Post Office 2.0 Plugin for Movable Type

Originally posted on VoIP & Gadgets Blog, here: http://blog.tmcnet.com/blog/tom-keating/movabletype/post-office-20-plugin-for-movable-type.asp.

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. tomkeating+5@tmcnet.com. 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 sspect 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.

Continue reading Post Office 2.0 Plugin for Movable Type...

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

Related Entries
  • Techmeme + Memo Plugin = Blogger Heaven! - Jun 23, 2011
    memo-plugin-techmeme-sample.jpg
  • New CKEditor (FCKEditor) on Movable Type - Mar 01, 2010
    ckeditor-movabletype.jpg
  • Upgraded to Movable Type 4.2 - Jun 13, 2008
  • uPhoneBlog enables Email to Blog Posts - Oct 22, 2007
  • WordPress 2.7 released - Dec 10, 2008
  • Facebook Connect for Movable Type plugin - Dec 05, 2008
    movable-type-facebook-connect-login.png
  • Enabled Comments from AOL/AIM, Yahoo, Movable Type, WordPress, LiveJournal, OpenID, or Vox users - Jun 27, 2008
  • Zemanta on Movable Type - May 21, 2008
  • Email Subscribe to Blog posts - Jan 04, 2008
  • Outlook 2007 Sucks - Jul 30, 2007
  • TrackBacks | Comments | Tag with del.icio.us | VoIP & Gadgets Blog Home | Permalink: Post Office 2.0 Plugin for Movable Type



    [ Back To TechZone360's Homepage ]


    blog comments powered by Disqus