I am using procmail to save email body, something like this:
:0: tmpProcmail.lock
* ^From:.*(SOME EMAIL).*
* ^Subject: SOME SUBJECT.*
| cat > /SOME DIRECTORY/$(date +\%Y\%m\%d).txt
I wonder if I can use the whole subject as my filename instead of date.
It doesn't strike me as a particularly good idea, but it's not hard to do. Just use the
\/
capturing token to get the matching text into$MATCH
.You say you save the body, but your recipe doesn't do that; it saves the whole message. (Add a
b
flag if you want only the body in the file.)Also note how I omitted the named lock file (it's more efficient to let Procmail figure out a lock file name in this scenario ... though locking probably deosn't matter all that much if you overwrite the file anyway) and the redundant
.*
in theFrom:
regex. (It's not redundant in the Subject because you want to capture the entire header.)This will of course fail if the Subject contains a slash and you don't have a corresponding directory name on disk.
If you don't want to overwrite, the default is to append, so no
cat
is required or useful.