Browse Source

15-lda.conf.erb template using variables

Xabier de Zuazo 11 years ago
parent
commit
115a5b5976
4 changed files with 49 additions and 11 deletions
  1. 13 0
      attributes/conf-15-lda.rb
  2. 4 0
      attributes/protocols.rb
  3. 17 0
      libraries/conf.rb
  4. 15 11
      templates/default/conf.d/15-lda.conf.erb

+ 13 - 0
attributes/conf-15-lda.rb

@@ -0,0 +1,13 @@
+
+default['dovecot']['conf']['postmaster_address'] = nil
+default['dovecot']['conf']['hostname'] = nil
+default['dovecot']['conf']['quota_full_tempfail'] = nil
+default['dovecot']['conf']['sendmail_path'] = nil
+default['dovecot']['conf']['submission_host'] = nil
+default['dovecot']['conf']['rejection_subject'] = nil
+default['dovecot']['conf']['rejection_reason'] = nil
+default['dovecot']['conf']['recipient_delimiter'] = nil
+default['dovecot']['conf']['lda_original_recipient_header'] = nil
+default['dovecot']['conf']['lda_mailbox_autocreate'] = nil
+default['dovecot']['conf']['lda_mailbox_autosubscribe'] = nil
+

+ 4 - 0
attributes/protocols.rb

@@ -3,3 +3,7 @@ default['dovecot']['protocols'] = {}
 
 default['dovecot']['protocols']['imap'] = {}
 
+# default['dovecot']['protocols']['lda'] = {
+#   'mail_plugins' => [ '$mail_plugins' ],
+# }
+

+ 17 - 0
libraries/conf.rb

@@ -69,6 +69,23 @@ module Dovecot
       )
     end
 
+    def self.protocol(name, conf)
+
+      template =
+'protocol <%= @name %> {
+  <% @conf.each do |key, value| -%>
+  <%=  key %> = <%= @Dovecot_Conf.value(value) %>
+  <% end -%>
+}'
+
+      eruby = Erubis::Eruby.new(template)
+      eruby.evaluate(
+        :name => name,
+        :conf => conf,
+        :Dovecot_Conf => Dovecot::Conf
+      )
+    end
+
     def self.service(name, conf)
 
       template =

+ 15 - 11
templates/default/conf.d/15-lda.conf.erb

@@ -4,45 +4,49 @@
 
 # Address to use when sending rejection mails.
 # Default is postmaster@<your domain>.
-#postmaster_address =
+<%= Dovecot::Conf.attribute(@conf, 'postmaster_address') %>
 
 # Hostname to use in various parts of sent mails, eg. in Message-Id.
 # Default is the system's real hostname.
-#hostname = 
+<%= Dovecot::Conf.attribute(@conf, 'hostname') %>
 
 # If user is over quota, return with temporary failure instead of
 # bouncing the mail.
-#quota_full_tempfail = no
+<%= Dovecot::Conf.attribute(@conf, 'quota_full_tempfail', false) %>
 
 # Binary to use for sending mails.
-#sendmail_path = /usr/sbin/sendmail
+<%= Dovecot::Conf.attribute(@conf, 'sendmail_path', '/usr/sbin/sendmail') %>
 
 # If non-empty, send mails via this SMTP host[:port] instead of sendmail.
-#submission_host =
+<%= Dovecot::Conf.attribute(@conf, 'submission_host') %>
 
 # Subject: header to use for rejection mails. You can use the same variables
 # as for rejection_reason below.
-#rejection_subject = Rejected: %s
+<%= Dovecot::Conf.attribute(@conf, 'rejection_subject', 'Rejected: %s') %>
 
 # Human readable error message for rejection mails. You can use variables:
 #  %n = CRLF, %r = reason, %s = original subject, %t = recipient
-#rejection_reason = Your message to <%t> was automatically rejected:%n%r
+<%= Dovecot::Conf.attribute(@conf, 'rejection_reason', 'Your message to <%t> was automatically rejected:%n%r') %>
 
 # Delimiter character between local-part and detail in email address.
-#recipient_delimiter = +
+<%= Dovecot::Conf.attribute(@conf, 'recipient_delimiter', '+') %>
 
 # Header where the original recipient address (SMTP's RCPT TO: address) is taken
 # from if not available elsewhere. With dovecot-lda -a parameter overrides this. 
 # A commonly used header for this is X-Original-To.
-#lda_original_recipient_header =
+<%= Dovecot::Conf.attribute(@conf, 'lda_original_recipient_header') %>
 
 # Should saving a mail to a nonexistent mailbox automatically create it?
-#lda_mailbox_autocreate = no
+<%= Dovecot::Conf.attribute(@conf, 'lda_mailbox_autocreate', false) %>
 
 # Should automatically created mailboxes be also automatically subscribed?
-#lda_mailbox_autosubscribe = no
+<%= Dovecot::Conf.attribute(@conf, 'lda_mailbox_autosubscribe', false) %>
 
+<% if @protocols['lda'].kind_of?(Hash) and @protocols['lda'].length > 0 -%>
+<%=  Dovecot::Conf.protocol('lda', @protocols['lda']) %>
+<% else -%>
 protocol lda {
   # Space separated list of plugins to load (default is global mail_plugins).
   #mail_plugins = $mail_plugins
 }
+<% end -%>