From 2a7c9d85293763f002bdb89f8e0ccc149496e01a Mon Sep 17 00:00:00 2001 From: SysAdmin Agent Date: Wed, 11 Mar 2026 21:01:05 +0000 Subject: [PATCH] Add IMAP configuration UI and sidebar navigation for email inbox - Email settings page at /administration/email/ with IMAP config form - Connection test button to verify IMAP connectivity - Sidebar link "E-Mail Eingang" for quick access - AppConfiguration model extended with email category and password type - init_config command includes IMAP default settings - DB-based IMAP config with env var fallback Co-Authored-By: Claude Opus 4.6 --- .../management/commands/init_config.py | 68 ++++++++- app/stiftung/models/system.py | 2 + app/stiftung/urls.py | 1 + app/stiftung/views/__init__.py | 1 + app/templates/base.html | 4 + app/templates/stiftung/administration.html | 6 + app/templates/stiftung/app_settings.html | 29 ++-- app/templates/stiftung/email_settings.html | 142 ++++++++++++++++++ 8 files changed, 241 insertions(+), 12 deletions(-) create mode 100644 app/templates/stiftung/email_settings.html diff --git a/app/stiftung/management/commands/init_config.py b/app/stiftung/management/commands/init_config.py index 5af320a..1a27205 100644 --- a/app/stiftung/management/commands/init_config.py +++ b/app/stiftung/management/commands/init_config.py @@ -91,10 +91,76 @@ class Command(BaseCommand): }, ] + # E-Mail / IMAP Settings + email_settings = [ + { + "key": "imap_host", + "display_name": "IMAP Server", + "description": "Hostname oder IP-Adresse des IMAP-Servers (z.B. mail.example.com)", + "value": "", + "default_value": "", + "setting_type": "text", + "category": "email", + "order": 1, + }, + { + "key": "imap_port", + "display_name": "IMAP Port", + "description": "Port des IMAP-Servers (Standard: 993 für SSL, 143 für unverschlüsselt)", + "value": "993", + "default_value": "993", + "setting_type": "number", + "category": "email", + "order": 2, + }, + { + "key": "imap_user", + "display_name": "IMAP Benutzername", + "description": "Benutzername / E-Mail-Adresse für die IMAP-Anmeldung", + "value": "", + "default_value": "", + "setting_type": "text", + "category": "email", + "order": 3, + }, + { + "key": "imap_password", + "display_name": "IMAP Passwort", + "description": "Passwort für die IMAP-Anmeldung", + "value": "", + "default_value": "", + "setting_type": "password", + "category": "email", + "order": 4, + }, + { + "key": "imap_folder", + "display_name": "IMAP Ordner", + "description": "Name des zu überwachenden Postfach-Ordners (Standard: INBOX)", + "value": "INBOX", + "default_value": "INBOX", + "setting_type": "text", + "category": "email", + "order": 5, + }, + { + "key": "imap_use_ssl", + "display_name": "SSL/TLS verwenden", + "description": "Sichere Verbindung zum IMAP-Server (empfohlen)", + "value": "True", + "default_value": "True", + "setting_type": "boolean", + "category": "email", + "order": 6, + }, + ] + + all_settings = paperless_settings + email_settings + created_count = 0 updated_count = 0 - for setting_data in paperless_settings: + for setting_data in all_settings: setting, created = AppConfiguration.objects.get_or_create( key=setting_data["key"], defaults=setting_data ) diff --git a/app/stiftung/models/system.py b/app/stiftung/models/system.py index 47eaa1f..1ee3f2a 100644 --- a/app/stiftung/models/system.py +++ b/app/stiftung/models/system.py @@ -313,6 +313,7 @@ class AppConfiguration(models.Model): SETTING_TYPE_CHOICES = [ ("text", "Text"), + ("password", "Password"), ("number", "Number"), ("boolean", "Boolean"), ("url", "URL"), @@ -322,6 +323,7 @@ class AppConfiguration(models.Model): CATEGORY_CHOICES = [ ("paperless", "Paperless Integration"), + ("email", "E-Mail / IMAP"), ("general", "General Settings"), ("corporate", "Corporate Identity"), ("notifications", "Notifications"), diff --git a/app/stiftung/urls.py b/app/stiftung/urls.py index 85292aa..9f493d6 100644 --- a/app/stiftung/urls.py +++ b/app/stiftung/urls.py @@ -262,6 +262,7 @@ urlpatterns = [ # Administration URLs path("administration/", views.administration, name="administration"), path("administration/settings/", views.app_settings, name="app_settings"), + path("administration/email/", views.email_settings, name="email_settings"), path("administration/audit-log/", views.audit_log_list, name="audit_log_list"), path("administration/backup/", views.backup_management, name="backup_management"), path( diff --git a/app/stiftung/views/__init__.py b/app/stiftung/views/__init__.py index 2956066..dce7bd0 100644 --- a/app/stiftung/views/__init__.py +++ b/app/stiftung/views/__init__.py @@ -156,6 +156,7 @@ from .system import ( # noqa: F401 user_login, user_logout, app_settings, + email_settings, edit_help_box, two_factor_setup, two_factor_qr, diff --git a/app/templates/base.html b/app/templates/base.html index 90302c1..670f92d 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -596,6 +596,10 @@ Foerderungen + + + E-Mail Eingang + Paechter diff --git a/app/templates/stiftung/administration.html b/app/templates/stiftung/administration.html index b4fd4c9..a081914 100644 --- a/app/templates/stiftung/administration.html +++ b/app/templates/stiftung/administration.html @@ -217,6 +217,12 @@ App Settings +
diff --git a/app/templates/stiftung/app_settings.html b/app/templates/stiftung/app_settings.html index 6acafcf..d1e4765 100644 --- a/app/templates/stiftung/app_settings.html +++ b/app/templates/stiftung/app_settings.html @@ -27,7 +27,7 @@

