Methods
- atom_safe?
- decode_RFC2231
- decode_params
- dquote
- join_domain
- message_id?
- mime_encoded?
- quote_atom
- quote_phrase
- quote_token
- time2str
- timezone_string_to_unixtime
- to_kcode
- token_safe?
Constants
| ATOM_UNSAFE | = | /[#{Regexp.quote aspecial}#{control}#{lwsp}]/n |
| PHRASE_UNSAFE | = | /[#{Regexp.quote aspecial}#{control}]/n |
| TOKEN_UNSAFE | = | /[#{Regexp.quote tspecial}#{control}#{lwsp}]/n |
| CONTROL_CHAR | = | /[#{control}]/n |
| ZONESTR_TABLE | = | { 'jst' => 9 * 60, 'eet' => 2 * 60, 'bst' => 1 * 60, 'met' => 1 * 60, 'gmt' => 0, 'utc' => 0, 'ut' => 0, 'nst' => -(3 * 60 + 30), 'ast' => -4 * 60, 'edt' => -4 * 60, 'est' => -5 * 60, 'cdt' => -5 * 60, 'cst' => -6 * 60, 'mdt' => -6 * 60, 'mst' => -7 * 60, 'pdt' => -7 * 60, 'pst' => -8 * 60, 'a' => -1 * 60, 'b' => -2 * 60, 'c' => -3 * 60, 'd' => -4 * 60, 'e' => -5 * 60, 'f' => -6 * 60, 'g' => -7 * 60, 'h' => -8 * 60, 'i' => -9 * 60, # j not use 'k' => -10 * 60, 'l' => -11 * 60, 'm' => -12 * 60, 'n' => 1 * 60, 'o' => 2 * 60, 'p' => 3 * 60, 'q' => 4 * 60, 'r' => 5 * 60, 's' => 6 * 60, 't' => 7 * 60, 'u' => 8 * 60, 'v' => 9 * 60, 'w' => 10 * 60, 'x' => 11 * 60, 'y' => 12 * 60, 'z' => 0 * 60 |
| WDAY | = | %w( Sun Mon Tue Wed Thu Fri Sat TMailBUG ) |
| MONTH | = | %w( TMailBUG Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec TMailBUG ) |
| MESSAGE_ID | = | /<[^\@>]+\@[^>\@]+>/ |
| MIME_ENCODED | = | /=\?[^\s?=]+\?[QB]\?[^\s?=]+\?=/i |
| NKF_FLAGS | = | { 'EUC' => '-e -m', 'SJIS' => '-s -m' |
| RFC2231_ENCODED | = | /\A(?:iso-2022-jp|euc-jp|shift_jis|us-ascii)?'[a-z]*'/in |
Public Instance methods
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 68
68: def atom_safe?( str )
69: not ATOM_UNSAFE === str
70: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 226
226: def decode_RFC2231( str )
227: m = RFC2231_ENCODED.match(str) or return str
228: begin
229: NKF.nkf(NKF_FLAGS[$KCODE],
230: m.post_match.gsub(/%[\da-f]{2}/in) {|s| s[1,2].hex.chr })
231: rescue
232: m.post_match.gsub(/%[\da-f]{2}/in, "")
233: end
234: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 195
195: def decode_params( hash )
196: new = Hash.new
197: encoded = nil
198: hash.each do |key, value|
199: if m = /\*(?:(\d+)\*)?\z/.match(key)
200: ((encoded ||= {})[m.pre_match] ||= [])[(m[1] || 0).to_i] = value
201: else
202: new[key] = to_kcode(value)
203: end
204: end
205: if encoded
206: encoded.each do |key, strings|
207: new[key] = decode_RFC2231(strings.join(''))
208: end
209: end
210:
211: new
212: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 94
94: def join_domain( arr )
95: arr.map {|i|
96: if /\A\[.*\]\z/ === i
97: i
98: else
99: quote_atom(i)
100: end
101: }.join('.')
102: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 183
183: def message_id?( str )
184: MESSAGE_ID === str
185: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 190
190: def mime_encoded?( str )
191: MIME_ENCODED === str
192: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 72
72: def quote_atom( str )
73: (ATOM_UNSAFE === str) ? dquote(str) : str
74: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 76
76: def quote_phrase( str )
77: (PHRASE_UNSAFE === str) ? dquote(str) : str
78: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 84
84: def quote_token( str )
85: (TOKEN_UNSAFE === str) ? dquote(str) : str
86: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 167
167: def time2str( tm )
168: # [ruby-list:7928]
169: gmt = Time.at(tm.to_i)
170: gmt.gmtime
171: offset = tm.to_i - Time.local(*gmt.to_a[0,6].reverse).to_i
172:
173: # DO NOT USE strftime: setlocale() breaks it
174: sprintf '%s, %s %s %d %02d:%02d:%02d %+.2d%.2d',
175: WDAY[tm.wday], tm.mday, MONTH[tm.month],
176: tm.year, tm.hour, tm.min, tm.sec,
177: *(offset / 60).divmod(60)
178: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 151
151: def timezone_string_to_unixtime( str )
152: if m = /([\+\-])(\d\d?)(\d\d)/.match(str)
153: sec = (m[2].to_i * 60 + m[3].to_i) * 60
154: m[1] == '-' ? -sec : sec
155: else
156: min = ZONESTR_TABLE[str.downcase] or
157: raise SyntaxError, "wrong timezone format '#{str}'"
158: min * 60
159: end
160: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 219
219: def to_kcode( str )
220: flag = NKF_FLAGS[$KCODE] or return str
221: NKF.nkf(flag, str)
222: end
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 80
80: def token_safe?( str )
81: not TOKEN_UNSAFE === str
82: end
Private Instance methods
[ show source ]
# File lib/action_mailer/vendor/tmail/utils.rb, line 88
88: def dquote( str )
89: '"' + str.gsub(/["\\]/n) {|s| '\\' + s } + '"'
90: end