aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/vendor/tmail/utils.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/lib/action_mailer/vendor/tmail/utils.rb')
-rwxr-xr-xactionmailer/lib/action_mailer/vendor/tmail/utils.rb57
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