Re: How mutt check to download emails from an imap server without downloading them more than once?

2023-03-19 Thread Cameron Simpson

On 19Mar2023 09:52, Peng Yu  wrote:

I use the following python code to download UNDELETED messages. But it
will fetch all messages without considering whether an message has
been downloaded previously. How does mutt solve this problem to only
download the emails that have not been downloaded before.


Mutt knows the message-ids of messages in the current mailbox. Skip 
those message-ids.


Cheers,
Cameron Simpson 


How mutt check to download emails from an imap server without downloading them more than once?

2023-03-19 Thread Peng Yu
Hi,

I use the following python code to download UNDELETED messages. But it
will fetch all messages without considering whether an message has
been downloaded previously. How does mutt solve this problem to only
download the emails that have not been downloaded before.

import email
with IMAPClient(host=host) as client:
  client.login(user, passwd)
  client.select_folder('INBOX', readonly=True) # preserve the \Recent flag.
  messages = client.search(search_criteria) # UNDELETED
  response = client.fetch(messages, ['RFC822'])
  for message_id, data in response.items():
with open('%s/%d.eml' % (outdir, message_id), 'wb') as f:
  f.write(data[b'RFC822'])

-- 
Regards,
Peng