Open garethrees opened 5 years ago
Linking to the raw email for reference.
This at least prevents the problem:
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb
index 71caaf345..38885f4ab 100644
--- a/app/models/foi_attachment.rb
+++ b/app/models/foi_attachment.rb
@@ -67,7 +67,7 @@ class FoiAttachment < ActiveRecord::Base
update_display_size!
@cached_body = d
if String.method_defined?(:encode)
- @cached_body = @cached_body.force_encoding("ASCII-8BIT")
+ @cached_body = @cached_body.dup.force_encoding("ASCII-8BIT")
end
end
It looks like the string is frozen when extracted…
m = IncomingMessage.last
attrs = MailHandler.get_attachment_attributes(m.raw_email.mail).select { |h| h[:hexdigest] == "d41d8cd98f00b204e9800998ecf8427e" }.first
get_part_body frozen? false
get_part_body frozen? true
get_part_body frozen? true
=> {:url_part_number=>2,
:content_type=>"application/pdf",
:filename=>"FOI 18-03028 Resp.pdf",
:charset=>nil,
:within_rfc822_subject=>nil,
:body=>"",
:hexdigest=>"d41d8cd98f00b204e9800998ecf8427e"}
Yep, Mail::Body#decoded
returns a frozen String, so I think this is something that we're not handling correctly.
From: /home/vagrant/alaveteli/lib/mail_handler/backends/mail_backend.rb @ line 86 MailHandler::Backends::MailBackend#get_part_body:
84: def get_part_body(part)
85: binding.pry
=> 86: decoded = part.body.decoded
87: puts "get_part_body frozen? #{decoded.frozen?}"
88: if part.content_type =~ /^text\//
89: decoded = convert_string_to_utf8_or_binary decoded, part.charset
90: end
91: decoded
92: end
part.body.decoded.frozen?
# => true
part.body.class
# => Mail::Body
Monkeypatched this change in the console and parsed the raw email which was successful. Looks like the attached PDF is corrupt though, as its showing as 0KB and I can't even see it if I open the raw email in Apple Mail.