Skip to content

Commit

Permalink
Fix white space attachment processing
Browse files Browse the repository at this point in the history
Some previously extracted attachment appear to have extra trailing
white space, this commits strips this in order identify the original
attachment body.

Fixes #7886
  • Loading branch information
gbp committed Sep 4, 2023
1 parent 5c4d3f0 commit 55d211c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/mail_handler/backends/mail_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ def attempt_to_find_original_attachment_attributes(mail, body:, nested: false)

def caluclate_hexdigest(body)

Check warning on line 402 in lib/mail_handler/backends/mail_backend.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Lint/NestedMethodDefinition: Method definitions must not be nested. Use lambda instead. (https://rubystyle.guide#no-nested-methods) Raw Output: lib/mail_handler/backends/mail_backend.rb:402:9: W: Lint/NestedMethodDefinition: Method definitions must not be nested. Use lambda instead. (https://rubystyle.guide#no-nested-methods) def caluclate_hexdigest(body) ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# ensure bodies have the same line endings
Digest::MD5.hexdigest(Mail::Utilities.binary_unsafe_to_lf(body))
Digest::MD5.hexdigest(Mail::Utilities.binary_unsafe_to_lf(
body.rstrip

Check warning on line 405 in lib/mail_handler/backends/mail_backend.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Layout/FirstArgumentIndentation: Indent the first argument one step more than Mail::Utilities.binary_unsafe_to_lf(. Raw Output: lib/mail_handler/backends/mail_backend.rb:405:13: C: [Correctable] Layout/FirstArgumentIndentation: Indent the first argument one step more than Mail::Utilities.binary_unsafe_to_lf(. body.rstrip ^^^^^^^^^^^
))
end

hexdigest = caluclate_hexdigest(body)
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/mail_handler/backends/mail_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@
it { is_expected.to include(body_without_headers: "Hello world\n") }
end

context 'when body has trailing whitespace' do
let(:body) { "bar\nbar\n" }
it { is_expected.to include(body: "bar\nbar") }
end

context 'when body does not match' do
let(:body) { 'this does not match' }
it { is_expected.to eq(nil) }
Expand Down

0 comments on commit 55d211c

Please sign in to comment.