UP | HOME
Kristian Alexander P

Kristian Alexander

Free Software Enthusiast | GNU Emacs User

Mail Configuration Using msmtp, offlineimap, and notmuch

Published on Mar 23, 2022 by Kristian Alexander P.

notmuch1.png
notmuch2.png

Mail

As per other posts in this blog, this is my actual configuration used in various machines. One benefit I can think of is with this setup is that I can use different clients1, of course here I’m using notmuch-emacs. I have four accounts configured in this setup:

  1. Gmail My primary account.
  2. Yahoo My “bulk” mail, usually for subscribing to news, mailing lists and such.
  3. Hotmail A.K.A windowslive. Not used often but still needed for connecting to ms stuffs.
  4. ymail Few mailing lists and stuffs.

msmtp

Configuration can be stored in ~/.msmtprc or ~/.config/msmtp/config.

# Set default values for all following accounts.
defaults
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        ~/.local/share/mail/msmtp.log
aliases        /etc/aliases

# Gmail
account        gmail
host           smtp.gmail.com
port           587
from           alexarians@gmail.com
user           alexarians
passwordeval   "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.local/etc/mail/mailpass-gmail.gpg"

# Yahoo service
account        yahoo
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
host           smtp.mail.yahoo.com
port           587
from           alexforsale@yahoo.com
user           alexforsale
passwordeval   "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.local/etc/mail/mailpass-yahoo.gpg"

# Hotmail
account        hotmail
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
#tls_certcheck  off
host           smtp-mail.outlook.com
port           587
from           christian.alexander@windowslive.com
user           christian.alexander@windowslive.com
passwordeval   "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.local/etc/mail/mailpass-hotmail.gpg"

# Ymail service
account        ymail
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
host           smtp.mail.yahoo.com
port           587
from           christian.alexander@ymail.com
user           christian.alexander@ymail.com
passwordeval   "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.local/etc/mail/mailpass-ymail.gpg"

# Set a default account
account default : yahoo

To easily encript the files in ~/.local/etc/mail/, open the file in Emacs and save it with .gpg extension, if you’ve setup gpg(see arch wiki for that) it’ll prompt you for the key to encrypt. Another option is to use password-store to store the password, details also in arch wiki.

CANCELLED isync

  • State “CANCELLED” from [2022-03-29 Tue 21:12]

For a while, isync works greate for me, but synchronizing around 86000 emails took a while, which meant using imapnotify is kinda pointless (I need to manually kill and restart mbsync to pull new mails). I’m keeping this configuration here just in case I need to revert back. This is what I configured in ~/.mbsyncrc:

IMAP Account

This set up the necessary information on connecting to the IMAP server.

IMAPAccount gmail
# Address to connect to
Host imap.gmail.com
User alexarians@gmail.com
# Pass ***************
# To store the password in an encrypted file use PassCmd instead of Pass
PassCmd "gpg -q --for-your-eyes-only --no-tty -d ~/.local/etc/mail/mailpass-gmail.gpg"
#
# Use SSL
SSLType IMAPS
# The following line should work. If get certificate errors, uncomment the two following lines and read the "Troubleshooting" section.
CertificateFile /etc/ssl/certs/ca-certificates.crt
#CertificateFile ~/.cert/imap.gmail.com.pem
#CertificateFile ~/.cert/Equifax_Secure_CA.pem

IMAPAccount yahoo
Host imap.mail.yahoo.com
User alexforsale@yahoo.com
PassCmd "gpg -q --for-your-eyes-only --no-tty -d ~/.local/etc/mail/mailpass-yahoo.gpg"
SSLType IMAPS
CertificateFile /etc/ssl/certs/ca-certificates.crt
PipelineDepth 10

IMAPAccount ymail
Host imap.mail.yahoo.com
User christian.alexander@ymail.com
PassCmd "gpg -q --for-your-eyes-only --no-tty -d ~/.local/etc/mail/mailpass-ymail.gpg"
SSLType IMAPS
CertificateFile /etc/ssl/certs/ca-certificates.crt
PipelineDepth 10

IMAPAccount hotmail
Host imap-mail.outlook.com
User christian.alexander@windowslive.com
PassCmd "gpg -q --for-your-eyes-only --no-tty -d ~/.local/etc/mail/mailpass-hotmail.gpg"
SSLType IMAPS
CertificateFile /etc/ssl/certs/ca-certificates.crt

Gmail

IMAPStore gmail-remote
Account gmail

MaildirStore gmail-local
SubFolders Verbatim
# The trailing "/" is important
Path /home/alexforsale/.mail/gmail/
Inbox /home/alexforsale/.mail/gmail/Inbox

Channel gmail-trash
Far :gmail-remote:"[Gmail]/Trash"
Near :gmail-local:trash
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel gmail-sent
Far :gmail-remote:"[Gmail]/Sent Mail"
Near :gmail-local:sent
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel gmail-drafts
Far :gmail-remote:"[Gmail]/Drafts"
Near :gmail-local:draft
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel gmail-allmail
Far :gmail-remote:"[Gmail]/All Mail"
Near :gmail-local:archive
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel gmail-spam
Far :gmail-remote:"[Gmail]/Spam"
Near :gmail-local:spam
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel gmail-other
Far :gmail-remote:
Near :gmail-local:
Patterns * "![Gmail]/*" "!trash*" "!sent*" "!draft*" "!archive*" "!spam*" "!INBOX" "!Inbox"
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel gmail-inbox
Far :gmail-remote:INBOX
Near :gmail-local:Inbox
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Group gmail
Channel gmail-inbox
Channel gmail-sent
Channel gmail-drafts
Channel gmail-trash
Channel gmail-allmail
Channel gmail-other
Channel gmail-spam

Yahoo

IMAPStore yahoo-remote
Account yahoo

MaildirStore yahoo-local
SubFolders Verbatim
Path /home/alexforsale/.mail/yahoo/
Inbox /home/alexforsale/.mail/yahoo/Inbox

Channel yahoo-draft
Far :yahoo-remote:Draft
Near :yahoo-local:draft
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel yahoo-trash
Far :yahoo-remote:Trash
Near :yahoo-local:trash
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel yahoo-sent
Far :yahoo-remote:Sent
Near :yahoo-local:sent
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel yahoo-spam
Far :yahoo-remote:"Bulk Mail"
Near :yahoo-local:spam
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel yahoo-archive
Far :yahoo-remote:Archive
Near :yahoo-local:archive
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel yahoo-other
Far :yahoo-remote:
Near :yahoo-local:
Create Both
Patterns *"!Draft*" "!draft*" "!Trash*" "!trash*" "!Sent*" "!sent*" "!Bulk Mail*" "!spam*" "!Archive*" "!archive" "!INBOX*" "!Inbox*"
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel yahoo-inbox
Far :yahoo-remote:INBOX
Near :yahoo-local:Inbox
Create Near
SyncState *
CopyArrivalDate yes

Group yahoo
Channel yahoo-spam
Channel yahoo-inbox
Channel yahoo-draft
Channel yahoo-sent
Channel yahoo-archive
Channel yahoo-trash
Channel yahoo-other

Hotmail

IMAPStore hotmail-remote
Account hotmail

MaildirStore hotmail-local
SubFolders Verbatim
Path /home/alexforsale/.mail/hotmail/
Inbox /home/alexforsale/.mail/hotmail/Inbox

