aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/incoming_message.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/incoming_message.rb')
-rw-r--r--app/models/incoming_message.rb32
1 files changed, 15 insertions, 17 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index fcb4671c5..60828e179 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -1,3 +1,5 @@
+# coding: utf-8
+
# == Schema Information
# Schema version: 114
#
@@ -17,9 +19,6 @@
# last_parsed :datetime
# mail_from :text
# sent_at :datetime
-#
-
-# encoding: UTF-8
# models/incoming_message.rb:
# An (email) message from really anybody to be logged with a request. e.g. A
@@ -75,11 +74,10 @@ class IncomingMessage < ActiveRecord::Base
# Documentation at http://i.loveruby.net/en/projects/tmail/doc/
def mail(force = nil)
if (!force.nil? || @mail.nil?) && !self.raw_email.nil?
- # Hack round bug in TMail's MIME decoding. Example request which provokes it:
- # http://www.whatdotheyknow.com/request/reviews_of_unduly_lenient_senten#incoming-4830
+ # Hack round bug in TMail's MIME decoding.
# Report of TMail bug:
# http://rubyforge.org/tracker/index.php?func=detail&aid=21810&group_id=4512&atid=17370
- copy_of_raw_data = self.raw_email.data.gsub(/; boundary=\s+"/ims,'; boundary="')
+ copy_of_raw_data = self.raw_email.data.gsub(/; boundary=\s+"/im,'; boundary="')
@mail = TMail::Mail.parse(copy_of_raw_data)
@mail.base64_decode
@@ -291,7 +289,7 @@ class IncomingMessage < ActiveRecord::Base
logger.warn "Unable to compress PDF; problem with your pdftk version?"
end
if !recompressed_text.nil? && !recompressed_text.empty?
- text[0..-1] = recompressed_text # [0..-1] makes it change the 'text' string in place
+ text.replace recompressed_text
end
end
end
@@ -345,16 +343,15 @@ class IncomingMessage < ActiveRecord::Base
name = Regexp.escape(self.info_request.user_name)
# To end of message sections
- # http://www.whatdotheyknow.com/request/university_investment_in_the_arm
- text.gsub!(/^#{name}[^\n]+\nSent by:[^\n]+\n.*/ims, "\n\n" + replacement)
+ text.gsub!(/^\s?#{name}[^\n]+\n([^\n]+\n)?\s?Sent by:[^\n]+\n.*/im, "\n\n" + replacement)
# Some other sort of forwarding quoting
- # http://www.whatdotheyknow.com/request/224/response/326
- text.gsub!(/^#{name}[^\n]+\n[0-9\/:\s]+\s+To\s+FOI requests at.*/ims, "\n\n" + replacement)
+ text.gsub!(/^\s?#{name}\s+To\s+FOI requests at.*/im, "\n\n" + replacement)
+
- # http://www.whatdotheyknow.com/request/how_do_the_pct_deal_with_retirin_33#incoming-930
# http://www.whatdotheyknow.com/request/229/response/809
- text.gsub!(/^From: [^\n]+\nSent: [^\n]+\nTo:\s+['"?]#{name}['"]?\nSubject:.*/ims, "\n\n" + replacement)
+ text.gsub!(/^\s?From: [^\n]+\n\s?Sent: [^\n]+\n\s?To:\s+['"]?#{name}['"]?\n\s?Subject:.*/im, "\n\n" + replacement)
+
return text
@@ -397,7 +394,7 @@ class IncomingMessage < ActiveRecord::Base
# http://www.whatdotheyknow.com/request/police_powers_to_inform_car_insu
# http://www.whatdotheyknow.com/request/secured_convictions_aided_by_cct
multiline_original_message = '(' + '''>>>.* \d\d/\d\d/\d\d\d\d\s+\d\d:\d\d(?::\d\d)?\s*>>>''' + ')'
- text.gsub!(/^(#{multiline_original_message}\n.*)$/ms, replacement)
+ text.gsub!(/^(#{multiline_original_message}\n.*)$/m, replacement)
# Single line sections
text.gsub!(/^(>.*\n)/, replacement)
@@ -568,7 +565,7 @@ class IncomingMessage < ActiveRecord::Base
text = self.get_main_body_text_internal
# Strip the uudecode parts from main text
# - this also effectively does a .dup as well, so text mods don't alter original
- text = text.split(/^begin.+^`\n^end\n/sm).join(" ")
+ text = text.split(/^begin.+^`\n^end\n/m).join(" ")
if text.size > 1000000 # 1 MB ish
raise "main body text more than 1 MB, need to implement clipping like for attachment text, or there is some other MIME decoding problem or similar"
@@ -580,7 +577,8 @@ class IncomingMessage < ActiveRecord::Base
# Remove existing quoted sections
folded_quoted_text = self.remove_lotus_quoting(text, 'FOLDED_QUOTED_SECTION')
- folded_quoted_text = IncomingMessage.remove_quoted_sections(text, "FOLDED_QUOTED_SECTION")
+ folded_quoted_text = IncomingMessage.remove_quoted_sections(folded_quoted_text, "FOLDED_QUOTED_SECTION")
+
self.cached_main_body_text_unfolded = text
self.cached_main_body_text_folded = folded_quoted_text
self.save!
@@ -706,7 +704,7 @@ class IncomingMessage < ActiveRecord::Base
# Returns attachments that are uuencoded in main body part
def _uudecode_and_save_attachments(text)
# Find any uudecoded things buried in it, yeuchly
- uus = text.scan(/^begin.+^`\n^end\n/sm)
+ uus = text.scan(/^begin.+^`\n^end\n/m)
attachments = []
for uu in uus
# Decode the string