actionmailer 2.3.18 → 3.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionmailer might be problematic. Click here for more details.

Files changed (154) hide show
  1. data/CHANGELOG +13 -16
  2. data/README +39 -21
  3. data/lib/action_mailer/adv_attr_accessor.rb +14 -18
  4. data/lib/action_mailer/base.rb +437 -560
  5. data/lib/action_mailer/collector.rb +36 -0
  6. data/lib/action_mailer/delivery_methods.rb +86 -0
  7. data/lib/action_mailer/deprecated_api.rb +139 -0
  8. data/lib/action_mailer/mail_helper.rb +25 -13
  9. data/lib/action_mailer/old_api.rb +248 -0
  10. data/lib/action_mailer/quoting.rb +4 -2
  11. data/lib/action_mailer/railtie.rb +25 -0
  12. data/lib/action_mailer/railties/subscriber.rb +20 -0
  13. data/lib/action_mailer/test_case.rb +4 -6
  14. data/lib/action_mailer/test_helper.rb +0 -1
  15. data/lib/action_mailer/tmail_compat.rb +34 -0
  16. data/lib/action_mailer/version.rb +3 -3
  17. data/lib/action_mailer.rb +25 -30
  18. metadata +41 -161
  19. data/Rakefile +0 -97
  20. data/install.rb +0 -30
  21. data/lib/action_mailer/helpers.rb +0 -113
  22. data/lib/action_mailer/part.rb +0 -107
  23. data/lib/action_mailer/part_container.rb +0 -55
  24. data/lib/action_mailer/utils.rb +0 -7
  25. data/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb +0 -1466
  26. data/lib/action_mailer/vendor/text_format.rb +0 -10
  27. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/Makefile +0 -18
  28. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/address.rb +0 -392
  29. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/attachments.rb +0 -65
  30. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/base64.rb +0 -46
  31. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/compat.rb +0 -41
  32. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/config.rb +0 -67
  33. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/core_extensions.rb +0 -63
  34. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb +0 -590
  35. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb +0 -962
  36. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/index.rb +0 -9
  37. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/interface.rb +0 -1162
  38. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/loader.rb +0 -3
  39. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb +0 -578
  40. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mailbox.rb +0 -496
  41. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/main.rb +0 -6
  42. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mbox.rb +0 -3
  43. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/net.rb +0 -250
  44. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/obsolete.rb +0 -132
  45. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/parser.rb +0 -1060
  46. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/parser.y +0 -416
  47. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/port.rb +0 -379
  48. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/quoting.rb +0 -164
  49. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/require_arch.rb +0 -58
  50. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/scanner.rb +0 -49
  51. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/scanner_r.rb +0 -262
  52. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/stringio.rb +0 -280
  53. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/utils.rb +0 -362
  54. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/COPYING +0 -504
  55. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/README +0 -12
  56. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/big5freq.rb +0 -927
  57. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/big5prober.rb +0 -42
  58. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb +0 -238
  59. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/charsetgroupprober.rb +0 -112
  60. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/charsetprober.rb +0 -75
  61. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/codingstatemachine.rb +0 -64
  62. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/constants.rb +0 -42
  63. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb +0 -89
  64. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escsm.rb +0 -244
  65. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/eucjpprober.rb +0 -88
  66. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euckrfreq.rb +0 -596
  67. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euckrprober.rb +0 -42
  68. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euctwfreq.rb +0 -430
  69. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euctwprober.rb +0 -42
  70. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312freq.rb +0 -474
  71. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312prober.rb +0 -42
  72. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/hebrewprober.rb +0 -289
  73. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/jisfreq.rb +0 -570
  74. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/jpcntx.rb +0 -229
  75. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langbulgarianmodel.rb +0 -229
  76. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langcyrillicmodel.rb +0 -330
  77. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langgreekmodel.rb +0 -227
  78. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langhebrewmodel.rb +0 -202
  79. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langhungarianmodel.rb +0 -226
  80. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langthaimodel.rb +0 -201
  81. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/latin1prober.rb +0 -147
  82. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcharsetprober.rb +0 -89
  83. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcsgroupprober.rb +0 -45
  84. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcssm.rb +0 -542
  85. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sbcharsetprober.rb +0 -124
  86. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sbcsgroupprober.rb +0 -56
  87. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sjisprober.rb +0 -88
  88. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/universaldetector.rb +0 -168
  89. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb +0 -87
  90. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet.rb +0 -67
  91. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/version.rb +0 -39
  92. data/lib/action_mailer/vendor/tmail-1.2.7/tmail.rb +0 -6
  93. data/lib/action_mailer/vendor/tmail.rb +0 -17
  94. data/lib/actionmailer.rb +0 -2
  95. data/test/abstract_unit.rb +0 -62
  96. data/test/asset_host_test.rb +0 -54
  97. data/test/delivery_method_test.rb +0 -51
  98. data/test/fixtures/asset_host_mailer/email_with_asset.html.erb +0 -1
  99. data/test/fixtures/auto_layout_mailer/hello.html.erb +0 -1
  100. data/test/fixtures/auto_layout_mailer/multipart.text.html.erb +0 -1
  101. data/test/fixtures/auto_layout_mailer/multipart.text.plain.erb +0 -1
  102. data/test/fixtures/explicit_layout_mailer/logout.html.erb +0 -1
  103. data/test/fixtures/explicit_layout_mailer/signup.html.erb +0 -1
  104. data/test/fixtures/first_mailer/share.erb +0 -1
  105. data/test/fixtures/helper_mailer/use_example_helper.erb +0 -1
  106. data/test/fixtures/helper_mailer/use_helper.erb +0 -1
  107. data/test/fixtures/helper_mailer/use_helper_method.erb +0 -1
  108. data/test/fixtures/helper_mailer/use_mail_helper.erb +0 -5
  109. data/test/fixtures/helpers/example_helper.rb +0 -5
  110. data/test/fixtures/layouts/auto_layout_mailer.html.erb +0 -1
  111. data/test/fixtures/layouts/auto_layout_mailer.text.erb +0 -1
  112. data/test/fixtures/layouts/spam.html.erb +0 -1
  113. data/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb +0 -1
  114. data/test/fixtures/raw_email +0 -14
  115. data/test/fixtures/raw_email10 +0 -20
  116. data/test/fixtures/raw_email12 +0 -32
  117. data/test/fixtures/raw_email13 +0 -29
  118. data/test/fixtures/raw_email2 +0 -114
  119. data/test/fixtures/raw_email3 +0 -70
  120. data/test/fixtures/raw_email4 +0 -59
  121. data/test/fixtures/raw_email5 +0 -19
  122. data/test/fixtures/raw_email6 +0 -20
  123. data/test/fixtures/raw_email7 +0 -66
  124. data/test/fixtures/raw_email8 +0 -47
  125. data/test/fixtures/raw_email9 +0 -28
  126. data/test/fixtures/raw_email_quoted_with_0d0a +0 -14
  127. data/test/fixtures/raw_email_with_invalid_characters_in_content_type +0 -104
  128. data/test/fixtures/raw_email_with_nested_attachment +0 -100
  129. data/test/fixtures/raw_email_with_partially_quoted_subject +0 -14
  130. data/test/fixtures/second_mailer/share.erb +0 -1
  131. data/test/fixtures/templates/signed_up.erb +0 -3
  132. data/test/fixtures/test_mailer/_subtemplate.text.plain.erb +0 -1
  133. data/test/fixtures/test_mailer/body_ivar.erb +0 -2
  134. data/test/fixtures/test_mailer/custom_templating_extension.text.html.haml +0 -6
  135. data/test/fixtures/test_mailer/custom_templating_extension.text.plain.haml +0 -6
  136. data/test/fixtures/test_mailer/implicitly_multipart_example.ignored.erb +0 -1
  137. data/test/fixtures/test_mailer/implicitly_multipart_example.rhtml.bak +0 -1
  138. data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb +0 -10
  139. data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~ +0 -10
  140. data/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.erb +0 -2
  141. data/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.erb +0 -1
  142. data/test/fixtures/test_mailer/included_subtemplate.text.plain.erb +0 -1
  143. data/test/fixtures/test_mailer/rxml_template.builder +0 -2
  144. data/test/fixtures/test_mailer/rxml_template.rxml +0 -2
  145. data/test/fixtures/test_mailer/signed_up.html.erb +0 -3
  146. data/test/fixtures/test_mailer/signed_up_with_url.erb +0 -5
  147. data/test/mail_helper_test.rb +0 -95
  148. data/test/mail_layout_test.rb +0 -123
  149. data/test/mail_render_test.rb +0 -116
  150. data/test/mail_service_test.rb +0 -1145
  151. data/test/quoting_test.rb +0 -105
  152. data/test/test_helper_test.rb +0 -129
  153. data/test/tmail_test.rb +0 -22
  154. data/test/url_test.rb +0 -76
