-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Inspired by https://github.com/odoo/odoo/blob/15.0/addons/mail/static/scripts/odoo-mailgate.py | ||
|
||
import logging | ||
import os | ||
import xmlrpc.client | ||
|
||
import boto3 | ||
|
||
from lambdoo import execute, make_response | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
s3 = boto3.client('s3') | ||
|
||
|
||
@make_response | ||
def email_gateway(event, context): | ||
bucket = os.environ['BUCKET'] | ||
key_prefix = os.environ['KEY_PREFIX'] | ||
for record in event['Records']: | ||
key = record['ses']['mail']['messageId'] | ||
if key_prefix: | ||
key = f"{key_prefix}/{key}" | ||
_logger.info("processing email s3://%s/%s", bucket, key) | ||
msg = s3.get_object(Bucket=bucket, Key=key)['Body'].read() | ||
execute('mail.thread', 'message_process', [False, xmlrpc.client.Binary(msg)], {}) |