Carlos wrote regarding 'Re: [SLE] Removing attachements from stored mails (or my problems with perl)' on Sun, Oct 31 at 06:04:
The Saturday 2004-10-23 at 01:53 +0200, Carlos E. R. wrote:
The Thursday 2004-10-21 at 10:28 -0500, Danny Sauer wrote:
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 [...] I'm trying to use your code. I call it thus:
formail -s stripattach < mbox_file.
But it complains that "Can't locate Email/MIME.pm ". You did mention that:
|> You'll have to install Email::MIME and |> Email::MIME::Attachment::Stripper from CPAN.
So, I start downloading things from CPAN (actually, from a mirror at perl.com you mentioned). I download Email-MIME-1.8.tar.gz and try to
Ok, this is *way* easier if you use the CPAN shell. Get yourself set up as a user who can install perl modules (typically this means root), and type perl -MCPAN -e'shell' Answer the questions, and type install Email::MIME::Attachment::Stripper (for example). The cpan module will take care of installing the module and whatever modules are required. If you say "follow" rather than the default of "ask" when the CPAN setup prompts you about how to handle dependencies, you won't even have to say "yes" when it asks to download the deps. Overall the CPAN shell is super nice.
Now, test your code [...] ¡It works! :-)
Well, that much is good. :)
Well, it doesn't put a text saying that the file was removed. Probably I can live with that, at least for the set of mails I want to handle.
Pull the body off, stick a line at the end, reattach the body. Or, add a new text attachment whose contents are "file $filename removed", etc. :) Hooray for having the source code, eh?
Some of the files have repeated names... now, that is a problem. I could prepend, for example, the email date :-?
So, I add the line:
my $from_header = $mail_parsed->header("Date");
But the date is in the format. "Fri, 24 Jan 2003 10:32:04 +0100". I would need to modify it to something like an ISO date: 2004-01-24
¿Is that doable? I suppose there are ready made functions for that kind of string manipulation, but I don't even know how can I browse an index of all functions (modules) available, preferably in hierarchical sort. [...]
You probably want to look at Date::Parse for that. It works quite well. For finding modules, I usually use http://search.cpan.org/ (though that particular module is one that I use often for log parsing, etc).
Yes, "info perl" says to look at "perlintro", but I get "not found". There is only "perldoc", which assumes I already know what module I want to look at. [...] Mmmm.... there is a "man perlintro". Is that it? Not a browsable help? Pfff. :-(
The perl documentation is viewable using the perldoc program, which functions similarly to man or info. So, "perldoc perlinfo" is what you're looking for as a start. If you do a "man perl", you'll get a list of lots of other docs that are also included, those sections are further described under "perldoc perltoc". Most of the time, the main perl docs are also installed as man pages, so you can do things like "man perlintro", or, for a nice read, "man -t perlintro | lpr". The perldsc page and the perlfaq pages should be mandtory reading, and the prelretut page will do wonders for the regexp uninitiated. Finally, read perlstyle, and start most any program out with #!/usr/bin/perl -w use strict; That'll really encourage clean, reliable code. Oh, and you'll likely want perlcheat located nearby for a while. :) --Danny, willing to take this off-list if no one else cares ;)