Channel hotmail-sent
Far :hotmail-remote:Sent
Near :hotmail-local:sent
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel hotmail-inbox
Far :hotmail-remote:INBOX
Near :hotmail-local:Inbox
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel hotmail-archive
Far :hotmail-remote:Archive
Near :hotmail-local:archive
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel hotmail-trash
Far :hotmail-remote:Deleted
Near :hotmail-local:trash
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel hotmail-draft
Far :hotmail-remote:Drafts
Near :hotmail-local:draft
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel hotmail-spam
Far :hotmail-remote:Junk
Near :hotmail-local:spam
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel hotmail-notes
Far :hotmail-remote:Notes
Near :hotmail-local:notes
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel hotmail-outbox
Far :hotmail-remote:Outbox
Near :hotmail-local:outbox
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel hotmail-other
Far :hotmail-remote:
Near :hotmail-local:
Patterns * "!Sent*" "!sent*" "!INBOX*" "!Inbox*" "!Archive*" "!archive*" "!Deleted*" "!trash*" "!Drafts*" "!draft*" "!Junk*" "!spam*" "!Notes*" "!notes*" "!Outbox*" "!outbox*"
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Group hotmail
Channel hotmail-inbox
Channel hotmail-sent
Channel hotmail-archive
Channel hotmail-trash
Channel hotmail-draft
Channel hotmail-spam
Channel hotmail-notes
Channel hotmail-other

Ymail

IMAPStore ymail-remote
Account ymail

MaildirStore ymail-local
SubFolders Verbatim
Path /home/alexforsale/.mail/ymail/
Inbox /home/alexforsale/.mail/ymail/Inbox

Channel ymail-spam
Far :ymail-remote:"Bulk Mail"
Near :ymail-local:spam
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel ymail-draft
Far :ymail-remote:Draft
Near :ymail-local:draft
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel ymail-inbox
Far :ymail-remote:INBOX
Near :ymail-local:Inbox
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel ymail-sent
Far :ymail-remote:Sent
Near :ymail-local:sent
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel ymail-trash
Far :ymail-remote:Trash
Near :ymail-local:trash
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel ymail-archive
Far :ymail-remote:Archive
Near :ymail-local:archive
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Channel ymail-other
Far :ymail-remote:
Near :ymail-local:
Patterns * "!INBOX*" "!Archive*" "!Sent*" "!Bulk Mail*" "!Draft*" "!Trash*" "!Inbox*" "!archive*" "!sent*" "!spam*" "!draft*" "!trash*"
Create Both
CopyArrivalDate yes
Sync All
Remove Both
Expunge Both
SyncState *

Group ymail
Channel ymail-inbox
Channel ymail-spam
Channel ymail-draft
Channel ymail-sent
Channel ymail-trash
Channel ymail-archive
Channel ymail-other

Run mbsync -Va for verbose logging to stdout. After that you could create a systemd user unit, or use goimapnotify to get push notification(almost?).

afew

header-args: :tangle ~/.config/afew/config :mkdirp t

It’s an initial tagging script for notmuch.

SpamFilter

spam_tag = <tag>

  • Add <tag> to all mails recognized as spam.
  • The default is spam.
  • You may use it to tag your spam as junk, scum or whatever suits your mood. Note that only a single tag is supported here.

I’m just using the defaults here.

[SpamFilter]

KillThreadsFilter

If the new message has been added to a thread that has already been tagged killed then add the killed tag to this message. This allows for ignoring all replies to a particular thread.

[KillThreadsFilter]

ArchiveSentMailsFilter

Emails filtered by this filter have the new tag removed, so will not have the inbox tag added by the InboxFilter.

[ArchiveSentMailsFilter]

SentMailsFilter

sent_tag = <tag>

  • Add <tag> to all mails sent from one of your configured mail addresses.
  • he default is to add no tag, so you need to specify something.
  • You may e.g. use it to tag all mails sent by you as sent. This may make special sense in conjunction with a mail client that is able to not only search for threads but individual mails as well.
[SentMailsFilter]
sent_tag = sent

FolderNameFilter

[FolderNameFilter]
folder_lowercases = true
maildir_separator = /

