[general]
# Пока одна учётка на CRM, не больше, потом перепишу на jinja и for box in models.CmfMailbox.list(...
accounts = {{ mailbox.email }}
# От него решил отказаться т.к. тащить сюда код на _python2_ который будет ходить в базу - тупо
# pythonfile = ~/.offlineimap.py

[Account {{ mailbox.email }}]
localrepository = {{ mailbox.email }}_Local
remoterepository = {{ mailbox.email }}_Remote
{% if mailbox.load_from_date and mailbox.type == 'Google' %}
maxage = {{ mailbox.load_from_date }}
{% endif %}

[Repository {{ mailbox.email }}_Local]
type = Maildir
localfolders = {{ localfolders }}

[Repository {{ mailbox.email }}_Remote]
{% if mailbox.type == 'google' %}
type = Gmail
{% else  %}
type = IMAP
remotehost = {{ mailbox.imap_server or 'imap.' + mailbox.email.split('@')[-1] }}
{% endif %}
{% if mailbox.imap_port %}
remoteport = {{ mailbox.imap_port }}
{% endif %}
{% if mailbox.imap_crypt == 'ssl' %}
ssl = yes
{% if not mailbox.imap_port %}remoteport = 993{% endif %}
{% else %}
ssl = no
{% if not mailbox.imap_port %}remoteport = 143{% endif %}
{% endif %}
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
{% if mailbox.imap_crypt != 'starttls' %}
starttls = no
{% endif %}
# Пока хардкод, потом добавим в опции
folderfilter = lambda foldername: foldername == 'INBOX'
remoteuser = {{ mailbox.login or mailbox.email }}
{% if not (mailbox.client_id.is_null or mailbox.refresh_token.is_null) %}
# oauth based auth
oauth2_client_id = {{ mailbox.client_id }}
oauth2_client_secret = {{ mailbox.get_client_secret() }}
oauth2_refresh_token = {{ mailbox.refresh_token }}

{% if mailbox.type == 'google' %}
oauth2_request_url = https://accounts.google.com/o/oauth2/token
{#{% elif mailbox.type == 'mail.ru' %}#}
{#oauth2_request_url = https://oauth.mail.ru/token#}
{% elif mailbox.type == 'yandex' %}
oauth2_request_url = https://oauth.yandex.ru/token
{% else %}
# BUG happened, no oauth request url specified for {{ mailbox.type }}
{% endif %}
{% elif not mailbox.password.is_null %}
# password type auth
remotepass = {{ mailbox.password.value.replace('%', '%%') }}
{% else %}
# no auth provided
{% endif %}
