aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2012-12-05 16:53:58 +0000
committerLouise Crow <louise.crow@gmail.com>2012-12-05 16:53:58 +0000
commit4cdede680722b4b69bd0e552608c63ccf82dc660 (patch)
tree7d33ca289c2237a1f460a3a2c8cb8a8e73f578ee
parent0375214ca0c295f0316ec80be8aebdbd1d1c1b8a (diff)
Separate mail-specific stuff from creation/update of model instances.
-rw-r--r--app/models/incoming_message.rb20
1 files changed, 12 insertions, 8 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index b059b143f..004df19fc 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -595,6 +595,7 @@ class IncomingMessage < ActiveRecord::Base
force = true
leaves = MailHandler.get_attachment_attributes(self.mail(force))
attachments = []
+ attachment_attributes = []
for leaf in leaves
body = MailHandler.get_part_body(leaf)
# As leaf.body causes MIME decoding which uses lots of RAM, do garbage collection here
@@ -631,14 +632,17 @@ class IncomingMessage < ActiveRecord::Base
#attachment.body = leaf.within_rfc822_attachment.port.to_s
end
end
- hexdigest = Digest::MD5.hexdigest(body)
- attachment = self.foi_attachments.find_or_create_by_hexdigest(:hexdigest => hexdigest)
- attachment.update_attributes(:url_part_number => leaf.url_part_number,
- :content_type => MailHandler.get_content_type(leaf),
- :filename => MailHandler.get_part_file_name(leaf),
- :charset => leaf.charset,
- :within_rfc822_subject => within_rfc822_subject,
- :body => body)
+ attachment_attributes << {:url_part_number => leaf.url_part_number,
+ :content_type => MailHandler.get_content_type(leaf),
+ :filename => MailHandler.get_part_file_name(leaf),
+ :charset => leaf.charset,
+ :within_rfc822_subject => within_rfc822_subject,
+ :body => body,
+ :hexdigest => Digest::MD5.hexdigest(body) }
+ end
+ attachment_attributes.each do |attrs|
+ attachment = self.foi_attachments.find_or_create_by_hexdigest(:hexdigest => attrs[:hexdigest])
+ attachment.update_attributes(attrs)
attachment.save!
attachments << attachment.id
end