On 12-Mar-09 18:36:33, Chris G wrote:
On Thu, Mar 12, 2009 at 01:34:59PM -0000, Ted Harding wrote:
On 12-Mar-09 13:15:52, Chris G wrote:
Can anyone suggest a neat/easy way to keep only (say) the last seven days of messages in an incoming mail spool?
I have a couple of mail spools where I want to be able to do this, possibly with different 'number of days' expiry.
-- Chris Green
Possibly some MUAs may have a configuration option to "Do [X] to messages in Folder [Y] which are more than [Z] days old", but probably most do not.
In my case, all my Mail folders are in MH format, i.e. each message is a separate file (whose name is a number) in the folder. Therefore I could run a cron job on selected folders, checking the age of each message from its timestamp, and then do with it what I will.
So, for flexibility, maybe think about using MH mail folders?
It is simple with maildir too but the problem is I mean a real Linux/Unix mail spool as in what you find in:-
/var/mail/<name of user>
I don't think these can be maildir can they?
-- Chris Green
True (I overlooked the word "spool" in your query). However, one should still be able to do the same sort of thing, since var/mail/... files are plaintext Unix mbox, which have a straightforward structure which can be parsed.
Namely: The first message starts on the first line of the file with the word "From " at the start of the line (which is why such lines in a message body get changed to ">From ").
Subsequent messages start in the same way, separated by a blank line from the preceding message.
Hence (e.g. with a suitable 'awk' program, or 'perl' if you are that sort of person) you can identify where in the file each message starts and ends, and read its "Date: ".
Then, if it's one that you want to do something with, do it; and delete it (including its preceding blank line, or the following one if it's the first).
It's probably a good idea to work with a copy of the file, and also to lock the real /var/mail file while you're doing it. Then, if the work on the copy succeeds, copy the changed version back over the original.
Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 12-Mar-09 Time: 18:57:57 ------------------------------ XFMail ------------------------------