Subject: Re: Piping mail out to Directory(ies)

From: Roman Czyborra <[email-masked]>
Date: Thu, 29 Sep 1994 21:58:00 +0100

> We're getting mail from the ATM-Forum and we need to archive it
> The mail arrives with the following type of subject lines:
> Subject: AF-NNI-LANE-SIG: Subject
> In this examples it needs to go to
> NNI/Subject , LANE/Subject and SIG/Subject
> Is there a way to pipe it out to all the relevant directories ?

I've neither heard of the ATM forum before nor am I sure I've
understood your question.  When you say NNI/Subject you mean the
message's headline should become the filename for the folder?

What is the purpose of your date prefix then?  You want the listing to
be sorted by time of arrival?  When you append them to one big file
this is what you get by default, and if you have them in several
files, you can use ls -t.

Also, one cannot ``pipe to directories''.  The procmail concept of
delivering to directories means to create a separate file for each
message, is that what you want?  Then you should think about
hardlinking each message to the proper directories.

> DATUM=`date +%y%m%d`
> DIRS=`formail -x Subject:  | cut -d : -f 1 | cut -d "-" -f 2-|sed "s/-/ 
> /g"`
> NAAM=`formail -x Subject:  | cut -d : -f 2-|sed -e "s/^[ ]*//" -e "s/[ 
> ]*$//" -e "s/[ ][ ]*/ /g" -e "s/[ ]/_/g"`
>
> :0:
> * Subject:.*AF-
> ${DATUM}__${NAAM}
> 
> :a
> for i in ${DIRS} ; do ; mkdir $i; cp ${DATUM}${NAAM} $i;done; rm 
> ${DATUM}${NAAM} 

The second recipe will not be executed because neither is there a c
flag on the first recipe telling procmail to continue past the
delivery to ${DATUM}__${NAAM} nor is there a pipe symbol saying that
"for i in ${DIRS} ..." is a program to execute instead of a filename.

You might have more luck with this:

DATUM=`date +%y%m%d`
NAAM="`formail -x Subject:`"
SHELL=/bin/sh

	:w:AF.lock
	^Subject: AF-
	| set $NAAM; dirs="$1"; \
	  shift; for word; do title="${title}_${word}"; done;\
	  IFS=-:/; set $dirs; shift; \
	  for dir; do [ -d $dir ] || mkdir $dir; \
	  files="$files $dir/$DATUM_$title"; done;\
	  IFS=' '; exec tee -a $files