This commit is contained in:
Andreas Knuth 2026-01-24 16:46:49 -06:00
parent adad46ce7d
commit 30e928c6e6
1 changed files with 22 additions and 18 deletions

View File

@ -16,41 +16,45 @@ table = dynamodb.Table(TABLE)
def generate_sieve(email, rules):
"""Generate Sieve script from DynamoDB rules"""
script = ['require ["copy","vacation","variables"];']
lines = ['require ["copy","vacation","variables"];', '']
# Skip if already processed by worker
script.append('# Skip if already processed by worker')
script.append('if header :contains "X-SES-Worker-Processed" "" {')
script.append(' keep;')
script.append(' stop;')
script.append('}')
lines.extend([
'# Skip if already processed by worker',
'if header :contains "X-SES-Worker-Processed" "" {',
' keep;',
' stop;',
'}',
''
])
# Forwards
forwards = rules.get('forwards', [])
if forwards:
script.append('# rule:[forward]')
lines.append('# rule:[forward]')
for fwd in forwards:
script.append(f'redirect :copy "{fwd}";')
lines.append(f'redirect :copy "{fwd}";')
lines.append('')
# OOO
if rules.get('ooo_active'):
msg = rules.get('ooo_message', 'I am away')
content_type = rules.get('ooo_content_type', 'text')
script.append('# rule:[reply]')
lines.append('# rule:[reply]')
if content_type == 'html':
# HTML mit :mime
script.append(f'vacation :days 1 :from "{email}" :mime text:')
script.append(f'Content-Type: text/html; charset=utf-8')
script.append(f'')
script.append(msg)
script.append('.')
lines.extend([
f'vacation :days 1 :from "{email}" :mime text:',
'Content-Type: text/html; charset=utf-8',
'',
msg,
'.'
])
else:
# Plain text
script.append(f'vacation :days 1 :from "{email}" "{msg}";')
lines.append(f'vacation :days 1 :from "{email}" "{msg}";')
return '\n'.join(script)
return '\n'.join(lines)
def sync():
"""Sync all rules from DynamoDB to Sieve"""