diff --git a/app.py b/app.py index 0ffbba1..93d2b0a 100644 --- a/app.py +++ b/app.py @@ -3574,12 +3574,18 @@ def delete_journal_entry(message_id): @login_required def delete_sent_email(sent_id): """Löscht einen einzelnen Outbox-Eintrag.""" - con = sqlite3.connect(EMAIL_JOURNAL_DB) - con.execute("DELETE FROM sent_emails WHERE id = ?", (sent_id,)) - con.commit() - con.close() - flash('Gesendete Email aus Log gelöscht.', 'success') - return redirect(url_for('email_log_view')) + try: + con = sqlite3.connect(EMAIL_JOURNAL_DB) + con.execute("DELETE FROM sent_emails WHERE id = ?", (sent_id,)) + con.commit() + con.close() + # JSON für fetch()-Aufrufe, Redirect-Fallback für direkte Formular-Posts + if 'application/json' in request.headers.get('Accept', ''): + return jsonify({'success': True}) + flash('Gesendete Email aus Log gelöscht.', 'success') + return redirect(url_for('emails')) + except Exception as e: + return jsonify({'success': False, 'message': str(e)}), 500 @app.route('/email-log') diff --git a/templates/emails.html b/templates/emails.html index 5277253..1f4a09c 100644 --- a/templates/emails.html +++ b/templates/emails.html @@ -131,12 +131,12 @@ Von Agent Task Status - + {% for mail in sent_emails %} - + {{ mail.id }} {{ mail.sent_at[:16].replace('T',' ') }} {{ mail.to_address }} @@ -153,11 +153,14 @@ {% endif %} - +
+ + +
{% endfor %} @@ -219,5 +222,23 @@ function showSentEmail(id, to, subject, date, agent, body) { document.getElementById('sentEmailBody').textContent = body || '(kein Inhalt gespeichert)'; new bootstrap.Modal(document.getElementById('sentEmailModal')).show(); } + +function deleteSentEmail(id) { + if (!confirm('Eintrag #' + id + ' aus dem Log löschen?')) return; + fetch('/emails/sent/' + id + '/delete', { + method: 'POST', + headers: {'Accept': 'application/json'} + }) + .then(r => r.json()) + .then(d => { + if (d.success) { + const row = document.getElementById('sent-row-' + id); + if (row) row.remove(); + } else { + alert('Fehler: ' + d.message); + } + }) + .catch(() => alert('Netzwerkfehler.')); +} {% endblock %}