Fetchmail User wrote:
What I'm looking for is a hack or a trick which would allow "keep"
or "nokeep" to depend on some sort of runtime criteria. ...
The end result of either of these cases would be that some messages
are kept on the remote server after fetchmail retrieves them, and
some are not,
I understand what you're trying to accomplish, but not why? Do you not
trust the data storage on one of the machines involved? Does your
network access let you get to different machines at different times and
you're trying to use fetchmail to work around that?
If you simply want a backup of the most recent 200 messages left on the
server, here is a procmail receipe that would do that.
## ## Copy all incoming mail to the backup directory, just in case
## Note: you must already have a directory named safetynet, and
## the messages will be placed in individual files.
:0 c
safetynet
## Prune the backup directory; keep only the first 200 notes
## to guard against mail loops overflowing the file system
## NOTE: this is a rolling log, so mails aren't kept for long
:0 ic
| cd safetynet && rm -f dummy `ls -t msg.* | sed -e 1,200d`
If you want something more complex and your email source is an IMAP
server, you could probably replace the delete message that fetchmail
sends to the source server. Issue a move command instead, placing your
old incoming messages into a folder that you manage some other way.
This is a simple modification to fetchmail, and would fit into the code
and configuration files much more easily.
To manage the folder with all the copies, I would look at the JavaMail
APIs, and write a small Java program that runs from cron. It can run
anywhere, not just on your source email system.
Alan