Repository: modoboa/modoboa

Issue:
handle_mailbox_operations command not working
Hello,

This is a new Modoboa 1.1.0 installation. When I try to run:

```
python /opt/modoboa_admin/manage.py handle_mailbox_operations
```

I get the following error:

```
NotDefined: Application 'admin' and/or parameter 'HANDLE_MAILBOXES' not defined
```

According to the [documentation](http://modoboa.readthedocs.org/en/1.1.0/getting_started/configuration.html#admin-params) there should be an option in Modoboa->Parameters->General to activate this HANDLE_MAILBOXES. But I don't see it anywhere.

I tried to outsmart the system by inserting the value in the lib_parameter table but no luck. I guess something else is required.

```
insert into lib_parameter (name, value) values ('admin.HANDLE_MAILBOXES', 'yes')
```

Am I missing something ? Here is the screenshot of my admin interface, logged as the default admin user:
![modoba-admin](https://f.cloud.github.com/assets/970403/1948128/247a46f0-807e-11e3-89ae-94fb9b7ec902.png)



Discussion:
Hi,

this option will be automatically hidden if one of the following condition is true:
- The filesystem containing the mailboxes is not accessible (hosted on another server for example)
- Modoboa can't find the 'doveadm' command (check your path)
- Dovecot < 2 is in use

Actually, modoboa looks for dovecot (not doveadm) to check if it must hide the setting or not.

https://github.com/tonioo/modoboa/blob/master/modoboa/extensions/admin/app_settings.py#L46

Hello,

Using dovecot 2.1.7 package that ships with Debian Wheezy. The dovecot command is in _/usr/sbin/dovecot_ which is not in the path of normal users and so `which dovecot` will never find it unless you run it as root or with sudo. Does Modoboa requires the dovecot command in any way to handle the mailbox operations to go as far as hide the feature if it can't find the command ?. What is the actual purpose of this validation ?

Cheers

Actually, modoboa needs the doveadm command which comes with Dovecot > 2 so we call dovecot --version to know the version in use. doveadm is usefull to find where home directories are stored.

If we can't find where mailboxes are stored, we can't rename or remove them, that's why the parameter is hidden. What do you think?

I'll make a quick fix to make the handle_mailbox_operations command quit properly.

Well, I can't think of any other way that is not OS specific to find the dovecot version. So I guess looking a bit more for the dovecot command is what it's needed. I mean `which dovecot` would be the first check and then we could look in _/usr/sbin/dovecot_ and _/usr/local/sbin/dovecot_. Would that make sense ?

Yes, I can add additional checks.


Resolving patch:
diff --git a/modoboa/extensions/admin/app_settings.py b/modoboa/extensions/admin/app_settings.py
--- a/modoboa/extensions/admin/app_settings.py
+++ b/modoboa/extensions/admin/app_settings.py
@@ -3,6 +3,7 @@
 from modoboa.lib.formutils import YesNoField, SeparatorField
 from modoboa.lib.sysutils import exec_cmd
 from modoboa.lib import parameters
+import os
 
 
 class AdminParametersForm(parameters.AdminParametersForm):
@@ -46,9 +47,16 @@ class AdminParametersForm(parameters.AdminParametersForm):
     def __init__(self, *args, **kwargs):
         super(AdminParametersForm, self).__init__(*args, **kwargs)
         hide_fields = False
+        dpath = None
         code, output = exec_cmd("which dovecot")
+        known_paths = ("/usr/sbin/dovecot", "/usr/local/sbin/dovecot")
         if not code:
             dpath = output.strip()
+        else:
+            for fpath in known_paths:
+                if os.path.isfile(fpath) and os.access(fpath, os.X_OK):
+                    dpath = fpath
+        if dpath:
             try:
                 code, version = exec_cmd("%s --version" % dpath)
             except OSError:


Test patch: