« Mobile Fun | Main | Phuture Phreaks »

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:

SHELL=/bin/sh
PMDIR=$HOME/procmail
LOGFILE=$PMDIR/pmlog

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

# 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.
MYDIR=/usr/boxes/my_account/mydomain.com/$MYACCOUNT^/.imap


#### 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".
:0:email2gallery.lock
* ^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.
:0
* ^Delivered-To:.*myaccount-mydomain:com-mygatewayemail@mydomain\\.com
/dev/null

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.

Comments

Yah mimesave is pretty bad. I forgot all about ripmime, we left it behind awhile back in our larger scale apps (it misses a lot of the subtler MIME stuff generated by microshaft as you explore it which really doesn't matter for a mobblog app) but I'll take another gander at it. Thanks for the reminder.

Note to all, my scripts at siberian.org are super rough and were tossed together in an afternoon, your mileage may vary, I pretty much built them around a few special cases. They are not secure and do not do the best parsing, they did the job at the time :)

As a security note, anyone doing mobblogging should really make sure their MTA keeps it secure by limiting who can sender and by obsfucating the receiving address. I say that on my webpage and Jon states it as well.

Can't emphasize that enough!

Thanks for the comments, John. I hope I wasn't being too harsh. I didn't mean to be. Obviously I didn't quite know how to do it myself, that's why I was looking at what others had set up.

I might not have even noticed. The pictures were showing up in my album exactly as I wanted them to. Only I went to get MT to talk to Gallery and suddenly I was saying to myself, "Wait a second. These aren't the names of the photos I sent. And my camera takes JPEGs not GIFs."

If you've got a better program in mind than ripmime, I'd love to hear about it.

The next thing I want to try to get going is a caption for the pictures. From what I remember from your code, I think you might have patched galleryadd.pl to support that. So I need to look at that.

Post a comment