We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `modoboa/extensions/admin/app_settings.py`
Content:
```
1 from django import forms
2 from django.utils.translation import ugettext_lazy
3 from modoboa.lib.formutils import YesNoField, SeparatorField
4 from modoboa.lib.sysutils import exec_cmd
5 from modoboa.lib import parameters
6 
7 
8 class AdminParametersForm(parameters.AdminParametersForm):
9     app = "admin"
10 
11     mbsep = SeparatorField(label=ugettext_lazy("Mailboxes"))
12 
13     handle_mailboxes = YesNoField(
14         label=ugettext_lazy("Handle mailboxes on filesystem"),
15         initial="no",
16         help_text=ugettext_lazy("Rename or remove mailboxes on the filesystem when they get renamed or removed within Modoboa")
17     )
18 
19     mailboxes_owner = forms.CharField(
20         label=ugettext_lazy("Mailboxes ower"),
21         initial="vmail",
22         help_text=ugettext_lazy("The UNIX account who owns mailboxes on the filesystem")
23     )
24 
25     default_domain_quota = forms.IntegerField(
26         label=ugettext_lazy("Default domain quota"),
27         initial=0,
28         help_text=ugettext_lazy(
29             "Default quota (in MB) applied to freshly created domains with no "
30             "value specified. A value of 0 means no quota."
31         ),
32         widget=forms.TextInput(attrs={'class': 'span2'})
33     )
34 
35     auto_account_removal = YesNoField(
36         label=ugettext_lazy("Automatic account removal"),
37         initial="no",
38         help_text=ugettext_lazy("When a mailbox is removed, also remove the associated account")
39     )
40 
41     # Visibility rules
42     visibility_rules = {
43         "mailboxes_owner": "handle_mailboxes=yes",
44     }
45 
46     def __init__(self, *args, **kwargs):
47         super(AdminParametersForm, self).__init__(*args, **kwargs)
48         hide_fields = False
49         code, output = exec_cmd("which dovecot")
50         if not code:
51             dpath = output.strip()
52             try:
53                 code, version = exec_cmd("%s --version" % dpath)
54             except OSError:
55                 hide_fields = True
56             else:
57                 if code or not version.strip().startswith("2"):
58                     hide_fields = True
59         else:
60             hide_fields = True
61         if hide_fields:
62             del self.fields["handle_mailboxes"]
63             del self.fields["mailboxes_owner"]
64 
65     def clean_default_domain_quota(self):
66         """Ensure quota is a positive integer."""
67         if self.cleaned_data['default_domain_quota'] < 0:
68             raise forms.ValidationError(
69                 ugettext_lazy('Must be a positive integer')
70             )
71         return self.cleaned_data['default_domain_quota']
72
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
     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:

{"golden_diff": "diff --git a/modoboa/extensions/admin/app_settings.py b/modoboa/extensions/admin/app_settings.py\n--- a/modoboa/extensions/admin/app_settings.py\n+++ b/modoboa/extensions/admin/app_settings.py\n@@ -3,6 +3,7 @@\n from modoboa.lib.formutils import YesNoField, SeparatorField\n from modoboa.lib.sysutils import exec_cmd\n from modoboa.lib import parameters\n+import os\n \n \n class AdminParametersForm(parameters.AdminParametersForm):\n@@ -46,9 +47,16 @@\n     def __init__(self, *args, **kwargs):\n         super(AdminParametersForm, self).__init__(*args, **kwargs)\n         hide_fields = False\n+        dpath = None\n         code, output = exec_cmd(\"which dovecot\")\n+        known_paths = (\"/usr/sbin/dovecot\", \"/usr/local/sbin/dovecot\")\n         if not code:\n             dpath = output.strip()\n+        else:\n+            for fpath in known_paths:\n+                if os.path.isfile(fpath) and os.access(fpath, os.X_OK):\n+                    dpath = fpath\n+        if dpath:\n             try:\n                 code, version = exec_cmd(\"%s --version\" % dpath)\n             except OSError:\n", "issue": "handle_mailbox_operations command not working\nHello,\n\nThis is a new Modoboa 1.1.0 installation. When I try to run:\n\n```\npython /opt/modoboa_admin/manage.py handle_mailbox_operations\n```\n\nI get the following error:\n\n```\nNotDefined: Application 'admin' and/or parameter 'HANDLE_MAILBOXES' not defined\n```\n\nAccording 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.\n\nI tried to outsmart the system by inserting the value in the lib_parameter table but no luck. I guess something else is required.\n\n```\ninsert into lib_parameter (name, value) values ('admin.HANDLE_MAILBOXES', 'yes')\n```\n\nAm I missing something ? Here is the screenshot of my admin interface, logged as the default admin user:\n![modoba-admin](https://f.cloud.github.com/assets/970403/1948128/247a46f0-807e-11e3-89ae-94fb9b7ec902.png)\n\n", "before_files": [{"content": "from django import forms\nfrom django.utils.translation import ugettext_lazy\nfrom modoboa.lib.formutils import YesNoField, SeparatorField\nfrom modoboa.lib.sysutils import exec_cmd\nfrom modoboa.lib import parameters\n\n\nclass AdminParametersForm(parameters.AdminParametersForm):\n    app = \"admin\"\n\n    mbsep = SeparatorField(label=ugettext_lazy(\"Mailboxes\"))\n\n    handle_mailboxes = YesNoField(\n        label=ugettext_lazy(\"Handle mailboxes on filesystem\"),\n        initial=\"no\",\n        help_text=ugettext_lazy(\"Rename or remove mailboxes on the filesystem when they get renamed or removed within Modoboa\")\n    )\n\n    mailboxes_owner = forms.CharField(\n        label=ugettext_lazy(\"Mailboxes ower\"),\n        initial=\"vmail\",\n        help_text=ugettext_lazy(\"The UNIX account who owns mailboxes on the filesystem\")\n    )\n\n    default_domain_quota = forms.IntegerField(\n        label=ugettext_lazy(\"Default domain quota\"),\n        initial=0,\n        help_text=ugettext_lazy(\n            \"Default quota (in MB) applied to freshly created domains with no \"\n            \"value specified. A value of 0 means no quota.\"\n        ),\n        widget=forms.TextInput(attrs={'class': 'span2'})\n    )\n\n    auto_account_removal = YesNoField(\n        label=ugettext_lazy(\"Automatic account removal\"),\n        initial=\"no\",\n        help_text=ugettext_lazy(\"When a mailbox is removed, also remove the associated account\")\n    )\n\n    # Visibility rules\n    visibility_rules = {\n        \"mailboxes_owner\": \"handle_mailboxes=yes\",\n    }\n\n    def __init__(self, *args, **kwargs):\n        super(AdminParametersForm, self).__init__(*args, **kwargs)\n        hide_fields = False\n        code, output = exec_cmd(\"which dovecot\")\n        if not code:\n            dpath = output.strip()\n            try:\n                code, version = exec_cmd(\"%s --version\" % dpath)\n            except OSError:\n                hide_fields = True\n            else:\n                if code or not version.strip().startswith(\"2\"):\n                    hide_fields = True\n        else:\n            hide_fields = True\n        if hide_fields:\n            del self.fields[\"handle_mailboxes\"]\n            del self.fields[\"mailboxes_owner\"]\n\n    def clean_default_domain_quota(self):\n        \"\"\"Ensure quota is a positive integer.\"\"\"\n        if self.cleaned_data['default_domain_quota'] < 0:\n            raise forms.ValidationError(\n                ugettext_lazy('Must be a positive integer')\n            )\n        return self.cleaned_data['default_domain_quota']\n", "path": "modoboa/extensions/admin/app_settings.py"}], "after_files": [{"content": "from django import forms\nfrom django.utils.translation import ugettext_lazy\nfrom modoboa.lib.formutils import YesNoField, SeparatorField\nfrom modoboa.lib.sysutils import exec_cmd\nfrom modoboa.lib import parameters\nimport os\n\n\nclass AdminParametersForm(parameters.AdminParametersForm):\n    app = \"admin\"\n\n    mbsep = SeparatorField(label=ugettext_lazy(\"Mailboxes\"))\n\n    handle_mailboxes = YesNoField(\n        label=ugettext_lazy(\"Handle mailboxes on filesystem\"),\n        initial=\"no\",\n        help_text=ugettext_lazy(\"Rename or remove mailboxes on the filesystem when they get renamed or removed within Modoboa\")\n    )\n\n    mailboxes_owner = forms.CharField(\n        label=ugettext_lazy(\"Mailboxes ower\"),\n        initial=\"vmail\",\n        help_text=ugettext_lazy(\"The UNIX account who owns mailboxes on the filesystem\")\n    )\n\n    default_domain_quota = forms.IntegerField(\n        label=ugettext_lazy(\"Default domain quota\"),\n        initial=0,\n        help_text=ugettext_lazy(\n            \"Default quota (in MB) applied to freshly created domains with no \"\n            \"value specified. A value of 0 means no quota.\"\n        ),\n        widget=forms.TextInput(attrs={'class': 'span2'})\n    )\n\n    auto_account_removal = YesNoField(\n        label=ugettext_lazy(\"Automatic account removal\"),\n        initial=\"no\",\n        help_text=ugettext_lazy(\"When a mailbox is removed, also remove the associated account\")\n    )\n\n    # Visibility rules\n    visibility_rules = {\n        \"mailboxes_owner\": \"handle_mailboxes=yes\",\n    }\n\n    def __init__(self, *args, **kwargs):\n        super(AdminParametersForm, self).__init__(*args, **kwargs)\n        hide_fields = False\n        dpath = None\n        code, output = exec_cmd(\"which dovecot\")\n        known_paths = (\"/usr/sbin/dovecot\", \"/usr/local/sbin/dovecot\")\n        if not code:\n            dpath = output.strip()\n        else:\n            for fpath in known_paths:\n                if os.path.isfile(fpath) and os.access(fpath, os.X_OK):\n                    dpath = fpath\n        if dpath:\n            try:\n                code, version = exec_cmd(\"%s --version\" % dpath)\n            except OSError:\n                hide_fields = True\n            else:\n                if code or not version.strip().startswith(\"2\"):\n                    hide_fields = True\n        else:\n            hide_fields = True\n        if hide_fields:\n            del self.fields[\"handle_mailboxes\"]\n            del self.fields[\"mailboxes_owner\"]\n\n    def clean_default_domain_quota(self):\n        \"\"\"Ensure quota is a positive integer.\"\"\"\n        if self.cleaned_data['default_domain_quota'] < 0:\n            raise forms.ValidationError(\n                ugettext_lazy('Must be a positive integer')\n            )\n        return self.cleaned_data['default_domain_quota']\n", "path": "modoboa/extensions/admin/app_settings.py"}]}