diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-11-06 14:24:32 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-11-06 14:24:32 +0000 |
commit | 2a51c8682d44ee71a3c0411e2e30ef8ff29d6f67 (patch) | |
tree | 071f2cb958c46c0c07034c9837800dba572a5218 /actionmailer/lib/action_mailer/vendor/tmail/utils.rb | |
parent | 7464a398e18592010243845edad1fa09b82d16a1 (diff) | |
download | rails-2a51c8682d44ee71a3c0411e2e30ef8ff29d6f67.tar.gz rails-2a51c8682d44ee71a3c0411e2e30ef8ff29d6f67.tar.bz2 rails-2a51c8682d44ee71a3c0411e2e30ef8ff29d6f67.zip |
Update TMail to v1.1.0. Use an updated version of TMail if available. [mikel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8084 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/lib/action_mailer/vendor/tmail/utils.rb')
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail/utils.rb | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/actionmailer/lib/action_mailer/vendor/tmail/utils.rb b/actionmailer/lib/action_mailer/vendor/tmail/utils.rb index 852acd7576..016330ffd5 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail/utils.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail/utils.rb @@ -1,6 +1,8 @@ -# -# utils.rb -# +=begin rdoc + += General Purpose TMail Utilities + +=end #-- # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net> # @@ -52,9 +54,9 @@ module TMail @uniq = 0 - module TextUtils - + # Defines characters per RFC that are OK for TOKENs, ATOMs, PHRASEs and CONTROL characters. + aspecial = '()<>[]:;.\\,"' tspecial = '()<>[];:\\,"/?=' lwsp = " \t\r\n" @@ -66,31 +68,50 @@ module TMail CONTROL_CHAR = /[#{control}]/n def atom_safe?( str ) + # Returns true if the string supplied is free from characters not allowed as an ATOM not ATOM_UNSAFE === str end def quote_atom( str ) + # If the string supplied has ATOM unsafe characters in it, will return the string quoted + # in double quotes, otherwise returns the string unmodified (ATOM_UNSAFE === str) ? dquote(str) : str end def quote_phrase( str ) + # If the string supplied has PHRASE unsafe characters in it, will return the string quoted + # in double quotes, otherwise returns the string unmodified (PHRASE_UNSAFE === str) ? dquote(str) : str end def token_safe?( str ) + # Returns true if the string supplied is free from characters not allowed as a TOKEN not TOKEN_UNSAFE === str end def quote_token( str ) + # If the string supplied has TOKEN unsafe characters in it, will return the string quoted + # in double quotes, otherwise returns the string unmodified (TOKEN_UNSAFE === str) ? dquote(str) : str end def dquote( str ) - '"' + str.gsub(/["\\]/n) {|s| '\\' + s } + '"' + # Wraps supplied string in double quotes unless it is already wrapped + # Returns double quoted string + unless str =~ /^".*?"$/ + '"' + str.gsub(/["\\]/n) {|s| '\\' + s } + '"' + else + str + end end private :dquote - + def unquote( str ) + # Unwraps supplied string from inside double quotes + # Returns unquoted string + str =~ /^"(.*?)"$/ ? $1 : str + end + def join_domain( arr ) arr.map {|i| if /\A\[.*\]\z/ === i @@ -149,6 +170,7 @@ module TMail } def timezone_string_to_unixtime( str ) + # Takes a time zone string from an EMail and converts it to Unix Time (seconds) if m = /([\+\-])(\d\d?)(\d\d)/.match(str) sec = (m[2].to_i * 60 + m[3].to_i) * 60 m[1] == '-' ? -sec : sec @@ -233,6 +255,27 @@ module TMail end end + def quote_boundary + # Make sure the Content-Type boundary= parameter is quoted if it contains illegal characters + # (to ensure any special characters in the boundary text are escaped from the parser + # (such as = in MS Outlook's boundary text)) + if @body =~ /^(.*)boundary=(.*)$/m + preamble = $1 + remainder = $2 + if remainder =~ /;/ + remainder =~ /^(.*)(;.*)$/m + boundary_text = $1 + post = $2.chomp + else + boundary_text = remainder.chomp + end + if boundary_text =~ /[\/\?\=]/ + boundary_text = "\"#{boundary_text}\"" unless boundary_text =~ /^".*?"$/ + @body = "#{preamble}boundary=#{boundary_text}#{post}" + end + end + end + end end |