How to stop Fetchmail marking messages as read

8,007

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
[email protected]
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
Share:
8,007
Steve HHH
Author by

Steve HHH

A quality assurance developer with a two decades of industry experience and strong interests in Linux, Unix, FreeNAS, Jenkins, FreeCAD, software quality, continuous integration, and automation.

Updated on September 18, 2022

Comments

  • Steve HHH
    Steve HHH almost 2 years

    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 "[email protected]"
        password 'password'
        folder 'INBOX'
        keep
        ssl
        mda "/usr/bin/procmail -f %F"
    
  • Steve HHH
    Steve HHH over 11 years
    No, the keep flag is to prevent fetchmail from deleting the message from the server once it has been downloaded. Indeed, I am using the keep flag, as I want to keep the messages on the server. I'd just like to find a way to keep the "New message" flag too.
  • vonbrand
    vonbrand over 11 years
    And how will fetchmail (or anybody else) know that it already got the message?
  • Steve HHH
    Steve HHH over 11 years
    By keeping track of the message id on the server, the same as an e-mail client would do. For example I would hope that fetchmail would know that it last downloaded message id 394, so if the next time it finds up to message 400, it should download messages 395-400, regardless of their 'unread' flag status. Downloading new messages based only upon the status of the 'unread' flag would be disappointingly simplistic for a tool with such a reputation as fetchmail.
  • vonbrand
    vonbrand over 11 years
    To keep track of the read/unread messages is precisely what the read/unread flag on the message is used for...
  • Steve HHH
    Steve HHH over 11 years
    Indeed. And I'd like to use that flag if possible, so I can keep track of messages that I've read. The problem being that I can't do that any more because fetchmail marks all my messages as read. So what I'd love to be able to do is have fetchmail 'read' my mail without marking messages as read. Take for example, my phone and my desktop e-mail clients. They both 'read' my messages, and can indeed apply mail rules, but neither of them marks messages as read until I've viewed them.
  • Ben
    Ben over 9 years
    I'm pretty sure that's what the uids flag (aka -U) is for, fetchmail would then work with the client to keep a tracked record of messages to download next regardless of the state of the read/unread flag.
  • Ben
    Ben over 5 years
    @Joril damn, that's a shame.