Browse Source

libraries to work with protocols and plugins

Xabier de Zuazo 11 years ago
parent
commit
144b24aa0b

+ 8 - 1
attributes/plugins.rb

@@ -1,3 +1,10 @@
 
-default['dovecot']['plugins'] = [ 'sieve' ]
+default['dovecot']['mail_plugins'] = [ 'sieve' ]
+
+default['dovecot']['plugins']['sieve'] = {}
+
+# default['dovecot']['plugins']['mail_log'] = {
+#   'mail_log_events' => 'delete undelete expunge copy mailbox_delete mailbox_rename',
+#   'mail_log_fields' => 'uid box msgid size'
+# }
 

+ 3 - 1
attributes/protocols.rb

@@ -1,3 +1,5 @@
 
-default['dovecot']['protocols'] = [ 'imap' ]
+default['dovecot']['protocols'] = {}
+
+default['dovecot']['protocols']['imap'] = {}
 

+ 23 - 0
libraries/conf.rb

@@ -16,6 +16,29 @@ module Dovecot
       end
     end
 
+    def self.protocols(conf)
+      Dovecot::Protocols.list(conf).join(' ')
+    end
+
+    def self.plugin(name, conf)
+
+      template =
+'plugin {
+  <% @conf.each do |key, value|
+       unless value.nil?
+  -%>
+  <%= key %> = <%= @Dovecot_Conf.value(value) %>
+  <%   end
+     end -%>
+}'
+
+      eruby = Erubis::Eruby.new(template)
+      eruby.evaluate(
+        :conf => conf,
+        :Dovecot_Conf => Dovecot::Conf
+      )
+    end
+
     def self.service(name, conf)
 
       template =

+ 13 - 0
libraries/plugins.rb

@@ -0,0 +1,13 @@
+module Dovecot
+  module Plugins
+
+    def self.required?(plugin, attrs)
+      return true if attrs.has_key?('mail_plugins') and attrs['mail_plugins'].include?(plugin)
+      attrs['protocols'].each do |protocol, conf|
+        return true if conf.has_key?('mail_plugins') and conf['mail_plugins'].include?(plugin)
+      end
+      false
+    end
+
+  end
+end

+ 17 - 0
libraries/protocols.rb

@@ -0,0 +1,17 @@
+module Dovecot
+  module Protocols
+
+    def self.enabled?(proto, protos)
+      protos.has_key?(proto) and protos[proto].kind_of?(Hash)
+    end
+
+    def self.list(protos)
+      list = []
+      protos.each do |proto, conf|
+        list.push(proto) if conf.kind_of?(Hash)
+      end
+      list
+    end
+
+  end
+end

+ 6 - 5
recipes/default.rb

@@ -35,7 +35,7 @@ when 'redhat','centos','scientific','fedora','suse','amazon' then
     node['dovecot']['conf_files']['ldap']
 
   # sieve
-  if node['dovecot']['plugins'].include?('sieve')
+  if Dovecot::Plugins.required?('sieve', node['dovecot'])
     package 'dovecot-pigeonhole'
     conf_files += node['dovecot']['conf_files']['sieve']
   end
@@ -47,25 +47,25 @@ when 'debian', 'ubuntu' then
   package 'dovecot-gssapi'
 
   # imap
-  if node['dovecot']['protocols'].include?('imap')
+  if Dovecot::Protocols.enabled?('imap', node['dovecot']['protocols'])
     package 'dovecot-imapd'
     conf_files += node['dovecot']['conf_files']['imap']
   end
 
   # pop3
-  if node['dovecot']['protocols'].include?('pop3')
+  if Dovecot::Protocols.enabled?('pop3', node['dovecot']['protocols'])
     package 'dovecot-pop3d'
     conf_files += node['dovecot']['conf_files']['pop3']
   end
 
   # lmtp
-  if node['dovecot']['protocols'].include?('lmtp')
+  if Dovecot::Protocols.enabled?('lmtp', node['dovecot']['protocols'])
     package 'dovecot-lmtpd'
     conf_files += node['dovecot']['conf_files']['lmtp']
   end
 
   # sieve
-  if node['dovecot']['plugins'].include?('sieve')
+  if Dovecot::Plugins.required?('sieve', node['dovecot'])
     package 'dovecot-sieve'
     package 'dovecot-managesieved'
     conf_files += node['dovecot']['conf_files']['sieve']
@@ -125,6 +125,7 @@ conf_files.each do |conf_file|
       :auth => node['dovecot']['auth'],
       :protocols => node['dovecot']['protocols'],
       :services => node['dovecot']['services'],
+      :plugins => node['dovecot']['plugins'],
       :conf => node['dovecot']['conf']
     )
   end

+ 1 - 1
templates/default/dovecot.conf.erb

@@ -18,7 +18,7 @@
 
 # Protocols we want to be serving.
 <% unless @protocols.nil? -%>
-protocols = <%= Dovecot::Conf.value(@protocols) %>
+protocols = <%= Dovecot::Conf.protocols(@protocols) %>
 <% else -%>
 #protocols = imap pop3 lmtp
 <% end -%>