This commit is contained in:
Andreas Knuth 2026-01-24 16:54:33 -06:00
parent 404168143a
commit f9e866d948
1 changed files with 14 additions and 3 deletions

View File

@ -5,6 +5,7 @@ sync_dynamodb_to_sieve.py - Sync DynamoDB rules to Dovecot Sieve
import boto3
import os
from pathlib import Path
import json
# Config
REGION = 'us-east-2'
@ -14,6 +15,8 @@ VMAIL_BASE = '/var/mail'
dynamodb = boto3.resource('dynamodb', region_name=REGION)
table = dynamodb.Table(TABLE)
import json
def generate_sieve(email, rules):
"""Generate Sieve script from DynamoDB rules"""
lines = ['require ["copy","vacation","variables"];', '']
@ -46,16 +49,24 @@ def generate_sieve(email, rules):
if content_type == 'html':
lines.extend([
f'vacation :days 1 :from "{email}" :mime text:',
'', # ← WICHTIG: Leerzeile nach text:
# HIER ENTFERNT: Die extra Leerzeile war falsch.
# .join() macht bereits den nötigen Umbruch nach 'text:'
'Content-Type: text/html; charset=utf-8',
'',
msg,
'.'
])
else:
lines.append(f'vacation :days 1 :from "{email}" "{msg}";')
# WICHTIG: Escape double quotes in msg, sonst Syntax-Fehler bei "I'm here"
# json.dumps erstellt einen String mit Anführungszeichen (z.B. "Text"),
# wir brauchen aber nur den escaped Inhalt.
safe_msg = json.dumps(msg, ensure_ascii=False)
# json.dumps gibt '"msg"' zurück, wir nutzen das direkt
lines.append(f'vacation :days 1 :from "{email}" {safe_msg};')
return '\n'.join(lines)
# WICHTIG: Ein Sieve-Script (und speziell der Multi-Line Block)
# muss zwingend mit einem Zeilenumbruch enden.
return '\n'.join(lines) + '\n'
def sync():
"""Sync all rules from DynamoDB to Sieve"""