Skip to content

Commit

Permalink
Set email flags in right way
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Gladkov <[email protected]>
  • Loading branch information
legionus committed Sep 13, 2023
1 parent 643ce63 commit f748a45
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions jiramail/change.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@
no_reply: bool = False


def set_mail_flags(mail: email.message.EmailMessage, flags: str) -> None:
header_status = ""
header_xstatus = ""

for flag in ('R', 'O'):
if flag in flags:
header_status += flag

for flag in ('D', 'F', 'A'):
if flag in flags:
header_xstatus += flag

del mail["Status"]
del mail["X-Status"]

mail["Status"] = header_status
mail["X-Status"] = header_xstatus


def get_issue(key: str) -> jira.resources.Issue | jiramail.Error:
try:
issue = jserv.jira.issue(key)
Expand Down Expand Up @@ -454,8 +473,7 @@ def process_commands(mail: email.message.Message, fd: TextIO,
resp.add_header("From", "jirachange")
resp.add_header("Date", email.utils.format_datetime(datetime.now()))
resp.add_header("Message-Id", msg_id)
resp.add_header("Status", "RO")
resp.add_header("X-Status", "A")
set_mail_flags(resp, "ROA")

subj = mail.get("Subject")
if subj:
Expand Down Expand Up @@ -547,9 +565,7 @@ def main(cmdargs: argparse.Namespace) -> int:

if cmdargs.stdin:
stdin_mail = email.message_from_file(sys.stdin)
stdin_mail["Status"] = "RO"
stdin_mail["X-Status"] = "A"

set_mail_flags(stdin_mail, "ROA")
mbox.append(stdin_mail)

if not process_mail(stdin_mail, replies):
Expand Down

0 comments on commit f748a45

Please sign in to comment.