Carlos wrote regarding 'Re: [SLE] Removing attachements from stored mails' on Wed, Oct 20 at 06:20:
The Friday 2004-10-15 at 03:21 +0200, Anders Johansson wrote:
This is perhaps something for you:
http://www.oneguycoding.com/opensource/
Second from the top, mimeStrip
Aha! It seems to be what I'm looking for. Unfortunately, I am unable to get it started:
cer@nimrodel:~/bin> ./mimeStrip.pl Can't modify constant item in lock at ./mimeStrip.pl line 58, near "STDIN)" Execution of ./mimeStrip.pl aborted due to compilation errors.
The code in question is:
open(STDIN,"+<$folder") || die "Error: opening input folder $folder\n"; if (!lock(STDIN)) { close(STDIN); printf STDERR "Error: could not lock folder $folder\n"; }
What? Why would this fellow reopen STDIN anyway? The filehandle is only used in one place - the while loop that reads the contents in - and it's explicitly specified in there. It's not like the code takes advantage of the special features of STDIN, like the ability to just say <> rather than <STDIN>. Anyway, you should probably replace STDIN with something that makes more sense anyway, like, perhaps FOLDER_HANDLE. Just a global search and replace oughtta do it. Why is it so hard for people to use reasonable variable names? And why is it so difficult for me to stay on-topic on this list? :) [...]
Commenting out the lock part, I can get it to work. It does strip files like I want. But not from one mailbox, the most important one for this task: it is a small daily publication in pdf I get, in which there is no text, only the attachement (ie, no "parts"). MimeStrip doesn't notice the attachement, unfortunately.
Even Pine complains:
Message 5 has only one part (the message body), and no attachments.
That's probably because there's only one part, and the content type is weird. Full headers would help, but in those, you really just need to parse the mbox (or run through a filter before delivering to the mbox) to separate the messages, then look for the first blank line. That'll be the division between the headers and body. The body then just needs decoded and saved. That should be a pretty simple exercise, I'd think, given some programming skillz. There are perl modules to deal with that, too. I'm not sure why that program doesn't just use one of those, but then, the whole program is structured a bit poorly, IMHO. Note, I posted some code on Aug 10 this year, under the subject "Re: [SLE] KMail question" which will pull the attachments out of messages fed in one at a time. It's a bit more compact and would require some modification for your use, though if you're happy with the somewhat questionable code you're running, that's not too relevent. :) --Danny, a bit full of himself this morning...