# My credentials used to be encrypted via GPG symmetric keys, but that turned
# out to be quite tiresome. Luckily though, it seems that 'kwalletmanager' is
# actually quite nice, and 'kwallet-query' seems to work flawlessly. So
# everything is safe and fast.
#
# As for the version of mbsync, it has to be the latest, as versions prior to
# 1.3 where lacking support for fetching subdirectories, and that was simply a
# nightmare. That being said, even Debian stable has a version higher than this,
# so I'm probably just ranting on memories from the good ol' days.
#
# You could call this whole thing directly, but I have the special
# 'bin/fetch-email' script which does the job better. In the end it's a
# glorified one-liner that uses GNU parallel to sync each channel in parallel.

##
# GMail

IMAPAccount gmail
Host imap.gmail.com
User mikisabate@gmail.com
PassCmd "kwallet-query --read-password gmail kdewallet --folder email"
TLSType IMAPS
AuthMechs Login
CertificateFile /etc/ssl/ca-bundle.pem
TLSVersions +1.2 +1.3
Timeout 0

# Use the account specified above as the remote storage.
IMAPStore gmail-remote
Account gmail

# Let's use ~/data/mail as the prefix for the local storage.
MaildirStore gmail-local
Path ~/data/mail/gmail/
Inbox ~/data/mail/gmail/inbox
SubFolders Verbatim

# We could have one only channel, and filter them through the Patterns
# directive. I prefer having multiple channels and then group them.

Channel gmail-inbox
Far :gmail-remote:
Near :gmail-local:
Patterns "INBOX"
Create Both
Expunge Both
Sync All
CopyArrivalDate yes

Channel gmail-all
Far :gmail-remote:"[Gmail]/Tot el correu"
Near :gmail-local:"All"
Create Both
Expunge None
Sync Pull
CopyArrivalDate yes

Channel gmail-sent
Far :gmail-remote:"[Gmail]/Enviats"
Near :gmail-local:"Sent"
Create Both
Expunge None
Sync Pull
CopyArrivalDate yes

# And finally group everything here.

Group gmail
Channel gmail-inbox
Channel gmail-all
Channel gmail-sent

##
# mailbox.org

MaildirStore mailbox-local
Subfolders Verbatim
Path "~/data/mail/mailbox/"
Inbox "~/data/mail/mailbox/inbox"
Trash "trash"

IMAPAccount mailbox
Host imap.mailbox.org
Port 993
User "mssola@mssola.com"
PassCmd "kwallet-query --read-password mailbox kdewallet --folder email"
TLSType IMAPS
TLSVersions +1.2 +1.3
AuthMechs Login

IMAPStore mailbox-remote
Account mailbox

Channel mailbox-inbox
Far :mailbox-remote:
Near :mailbox-local:
Sync All
Expunge Both
Create Both
CopyArrivalDate yes

Channel mailbox-sent
Far :mailbox-remote:Sent
Near :mailbox-local:sent
Sync All
Expunge Both
Create Both
CopyArrivalDate yes

Channel mailbox-archive
Far :mailbox-remote:
Near :mailbox-local:
Pattern Archive/*
Sync All
Expunge Both
Create Both
CopyArrivalDate yes

Group mailbox
Channels mailbox-inbox mailbox-sent mailbox-archive

##
# suse.com

IMAPAccount comsuse
Host imap.gmail.com
User msabate@suse.com
PassCmd "kwallet-query --read-password susecom kdewallet --folder email"
TLSType IMAPS
AuthMechs Login
CertificateFile /etc/ssl/ca-bundle.pem

# Use the account specified above as the remote storage.
IMAPStore comsuse-remote
Account comsuse

# Let's use /home/mssola/data/mail as the prefix for the local storage.
MaildirStore comsuse-local
Path /home/mssola/data/mail/comsuse/
Inbox /home/mssola/data/mail/comsuse/inbox
SubFolders Verbatim

# We could have one only channel, and filter them through the Patterns
# directive. I prefer having multiple channels and then group them.

Channel comsuse-inbox
Far :comsuse-remote:
Near :comsuse-local:
Patterns "INBOX"
Create Both
Expunge Both
Sync All
SyncState *
CopyArrivalDate yes

Channel comsuse-all
Far :comsuse-remote:"[Gmail]/Tot el correu"
Near :comsuse-local:"All"
Create Both
Expunge None
Sync Pull
SyncState *
CopyArrivalDate yes

Channel comsuse-sent
Far :comsuse-remote:"[Gmail]/Enviats"
Near :comsuse-local:"Sent"
Create Both
Expunge None
Sync Pull
SyncState *
CopyArrivalDate yes

# And finally group everything here.

Group comsuse
Channel comsuse-inbox
Channel comsuse-all
Channel comsuse-sent

##
# cgtsuse.org

IMAPAccount sindicat
Host cgtsuse.org
User msabate@cgtsuse.org
PassCmd "kwallet-query --read-password susede kdewallet --folder email"
TLSType IMAPS
AuthMechs Login
CertificateFile /etc/ssl/ca-bundle.pem
Timeout 0

IMAPStore sindicat-remote
Account sindicat

MaildirStore sindicat-local
Path /home/mssola/data/mail/sindicat/
Inbox /home/mssola/data/mail/sindicat/inbox
SubFolders Verbatim

Channel sindicat
Far :sindicat-remote:
Near :sindicat-local:
Patterns * !Calendar !INBOX/Archive !INBOX/Drafts !INBOX/Sent !INBOX/Trash
Create None
Sync All
Expunge None
SyncState *
CopyArrivalDate yes

##
# uoc.edu

IMAPAccount uoc
Host imap.gmail.com
User mssola@uoc.edu
PassCmd "kwallet-query --read-password uoc kdewallet --folder email"
TLSType IMAPS
AuthMechs Login
CertificateFile /etc/ssl/ca-bundle.pem
TLSVersions +1.2 +1.3

# Use the account specified above as the remote storage.
IMAPStore uoc-remote
Account uoc

# Let's use ~/data/mail as the prefix for the local storage.
MaildirStore uoc-local
Path ~/data/mail/uoc/
Inbox ~/data/mail/uoc/inbox
SubFolders Verbatim

Channel uoc-inbox
Far :uoc-remote:
Near :uoc-local:
Patterns "INBOX"
Create Both
Expunge Both
Sync All
CopyArrivalDate yes

Channel uoc-all
Far :uoc-remote:"[Gmail]/Tot el correu"
Near :uoc-local:"All"
Create Both
Expunge None
Sync Pull
CopyArrivalDate yes

Channel uoc-sent
Far :uoc-remote:"[Gmail]/Enviats"
Near :uoc-local:"Sent"
Create Both
Expunge None
Sync Pull
SyncState *
CopyArrivalDate yes

# And finally group everything here.

Group uoc
Channel uoc-inbox
Channel uoc-all
Channel uoc-sent
