Skip to content

Commit

Permalink
Add a mysql query to virtual_mailbox_domains, virtual_alias_maps virt…
Browse files Browse the repository at this point in the history
…ual_mailbox_maps if mysql is declared in main.cf within these options
  • Loading branch information
vquie committed Apr 12, 2017
1 parent 21fc78d commit f8514b3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
14 changes: 14 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ postfix:
hosts: DB_HOST
dbname: postfix_db

mysql:
virtual_mailbox_domains:
table: virtual_domains
select_field: 1
where_field: name
virtual_alias_maps:
table: virtual_aliases
select_field: destination
where_field: email
virtual_mailbox_maps:
table: virtual_users
select_field: 1
where_field: email

certificates:
server-cert:
public_cert: |
Expand Down
9 changes: 8 additions & 1 deletion postfix/files/virtual_alias_maps.cf
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{%- if 'mysql' in salt['pillar.get']('postfix:config:virtual_alias_maps', '') %}
{%- set config = salt['pillar.get']('postfix:mysql:virtual_alias_maps', {}) -%}
{%- for key,value in salt['pillar.get']('postfix:vmail').items() %}
{{ key }} = {{ value }}
{%- endfor %}
query = SELECT {{ config.select_field|default('destination') }} FROM {{ config.table|default('virtual_aliases') }} WHERE {{ config.where_field|default('email') }}='%s'
{%- else %}
{% set config = salt['pillar.get']('postfix:vmail', {}) -%}
{% macro set_parameter(parameter, default=None) -%}
{% set value = config.get(parameter, default) -%}
Expand All @@ -14,4 +21,4 @@
{{ set_parameter('table', 'alias') }}
{{ set_parameter('select_field', 'goto') }}
{{ set_parameter('where_field', 'address') }}

{%- endif %}
9 changes: 8 additions & 1 deletion postfix/files/virtual_mailbox_domains.cf
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{%- if 'mysql' in salt['pillar.get']('postfix:config:virtual_mailbox_domains', '') %}
{%- set config = salt['pillar.get']('postfix:mysql:virtual_mailbox_domains', {}) -%}
{%- for key,value in salt['pillar.get']('postfix:vmail').items() %}
{{ key }} = {{ value }}
{%- endfor %}
query = SELECT {{ config.select_field|default('1') }} FROM {{ config.table|default('virtual_domains') }} WHERE {{ config.where_field|default('name') }}='%s'
{%- else %}
{% set config = salt['pillar.get']('postfix:vmail', {}) -%}
{% macro set_parameter(parameter, default=None) -%}
{% set value = config.get(parameter, default) -%}
Expand All @@ -14,4 +21,4 @@
{{ set_parameter('table', 'domain') }}
{{ set_parameter('select_field', 'domain') }}
{{ set_parameter('where_field', 'domain') }}

{%- endif %}
9 changes: 8 additions & 1 deletion postfix/files/virtual_mailbox_maps.cf
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{%- if 'mysql' in salt['pillar.get']('postfix:config:virtual_mailbox_maps', '') %}
{%- set config = salt['pillar.get']('postfix:mysql:virtual_mailbox_maps', {}) -%}
{%- for key,value in salt['pillar.get']('postfix:vmail').items() %}
{{ key }} = {{ value }}
{%- endfor %}
query = SELECT {{ config.select_field|default('1') }} FROM {{ config.table|default('virtual_users') }} WHERE {{ config.where_field|default('email') }}='%s'
{%- else %}
{% set config = salt['pillar.get']('postfix:vmail', {}) -%}
{% macro set_parameter(parameter, default=None) -%}
{% set value = config.get(parameter, default) -%}
Expand All @@ -14,4 +21,4 @@
{{ set_parameter('table', 'mailbox') }}
{{ set_parameter('select_field', 'maildir') }}
{{ set_parameter('where_field', 'username') }}

{%- endif %}

0 comments on commit f8514b3

Please sign in to comment.