diff --git a/.kitchen.dokken.yml b/.kitchen.dokken.yml index 53963e3..0227c09 100644 --- a/.kitchen.dokken.yml +++ b/.kitchen.dokken.yml @@ -105,3 +105,11 @@ suites: sasl: smtp_sasl_user_name: "kitchenuser" smtp_sasl_passwd: "not-a-real-thing" + +- name: canonical + run_list: + - recipe[postfix] + attributes: + postfix: + recipient_canonical_map_entries: + john: john@doe.com \ No newline at end of file diff --git a/.kitchen.yml b/.kitchen.yml index d27ae83..fcd3387 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -47,3 +47,12 @@ suites: sasl: smtp_sasl_user_name: "kitchenuser" smtp_sasl_passwd: "not-a-real-thing" + +- name: canonical + run_list: + - recipe[postfix] + attributes: + postfix: + recipient_canonical_map_entries: + john: john@doe.com + \ No newline at end of file diff --git a/attributes/default.rb b/attributes/default.rb index d467072..b64cc1f 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -33,6 +33,7 @@ default['postfix']['main_template_source'] = 'postfix' default['postfix']['master_template_source'] = 'postfix' default['postfix']['sender_canonical_map_entries'] = {} default['postfix']['smtp_generic_map_entries'] = {} +default['postfix']['recipient_canonical_map_entries'] = {} default['postfix']['access_db_type'] = 'hash' default['postfix']['aliases_db_type'] = 'hash' default['postfix']['transport_db_type'] = 'hash' diff --git a/recipes/_common.rb b/recipes/_common.rb index 17d5e0e..fe141fd 100644 --- a/recipes/_common.rb +++ b/recipes/_common.rb @@ -109,6 +109,25 @@ unless node['postfix']['smtp_generic_map_entries'].empty? end end +execute 'update-postfix-recipient_canonical' do + command "postmap #{node['postfix']['conf_dir']}/recipient_canonical" + action :nothing +end + +unless node['postfix']['recipient_canonical_map_entries'].empty? + template "#{node['postfix']['conf_dir']}/recipient_canonical" do + owner 'root' + group node['root_group'] + mode '0644' + notifies :run, 'execute[update-postfix-recipient_canonical]' + notifies :reload, 'service[postfix]' + end + + unless node['postfix']['main'].key?('recipient_canonical_maps') + node.normal['postfix']['main']['recipient_canonical_maps'] = "hash:#{node['postfix']['conf_dir']}/recipient_canonical" + end +end + %w( main master ).each do |cfg| template "#{node['postfix']['conf_dir']}/#{cfg}.cf" do source "#{cfg}.cf.erb" diff --git a/templates/default/recipient_canonical.erb b/templates/default/recipient_canonical.erb new file mode 100644 index 0000000..bfff5c1 --- /dev/null +++ b/templates/default/recipient_canonical.erb @@ -0,0 +1,9 @@ +# +# Auto-generated by Chef. +# Local modifications will be overwritten. +# +# See man 5 canonical for format + +<% node['postfix']['recipient_canonical_map_entries'].each do |name, value| %> +<%= name %> <%= value %> +<% end unless node['postfix']['recipient_canonical_map_entries'].nil? %>