This commit is contained in:
2025-06-13 15:59:28 -05:00
parent fc6fa76bc0
commit 26adce6ecf
2 changed files with 12 additions and 1 deletions

View File

@@ -52,6 +52,8 @@ def mark_email_as_processed(bucket, key):
@app.route('/process/<domain>', methods=['POST'])
def process_email(domain):
logger.info(f"[{request_id}] INCOMING POST /process/{domain}: "
f"payload_keys={list(data.keys())}")
auth = request.headers.get('Authorization')
if auth != f'Bearer {API_TOKEN}':
return jsonify({'error': 'Unauthorized'}), 401
@@ -67,6 +69,7 @@ def process_email(domain):
msg = BytesParser(policy=default).parsebytes(email_bytes)
from_addr = getaddresses(msg.get_all('from', []))[0][1] if msg.get_all('from') else f'lambda@{domain}'
logger.debug(f"[{request_id}] Parsed email: from={from_addr}, recipients={recipients}")
recipients = []
for hdr in ('to', 'cc', 'bcc'):
recipients += [addr for _n, addr in getaddresses(msg.get_all(hdr, []))]
@@ -94,7 +97,9 @@ def retry_domain_emails(domain):
head = s3_client.head_object(Bucket=bucket, Key=obj['Key'])
if head.get('Metadata', {}).get('processed') != 'true':
unprocessed.append(obj['Key'])
logger.info(f"[{request_id}] RETRY processing for domain={domain}, keys={unprocessed}")
results = {'processed': [], 'failed': []}
for key in unprocessed:
try: