procmail
[Top] [All Lists]

Re: Adding date to file name

1999-06-24 00:35:04
On Wed, 23 Jun 1999 20:16:53 -0700 (PDT), Larry Wright
<lwright(_at_)netcom(_dot_)com> wrote:
On Wed, 23 Jun 1999, era eriksson wrote:
On Sat, 19 Jun 1999 02:53:15 -0700 (PDT), Larry Wright
<lwright(_at_)netcom(_dot_)com> wrote:
I get one message a day from a particular source. I'd like to
send that email message to a different directory as a separate
file, with the file name being the source, with the date
appended in YYMMDD format (example: from JSmith(_at_)hisadd(_dot_)com -->
filename JSmith990612). I'd prefer the date to be the date of
the message, but the local machine date would be OK if easier to
do. How can I add the formatted date, within procmail, to make
the file name?
Grab it out of the From_ line. See recent messages to the list about
this. I also updated the FAQ with an answer to this question. See
<http://www.iki.fi/era/procmail/mini-faq.html>
I checked the past messages & the faq. They mostly address getting
data from the line. As I see it, the problem is in correctly
getting and then formatting the data one would get from the From_
line into YYMMDD format. Any suggestions much appreciated.

Check out Alan Stebbens' Procmail library, it has some functions for
date parsing I believe. There's a copy at the Xoom site (see .sig)
[and I thought there would also be a copy on www.procmail.org, but it
looks like it's not there yet].

... or you can check the archives of this list; try looking for e.g.
jan.feb.mar.apr.may or something like that. (Mental note: this regex
can be optimized to (J(an|u[nl])|Feb|Ma[ry]|A(pr|ug)|Sep|Oct|Nov|Dec)
so it's probably better to search for sep.oct.nov.dec ... except some
of the matches in the archives actually erroneously omit October! :-)
<http://www.rosat.mpe-garching.mpg.de/mailing-lists/procmail/>

Out of the matches I got, the most useful one is probably the oldest,
<http://www.xray.mpe.mpg.de/mailing-lists/procmail/1996-09/msg00143.html>
which has a useful (albeit brute-force) technique for getting the
month number (also, incidentally, by Alan Stebbens).

In a way, it's simpler to just use the same file all the time, and
then rename it to `date +name-%y%m%d` each night out of a cron job.
This may indeed be easier. I'm checking to see if we can run cron -
my recollection is that we are no longer able to do this.

Presumably your admins have a reason for disabling cron for you, but
if you ask nicely they might set one up for you. Or see if you can at
least run at(1) jobs (but probably those will be disabled as well
then).

(Or be a Sunday anarchist: Get a different account where you do get to
run cron, schedule it to send a token mail to this account, where it
gets intercepted by Procmail, which then proceeds to do the actual
processing you want done. :-)

In the near future, the info I need will be in an attachment
(possibly as octet coded text) rather than the msg text. Is there a
way to get the info from the coded attachment, and save it as a
text file with the date?
I don't understand this. But the simple and straightforward answer is
that if you can do it (in this case, extract the data you need from
the attachment) from the Unix prompt, you can do the same thing from
within Procmail.
The info is in a MIME attachment. I can get these from within Pine,
which will write the attachment out as a file. Someone suggested
uudeview, but we don't have that pgm at my ISP. I'm not sure how to
get the attachment text, from the Unix prompt, with what we have.
Any alternative suggestions / pgms much appreciated.

I haven't found any really good attachment-handling tools, but some
basic utilities are available, and you can write your own little Perl
scripts to wrap up the parts (or do the processing in Perl itself,
there's a fancy MIME module for Perl you can use).

See the comp.mail.mime FAQs for pointers (and pointers to pointers to
this info at <http://www.iki.fi/era/procmail/links.html#faqs> :-)

/* era */

-- 
.obBotBait: It shouldn't even matter whether     <http://www.iki.fi/era/>
I am a resident of the state of Washington. <http://members.xoom.com/procmail/>
 * Sign the European spam petition! <http://www.politik-digital.de/spam/en/> *

<Prev in Thread] Current Thread [Next in Thread>