Browse Source

added namespaces support

Xabier de Zuazo 11 years ago
parent
commit
bafc137999
4 changed files with 48 additions and 0 deletions
  1. 22 0
      attributes/namespaces.rb
  2. 19 0
      libraries/conf.rb
  3. 1 0
      recipes/default.rb
  4. 6 0
      templates/default/conf.d/10-mail.conf.erb

+ 22 - 0
attributes/namespaces.rb

@@ -0,0 +1,22 @@
+
+default['dovecot']['namespaces'] = [
+#   {
+#     'separator' => '/',
+#     'prefix' => '"#mbox/"',
+#     'location' => 'mbox:~/mail:INBOX=/var/mail/%u',
+#     'inbox' => true,
+#     'hidden' => true,
+#     'list' => false,
+#   }, {
+#     'separator' => '/',
+#     'prefix' => '',
+#     'location' => 'maildir:~/Maildir',
+#   },
+#   {
+#     'name' => 'inbox',
+#     'separator' => '/',
+#     'prefix' => '',
+#     'inbox' => 'yes',
+#   },
+]
+

+ 19 - 0
libraries/conf.rb

@@ -50,6 +50,25 @@ module Dovecot
       )
     end
 
+    def self.namespace(ns)
+      template =
+'namespace <%= @ns["name"] %> {
+<%   @ns.each do |key, value|
+       if key != "name"
+  -%>
+  <%=    key %> = <%= @Dovecot_Conf.value(value) %>
+  <%   end
+     end
+-%>
+}'
+
+      eruby = Erubis::Eruby.new(template)
+      eruby.evaluate(
+        :ns => ns,
+        :Dovecot_Conf => Dovecot::Conf
+      )
+    end
+
     def self.service(name, conf)
 
       template =

+ 1 - 0
recipes/default.rb

@@ -126,6 +126,7 @@ conf_files.each do |conf_file|
       :protocols => node['dovecot']['protocols'],
       :services => node['dovecot']['services'],
       :plugins => node['dovecot']['plugins'],
+      :namespaces => node['dovecot']['namespaces'],
       :conf => node['dovecot']['conf']
     )
   end

+ 6 - 0
templates/default/conf.d/10-mail.conf.erb

@@ -44,6 +44,11 @@
 # explicitly, ie. mail_location does nothing unless you have a namespace
 # without a location setting. Default namespace is simply done by having a
 # namespace with empty prefix.
+<% if @namespaces.kind_of?(Array) and @namespaces.length > 0 -%>
+<%   @namespaces.each do |ns| -%>
+<%=    Dovecot::Conf.namespace(ns) %>
+<%   end -%>
+<% else -%>
 #namespace {
   # Namespace type: private, shared or public
   #type = private
@@ -81,6 +86,7 @@
   # namespace handles them (empty prefix should always have this as "yes")
   #subscriptions = yes
 #}
+<% end -%>
 
 # Example shared namespace configuration
 #namespace {