- + {{ category_name }}

@@ -49,9 +49,9 @@ {% if setting.setting_type == 'boolean' %}
- {% endif %} - {% elif setting.setting_type == 'integer' %} - + {% elif setting.setting_type == 'integer' or setting.setting_type == 'number' %} + {% elif setting.setting_type == 'text' or setting.setting_type == 'url' %} - diff --git a/app/templates/stiftung/email_settings.html b/app/templates/stiftung/email_settings.html new file mode 100644 index 0000000..d8ca4dd --- /dev/null +++ b/app/templates/stiftung/email_settings.html @@ -0,0 +1,142 @@ +{% extends 'base.html' %} + +{% block title %}{{ title }} - Stiftung{% endblock %} + +{% block breadcrumb %} +Stiftungsverwaltung +/ +Administration +/ +{{ title }} +{% endblock %} + +{% block content %} +
+
+
+
+
+

+ + {{ title }} +

+ + Zurück + +
+ +
+ {% if test_result %} +
+ + {{ test_result.message }} + +
+ {% endif %} + +
+ {% csrf_token %} + + {% for setting in imap_settings %} +
+ + {% if setting.description %} +
{{ setting.description }}
+ {% endif %} + + {% if setting.setting_type == 'boolean' %} +
+ + +
+ + {% elif setting.setting_type == 'password' %} +
+ + +
+ + {% elif setting.setting_type == 'number' %} + + + {% else %} + + {% endif %} +
+ {% endfor %} + +
+
+ + + + Zum Posteingang + +
+
+
+
+
+ + +
+
+
+ Hinweise +
+
+

Konfigurieren Sie hier die IMAP-Verbindung zum E-Mail-Server. Eingehende E-Mails werden automatisch alle 15 Minuten abgerufen und den Destinatären zugeordnet.

+
+

Typische Einstellungen:

+
    +
  • SSL/TLS: Port 993
  • +
  • Unverschlüsselt: Port 143
  • +
+
+

Das Passwort wird in der Datenbank gespeichert. Umgebungsvariablen (IMAP_HOST, etc.) werden als Fallback verwendet, wenn hier keine Werte gesetzt sind.

+
+
+
+
+
+ + +{% endblock %}