3

I know that fetchmail can be configured to leave mail on the server (usually done with the keep uidl keyword combination), but is there a way to configure it to leave mail on the server for a specified minimum period of time and delete them thereafter?

For example, suppose I want messages to remain on the server for 48 hours after they have been downloaded, and then be deleted on the next fetchmail invocation against that server.

I am mostly interested in solutions that work with POP3.

user
  • 28,901

2 Answers2

2

Short: it doesn't do that.

Long: fetchmail is only designed to do one of these:

  • read entire mailboxes, or
  • read the unread messages from a mailbox

When it has read a message, it can mark this (on the server) as "read". But there is no timestamp associated with this.

The inability to do this is known, and according to a reply on fetchmail users by by Rob MacGregor, probably an FAQ:

That'll be because that's not what Fetchmail was designed to do. Fetchmail is designed to download entire mailboxes or at least the unread messages. Without changes to the source there's no way to download only the seen email.

It also doesn't delete email after N days (I'm pretty sure that's in the FAQ - it certainly used to be).

Thomas Dickey
  • 76,765
0

getmail is the solution, in your case. https://pyropus.ca/software/getmail The linux program getmail can fetch INBOX and/or other folders (in case of IMAP protocol), with or without SSL, and delete email after N days.

Example of getmailrc file, placed in ~/.getmail directory:

[retriever]
type = SimpleIMAPSSLRetriever
server = IMAP_SERVER_CHANGEME
port = 993
username = USERNAME_CHANGEME
password = PASSWORD_CHANGEME
mailboxes = ("INBOX","Junk",)

[destination] type = Maildir path = ~/Maildir/

[options] message_log_syslog = true message_log_verbose = true

retrieve only new emails

read_all = false

delete on server after x days

delete_after = 6

do not add a Delivered-To: header field

delivered_to = false

do not add a Received: header field

received = false