---
{%- from "dovecot/map.jinja" import dovecot with context %}

dovecot-imap-user:
  user.present:
    - name: {{ dovecot.imap_user }}
    - uid: {{ dovecot.imap_user_id }}

{%- for name, config in dovecot.config.main.items() %}
dovecot-config-main-{{ name }}:
  file.managed:
    - name: {{ dovecot.config_dir }}/{{ name }}
    - source: salt://dovecot/files/config.j2
    - template: jinja
    - user: root
    - group: root
    - watch_in:
      - service: dovecot-service
    - context:
      config: {{ config }}
{%- endfor %}

{%- for name, config in dovecot.config.confd.items() %}
dovecot-config-conf.d-{{ name }}:
  file.managed:
    - name: {{ dovecot.config_dir }}/conf.d/{{ name }}
    - source: salt://dovecot/files/config.j2
    - template: jinja
    - user: root
    - group: root
    - watch_in:
      - service: dovecot-service
    - context:
      config: {{ config }}
{%- endfor %}