For each email, it looks at all folders it is in, and uses the path and filename as a tag, for the email. So if you have a procmail or sieve set up that puts emails in folders for you, this might be useful.

  • folder_explicit_list = <folder list>
    • Tag mails with tag in <folder list> only. <folder list> is a space separated list, not enclosed in quotes or any other way.
    • Empty list means all folders (of course blacklist still applies).
    • The default is empty list.
    • You may use it e.g. to set tags only for specific folders like Sent.
  • folder_blacklist = <folder list>
    • Never tag mails with tag in <folder list>. <folder list> is a space separated list, not enclosed in quotes or any other way.
    • The default is to blacklist no folders.
    • You may use it e.g. to avoid mails being tagged as INBOX when there is the more standard inbox tag.
  • folder_transforms = <transformation rules>
    • Transform folder names according to the specified rules before tagging mails. <transformation rules> is a space separated list consisting of folder:tag style pairs. The colon separates the name of the folder to be transformed from the tag it is to be transformed into.
    • The default is to transform to folder names.
    • You may use the rules e.g. to transform the name of your ‘Junk’ folder into your ‘spam’ tag or fix capitalization of your draft and sent folder:

      folder_transforms = Junk:spam Drafts:draft Sent:sent
      
  • folder_lowercases = true
    • Use lowercase tags for all folder names
  • maildir_separator = <sep>
    • Use <sep> to split your maildir hierarchy into individual tags.
    • The default is to split on .
    • If your maildir hierarchy is represented in the filesystem as collapsed dirs, <sep> is used to split it again before applying tags. If your maildir looks like this:

      [...]
      /path/to/maildir/devel.afew/[cur|new|tmp]/...
      /path/to/maildir/devel.alot/[cur|new|tmp]/...
      /path/to/maildir/devel.notmuch/[cur|new|tmp]/...
      [...]
      

the mails in your afew folder will be tagged with ‘devel’ and ‘afew’. If instead your hierarchy is split by a more conventional / or any other divider

[...]
/path/to/maildir/devel/afew/[cur|new|tmp]/...
/path/to/maildir/devel/alot/[cur|new|tmp]/...
/path/to/maildir/devel/notmuch/[cur|new|tmp]/...
[...]

you need to configure that divider to have your mails properly tagged:

maildir_separator = /

InboxFilter

This removes the new tag, and adds the inbox tag, to any message that isn’t killed or spam. (The new tags are set in your notmuch config, and default to just new.)

[InboxFilter]

Custom Filter

See the afew documentation on how to create custom filters.

  • Yearly Archives

    For efficiency, this should be done from the server side, but some IMAP providers webmail UI isn’t always capable of doing simple mail searching. Also if these tags are meant to be transformed into IMAP folders, locally the folders should already exists before doing afew --move-mails command.

    • 2021
      [Filter.21]
      query = date:2021
      tags = +archive2021;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2021-archive
      
    • 2020
      [Filter.20]
      query = date:2020
      tags = +archive2020;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2020-archive
      
    • 2019
      [Filter.19]
      query = date:2019
      tags = +archive2019;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2019-archive
      
    • 2018
      [Filter.18]
      query = date:2018
      tags = +archive2018;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2018-archive
      
    • 2017
      [Filter.17]
      query = date:2017
      tags = +archive2017;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2017-archive
      
    • 2016
      [Filter.16]
      query = date:2016
      tags = +archive2016;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2016-archive
      
    • 2015
      [Filter.15]
      query = date:2015
      tags = +archive2015;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2015-archive
      
    • 2014
      [Filter.14]
      query = date:2014
      tags = +archive2014;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2014-archive
      
    • 2013
      [Filter.13]
      query = date:2013
      tags = +archive2013;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2013-archive
      
    • 2012
      [Filter.12]
      query = date:2012
      tags = +archive2012;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2012-archive
      
    • 2011
      [Filter.11]
      query = date:2011
      tags = +archive2011;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2011-archive
      
    • 2010
      [Filter.10]
      query = date:2010
      tags = +archive2010;-yahoo/archive;-gmail/archive;-hotmail/archive;-ymail/archive;-archive-inbox;-yahoo/inbox;-gmail/inbox;-hotmail/inbox;-ymail/inbox
      message = tagged 2010-archive
      

notmuch

run notmuch setup for initializing mail accounts, and notmuch new AFTER all your mailboxes syncronized.

Hooks

Notmuch provides 3 hooks:

