A Bit About Gallery Photo Moblogging

It turns out that the email to Gallery gateway that I set up was uglier than I thought. I would strongly recommend not using these scripts to post photos from your camera phone to a webpage. I thought it was just that my implementation of procmail was bad because I didn’t really know what I was doing. Well it was bad, but the scripts aren’t very good either. At least the mimesave.pl one isn’t. I’m still learning Perl so I only have a bit of an idea of what’s going on, but it definitely does a few bad things. I would stay away from it unless you’re willing to rewrite some sections. The parsing of the mime attachments is the real culprit. It decodes the mime attachment and reads the raw data into a new file and generates a random name for it with a .gif extension instead of looking at the actual name of the attached file.

This is a much better way to do it. You’ll need to learn a bit about procmail—though you have to do it with those bad scripts above anyway. Instead of the flakey mimesave.pl script, you use the nice Unix C-program ripMIME. Pair.com, my hosting service, does an amazing job of having many, many programs pre-installed on all their servers. If you look at the list of Perl modules they have installed, it’s staggering. Or at least I think it is. Maybe those are standard on most web servers. I don’t know. Anyway, they already had ripMIME installed so I didn’t have to compile it myself.

Infinite Ink has an amazing starting guide to procmail. I’m certainly no expert now but it taught me enough to set up a couple of proper recipes on a special Gallery gateway email address I created to send pictures from my phone and have them posted to my Gallery webpage. This article by Zig, and this one by Phil, have some nice specifics about dealing with the Qmail mail transfer agent on pair.com and interfacing it with procmail. There’s also a ton of information here at PairUsers—not only about email but pretty much every aspect of anything you might want to do with your website.

This is a simplified version of the ~/.procmailrc file that I setup to handle the email to Gallery gateway:


# prevent qmail (the program that is calling procmail
# as a filter) from delivering the original mail. We'll
# handle all delivery from here, thankyouverymuch.

# This is for support of the virtual mailboxes on pair.com
# The $MYACCOUNT variable is sent to Procmail when it is envoked from Qmail.
# You need to change "my_account" and "mydomain.com" to your own.

#### End Variables section; Begin Processing section ####  

# This is setup for virtual mailboxes on pair.com
# You need to change "myaccount-mydomain:com-mygatewayemail@mydomain.com"
# and "phoneemailaddress" and "http://gallery" and "uname" and
# "pwd" and "album". Also change path to "galleryadd.pl".
* ^Delivered-To:.*myaccount-mydomain:com-mygatewayemail@mydomain.com
* ^Content-Type:.*multipart/mixed
* ^From:.*phoneemailaddress
| ripmime -i - -d $HOME/tempdir/ --syslog_on --no_nameless &&
  ./galleryadd.pl -l http://gallery -u uname -p pwd -a album $HOME/tempdir/* &&
  rm $HOME/tempdir/*

# If email comes in for mygatewayemail and it doesn't match any of the
# rules above, trash it.
* ^Delivered-To:.*myaccount-mydomain:com-mygatewayemail@mydomain.com

As it exists right now, it will only really work for pair.com accounts if you swap out the placeholders I mention in the comments for your own information. Unless there are other web space providers who set up their mail like Pair does. It seems a little unique to me. But the basic idea is there for people at other places. I strongly suggest you go through Infinte Ink’s quick start guide to learn how it works and then compare my recipe to the one that jmullen provided in the link above to see how I had to adapt it to my particular situation.

For extra security, a password system should be implemented as well. But as long as you keep your gateway email address private, this should keep out most spam. You could even add in a check for other headers that might show in email sent from your phone. There are probably a few other bits that would make it a little more unique and a little less possible to spam.