Tokyo Tidbits Technical How-to
Author: Dav Coleman, Tokyo Tidbits Webguy
Mie takes photos with her keitai, attaches them to an email, and sends it to a secret email address at TokyoTidbits.com, my server located in San Francisco. This server is both the web host and the mail host for TokyoTidbits.com. It is running sendmail and procmail. A procmail rule recognizes the email address of the incoming mail and passes it to a script called blogpost.pl. The blogost.pl script takes the photos from the email and stores them in the web space for Tokyo Tidbits then posts the photos and text to the blog page using to Moveable Type XML-RPC interface.
More Detailed Overview
This tells sendmail that any incoming email addressed to s3cr3tbl0gp0st@TokyoTidbits.com should be delivered to the (already existing) user named 'mie'. Note, after adding the line to /etc/aliases remember to run newaliases at the command line so that sendmail will re-read the /etc/aliases file.
You should send a test email to this new address to make sure it gets delivered to the intended user.
Copy the blogpost.pl script to your server and make sure it is marked executable. This script is something I wrote, and you can get it here. You can install it wherever you like, for instance in /home/mie. Use chmod a+rx blogpost.pl to make it executable.
You need to have the perl MIME::Explode and XMLRPC::Lite modules installed. You can get them at CPAN. If your local perl installation has the CPAN utility installed this can be done trivially by running 'cpan' at the server command prompt (as root) and then 'install module name' at the cpan prompt (like 'install MIME::Explode').
Note that I have another script which attempts to translate the special Japanese characters in Mie's emails into the appropriate UNICODE HTML entities. If you don't need that then edit the blogpost.pl script and take out the necessary lines. Do a find in the script for the word NOTICE (it is in two places) and delete the three indicated lines.
Create a blogpostrc script which tells blogpost.pl how to post to the intended moveable type blog. It will look something like this:
blogurl = http://www.TokyoTidbits.com/ blogxmlrpc = http://www.TokyoTidbits.com/blog/mt-xmlrpc.cgi blogimgurl = http://www.TokyoTidbits.com/cellposts output_dir = /home/www/tokyotidbits.com/cellposts bloguser = mie blogpass = mypassword blogid = 1 defaulttitle = new cell post defaultbody = no comment
You need to create the output_dir (in this case /home/www/tokyotidbits.com/cellposts) and a subdirectory called default (or in this case /home/www/tokyotidbits.com/cellposts/default). This is where the blogpost.pl script will store the attachments that it gets from the emails, so the directory should be accessible vie the web server and the blogimgurl value needs to be set to the URL for that directory. The xmlrpc cgi will be located in the same directory as the rest of your MT cgi's. The blogid is the MT blog number for the blog you want to post to. You can see it in the URL when you log into the admin scetion for your MT blog.
You should set the blogpostrc file to be readable only by you (in this example, by the user 'mie') by doing a chmod go-rwx blogpostrc, since it has the blog posting password in it.
Now, you tell procmail to use blogpost.pl and blogpostrc to do the posting whenever the proper email comes in. To do this create or edit your ~/.procmailrc file to include a three line rule like this:
:0: * ^TOs3cr3tbl0gp0st |/home/mie/blogpost.pl -c/home/mie/blogpostrc
That should do it.
You can get fancier with the procmailrc rules, like add a check of the FROM address as an extra level of security (the way it is above, if anyone guesses the secret email address, they can post to the blog too!),
or add more email addresses and multiple blogpostrc files (just give them differnt filenames) that post to other blogs or different categories (you can specify the posting category in blogpostrc too)
but I'll leave that up to you to figure out.