10

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
  • 683
  • 7
  • 12

2 Answers2

9

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
Steve HHH
  • 683
  • 7
  • 12
-1

My fetchmail(1) cites flags -k, --keep, and option keep to not download the messages.

fetchmail-6.3.22-1.fc18.x86_64, Fedora 18.

vonbrand
  • 18,156
  • 2
  • 37
  • 59
  • 4
    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. – Steve HHH Mar 07 '13 at 23:08
  • And how will fetchmail (or anybody else) know that it already got the message? – vonbrand Mar 07 '13 at 23:11
  • 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. – Steve HHH Mar 07 '13 at 23:24
  • To keep track of the read/unread messages is precisely what the read/unread flag on the message is used for... – vonbrand Mar 07 '13 at 23:37
  • 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. – Steve HHH Mar 07 '13 at 23:55
  • 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 Dec 27 '14 at 08:11
  • @Ben sadly -U is only for POP3, not IMAP :/ – Joril Jan 18 '19 at 10:58
  • @Joril damn, that's a shame. – Ben Jan 27 '19 at 12:06