BugFixing
This commit is contained in:
parent
26adce6ecf
commit
434f94f882
|
|
@ -52,8 +52,6 @@ def mark_email_as_processed(bucket, key):
|
||||||
|
|
||||||
@app.route('/process/<domain>', methods=['POST'])
|
@app.route('/process/<domain>', methods=['POST'])
|
||||||
def process_email(domain):
|
def process_email(domain):
|
||||||
logger.info(f"[{request_id}] INCOMING POST /process/{domain}: "
|
|
||||||
f"payload_keys={list(data.keys())}")
|
|
||||||
auth = request.headers.get('Authorization')
|
auth = request.headers.get('Authorization')
|
||||||
if auth != f'Bearer {API_TOKEN}':
|
if auth != f'Bearer {API_TOKEN}':
|
||||||
return jsonify({'error': 'Unauthorized'}), 401
|
return jsonify({'error': 'Unauthorized'}), 401
|
||||||
|
|
@ -61,15 +59,21 @@ def process_email(domain):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if not data:
|
if not data:
|
||||||
return jsonify({'error': 'Invalid payload'}), 400
|
return jsonify({'error': 'Invalid payload'}), 400
|
||||||
|
|
||||||
|
request_id = data.get('request_id', 'no-request-id')
|
||||||
content = data.get('email_content')
|
content = data.get('email_content')
|
||||||
compressed = data.get('compressed', False)
|
compressed = data.get('compressed', False)
|
||||||
raw = base64.b64decode(content)
|
raw = base64.b64decode(content)
|
||||||
email_bytes = gzip.decompress(raw) if compressed else raw
|
email_bytes = gzip.decompress(raw) if compressed else raw
|
||||||
|
|
||||||
|
logger.info(f"[{request_id}] INCOMING POST /process/{domain}: "
|
||||||
|
f"payload_keys={list(data.keys())}")
|
||||||
|
|
||||||
msg = BytesParser(policy=default).parsebytes(email_bytes)
|
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}'
|
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}")
|
logger.debug(f"[{request_id}] Parsed email: from={from_addr}, recipients={recipients}")
|
||||||
|
|
||||||
recipients = []
|
recipients = []
|
||||||
for hdr in ('to', 'cc', 'bcc'):
|
for hdr in ('to', 'cc', 'bcc'):
|
||||||
recipients += [addr for _n, addr in getaddresses(msg.get_all(hdr, []))]
|
recipients += [addr for _n, addr in getaddresses(msg.get_all(hdr, []))]
|
||||||
|
|
@ -98,6 +102,7 @@ def retry_domain_emails(domain):
|
||||||
if head.get('Metadata', {}).get('processed') != 'true':
|
if head.get('Metadata', {}).get('processed') != 'true':
|
||||||
unprocessed.append(obj['Key'])
|
unprocessed.append(obj['Key'])
|
||||||
|
|
||||||
|
request_id = f"retry-{domain}-{int(time.time())}"
|
||||||
logger.info(f"[{request_id}] RETRY processing for domain={domain}, keys={unprocessed}")
|
logger.info(f"[{request_id}] RETRY processing for domain={domain}, keys={unprocessed}")
|
||||||
|
|
||||||
results = {'processed': [], 'failed': []}
|
results = {'processed': [], 'failed': []}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue