Subject: Re: processing mails from mailing lists?

From: [email-masked] (Hans-Albert Schneider)
Date: Thu, 3 Feb 1994 18:41:41 +0100

On Feb 1, 11:02am, Alexander Kotopoulis wrote
on subject "processing mails from mailing lists?"
} 
} Hi!
} 
} Does anybody use procmail for processing mails from other
} mailing lists, sorting the mail into different folders or
} saving it into directories?

Yes, I do. I have set up a recipe per mailing list that does:

: Options
expressions_to_identify
mails_from_the_list
/file/or/directory/for/archive

e.g.:

	# Constraint Logic Programming
	# (I run a local sublist [with procmail, of course :-)]
	# that archives it), so I do not move it to an arvhive
	# file.
	::
	^X-Mailing-List:.*clp@
	$DEFAULT

	# procmail list.
	# I store it by archive number (derived from
	# the X-Mailing-List: header) to the directory
	# LISTEN/Procmail/New .
	# The script "storeListMail" is added to the end.
	# It prints "moved to archive/file/name" which I capture
	# by the LOG=...
	:
	^X-Mailing-List:.*procmail
	LOG=| storeListMail LISTEN/Procmail/New X-Mailing-List:
		# The variable assignment implies the "c" flag
		# to the above recipe, so:
		:0a
		/dev/null

	# mailagent-3.0 users list
	# Same as above, but different header.
	:
	^X-Sequence: agent-users
	LOG=| storeListMail LISTEN/AgentUsers/New X-Sequence:
		:0a
		/dev/null

	# And this mailing list to a MH like directory:
	# HLSW-people
	::
	[email-masked]
	LISTEN/HLSW-people/.

	# German Sun Users Group.
	# Save to a file. Note the second colon implying the use
	# of a local lockfile.
	::
	^TOsug-info
	sug-info

	# "Gesellschaft fuer Informatik" (GI), Fachgruppe 1.2.1
	# Mail comes
	#	From: fg121@...
	# and has
	#	Subject: FG 1.2.1 mail #48
	:
	^From:.*fg121
	LOG=| storeListMail LISTEN/GI-1.2.1 Subject:
		:0a
		/dev/null

As you can see, the identifying regular expressions may be very
individual: special header lines (like X-Mailing-List: or
X-Sequence:), or just a trivial From: or To:/Cc:/... They need
not be identical to the line containing the mail number, as the
last example shows.

You have to find out for the respective list (in case it is
managed by procmail, it will most probably be X-Mailing-List:).

Here comes my "storeListMail" script:

############### cut here #######################
#!/bin/sh

# Store a Mail message coming through a list
# that has assigned a number to it by that number.

# Arguments:
#	Directory to store the mails in:
directory=$1
#	Which header line contains the number?
#	We assume that the number is the last thin in that line.
header=$2

tmp=/tmp/mail.$USER.$$

cat - > $tmp

number=`formail < $tmp -x "$header" | sed -e 's/.*[^0-9]\([0-9]*\)$/\1/'`

# catch some strange situations:

# No number present:
if [ -z "$number" ]
then	number=$$
fi

# Mail $number already exists:
file=$directory/$number
if [ -f $file ]
then
	file=$file.$$
fi

# Now store the mail
mv $tmp $file

# and produce an output for procmails logfile
echo "moved to $file"
echo ""

exit 0
################# cut here #################

I hope this helps,
	Hans-Albert

--
Hans-Albert Schneider		<[email-masked]>
Siemens AG				phone:	(+49) 89 636 45445
Corporate Research and Development	fax:	(+49) 89 636 42284
Munich, Germany