fetchmail-friends
[Top] [All Lists]

Re: [fetchmail]Selective deletion of email from remote server?

2002-05-05 10:11:55
On Sun, May 05, 2002 at 09:53:49AM +0100, Alan Peery wrote:
Fetchmail User wrote:

[ ... ]

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?

Here is why:

I have a number of email accounts in various places.  I also manage
a server.  On this server, I want to retrieve the email from these
various accounts, and redistribute it to local (to the server)
accounts that I use for various purposes.  So far, so good:
fetchmail works splendidly for this purpose.

However, sometimes I don't have access to my server, only to the
other, remote accounts.  In these somewhat infrequent cases, I want
to be able to connect to these other accounts and read my recent
email. Therefore, I use fetchmail's "keep" option, so that the email
remains on these other servers.  In other words, I want the email to
remain on the various remote accounts, NOT in some backup account on
my own server.

However, I don't want to keep the mail on these remote sources
forever.  5-7 days of backlog is plenty.  That's why I want some
sort of conditional "keep" functionality, which would allow me to
program how much backlog I want on each of these servers.

I know that I could write something in Java, Python, Perl, Ruby, and
no doubt any number of other languages to periodically run on my
server to attach via IMAP or POP3, as appropriate, to each of these
remote mail sources and clean up the backlog.  I'm willing and able
to do this.

However, before starting a project like that, I was wondering if
there was a way to get fetchmail to perform this task, since it
already has the ability to do most of it.  I was also wondering if
perhaps someone had already figured out a trick to get fetchmail to
do this, or perhaps submitted some kind of unofficial patch for this
purpose.

Perhaps a new option, maybe called something like "keepfor" and
which takes a duration parameter, might be added to fetchmail.  I'm
willing to take on this task, if there is any interest in this
functionality besides my own.

But if not, I'm glad to go off and tackle this problem in a
different way.  Just thought I'd check here first, to see if perhaps
there was already some work done in this area, or some interest
in this capability.



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



_______________________________________________
Fetchmail-friends mailing list
Fetchmail-friends(_at_)lists(_dot_)ccil(_dot_)org
http://lists.ccil.org/mailman/listinfo/fetchmail-friends