procmail recipe for email to gallery (experts only)

jmullan
jmullan's picture

Joined: 2002-07-28
Posts: 974
Posted: Tue, 2003-07-08 01:23

This is a procmail recipe. It goes with your other procmail recipes in your .procmailrc

There might be easier ways to do this, but I use a multi-step process. Each piece may be a little complicated, but they interact in a simple way. You will need procmail, ripmime, and galleryadd.pl.

Here's the flow for my installation:
1) Emails are received by postfix. Sendmail works in a similar fashion.
2) Emails are piped through procmail.
http://www.procmail.org/
3) Procmail checks to see if the email meets certain criteria (subject, sender, etc.)
4) Procmail sends the email to ripmime, which extracts the attachments
http://www.pldaniels.com/ripmime/
5) Procmail then runs galleryadd.pl to put the attachments into the gallery

6) Procmail runs rm to clean up the attachments

7) You can have procmail also run stripmime to remove the attachments from the email if you want to get the email without attachments
http://www.phred.org/~alex/stripmime.html

Let me know if this points you in the right direction. You might even not need procmail. Hmm.

You must customize this to work with your server. You must have procmail, ripmime, and galleryadd.pl already installed and running. I included an example subject match. Don't do this with every message or your target album will probably fill up with spam images.

:0:email2gallery.lock
* ^Content-Type:.*multipart/mixed 
* ^Subject:.*picture
| ripmime -i - -d tempdir/ --syslog_on --paranoid --no_nameless &&\
  galleryadd.pl -l http://gallery -u username -p password -a album tempdir/* &&\
  rm tempdir/*

Then again, maybe you want your spam images.

If you get it working, you could use this to add images emailed from your cell phone, if you have spent the money on that kind of thing. I haven't.

 
loxly

Joined: 2003-01-28
Posts: 126
Posted: Sun, 2003-07-20 04:32

Sorry to sound stupid, but where does this code go?

 
jmullan
jmullan's picture

Joined: 2002-07-28
Posts: 974
Posted: Sun, 2003-07-20 05:13

I updated my message to include more explanation. If it doesn't help, try this other thread, which has an easier method:
http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=7641&highlight=cell

 
kopplin

Joined: 2003-09-12
Posts: 5
Posted: Sun, 2004-07-11 18:33
jmullan wrote:
This is a procmail recipe. It goes with your other procmail recipes in your .procmailrc

:0:email2gallery.lock
* ^Content-Type:.*multipart/mixed 
* ^Subject:.*picture
| ripmime -i - -d tempdir/ --syslog_on --paranoid --no_nameless &&\
  galleryadd.pl -l http://gallery -u username -p password -a album tempdir/* &&\
  rm tempdir/*

Should that be --syslog instead of --syslog_on ? I kept getting errors about can't write to a file until I changed that.

 
jmullan
jmullan's picture

Joined: 2002-07-28
Posts: 974
Posted: Mon, 2004-07-12 03:33

It would appear that you are correct - the changelog for ripmime contains this text:

Quote:
Mon Mar 01 2004
- PLD:DEV:
Removed --syslog_on and --stderr_off paramters from the help dump
(thanks to Mat Williams for noticing this). These paramters have
been deprecated for quite a long time.

 
kopplin

Joined: 2003-09-12
Posts: 5
Posted: Mon, 2004-07-12 06:27

Thank you for galleryadd and the example procmail recipe. After figuring out the --syslog thing I'm now using them along with formail to process mailing list archives with thousands of attached images.

I think I've come across a bug. I was processing one of the archives and started getting HTTP error 500 messages to the console. I finally narrowed it down to one attachment. It seems to be a problem with the filename itself. The ripped file is named Jupiter_01_03_04.jpg

If I run galleryadd.pl on that single file I get

Logging In
Logged In successfully
Fetching list of albums (may be slow)
Fetched list of albums.
Found album 'test'
Uploading image 'Jupiter_01_03_04.jpg'

And then eventually

Could not upload image: HTTP error 500  <HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
500 read timeout
</BODY>
</HTML>

If I change the name to just jupiter.jpg it works fine so it's not the file itself. Changing the underscores to dashes gives the same problem. Using the add photos form in gallery worked ok for either underscore or dash.

 
jmullan
jmullan's picture

Joined: 2002-07-28
Posts: 974
Posted: Mon, 2004-07-12 16:52

I'm not sure what to tell you - do you have this problem with any other file?

Would you mind sending me the file to test?

 
kopplin

Joined: 2003-09-12
Posts: 5
Posted: Mon, 2004-07-12 18:30

This is really odd.

I saved another image file to the name Jupiter-01-03-04.jpg and galleryadd pops it in no problem.That would indicate it's not the filename causing the error. So, I resaved the real image and tried uploading. Error 500. Renamed the file using 'mv Jupiter-01-03-04.jpg Jupiter.jpg' and now galleryadd loads it.

Huh? I'm confused!

As for other files that do this, yes, apparently. I modified the mail archive changing the problem name, but it started throwing errors again at some point. I haven't determined this file yet.

I'll send the Jupiter file shortly.

 
kopplin

Joined: 2003-09-12
Posts: 5
Posted: Fri, 2004-07-16 01:19

I found the source of the problem. It's an obscure bug for sure, but it's there somewhere. In the unlikely event anyone else has a similar problem I will describe what's happening.

I mentioned in my previous posts that a specific file would not upload using galleryadd.pl (timeout error). If the name was changed, the file would load. Or an image with the same name would load. This was reproducible. I found at least one more file that would exhibit the same problem.

Well, turns out the location of the problem is my router. My server sits behind a Dlink router. There are several domains hosted on the server, using name-based virtual hosting. I was attempting to run galleryadd from the server itself to one of these virtual servers. Today I noticed error messages in the logs about the time I was trying to load the file, " do_nat: buffer (1) too small". The domain I was trying to upload to was not in my hosts file, so the requests were going to the router, which is smart enough to loop the requests back to the correct machine on the lan. I've never had any other problems related to this, and the problem would only occur with galleryadd on very specific files. I added the domain to the hosts file so galleryadd contacts the localhost directly. And the problem dissappears, the file uploads correctly. Delete it from the hosts file, the problem comes back. Uploading the offending file to remote hosts also works.

It seems the problem only occurs with specific files, with specific names, when the request has to be routed through the loopback feature of the router.

So, I've avoided the problem by adding the domain to my hosts file, but I am curious if it's a bug in the router with some magical combination of data and filename, or if it's a bug in the galleryremote protocol.

 
drewish

Joined: 2002-08-19
Posts: 16
Posted: Mon, 2004-08-30 19:21

I'm trying to use this from a sendmail alias and having some problems.

The entry in the alias file looks like (i'm copying root for testing purposes):

moblog: root, "|/usr/local/bin/procmail -m /usr/local/etc/procmail/photoblog"

The procmail recipe is:

multivac# more /usr/local/etc/procmail/photoblog
#
# gallery adding
#
:0:email2gallery.lock
* ^Content-Type:.*multipart/mixed
| ripmime -i - -d /tmp/moblog --syslog --paranoid --no_nameless &&\
  galleryadd.pl -noverify -q -l http://drewish.com/gallery/ -u cell -p callme -a moblog /tmp/moblog/* &&\
  rm /tmp/moblog/*

And the error in the maillog is:

Aug 30 11:46:02 <2.6> multivac sm-mta[84144]: i7UIk09A084144: from=<[mycellphone]@vzwpix.com>, size=47162, class=0, nrcpts=1, msg
id=<30279756.1093891508073.JavaMail.root@njbr-j-md-19>, proto=ESMTP, daemon=MTA, relay=smtp.vzwpix.com [66.174.76.42]
Aug 30 11:46:03 <2.6> multivac sm-mta[84144]: i7UIk09A084144: Milter add: header: X-Virus-Scanned: clamd / ClamAV version 0.75
.1, clamav-milter version 0.75c\n\ton multivac.drewish.com
Aug 30 11:46:03 <2.6> multivac sm-mta[84144]: i7UIk09A084144: Milter add: header: X-Virus-Status: Clean
Aug 30 11:46:04 <2.6> multivac sm-mta[84145]: i7UIk09A084144: to="|/usr/local/bin/procmail -m /usr/local/etc/procmail/photoblo
g", ctladdr=<moblog@[my domain name]> (26/0), delay=00:00:03, xdelay=00:00:01, mailer=prog, pri=107524, dsn=5.0.0, stat=Can't creat
e output

It works fine when I call procmail with a test message:cat testmail | /usr/local/bin/procmail -m /usr/local/etc/procmail/photoblog

When I pass that same message through sendmail cat testmail | sendmail moblog
it acts like everything is fine but I get the above errors.

Do you have any idea what's causing that "Can't create output" error?

 
jmullan
jmullan's picture

Joined: 2002-07-28
Posts: 974
Posted: Tue, 2004-08-31 09:24

Perhaps sendmail is running as a user that does not have permissions to write out the files?

 
Randolph Hoppe

Joined: 2006-08-05
Posts: 1
Posted: Sat, 2006-08-05 20:03

I'd like to have graphic attachments sent via different Yahoo Groups uploaded into albums for each group. Are the steps described here still the best starting point? I'm running Gallery2 at http://kirbymuseum.org/gallery/v/groups/ and would welcome any advice/help/pointers.

- Rand

 
jadmanx
jadmanx's picture

Joined: 2005-09-06
Posts: 83
Posted: Mon, 2006-09-11 02:28

i whant pics add via email
how is it worke ?
is there a module i can install ?
please help

http://www.blubbs.com is my page

 
jadmanx
jadmanx's picture

Joined: 2005-09-06
Posts: 83
Posted: Wed, 2006-10-04 11:25

please help ???????

http://www.blubbs.com is my page