@@ -1,379 +0,0 @@
1
- =begin rdoc
2
-
3
- = Port class
4
-
5
- =end
6
- #--
7
- # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
8
- #
9
- # Permission is hereby granted, free of charge, to any person obtaining
10
- # a copy of this software and associated documentation files (the
11
- # "Software"), to deal in the Software without restriction, including
12
- # without limitation the rights to use, copy, modify, merge, publish,
13
- # distribute, sublicense, and/or sell copies of the Software, and to
14
- # permit persons to whom the Software is furnished to do so, subject to
15
- # the following conditions:
16
- #
17
- # The above copyright notice and this permission notice shall be
18
- # included in all copies or substantial portions of the Software.
19
- #
20
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
- #
28
- # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
29
- # with permission of Minero Aoki.
30
- #++
31
-
32
- require 'tmail/stringio'
33
-
34
-
35
- module TMail
36
-
37
- class Port
38
- def reproducible?
39
- false
40
- end
41
- end
42
-
43
-
44
- ###
45
- ### FilePort
46
- ###
47
-
48
- class FilePort < Port
49
-
50
- def initialize( fname )
51
- @filename = File.expand_path(fname)
52
- super()
53
- end
54
-
55
- attr_reader :filename
56
-
57
- alias ident filename
58
-
59
- def ==( other )
60
- other.respond_to?(:filename) and @filename == other.filename
61
- end
62
-
63
- alias eql? ==
64
-
65
- def hash
66
- @filename.hash
67
- end
68
-
69
- def inspect
70
- "#<#{self.class}:#{@filename}>"
71
- end
72
-
73
- def reproducible?
74
- true
75
- end
76
-
77
- def size
78
- File.size @filename
79
- end
80
-
81
-
82
- def ropen( &block )
83
- File.open(@filename, &block)
84
- end
85
-
86
- def wopen( &block )
87
- File.open(@filename, 'w', &block)
88
- end
89
-
90
- def aopen( &block )
91
- File.open(@filename, 'a', &block)
92
- end
93
-
94
-
95
- def read_all
96
- ropen {|f|
97
- return f.read
98
- }
99
- end
100
-
101
-
102
- def remove
103
- File.unlink @filename
104
- end
105
-
106
- def move_to( port )
107
- begin
108
- File.link @filename, port.filename
109
- rescue Errno::EXDEV
110
- copy_to port
111
- end
112
- File.unlink @filename
113
- end
114
-
115
- alias mv move_to
116
-
117
- def copy_to( port )
118
- if FilePort === port
119
- copy_file @filename, port.filename
120
- else
121
- File.open(@filename) {|r|
122
- port.wopen {|w|
123
- while s = r.sysread(4096)
124
- w.write << s
125
- end
126
- } }
127
- end
128
- end
129
-
130
- alias cp copy_to
131
-
132
- private
133
-
134
- # from fileutils.rb
135
- def copy_file( src, dest )
136
- st = r = w = nil
137
-
138
- File.open(src, 'rb') {|r|
139
- File.open(dest, 'wb') {|w|
140
- st = r.stat
141
- begin
142
- while true
143
- w.write r.sysread(st.blksize)
144
- end
145
- rescue EOFError
146
- end
147
- } }
148
- end
149
-
150
- end
151
-
152
-
153
- module MailFlags
154
-
155
- def seen=( b )
156
- set_status 'S', b
157
- end
158
-
159
- def seen?
160
- get_status 'S'
161
- end
162
-
163
- def replied=( b )
164
- set_status 'R', b
165
- end
166
-
167
- def replied?
168
- get_status 'R'
169
- end
170
-
171
- def flagged=( b )
172
- set_status 'F', b
173
- end
174
-
175
- def flagged?
176
- get_status 'F'
177
- end
178
-
179
- private
180
-
181
- def procinfostr( str, tag, true_p )
182
- a = str.upcase.split(//)
183
- a.push true_p ? tag : nil
184
- a.delete tag unless true_p
185
- a.compact.sort.join('').squeeze
186
- end
187
-
188
- end
189
-
190
-
191
- class MhPort < FilePort
192
-
193
- include MailFlags
194
-
195
- private
196
-
197
- def set_status( tag, flag )
198
- begin
199
- tmpfile = @filename + '.tmailtmp.' + $$.to_s
200
- File.open(tmpfile, 'w') {|f|
201
- write_status f, tag, flag
202
- }
203
- File.unlink @filename
204
- File.link tmpfile, @filename
205
- ensure
206
- File.unlink tmpfile
207
- end
208
- end
209
-
210
- def write_status( f, tag, flag )
211
- stat = ''
212
- File.open(@filename) {|r|
213
- while line = r.gets
214
- if line.strip.empty?
215
- break
216
- elsif m = /\AX-TMail-Status:/i.match(line)
217
- stat = m.post_match.strip
218
- else
219
- f.print line
220
- end
221
- end
222
-
223
- s = procinfostr(stat, tag, flag)
224
- f.puts 'X-TMail-Status: ' + s unless s.empty?
225
- f.puts
226
-
227
- while s = r.read(2048)
228
- f.write s
229
- end
230
- }
231
- end
232
-
233
- def get_status( tag )
234
- File.foreach(@filename) {|line|
235
- return false if line.strip.empty?
236
- if m = /\AX-TMail-Status:/i.match(line)
237
- return m.post_match.strip.include?(tag[0])
238
- end
239
- }
240
- false
241
- end
242
-
243
- end
244
-
245
-
246
- class MaildirPort < FilePort
247
-
248
- def move_to_new
249
- new = replace_dir(@filename, 'new')
250
- File.rename @filename, new
251
- @filename = new
252
- end
253
-
254
- def move_to_cur
255
- new = replace_dir(@filename, 'cur')
256
- File.rename @filename, new
257
- @filename = new
258
- end
259
-
260
- def replace_dir( path, dir )
261
- "#{File.dirname File.dirname(path)}/#{dir}/#{File.basename path}"
262
- end
263
- private :replace_dir
264
-
265
-
266
- include MailFlags
267
-
268
- private
269
-
270
- MAIL_FILE = /\A(\d+\.[\d_]+\.[^:]+)(?:\:(\d),(\w+)?)?\z/
271
-
272
- def set_status( tag, flag )
273
- if m = MAIL_FILE.match(File.basename(@filename))
274
- s, uniq, type, info, = m.to_a
275
- return if type and type != '2' # do not change anything
276
- newname = File.dirname(@filename) + '/' +
277
- uniq + ':2,' + procinfostr(info.to_s, tag, flag)
278
- else
279
- newname = @filename + ':2,' + tag
280
- end
281
-
282
- File.link @filename, newname
283
- File.unlink @filename
284
- @filename = newname
285
- end
286
-
287
- def get_status( tag )
288
- m = MAIL_FILE.match(File.basename(@filename)) or return false
289
- m[2] == '2' and m[3].to_s.include?(tag[0])
290
- end
291
-
292
- end
293
-
294
-
295
- ###
296
- ### StringPort
297
- ###
298
-
299
- class StringPort < Port
300
-
301
- def initialize( str = '' )
302
- @buffer = str
303
- super()
304
- end
305
-
306
- def string
307
- @buffer
308
- end
309
-
310
- def to_s
311
- @buffer.dup
312
- end
313
-
314
- alias read_all to_s
315
-
316
- def size
317
- @buffer.size
318
- end
319
-
320
- def ==( other )
321
- StringPort === other and @buffer.equal? other.string
322
- end
323
-
324
- alias eql? ==
325
-
326
- def hash
327
- @buffer.object_id.hash
328
- end
329
-
330
- def inspect
331
- "#<#{self.class}:id=#{sprintf '0x%x', @buffer.object_id}>"
332
- end
333
-
334
- def reproducible?
335
- true
336
- end
337
-
338
- def ropen( &block )
339
- @buffer or raise Errno::ENOENT, "#{inspect} is already removed"
340
- StringInput.open(@buffer, &block)
341
- end
342
-
343
- def wopen( &block )
344
- @buffer = ''
345
- StringOutput.new(@buffer, &block)
346
- end
347
-
348
- def aopen( &block )
349
- @buffer ||= ''
350
- StringOutput.new(@buffer, &block)
351
- end
352
-
353
- def remove
354
- @buffer = nil
355
- end
356
-
357
- alias rm remove
358
-
359
- def copy_to( port )
360
- port.wopen {|f|
361
- f.write @buffer
362
- }
363
- end
364
-
365
- alias cp copy_to
366
-
367
- def move_to( port )
368
- if StringPort === port
369
- str = @buffer
370
- port.instance_eval { @buffer = str }
371
- else
372
- copy_to port
373
- end
374
- remove
375
- end
376
-
377
- end
378
-
379
- end # module TMail
@@ -1,164 +0,0 @@
1
- =begin rdoc
2
-
3
- = Quoting methods
4
-
5
- =end
6
- module TMail
7
- class Mail
8
- def subject(to_charset = 'utf-8')
9
- Unquoter.unquote_and_convert_to(quoted_subject, to_charset)
10
- end
11
-
12
- def unquoted_body(to_charset = 'utf-8')
13
- from_charset = charset
14
- case (content_transfer_encoding || "7bit").downcase
15
- when "quoted-printable"
16
- # the default charset is set to iso-8859-1 instead of 'us-ascii'.
17
- # This is needed as many mailer do not set the charset but send in ISO. This is only used if no charset is set.
18
- if !from_charset.blank? && from_charset.downcase == 'us-ascii'
19
- from_charset = 'iso-8859-1'
20
- end
21
-
22
- Unquoter.unquote_quoted_printable_and_convert_to(quoted_body,
23
- to_charset, from_charset, true)
24
- when "base64"
25
- Unquoter.unquote_base64_and_convert_to(quoted_body, to_charset,
26
- from_charset)
27
- when "7bit", "8bit"
28
- Unquoter.convert_to(quoted_body, to_charset, from_charset)
29
- when "binary"
30
- quoted_body
31
- else
32
- quoted_body
33
- end
34
- end
35
-
36
- def body(to_charset = 'utf-8', &block)
37
- attachment_presenter = block || Proc.new { |file_name| "Attachment: #{file_name}\n" }
38
-
39
- if multipart?
40
- parts.collect { |part|
41
- header = part["content-type"]
42
-
43
- if part.multipart?
44
- part.body(to_charset, &attachment_presenter)
45
- elsif header.nil?
46
- ""
47
- elsif !attachment?(part)
48
- part.unquoted_body(to_charset)
49
- else
50
- attachment_presenter.call(header["name"] || "(unnamed)")
51
- end
52
- }.join
53
- else
54
- unquoted_body(to_charset)
55
- end
56
- end
57
- end
58
-
59
- class Attachment
60
-
61
- include TextUtils
62
-
63
- def quoted?(string)
64
- !!((string =~ /.+'\w\w'.+/) || (string =~ /=\?.+\?.\?.+\?=/))
65
- end
66
-
67
- # Only unquote if quoted
68
- def original_filename(to_charset = 'utf-8')
69
- if quoted?(quoted_filename)
70
- Unquoter.unquote_and_convert_to(quoted_filename, to_charset).chomp
71
- else
72
- quoted_filename
73
- end
74
- end
75
- end
76
-
77
- class Unquoter
78
- class << self
79
- def unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1", preserve_underscores=false)
80
- return "" if text.nil?
81
- text.gsub!(/\?=(\s*)=\?/, '?==?') # Remove whitespaces between 'encoded-word's
82
- text.gsub(/(.*?)(?:(?:=\?(.*?)\?(.)\?(.*?)\?=)|$)/) do
83
- before = $1
84
- from_charset = $2
85
- quoting_method = $3
86
- text = $4
87
-
88
- before = convert_to(before, to_charset, from_charset) if before.length > 0
89
- before + case quoting_method
90
- when "q", "Q" then
91
- unquote_quoted_printable_and_convert_to(text, to_charset, from_charset, preserve_underscores)
92
- when "b", "B" then
93
- unquote_base64_and_convert_to(text, to_charset, from_charset)
94
- when nil then
95
- # will be nil at the end of the string, due to the nature of
96
- # the regex used.
97
- ""
98
- else
99
- raise "unknown quoting method #{quoting_method.inspect}"
100
- end
101
- end
102
- end
103
-
104
- def convert_to_with_fallback_on_iso_8859_1(text, to, from)
105
- return text if to == 'utf-8' and text.isutf8
106
-
107
- if from.blank? and !text.is_binary_data?
108
- from = CharDet.detect(text)['encoding']
109
-
110
- # Chardet ususally detects iso-8859-2 (aka windows-1250), but the text is
111
- # iso-8859-1 (aka windows-1252 and Latin1). http://en.wikipedia.org/wiki/ISO/IEC_8859-2
112
- # This can cause unwanted characters, like ŕ instead of à.
113
- # (I know, could be a very bad decision...)
114
- from = 'iso-8859-1' if from =~ /iso-8859-2/i
115
- end
116
-
117
- begin
118
- convert_to_without_fallback_on_iso_8859_1(text, to, from)
119
- rescue Iconv::InvalidCharacter
120
- unless from == 'iso-8859-1'
121
- from = 'iso-8859-1'
122
- retry
123
- end
124
- end
125
- end
126
-
127
- def unquote_quoted_printable_and_convert_to(text, to, from, preserve_underscores=false)
128
- text = text.gsub(/_/, " ") unless preserve_underscores
129
- text = text.gsub(/\r\n|\r/, "\n") # normalize newlines
130
- convert_to(text.unpack("M*").first, to, from)
131
- end
132
-
133
- def unquote_base64_and_convert_to(text, to, from)
134
- convert_to(Base64.decode(text), to, from)
135
- end
136
-
137
- begin
138
- require 'iconv'
139
- def convert_to(text, to, from)
140
- return text unless to && from
141
- text ? Iconv.iconv(to, from, text).first : ""
142
- rescue Iconv::IllegalSequence, Iconv::InvalidEncoding, Errno::EINVAL
143
- # the 'from' parameter specifies a charset other than what the text
144
- # actually is...not much we can do in this case but just return the
145
- # unconverted text.
146
- #
147
- # Ditto if either parameter represents an unknown charset, like
148
- # X-UNKNOWN.
149
- text
150
- end
151
- rescue LoadError
152
- # Not providing quoting support
153
- def convert_to(text, to, from)
154
- warn "Action Mailer: iconv not loaded; ignoring conversion from #{from} to #{to} (#{__FILE__}:#{__LINE__})"
155
- text
156
- end
157
- end
158
-
159
- alias_method :convert_to_without_fallback_on_iso_8859_1, :convert_to
160
- alias_method :convert_to, :convert_to_with_fallback_on_iso_8859_1
161
-
162
- end
163
- end
164
- end
@@ -1,58 +0,0 @@
1
- #:stopdoc:
2
- require 'rbconfig'
3
-
4
- # Attempts to require anative extension.
5
- # Falls back to pure-ruby version, if it fails.
6
- #
7
- # This uses Config::CONFIG['arch'] from rbconfig.
8
-
9
- def require_arch(fname)
10
- arch = Config::CONFIG['arch']
11
- begin
12
- path = File.join("tmail", arch, fname)
13
- require path
14
- rescue LoadError => e
15
- # try pre-built Windows binaries
16
- if arch =~ /mswin/
17
- require File.join("tmail", 'mswin32', fname)
18
- else
19
- raise e
20
- end
21
- end
22
- end
23
-
24
-
25
- # def require_arch(fname)
26
- # dext = Config::CONFIG['DLEXT']
27
- # begin
28
- # if File.extname(fname) == dext
29
- # path = fname
30
- # else
31
- # path = File.join("tmail","#{fname}.#{dext}")
32
- # end
33
- # require path
34
- # rescue LoadError => e
35
- # begin
36
- # arch = Config::CONFIG['arch']
37
- # path = File.join("tmail", arch, "#{fname}.#{dext}")
38
- # require path
39
- # rescue LoadError
40
- # case path
41
- # when /i686/
42
- # path.sub!('i686', 'i586')
43
- # when /i586/
44
- # path.sub!('i586', 'i486')
45
- # when /i486/
46
- # path.sub!('i486', 'i386')
47
- # else
48
- # begin
49
- # require fname + '.rb'
50
- # rescue LoadError
51
- # raise e
52
- # end
53
- # end
54
- # retry
55
- # end
56
- # end
57
- # end
58
- #:startdoc:
@@ -1,49 +0,0 @@
1
- =begin rdoc
2
-
3
- = Scanner for TMail
4
-
5
- =end
6
- #--
7
- # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
8
- #
9
- # Permission is hereby granted, free of charge, to any person obtaining
10
- # a copy of this software and associated documentation files (the
11
- # "Software"), to deal in the Software without restriction, including
12
- # without limitation the rights to use, copy, modify, merge, publish,
13
- # distribute, sublicense, and/or sell copies of the Software, and to
14
- # permit persons to whom the Software is furnished to do so, subject to
15
- # the following conditions:
16
- #
17
- # The above copyright notice and this permission notice shall be
18
- # included in all copies or substantial portions of the Software.
19
- #
20
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
- #
28
- # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
29
- # with permission of Minero Aoki.
30
- #++
31
- #:stopdoc:
32
- #require 'tmail/require_arch'
33
- require 'tmail/utils'
34
- require 'tmail/config'
35
-
36
- module TMail
37
- # NOTE: It woiuld be nice if these two libs could boith be called "tmailscanner", and
38
- # the native extension would have precedence. However RubyGems boffs that up b/c
39
- # it does not gaurantee load_path order.
40
- begin
41
- raise LoadError, 'Turned off native extentions by user choice' if ENV['NORUBYEXT']
42
- require('tmail/tmailscanner') # c extension
43
- Scanner = TMailScanner
44
- rescue LoadError
45
- require 'tmail/scanner_r'
46
- Scanner = TMailScanner
47
- end
48
- end
49
- #:stopdoc: