Skip to content

Commit e3da057

Browse files
committed
Add message-id to email steps
1 parent 5d549b6 commit e3da057

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

patchwork/steps/ReadEmail/ReadEmail.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
from patchwork.step import Step
1313
from patchwork.steps.ReadEmail.typed import ReadEmailInputs, ReadEmailOutputs
1414

15+
class InnerParsedHeader(BaseModel):
16+
message_id: list[str] = Field(alias="message-id")
1517

1618
class ParsedHeader(BaseModel):
1719
subject: str
1820
from_: str = Field(alias="from")
1921
to: list[str]
2022
date: datetime
23+
header: InnerParsedHeader
2124

2225

2326
class ParsedBody(BaseModel):
@@ -74,6 +77,10 @@ def run(self) -> dict:
7477
"body": "",
7578
}
7679

80+
message_id = next(iter(email_data.header.header.message_id), None)
81+
if message_id is not None:
82+
rv["message_id"] = message_id
83+
7784
base_path = Path(self.base_path)
7885
base_path.mkdir(parents=True, exist_ok=True)
7986
for attachment in email_data.attachment:
@@ -92,3 +99,9 @@ def run(self) -> dict:
9299
rv["body"] += body.content
93100

94101
return rv
102+
103+
if __name__ == "__main__":
104+
k = ReadEmail(dict(
105+
eml_file_path="/Users/tianyouchen/Downloads/email.eml",
106+
)).run()
107+
print(k)

patchwork/steps/ReadEmail/typed.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ class ReadEmailOutputs(TypedDict):
2121
datetime: str
2222
from_: str # this is actually from instead of from_
2323
body: str
24+
message_id: str
2425
attachments: List[Attachment]

patchwork/steps/SendEmail/SendEmail.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ def __init__(self, inputs):
1919
self.password = inputs["sender_email_password"]
2020
self.smtp_host = inputs.get("smtp_host", "smtp.gmail.com")
2121
self.smtp_port = int(inputs.get("smtp_port", 465))
22+
self.reply_message_id = inputs.get("reply_message_id")
2223

2324
def run(self) -> dict:
2425
msg = MIMEText(mustache_render(self.body, self.email_template_value))
2526
msg["Subject"] = mustache_render(self.subject, self.email_template_value)
2627
msg["From"] = self.sender_email
2728
msg["To"] = self.recipient_email
29+
if self.reply_message_id is not None:
30+
msg.add_header('Reference', self.reply_message_id)
31+
msg.add_header('In-Reply-To', self.reply_message_id)
2832

2933
# TODO: support smtp without ssl
3034
with smtplib.SMTP_SSL(self.smtp_host, self.smtp_port) as smtp_server:

patchwork/steps/SendEmail/typed.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from typing_extensions import Annotated, Any, Dict, TypedDict
2-
3-
from patchwork.common.utils.step_typing import StepTypeConfig
1+
from typing_extensions import Any, TypedDict
42

53

64
class __SendEmailRequiredInputs(TypedDict):
@@ -15,6 +13,7 @@ class SendEmailInputs(__SendEmailRequiredInputs, total=False):
1513
body: str
1614
smtp_host: str
1715
smtp_port: int
16+
reply_message_id: str
1817

1918

2019
class SendEmailOutputs(TypedDict):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "patchwork-cli"
3-
version = "0.0.99.dev0"
3+
version = "0.0.99.dev1"
44
description = ""
55
authors = ["patched.codes"]
66
license = "AGPL"

0 commit comments

Comments
 (0)