pre-new
Invoked by notmuch new command before scanning or importing new messages into the database. If this hook exits with a non-zero status, notmuch will abort further processing of the notmuch new command.
post-new
This hook is invoked by the notmuch new command after new messages have been imported into the database and initial tags have been applied. The hook will not be run if there have been any errors during the scan or import.
post-insert
This hook is invoked by the notmuch insert command after the message has been delivered, added to the database, and initial tags have been applied. The hook will not be run if there have been any errors during the message delivery; what is regarded as successful delivery depends on the --keep option.

I’ll be using the pre-new hooks for afew and also offlineimap while the post-new hooks will be used by afew to tag new mails. Usually the hook directory resides inside the mail directory set in notmuch-config.

  • Post New Hook
    _AFEW="$(command -v afew)"
    
    [ -n "${_AFEW}" ] &&
        "${_AFEW}" --tag --new -vv
    

offlineimap

header-args: :tangle ~/.config/offlineimap/config :mkdirp t

The configuration file can be stored at ~/.offlineimaprc or ~/.config/offlineimap/config, I chose the latter. I’m using the python3 version of offlineimap.

General options

List the accounts that will be managed by offlineimap

[general]
accounts = gmail, hotmail, ymail, yahoo

Controls how many accounts may be synced simultaneously

maxsyncaccounts = 1

Set pythonfile

This is an helper script used by offlineimap. If this file is not located within $PATH, provide full path.

pythonfile = ~/.local/share/offlineimap/offlineimap.py
  • The offlineimap.py content
    """Offlineimap helper script."""
    
    from subprocess import check_output
    
    
    def get_pass(account):
        """Return password for ACCOUNT."""
        match account:
            case "yahoo":
                return check_output(
                    "pass login.yahoo.com/app_pass/alexforsale@yahoo.com",
                    shell=True).decode('utf-8').strip('\n')
            case "ymail":
                return check_output(
                    "pass login.yahoo.com/app_pass/christian.alexander@ymail.com",
                    shell=True).decode('utf-8').strip('\n')
            case "gmail":
                return check_output(
                    "pass google.com/app_pass/alexarians@gmail.com",
                    shell=True).decode('utf-8').strip('\n')
            case "hotmail":
                return check_output(
                    "pass outlook.live.com/christian.alexander@windowslive.com",
                    shell=True).decode('utf-8').strip('\n')
    

Credentials for gmail account

The configuration itself will vary depending to how you will use offlineimap, if you’re using it as a daemon (continously running in the background) you should uncomment the autorefresh and quick option. I’m not using it as a daemon since I want the offlineimap process only run when called by notmuch via hooks. Also check the full configuration directives at their github repo.

[Account gmail]
localrepository = gmail-local
remoterepository = gmail-remote
synclabels = yes
labelsheader = X-Keywords
autorefresh = 15
quick = 10
postsynchook = notmuch new --verbose

[Repository gmail-local]
Type = GmailMaildir
localfolders = ~/.mail/gmail
sync_deletes = yes
nametrans = lambda f: re.sub('spam', '[Gmail]/Spam',
                     re.sub('draft', '[Gmail]/Drafts',
                     re.sub('inbox', 'INBOX',
                     re.sub('sent', '[Gmail]/Sent Mail',
                     re.sub('trash', '[Gmail]/Trash',
                     re.sub('archive*', 'Archive',
                     re.sub('archive$', '[Gmail]/All Mail', f)))))))

[Repository gmail-remote]
Type = Gmail
remoteuser = alexarians@gmail.com
remotepasseval = get_pass("gmail")
nametrans = lambda f: re.sub('.*All Mail$', 'archive',
                      re.sub('^Archive', 'archive',
                      re.sub('.*Drafts$', 'draft',
                      re.sub('.*Spam$', 'spam',
                      re.sub('.*Sent Mail$', 'sent',
                      re.sub('.*Trash$', 'trash',
                      re.sub('INBOX', 'inbox', f)))))))
folderfilter = lambda foldername: foldername not in ['[Gmail]/Important', '[Gmail]/Starred']
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
ssl_version = tls1_2
usecompression = yes

Yahoo

I have to use maxconnections = 1 for yahoo and ymail since they bound to generate error regarding UID when using the default.

[Account yahoo]
localrepository = yahoo-local
remoterepository = yahoo-remote
autorefresh = 20
quick = 10
postsynchook = notmuch new --verbose

[Repository yahoo-local]
Type = Maildir
localfolders = ~/.mail/yahoo
sync_deletes = yes
nametrans = lambda f: re.sub('spam', 'Bulk Mail',
                     re.sub('draft', 'Draft',
                     re.sub('inbox', 'Inbox',
                     re.sub('sent', 'Sent',
                     re.sub('trash', 'Trash',
                     re.sub('archive', 'Archive', f))))))
[Repository yahoo-remote]
Type = IMAP
remotehost = imap.mail.yahoo.com
remoteuser = alexforsale@yahoo.com
remotepasseval = get_pass("yahoo")
nametrans = lambda f: re.sub('.*Archive', 'archive',
                      re.sub('.*Draft$', 'draft',
                      re.sub('.*Bulk Mail$', 'spam',
                      re.sub('.*Sent$', 'sent',
                      re.sub('.*Trash$', 'trash',
                      re.sub('Inbox', 'inbox', f))))))
maxconnections = 1
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
ssl_version = tls1_2
usecompression = no

Hotmail

[Account hotmail]
localrepository = hotmail-local
remoterepository = hotmail-remote
autorefresh = 30
quick = 10
postsynchook = notmuch new --verbose

[Repository hotmail-local]
Type = Maildir
localfolders = ~/.mail/hotmail
sync_deletes = yes
nametrans = lambda f: re.sub('spam', 'Junk',
                     re.sub('draft', 'Drafts',
                     re.sub('inbox', 'Inbox',
                     re.sub('sent', 'Sent',
                     re.sub('trash', 'Deleted',
                     re.sub('notes', 'Notes',
                     re.sub('outbox', 'Outbox',
                     re.sub('archive', 'Archive', f))))))))
[Repository hotmail-remote]
Type = IMAP
remotehost = imap-mail.outlook.com
remoteuser = christian.alexander@windowslive.com
remotepasseval = get_pass("hotmail")
nametrans = lambda f: re.sub('.*Archive', 'archive',
                      re.sub('.*Drafts$', 'draft',
                      re.sub('.*Junk$', 'spam',
                      re.sub('.*Sent$', 'sent',
                      re.sub('.*Deleted$', 'trash',
                      re.sub('.*Outbox$', 'outbox',
                      re.sub('.*Notes$', 'notes',
                      re.sub('Inbox', 'inbox', f))))))))
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
ssl_version = tls1_2
usecompression = no

Ymail

[Account ymail]
localrepository = ymail-local
remoterepository = ymail-remote
autorefresh = 60
quick = 10
postsynchook = notmuch new --verbose

[Repository ymail-local]
Type = Maildir
localfolders = ~/.mail/ymail
sync_deletes = yes
nametrans = lambda f: re.sub('spam', 'Bulk Mail',
                     re.sub('draft', 'Draft',
                     re.sub('inbox', 'Inbox',
                     re.sub('sent', 'Sent',
                     re.sub('trash', 'Trash',
                     re.sub('archive', 'Archive', f))))))

[Repository ymail-remote]
Type = IMAP
remotehost = imap.mail.yahoo.com
remoteuser = christian.alexander@ymail.com
remotepasseval = get_pass("ymail")
nametrans = lambda f: re.sub('.*Archive', 'archive',
                      re.sub('.*Draft$', 'draft',
                      re.sub('.*Bulk Mail$', 'spam',
                      re.sub('.*Sent$', 'sent',
                      re.sub('.*Trash$', 'trash',
                      re.sub('Inbox', 'inbox', f))))))
maxconnections = 1
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
ssl_version = tls1_2
usecompression = no

Footnotes:

1

see here for the list of available frontends.