How to stop Fetchmail marking messages as read

fetchmailprocmail

When fetchmail checks my IMAP inbox, it downloads any unread messages and removes the message 'unread' flag on the mail server.

Is there a way to have fetchmail download new messages without marking them as read?

I use procmail to automatically process new mail messages and run scripts based upon mail rules, so I want the messages downloaded, but would prefer it if the "new message" flag was preserved on messages I have not yet read in my e-mail client.

This is my .fetchmailrc file:

poll mail.domain.com protocol IMAP
    user "user@domain.com"
    password 'password'
    folder 'INBOX'
    keep
    ssl
    mda "/usr/bin/procmail -f %F"

Best Answer

I could not find a way to preserve or re-instate the 'unread' flag on the server.

In the end, I switched to using getmail, a more modern alternative to fetchmail that's written in Python. Unlike fetchmail, getmail retrieves messages based upon the server's message id rather than the message 'unread' flag.

This is the getmail configuration file I created that provided equivalence to my fetchmail configuration:

# ~/.getmail/getmailrc
# Configuration file to retrieve messages over secure IMAP
# and send them to procmail

[retriever]
type=SimpleIMAPSSLRetriever
server=mail.domain.com
username=user@domain.com
password=password

[destination]
type=MDA_external
path=/usr/bin/procmail

[options]
verbose=0
read_all=false
delete=false
delete_after=0
delete_bigger_than=0
max_bytes_per_session=0
max_message_size=0
max_messages_per_session=0
delivered_to=false
received=false
message_log=~/getmail.log
message_log_syslog=false
message_log_verbose=true
Related Question