Skip to content

Commit

Permalink
Add message-id to email steps
Browse files Browse the repository at this point in the history
  • Loading branch information
CTY-git committed Feb 13, 2025
1 parent 5d549b6 commit 8201bd6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions patchwork/steps/ReadEmail/ReadEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
from patchwork.step import Step
from patchwork.steps.ReadEmail.typed import ReadEmailInputs, ReadEmailOutputs

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

class ParsedHeader(BaseModel):
subject: str
from_: str = Field(alias="from")
to: list[str]
date: datetime
header: InnerParsedHeader


class ParsedBody(BaseModel):
Expand Down Expand Up @@ -74,6 +77,10 @@ def run(self) -> dict:
"body": "",
}

message_id = next(iter(email_data.header.header.message_id), None)
if message_id is not None:
rv["message_id"] = message_id

base_path = Path(self.base_path)
base_path.mkdir(parents=True, exist_ok=True)
for attachment in email_data.attachment:
Expand Down
1 change: 1 addition & 0 deletions patchwork/steps/ReadEmail/typed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ class ReadEmailOutputs(TypedDict):
datetime: str
from_: str # this is actually from instead of from_
body: str
message_id: str
attachments: List[Attachment]
4 changes: 4 additions & 0 deletions patchwork/steps/SendEmail/SendEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ def __init__(self, inputs):
self.password = inputs["sender_email_password"]
self.smtp_host = inputs.get("smtp_host", "smtp.gmail.com")
self.smtp_port = int(inputs.get("smtp_port", 465))
self.reply_message_id = inputs.get("reply_message_id")

def run(self) -> dict:
msg = MIMEText(mustache_render(self.body, self.email_template_value))
msg["Subject"] = mustache_render(self.subject, self.email_template_value)
msg["From"] = self.sender_email
msg["To"] = self.recipient_email
if self.reply_message_id is not None:
msg.add_header('Reference', self.reply_message_id)
msg.add_header('In-Reply-To', self.reply_message_id)

# TODO: support smtp without ssl
with smtplib.SMTP_SSL(self.smtp_host, self.smtp_port) as smtp_server:
Expand Down
5 changes: 2 additions & 3 deletions patchwork/steps/SendEmail/typed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing_extensions import Annotated, Any, Dict, TypedDict

from patchwork.common.utils.step_typing import StepTypeConfig
from typing_extensions import Any, TypedDict


class __SendEmailRequiredInputs(TypedDict):
Expand All @@ -15,6 +13,7 @@ class SendEmailInputs(__SendEmailRequiredInputs, total=False):
body: str
smtp_host: str
smtp_port: int
reply_message_id: str


class SendEmailOutputs(TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "patchwork-cli"
version = "0.0.99.dev0"
version = "0.0.99.dev1"
description = ""
authors = ["patched.codes"]
license = "AGPL"
Expand Down

0 comments on commit 8201bd6

Please sign in to comment.