Dup Ver Goto 📝

MBSync Example Config 1

PT2/mail/mbsync mail sync mbsync config does not exist
To
56 lines, 221 words, 1709 chars Page 'ExampleConfig1' does not exist.

The aim here is to download all messages from a given IMAP mailbox. To then delete from the server, move the messages from cur, new, to something like a directory called arc. Then mbsync will notice that the messages have disappeared from new and cur, and expunge them from the server. I generally have email accounts on my webhost to redirect things to, along with forwarding to my main email account. Periodically I want to clear everything out, download it, and stick it on a backup drive where, most likely, it will never be touched again. But if necessary I can search and index locally as I see fit.

Template

IMAPAccount EMAILM
# Address to connect to
Host IMAPHOST
User EMAILA
Pass PASSWORD
# Use TLS
SSLType IMAPS
# The following line should work. If you get certificate errors, uncomment the two following lines and read the "Troubleshooting" section.
CertificateFile /etc/ssl/certs/ca-certificates.crt

IMAPStore EMAILM_remote
Account EMAILM

MaildirStore EMAILM_local
SubFolders Verbatim
Path ~/Mail/EMAILA
Inbox ~/Mail/EMAILA/Inbox

Channel EMAILM_ch
Far :EMAILM_remote:
Near :EMAILM_local:
Patterns *
Expunge Far

Python Helper

#!/usr/bin/env python
template = open("template.mbsyncrc").read()
import sys
import os
imaphost = os.getenv("IMAPHOST","my.domain.com")
args = sys.argv[1:]
import re
for arg in args:
  email,password = arg.split(":")
  emailm = re.sub(r"[^A-Za-z0-9]","_",email)
  output = template.replace("EMAILA",email).\
    replace("EMAILM",emailm).replace("PASSWORD",password).\
    replace("IMAPHOST",imaphost)
  with open(f"{email}.mbsyncrc","wt") as f:
    print(output,file=f)
    os.makedirs(email,exist_ok=True)
    print(f"Made {email}")