aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tmail_extensions.rb
diff options
context:
space:
mode:
authorfrancis <francis>2009-04-08 07:31:07 +0000
committerfrancis <francis>2009-04-08 07:31:07 +0000
commit0960200802d7c87940cd0c7348d2f612c4f15d65 (patch)
tree9ed72928a3759b4a7e0d0cebb1710f6a8a7d2e9c /lib/tmail_extensions.rb
parent2424bdf7da5346a6bf28dbaf9ff4d9bfd70b070c (diff)
TMail rebuilds address when constructing emails. Move our more
aggressive quoting rule into a TMail monkey patch proper so it is always called when constructing emails, and remove the hacky function (Address.encode_quoted_string) it used to call in special places
Diffstat (limited to 'lib/tmail_extensions.rb')
-rw-r--r--lib/tmail_extensions.rb35
1 files changed, 15 insertions, 20 deletions
diff --git a/lib/tmail_extensions.rb b/lib/tmail_extensions.rb
index a02460f7f..711463050 100644
--- a/lib/tmail_extensions.rb
+++ b/lib/tmail_extensions.rb
@@ -4,7 +4,7 @@
# 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.2 2009-04-08 05:29:36 francis Exp $
+# $Id: tmail_extensions.rb,v 1.3 2009-04-08 07:31:08 francis Exp $
# Monkeypatch!
@@ -32,27 +32,22 @@ module TMail
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 = text.gsub(/(["\\])/, "\\\\\\1")
- text = '"' + text + '"'
- end
- return text
+ # Monkeypatch! Constructor which makes a TMail::Address given
+ # a name and an email
+ def Address.address_from_name_and_email(name, email)
+ # Botch an always quoted RFC address, then parse it
+ name = name.gsub(/(["\\])/, "\\\\\\1")
+ TMail::Address.parse('"' + name + '" <' + email + '>')
end
+ end
- # Monkeypatch!
- def full_quoted_address
- if self.name
- # sanitise name - some mail servers can't cope with @ in the name part
- name = self.name.gsub(/@/, " ")
- Address.encode_quoted_string(name) + " <" + self.spec + ">"
- else
- self.spec
- end
+ module TextUtils
+ # Monkeypatch! Much more aggressive list of characters to cause quoting
+ # than in normal TMail. e.g. Have found real cases where @ needs quoting.
+ # We list characters to allow, rather than characters not to allow.
+ NEW_PHRASE_UNSAFE=/[^A-Za-z0-9!#\$%&'*+\-\/=?^_`{|}~ ]/n
+ def quote_phrase( str )
+ (NEW_PHRASE_UNSAFE === str) ? dquote(str) : str
end
end
end