diff options
author | francis <francis> | 2009-04-07 16:23:28 +0000 |
---|---|---|
committer | francis <francis> | 2009-04-07 16:23:28 +0000 |
commit | 6a6c100fb7651c08420e89472c71a63171295771 (patch) | |
tree | bff4ba5cdb53103a5b1348e67637b3cac0e59069 | |
parent | da1b75d7813f5a3bd892d8f2310ca07c48c56a0e (diff) |
Move TMail monkey patches into their own file
-rw-r--r-- | config/environment.rb | 39 | ||||
-rw-r--r-- | lib/tmail_extensions.rb | 48 |
2 files changed, 50 insertions, 37 deletions
diff --git a/config/environment.rb b/config/environment.rb index 9fecc98f0..2740d8352 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -120,43 +120,8 @@ module WillPaginate end end -# These mainly used in app/models/incoming_message.rb -module TMail - class Mail - # Monkeypatch! (check to see if this becomes a standard function in - # TMail::Mail, then use that, whatever it is called) - def self.get_part_file_name(part) - file_name = (part['content-location'] && - part['content-location'].body) || - part.sub_header("content-type", "name") || - part.sub_header("content-disposition", "filename") - end - end - - class Address - # Monkeypatch! - def Address.encode_quoted_string(text) - # XXX have added space to this, so we don't excessive quoting - if text.match(/[^A-Za-z0-9!#\$%&'*+\-\/=?^_`{|}~ ]/) - # Contains characters which aren't valid in atoms, so make a - # quoted-pair instead. - text.gsub!(/(["\\])/, "\\\\\\1") - text = '"' + text + '"' - end - return text - end - - # Monkeypatch! - def quoted_full - if self.name - Address.encode_quoted_string(self.name) + " <" + self.spec + ">" - else - self.spec - end - end - end -end - +# Load monkey patches from lib/ +require 'tmail_extensions' # XXX temp debug for SQL logging production sites #ActiveRecord::Base.logger = Logger.new(STDOUT) diff --git a/lib/tmail_extensions.rb b/lib/tmail_extensions.rb new file mode 100644 index 000000000..9aabdfeed --- /dev/null +++ b/lib/tmail_extensions.rb @@ -0,0 +1,48 @@ +# models/request_mailer.rb: +# Extensions / fixes to TMail. +# +# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. +# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: tmail_extensions.rb,v 1.1 2009-04-07 16:23:28 francis Exp $ + +# Monkeypatch! + +# These mainly used in app/models/incoming_message.rb +module TMail + class Mail + # Monkeypatch! (check to see if this becomes a standard function in + # TMail::Mail, then use that, whatever it is called) + def self.get_part_file_name(part) + file_name = (part['content-location'] && + part['content-location'].body) || + part.sub_header("content-type", "name") || + part.sub_header("content-disposition", "filename") + end + end + + class Address + # Monkeypatch! + def Address.encode_quoted_string(text) + # XXX have added space to this, so we don't excessive quoting + if text.match(/[^A-Za-z0-9!#\$%&'*+\-\/=?^_`{|}~ ]/) + # Contains characters which aren't valid in atoms, so make a + # quoted-pair instead. + text.gsub!(/(["\\])/, "\\\\\\1") + text = '"' + text + '"' + end + return text + end + + # Monkeypatch! + def quoted_full + if self.name + Address.encode_quoted_string(self.name) + " <" + self.spec + ">" + else + self.spec + end + end + end +end + + |