Skip to content

Commit

Permalink
fix: update raw headers after changing messages to during parsing
Browse files Browse the repository at this point in the history
Previously, headers were not updated but the mail gem parsing may decide
to change the transfer encoding. If it does this, the body is updated to
the new format but the header is not, this results in a mismatch when the
message it sent onwards and the client being unable render the message.

The specific situation identified was changing an HTML-only e-mail from
quoted-printable to 7bit.

closes #2816
  • Loading branch information
adamcooke committed Feb 23, 2024
1 parent 559b08d commit 2834e2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/postal/message_db/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ def parse_content
if parse_result.actioned?
# 聽Somethign was changed, update the raw message
@database.update(raw_table, { data: parse_result.new_body }, where: { id: raw_body_id })
@database.update(raw_table, { data: parse_result.new_headers }, where: { id: raw_headers_id })
@raw = parse_result.new_body
@raw_headers = parse_result.new_headers
@raw_message = nil
end
update("parsed" => 1, "tracked_links" => parse_result.tracked_links, "tracked_images" => parse_result.tracked_images)
Expand Down
8 changes: 6 additions & 2 deletions lib/postal/message_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(message)

return unless @domain

@parsed_output = generate
@parsed_output = generate.split("\r\n\r\n", 2)
end

attr_reader :tracked_links
Expand All @@ -25,7 +25,11 @@ def actioned?
end

def new_body
@parsed_output.split("\r\n\r\n", 2)[1]
@parsed_output[1]
end

def new_headers
@parsed_output[0]
end

private
Expand Down

0 comments on commit 2834e2c

Please sign in to comment.