actionmailer-rack-upgrade 2.3.14.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +387 -0
- data/MIT-LICENSE +21 -0
- data/README +149 -0
- data/Rakefile +97 -0
- data/install.rb +30 -0
- data/lib/action_mailer/adv_attr_accessor.rb +30 -0
- data/lib/action_mailer/base.rb +739 -0
- data/lib/action_mailer/helpers.rb +113 -0
- data/lib/action_mailer/mail_helper.rb +17 -0
- data/lib/action_mailer/part.rb +107 -0
- data/lib/action_mailer/part_container.rb +55 -0
- data/lib/action_mailer/quoting.rb +62 -0
- data/lib/action_mailer/test_case.rb +64 -0
- data/lib/action_mailer/test_helper.rb +68 -0
- data/lib/action_mailer/utils.rb +7 -0
- data/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb +1466 -0
- data/lib/action_mailer/vendor/text_format.rb +10 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/Makefile +18 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/address.rb +392 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/attachments.rb +65 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/base64.rb +46 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/compat.rb +41 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/config.rb +67 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/core_extensions.rb +63 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb +590 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb +962 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/index.rb +9 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/interface.rb +1162 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/loader.rb +3 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb +578 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mailbox.rb +496 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/main.rb +6 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mbox.rb +3 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/net.rb +250 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/obsolete.rb +132 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/parser.rb +1060 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/parser.y +416 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/port.rb +379 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/quoting.rb +164 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/require_arch.rb +58 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/scanner.rb +49 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/scanner_r.rb +262 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/stringio.rb +280 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/utils.rb +362 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/COPYING +504 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/README +12 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/big5freq.rb +927 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/big5prober.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb +238 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/charsetgroupprober.rb +112 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/charsetprober.rb +75 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/codingstatemachine.rb +64 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/constants.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb +89 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escsm.rb +244 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/eucjpprober.rb +88 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euckrfreq.rb +596 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euckrprober.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euctwfreq.rb +430 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euctwprober.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312freq.rb +474 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312prober.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/hebrewprober.rb +289 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/jisfreq.rb +570 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/jpcntx.rb +229 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langbulgarianmodel.rb +229 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langcyrillicmodel.rb +330 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langgreekmodel.rb +227 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langhebrewmodel.rb +202 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langhungarianmodel.rb +226 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langthaimodel.rb +201 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/latin1prober.rb +147 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcharsetprober.rb +89 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcsgroupprober.rb +45 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcssm.rb +542 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sbcharsetprober.rb +124 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sbcsgroupprober.rb +56 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sjisprober.rb +88 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/universaldetector.rb +168 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb +87 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet.rb +67 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/version.rb +39 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail.rb +6 -0
- data/lib/action_mailer/vendor/tmail.rb +17 -0
- data/lib/action_mailer/version.rb +9 -0
- data/lib/action_mailer.rb +62 -0
- data/lib/actionmailer.rb +2 -0
- data/test/abstract_unit.rb +62 -0
- data/test/asset_host_test.rb +54 -0
- data/test/delivery_method_test.rb +51 -0
- data/test/fixtures/asset_host_mailer/email_with_asset.html.erb +1 -0
- data/test/fixtures/auto_layout_mailer/hello.html.erb +1 -0
- data/test/fixtures/auto_layout_mailer/multipart.text.html.erb +1 -0
- data/test/fixtures/auto_layout_mailer/multipart.text.plain.erb +1 -0
- data/test/fixtures/explicit_layout_mailer/logout.html.erb +1 -0
- data/test/fixtures/explicit_layout_mailer/signup.html.erb +1 -0
- data/test/fixtures/first_mailer/share.erb +1 -0
- data/test/fixtures/helper_mailer/use_example_helper.erb +1 -0
- data/test/fixtures/helper_mailer/use_helper.erb +1 -0
- data/test/fixtures/helper_mailer/use_helper_method.erb +1 -0
- data/test/fixtures/helper_mailer/use_mail_helper.erb +5 -0
- data/test/fixtures/helpers/example_helper.rb +5 -0
- data/test/fixtures/layouts/auto_layout_mailer.html.erb +1 -0
- data/test/fixtures/layouts/auto_layout_mailer.text.erb +1 -0
- data/test/fixtures/layouts/spam.html.erb +1 -0
- data/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb +1 -0
- data/test/fixtures/raw_email +14 -0
- data/test/fixtures/raw_email10 +20 -0
- data/test/fixtures/raw_email12 +32 -0
- data/test/fixtures/raw_email13 +29 -0
- data/test/fixtures/raw_email2 +114 -0
- data/test/fixtures/raw_email3 +70 -0
- data/test/fixtures/raw_email4 +59 -0
- data/test/fixtures/raw_email5 +19 -0
- data/test/fixtures/raw_email6 +20 -0
- data/test/fixtures/raw_email7 +66 -0
- data/test/fixtures/raw_email8 +47 -0
- data/test/fixtures/raw_email9 +28 -0
- data/test/fixtures/raw_email_quoted_with_0d0a +14 -0
- data/test/fixtures/raw_email_with_invalid_characters_in_content_type +104 -0
- data/test/fixtures/raw_email_with_nested_attachment +100 -0
- data/test/fixtures/raw_email_with_partially_quoted_subject +14 -0
- data/test/fixtures/second_mailer/share.erb +1 -0
- data/test/fixtures/templates/signed_up.erb +3 -0
- data/test/fixtures/test_mailer/_subtemplate.text.plain.erb +1 -0
- data/test/fixtures/test_mailer/body_ivar.erb +2 -0
- data/test/fixtures/test_mailer/custom_templating_extension.text.html.haml +6 -0
- data/test/fixtures/test_mailer/custom_templating_extension.text.plain.haml +6 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.ignored.erb +1 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.rhtml.bak +1 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb +10 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~ +10 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.erb +2 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.erb +1 -0
- data/test/fixtures/test_mailer/included_subtemplate.text.plain.erb +1 -0
- data/test/fixtures/test_mailer/rxml_template.builder +2 -0
- data/test/fixtures/test_mailer/rxml_template.rxml +2 -0
- data/test/fixtures/test_mailer/signed_up.html.erb +3 -0
- data/test/fixtures/test_mailer/signed_up_with_url.erb +5 -0
- data/test/mail_helper_test.rb +95 -0
- data/test/mail_layout_test.rb +123 -0
- data/test/mail_render_test.rb +116 -0
- data/test/mail_service_test.rb +1145 -0
- data/test/quoting_test.rb +105 -0
- data/test/test_helper_test.rb +129 -0
- data/test/tmail_test.rb +22 -0
- data/test/url_test.rb +76 -0
- metadata +209 -0
@@ -0,0 +1,262 @@
|
|
1
|
+
# encoding: us-ascii
|
2
|
+
# scanner_r.rb
|
3
|
+
#
|
4
|
+
#--
|
5
|
+
# Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
# a copy of this software and associated documentation files (the
|
9
|
+
# "Software"), to deal in the Software without restriction, including
|
10
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
# the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be
|
16
|
+
# included in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
#
|
26
|
+
# Note: Originally licensed under LGPL v2+. Using MIT license for Rails
|
27
|
+
# with permission of Minero Aoki.
|
28
|
+
#++
|
29
|
+
#:stopdoc:
|
30
|
+
require 'tmail/config'
|
31
|
+
|
32
|
+
module TMail
|
33
|
+
|
34
|
+
class TMailScanner
|
35
|
+
|
36
|
+
Version = '1.2.3'
|
37
|
+
Version.freeze
|
38
|
+
|
39
|
+
MIME_HEADERS = {
|
40
|
+
:CTYPE => true,
|
41
|
+
:CENCODING => true,
|
42
|
+
:CDISPOSITION => true
|
43
|
+
}
|
44
|
+
|
45
|
+
alnum = 'a-zA-Z0-9'
|
46
|
+
atomsyms = %q[ _#!$%&`'*+-{|}~^/=? ].strip
|
47
|
+
tokensyms = %q[ _#!$%&`'*+-{|}~^@. ].strip
|
48
|
+
atomchars = alnum + Regexp.quote(atomsyms)
|
49
|
+
tokenchars = alnum + Regexp.quote(tokensyms)
|
50
|
+
iso2022str = '\e(?!\(B)..(?:[^\e]+|\e(?!\(B)..)*\e\(B'
|
51
|
+
|
52
|
+
eucstr = "(?:[\xa1-\xfe][\xa1-\xfe])+"
|
53
|
+
sjisstr = "(?:[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc])+"
|
54
|
+
utf8str = "(?:[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf])+"
|
55
|
+
|
56
|
+
quoted_with_iso2022 = /\A(?:[^\\\e"]+|#{iso2022str})+/n
|
57
|
+
domlit_with_iso2022 = /\A(?:[^\\\e\]]+|#{iso2022str})+/n
|
58
|
+
comment_with_iso2022 = /\A(?:[^\\\e()]+|#{iso2022str})+/n
|
59
|
+
|
60
|
+
quoted_without_iso2022 = /\A[^\\"]+/n
|
61
|
+
domlit_without_iso2022 = /\A[^\\\]]+/n
|
62
|
+
comment_without_iso2022 = /\A[^\\()]+/n
|
63
|
+
|
64
|
+
PATTERN_TABLE = {}
|
65
|
+
PATTERN_TABLE['EUC'] =
|
66
|
+
[
|
67
|
+
/\A(?:[#{atomchars}]+|#{iso2022str}|#{eucstr})+/n,
|
68
|
+
/\A(?:[#{tokenchars}]+|#{iso2022str}|#{eucstr})+/n,
|
69
|
+
quoted_with_iso2022,
|
70
|
+
domlit_with_iso2022,
|
71
|
+
comment_with_iso2022
|
72
|
+
]
|
73
|
+
PATTERN_TABLE['SJIS'] =
|
74
|
+
[
|
75
|
+
/\A(?:[#{atomchars}]+|#{iso2022str}|#{sjisstr})+/n,
|
76
|
+
/\A(?:[#{tokenchars}]+|#{iso2022str}|#{sjisstr})+/n,
|
77
|
+
quoted_with_iso2022,
|
78
|
+
domlit_with_iso2022,
|
79
|
+
comment_with_iso2022
|
80
|
+
]
|
81
|
+
PATTERN_TABLE['UTF8'] =
|
82
|
+
[
|
83
|
+
/\A(?:[#{atomchars}]+|#{utf8str})+/n,
|
84
|
+
/\A(?:[#{tokenchars}]+|#{utf8str})+/n,
|
85
|
+
quoted_without_iso2022,
|
86
|
+
domlit_without_iso2022,
|
87
|
+
comment_without_iso2022
|
88
|
+
]
|
89
|
+
PATTERN_TABLE['NONE'] =
|
90
|
+
[
|
91
|
+
/\A[#{atomchars}]+/n,
|
92
|
+
/\A[#{tokenchars}]+/n,
|
93
|
+
quoted_without_iso2022,
|
94
|
+
domlit_without_iso2022,
|
95
|
+
comment_without_iso2022
|
96
|
+
]
|
97
|
+
|
98
|
+
|
99
|
+
def initialize( str, scantype, comments )
|
100
|
+
init_scanner str
|
101
|
+
@comments = comments || []
|
102
|
+
@debug = false
|
103
|
+
|
104
|
+
# fix scanner mode
|
105
|
+
@received = (scantype == :RECEIVED)
|
106
|
+
@is_mime_header = MIME_HEADERS[scantype]
|
107
|
+
|
108
|
+
atom, token, @quoted_re, @domlit_re, @comment_re = PATTERN_TABLE[TMail.KCODE]
|
109
|
+
@word_re = (MIME_HEADERS[scantype] ? token : atom)
|
110
|
+
end
|
111
|
+
|
112
|
+
attr_accessor :debug
|
113
|
+
|
114
|
+
def scan( &block )
|
115
|
+
if @debug
|
116
|
+
scan_main do |arr|
|
117
|
+
s, v = arr
|
118
|
+
printf "%7d %-10s %s\n",
|
119
|
+
rest_size(),
|
120
|
+
s.respond_to?(:id2name) ? s.id2name : s.inspect,
|
121
|
+
v.inspect
|
122
|
+
yield arr
|
123
|
+
end
|
124
|
+
else
|
125
|
+
scan_main(&block)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
RECV_TOKEN = {
|
132
|
+
'from' => :FROM,
|
133
|
+
'by' => :BY,
|
134
|
+
'via' => :VIA,
|
135
|
+
'with' => :WITH,
|
136
|
+
'id' => :ID,
|
137
|
+
'for' => :FOR
|
138
|
+
}
|
139
|
+
|
140
|
+
def scan_main
|
141
|
+
until eof?
|
142
|
+
if skip(/\A[\n\r\t ]+/n) # LWSP
|
143
|
+
break if eof?
|
144
|
+
end
|
145
|
+
|
146
|
+
if s = readstr(@word_re)
|
147
|
+
if @is_mime_header
|
148
|
+
yield [:TOKEN, s]
|
149
|
+
else
|
150
|
+
# atom
|
151
|
+
if /\A\d+\z/ === s
|
152
|
+
yield [:DIGIT, s]
|
153
|
+
elsif @received
|
154
|
+
yield [RECV_TOKEN[s.downcase] || :ATOM, s]
|
155
|
+
else
|
156
|
+
yield [:ATOM, s]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
elsif skip(/\A"/)
|
161
|
+
yield [:QUOTED, scan_quoted_word()]
|
162
|
+
|
163
|
+
elsif skip(/\A\[/)
|
164
|
+
yield [:DOMLIT, scan_domain_literal()]
|
165
|
+
|
166
|
+
elsif skip(/\A\(/)
|
167
|
+
@comments.push scan_comment()
|
168
|
+
|
169
|
+
else
|
170
|
+
c = readchar()
|
171
|
+
yield [c, c]
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
yield [false, '$']
|
176
|
+
end
|
177
|
+
|
178
|
+
def scan_quoted_word
|
179
|
+
scan_qstr(@quoted_re, /\A"/, 'quoted-word')
|
180
|
+
end
|
181
|
+
|
182
|
+
def scan_domain_literal
|
183
|
+
'[' + scan_qstr(@domlit_re, /\A\]/, 'domain-literal') + ']'
|
184
|
+
end
|
185
|
+
|
186
|
+
def scan_qstr( pattern, terminal, type )
|
187
|
+
result = ''
|
188
|
+
until eof?
|
189
|
+
if s = readstr(pattern) then result << s
|
190
|
+
elsif skip(terminal) then return result
|
191
|
+
elsif skip(/\A\\/) then result << readchar()
|
192
|
+
else
|
193
|
+
raise "TMail FATAL: not match in #{type}"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
scan_error! "found unterminated #{type}"
|
197
|
+
end
|
198
|
+
|
199
|
+
def scan_comment
|
200
|
+
result = ''
|
201
|
+
nest = 1
|
202
|
+
content = @comment_re
|
203
|
+
|
204
|
+
until eof?
|
205
|
+
if s = readstr(content) then result << s
|
206
|
+
elsif skip(/\A\)/) then nest -= 1
|
207
|
+
return result if nest == 0
|
208
|
+
result << ')'
|
209
|
+
elsif skip(/\A\(/) then nest += 1
|
210
|
+
result << '('
|
211
|
+
elsif skip(/\A\\/) then result << readchar()
|
212
|
+
else
|
213
|
+
raise 'TMail FATAL: not match in comment'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
scan_error! 'found unterminated comment'
|
217
|
+
end
|
218
|
+
|
219
|
+
# string scanner
|
220
|
+
|
221
|
+
def init_scanner( str )
|
222
|
+
@src = str
|
223
|
+
end
|
224
|
+
|
225
|
+
def eof?
|
226
|
+
@src.empty?
|
227
|
+
end
|
228
|
+
|
229
|
+
def rest_size
|
230
|
+
@src.size
|
231
|
+
end
|
232
|
+
|
233
|
+
def readstr( re )
|
234
|
+
if m = re.match(@src)
|
235
|
+
@src = m.post_match
|
236
|
+
m[0]
|
237
|
+
else
|
238
|
+
nil
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def readchar
|
243
|
+
readstr(/\A./)
|
244
|
+
end
|
245
|
+
|
246
|
+
def skip( re )
|
247
|
+
if m = re.match(@src)
|
248
|
+
@src = m.post_match
|
249
|
+
true
|
250
|
+
else
|
251
|
+
false
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def scan_error!( msg )
|
256
|
+
raise SyntaxError, msg
|
257
|
+
end
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
end # module TMail
|
262
|
+
#:startdoc:
|
@@ -0,0 +1,280 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
|
4
|
+
= String handling class
|
5
|
+
|
6
|
+
=end
|
7
|
+
#--
|
8
|
+
# Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
|
9
|
+
#
|
10
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
11
|
+
# a copy of this software and associated documentation files (the
|
12
|
+
# "Software"), to deal in the Software without restriction, including
|
13
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
14
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
15
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
16
|
+
# the following conditions:
|
17
|
+
#
|
18
|
+
# The above copyright notice and this permission notice shall be
|
19
|
+
# included in all copies or substantial portions of the Software.
|
20
|
+
#
|
21
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
22
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
24
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
25
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
26
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
27
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
28
|
+
#
|
29
|
+
# Note: Originally licensed under LGPL v2+. Using MIT license for Rails
|
30
|
+
# with permission of Minero Aoki.
|
31
|
+
#++
|
32
|
+
|
33
|
+
class StringInput#:nodoc:
|
34
|
+
|
35
|
+
include Enumerable
|
36
|
+
|
37
|
+
class << self
|
38
|
+
|
39
|
+
def new( str )
|
40
|
+
if block_given?
|
41
|
+
begin
|
42
|
+
f = super
|
43
|
+
yield f
|
44
|
+
ensure
|
45
|
+
f.close if f
|
46
|
+
end
|
47
|
+
else
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
alias open new
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize( str )
|
57
|
+
@src = str
|
58
|
+
@pos = 0
|
59
|
+
@closed = false
|
60
|
+
@lineno = 0
|
61
|
+
end
|
62
|
+
|
63
|
+
attr_reader :lineno
|
64
|
+
|
65
|
+
def string
|
66
|
+
@src
|
67
|
+
end
|
68
|
+
|
69
|
+
def inspect
|
70
|
+
"#<#{self.class}:#{@closed ? 'closed' : 'open'},src=#{@src[0,30].inspect}>"
|
71
|
+
end
|
72
|
+
|
73
|
+
def close
|
74
|
+
stream_check!
|
75
|
+
@pos = nil
|
76
|
+
@closed = true
|
77
|
+
end
|
78
|
+
|
79
|
+
def closed?
|
80
|
+
@closed
|
81
|
+
end
|
82
|
+
|
83
|
+
def pos
|
84
|
+
stream_check!
|
85
|
+
[@pos, @src.size].min
|
86
|
+
end
|
87
|
+
|
88
|
+
alias tell pos
|
89
|
+
|
90
|
+
def seek( offset, whence = IO::SEEK_SET )
|
91
|
+
stream_check!
|
92
|
+
case whence
|
93
|
+
when IO::SEEK_SET
|
94
|
+
@pos = offset
|
95
|
+
when IO::SEEK_CUR
|
96
|
+
@pos += offset
|
97
|
+
when IO::SEEK_END
|
98
|
+
@pos = @src.size - offset
|
99
|
+
else
|
100
|
+
raise ArgumentError, "unknown seek flag: #{whence}"
|
101
|
+
end
|
102
|
+
@pos = 0 if @pos < 0
|
103
|
+
@pos = [@pos, @src.size + 1].min
|
104
|
+
offset
|
105
|
+
end
|
106
|
+
|
107
|
+
def rewind
|
108
|
+
stream_check!
|
109
|
+
@pos = 0
|
110
|
+
end
|
111
|
+
|
112
|
+
def eof?
|
113
|
+
stream_check!
|
114
|
+
@pos > @src.size
|
115
|
+
end
|
116
|
+
|
117
|
+
def each( &block )
|
118
|
+
stream_check!
|
119
|
+
begin
|
120
|
+
@src.each(&block)
|
121
|
+
ensure
|
122
|
+
@pos = 0
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def gets
|
127
|
+
stream_check!
|
128
|
+
if idx = @src.index(?\n, @pos)
|
129
|
+
idx += 1 # "\n".size
|
130
|
+
line = @src[ @pos ... idx ]
|
131
|
+
@pos = idx
|
132
|
+
@pos += 1 if @pos == @src.size
|
133
|
+
else
|
134
|
+
line = @src[ @pos .. -1 ]
|
135
|
+
@pos = @src.size + 1
|
136
|
+
end
|
137
|
+
@lineno += 1
|
138
|
+
|
139
|
+
line
|
140
|
+
end
|
141
|
+
|
142
|
+
def getc
|
143
|
+
stream_check!
|
144
|
+
ch = @src[@pos]
|
145
|
+
@pos += 1
|
146
|
+
@pos += 1 if @pos == @src.size
|
147
|
+
ch
|
148
|
+
end
|
149
|
+
|
150
|
+
def read( len = nil )
|
151
|
+
stream_check!
|
152
|
+
return read_all unless len
|
153
|
+
str = @src[@pos, len]
|
154
|
+
@pos += len
|
155
|
+
@pos += 1 if @pos == @src.size
|
156
|
+
str
|
157
|
+
end
|
158
|
+
|
159
|
+
alias sysread read
|
160
|
+
|
161
|
+
def read_all
|
162
|
+
stream_check!
|
163
|
+
return nil if eof?
|
164
|
+
rest = @src[@pos ... @src.size]
|
165
|
+
@pos = @src.size + 1
|
166
|
+
rest
|
167
|
+
end
|
168
|
+
|
169
|
+
def stream_check!
|
170
|
+
@closed and raise IOError, 'closed stream'
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
class StringOutput#:nodoc:
|
177
|
+
|
178
|
+
class << self
|
179
|
+
|
180
|
+
def new( str = '' )
|
181
|
+
if block_given?
|
182
|
+
begin
|
183
|
+
f = super
|
184
|
+
yield f
|
185
|
+
ensure
|
186
|
+
f.close if f
|
187
|
+
end
|
188
|
+
else
|
189
|
+
super
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
alias open new
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
def initialize( str = '' )
|
198
|
+
@dest = str
|
199
|
+
@closed = false
|
200
|
+
end
|
201
|
+
|
202
|
+
def close
|
203
|
+
@closed = true
|
204
|
+
end
|
205
|
+
|
206
|
+
def closed?
|
207
|
+
@closed
|
208
|
+
end
|
209
|
+
|
210
|
+
def string
|
211
|
+
@dest
|
212
|
+
end
|
213
|
+
|
214
|
+
alias value string
|
215
|
+
alias to_str string
|
216
|
+
|
217
|
+
def size
|
218
|
+
@dest.size
|
219
|
+
end
|
220
|
+
|
221
|
+
alias pos size
|
222
|
+
|
223
|
+
def inspect
|
224
|
+
"#<#{self.class}:#{@dest ? 'open' : 'closed'},#{object_id}>"
|
225
|
+
end
|
226
|
+
|
227
|
+
def print( *args )
|
228
|
+
stream_check!
|
229
|
+
raise ArgumentError, 'wrong # of argument (0 for >1)' if args.empty?
|
230
|
+
args.each do |s|
|
231
|
+
raise ArgumentError, 'nil not allowed' if s.nil?
|
232
|
+
@dest << s.to_s
|
233
|
+
end
|
234
|
+
nil
|
235
|
+
end
|
236
|
+
|
237
|
+
def puts( *args )
|
238
|
+
stream_check!
|
239
|
+
args.each do |str|
|
240
|
+
@dest << (s = str.to_s)
|
241
|
+
@dest << "\n" unless s[-1] == ?\n
|
242
|
+
end
|
243
|
+
@dest << "\n" if args.empty?
|
244
|
+
nil
|
245
|
+
end
|
246
|
+
|
247
|
+
def putc( ch )
|
248
|
+
stream_check!
|
249
|
+
@dest << ch.chr
|
250
|
+
nil
|
251
|
+
end
|
252
|
+
|
253
|
+
def printf( *args )
|
254
|
+
stream_check!
|
255
|
+
@dest << sprintf(*args)
|
256
|
+
nil
|
257
|
+
end
|
258
|
+
|
259
|
+
def write( str )
|
260
|
+
stream_check!
|
261
|
+
s = str.to_s
|
262
|
+
@dest << s
|
263
|
+
s.size
|
264
|
+
end
|
265
|
+
|
266
|
+
alias syswrite write
|
267
|
+
|
268
|
+
def <<( str )
|
269
|
+
stream_check!
|
270
|
+
@dest << str.to_s
|
271
|
+
self
|
272
|
+
end
|
273
|
+
|
274
|
+
private
|
275
|
+
|
276
|
+
def stream_check!
|
277
|
+
@closed and raise IOError, 'closed stream'
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|