actionmailer-2.3.17-rack-upgrade 2.3.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/CHANGELOG +387 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +149 -0
  4. data/Rakefile +97 -0
  5. data/install.rb +30 -0
  6. data/lib/action_mailer.rb +62 -0
  7. data/lib/action_mailer/adv_attr_accessor.rb +30 -0
  8. data/lib/action_mailer/base.rb +739 -0
  9. data/lib/action_mailer/helpers.rb +113 -0
  10. data/lib/action_mailer/mail_helper.rb +17 -0
  11. data/lib/action_mailer/part.rb +107 -0
  12. data/lib/action_mailer/part_container.rb +55 -0
  13. data/lib/action_mailer/quoting.rb +62 -0
  14. data/lib/action_mailer/test_case.rb +64 -0
  15. data/lib/action_mailer/test_helper.rb +68 -0
  16. data/lib/action_mailer/utils.rb +7 -0
  17. data/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb +1466 -0
  18. data/lib/action_mailer/vendor/text_format.rb +10 -0
  19. data/lib/action_mailer/vendor/tmail-1.2.7/tmail.rb +6 -0
  20. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/Makefile +18 -0
  21. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/address.rb +392 -0
  22. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/attachments.rb +65 -0
  23. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/base64.rb +46 -0
  24. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/compat.rb +41 -0
  25. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/config.rb +67 -0
  26. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/core_extensions.rb +63 -0
  27. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb +590 -0
  28. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb +962 -0
  29. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/index.rb +9 -0
  30. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/interface.rb +1162 -0
  31. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/loader.rb +3 -0
  32. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb +578 -0
  33. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mailbox.rb +496 -0
  34. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/main.rb +6 -0
  35. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mbox.rb +3 -0
  36. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/net.rb +250 -0
  37. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/obsolete.rb +132 -0
  38. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/parser.rb +1060 -0
  39. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/parser.y +416 -0
  40. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/port.rb +379 -0
  41. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/quoting.rb +164 -0
  42. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/require_arch.rb +58 -0
  43. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/scanner.rb +49 -0
  44. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/scanner_r.rb +262 -0
  45. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/stringio.rb +280 -0
  46. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/utils.rb +362 -0
  47. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/COPYING +504 -0
  48. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/README +12 -0
  49. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet.rb +67 -0
  50. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/big5freq.rb +927 -0
  51. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/big5prober.rb +42 -0
  52. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb +238 -0
  53. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/charsetgroupprober.rb +112 -0
  54. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/charsetprober.rb +75 -0
  55. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/codingstatemachine.rb +64 -0
  56. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/constants.rb +42 -0
  57. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb +89 -0
  58. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escsm.rb +244 -0
  59. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/eucjpprober.rb +88 -0
  60. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euckrfreq.rb +596 -0
  61. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euckrprober.rb +42 -0
  62. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euctwfreq.rb +430 -0
  63. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euctwprober.rb +42 -0
  64. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312freq.rb +474 -0
  65. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312prober.rb +42 -0
  66. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/hebrewprober.rb +289 -0
  67. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/jisfreq.rb +570 -0
  68. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/jpcntx.rb +229 -0
  69. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langbulgarianmodel.rb +229 -0
  70. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langcyrillicmodel.rb +330 -0
  71. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langgreekmodel.rb +227 -0
  72. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langhebrewmodel.rb +202 -0
  73. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langhungarianmodel.rb +226 -0
  74. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langthaimodel.rb +201 -0
  75. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/latin1prober.rb +147 -0
  76. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcharsetprober.rb +89 -0
  77. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcsgroupprober.rb +45 -0
  78. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcssm.rb +542 -0
  79. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sbcharsetprober.rb +124 -0
  80. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sbcsgroupprober.rb +56 -0
  81. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sjisprober.rb +88 -0
  82. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/universaldetector.rb +168 -0
  83. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb +87 -0
  84. data/lib/action_mailer/vendor/tmail-1.2.7/tmail/version.rb +39 -0
  85. data/lib/action_mailer/vendor/tmail.rb +17 -0
  86. data/lib/action_mailer/version.rb +9 -0
  87. data/lib/actionmailer.rb +2 -0
  88. data/test/abstract_unit.rb +62 -0
  89. data/test/asset_host_test.rb +54 -0
  90. data/test/delivery_method_test.rb +51 -0
  91. data/test/fixtures/asset_host_mailer/email_with_asset.html.erb +1 -0
  92. data/test/fixtures/auto_layout_mailer/hello.html.erb +1 -0
  93. data/test/fixtures/auto_layout_mailer/multipart.text.html.erb +1 -0
  94. data/test/fixtures/auto_layout_mailer/multipart.text.plain.erb +1 -0
  95. data/test/fixtures/explicit_layout_mailer/logout.html.erb +1 -0
  96. data/test/fixtures/explicit_layout_mailer/signup.html.erb +1 -0
  97. data/test/fixtures/first_mailer/share.erb +1 -0
  98. data/test/fixtures/helper_mailer/use_example_helper.erb +1 -0
  99. data/test/fixtures/helper_mailer/use_helper.erb +1 -0
  100. data/test/fixtures/helper_mailer/use_helper_method.erb +1 -0
  101. data/test/fixtures/helper_mailer/use_mail_helper.erb +5 -0
  102. data/test/fixtures/helpers/example_helper.rb +5 -0
  103. data/test/fixtures/layouts/auto_layout_mailer.html.erb +1 -0
  104. data/test/fixtures/layouts/auto_layout_mailer.text.erb +1 -0
  105. data/test/fixtures/layouts/spam.html.erb +1 -0
  106. data/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb +1 -0
  107. data/test/fixtures/raw_email +14 -0
  108. data/test/fixtures/raw_email10 +20 -0
  109. data/test/fixtures/raw_email12 +32 -0
  110. data/test/fixtures/raw_email13 +29 -0
  111. data/test/fixtures/raw_email2 +114 -0
  112. data/test/fixtures/raw_email3 +70 -0
  113. data/test/fixtures/raw_email4 +59 -0
  114. data/test/fixtures/raw_email5 +19 -0
  115. data/test/fixtures/raw_email6 +20 -0
  116. data/test/fixtures/raw_email7 +66 -0
  117. data/test/fixtures/raw_email8 +47 -0
  118. data/test/fixtures/raw_email9 +28 -0
  119. data/test/fixtures/raw_email_quoted_with_0d0a +14 -0
  120. data/test/fixtures/raw_email_with_invalid_characters_in_content_type +104 -0
  121. data/test/fixtures/raw_email_with_nested_attachment +100 -0
  122. data/test/fixtures/raw_email_with_partially_quoted_subject +14 -0
  123. data/test/fixtures/second_mailer/share.erb +1 -0
  124. data/test/fixtures/templates/signed_up.erb +3 -0
  125. data/test/fixtures/test_mailer/_subtemplate.text.plain.erb +1 -0
  126. data/test/fixtures/test_mailer/body_ivar.erb +2 -0
  127. data/test/fixtures/test_mailer/custom_templating_extension.text.html.haml +6 -0
  128. data/test/fixtures/test_mailer/custom_templating_extension.text.plain.haml +6 -0
  129. data/test/fixtures/test_mailer/implicitly_multipart_example.ignored.erb +1 -0
  130. data/test/fixtures/test_mailer/implicitly_multipart_example.rhtml.bak +1 -0
  131. data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb +10 -0
  132. data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~ +10 -0
  133. data/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.erb +2 -0
  134. data/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.erb +1 -0
  135. data/test/fixtures/test_mailer/included_subtemplate.text.plain.erb +1 -0
  136. data/test/fixtures/test_mailer/rxml_template.builder +2 -0
  137. data/test/fixtures/test_mailer/rxml_template.rxml +2 -0
  138. data/test/fixtures/test_mailer/signed_up.html.erb +3 -0
  139. data/test/fixtures/test_mailer/signed_up_with_url.erb +5 -0
  140. data/test/mail_helper_test.rb +95 -0
  141. data/test/mail_layout_test.rb +123 -0
  142. data/test/mail_render_test.rb +116 -0
  143. data/test/mail_service_test.rb +1145 -0
  144. data/test/quoting_test.rb +105 -0
  145. data/test/test_helper_test.rb +129 -0
  146. data/test/tmail_test.rb +22 -0
  147. data/test/url_test.rb +76 -0
  148. metadata +209 -0
@@ -0,0 +1,10 @@
1
+ # Prefer gems to the bundled libs.
2
+ require 'rubygems'
3
+
4
+ begin
5
+ gem 'text-format', '>= 0.6.3'
6
+ rescue Gem::LoadError
7
+ $:.unshift "#{File.dirname(__FILE__)}/text-format-0.6.3"
8
+ end
9
+
10
+ require 'text/format'
@@ -0,0 +1,6 @@
1
+ require 'tmail/version'
2
+ require 'tmail/mail'
3
+ require 'tmail/mailbox'
4
+ require 'tmail/core_extensions'
5
+ require 'tmail/net'
6
+ require 'tmail/vendor/rchardet-1.3/lib/rchardet'
@@ -0,0 +1,18 @@
1
+ # lib/tmail/Makefile
2
+ #
3
+
4
+ debug:
5
+ rm -f parser.rb
6
+ make parser.rb DEBUG=true
7
+
8
+ parser.rb: parser.y
9
+ if [ "$(DEBUG)" = true ]; then \
10
+ racc -v -g -o$@ parser.y ;\
11
+ else \
12
+ racc -E -o$@ parser.y ;\
13
+ fi
14
+
15
+ clean:
16
+ rm -f parser.rb parser.output
17
+
18
+ distclean: clean
@@ -0,0 +1,392 @@
1
+ =begin rdoc
2
+
3
+ = Address handling 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/encode'
33
+ require 'tmail/parser'
34
+
35
+
36
+ module TMail
37
+
38
+ # = Class Address
39
+ #
40
+ # Provides a complete handling library for email addresses. Can parse a string of an
41
+ # address directly or take in preformatted addresses themselves. Allows you to add
42
+ # and remove phrases from the front of the address and provides a compare function for
43
+ # email addresses.
44
+ #
45
+ # == Parsing and Handling a Valid Address:
46
+ #
47
+ # Just pass the email address in as a string to Address.parse:
48
+ #
49
+ # email = TMail::Address.parse('Mikel Lindsaar <mikel@lindsaar.net>')
50
+ # #=> #<TMail::Address mikel@lindsaar.net>
51
+ # email.address
52
+ # #=> "mikel@lindsaar.net"
53
+ # email.local
54
+ # #=> "mikel"
55
+ # email.domain
56
+ # #=> "lindsaar.net"
57
+ # email.name # Aliased as phrase as well
58
+ # #=> "Mikel Lindsaar"
59
+ #
60
+ # == Detecting an Invalid Address
61
+ #
62
+ # If you want to check the syntactical validity of an email address, just pass it to
63
+ # Address.parse and catch any SyntaxError:
64
+ #
65
+ # begin
66
+ # TMail::Address.parse("mikel 2@@@@@ me .com")
67
+ # rescue TMail::SyntaxError
68
+ # puts("Invalid Email Address Detected")
69
+ # else
70
+ # puts("Address is valid")
71
+ # end
72
+ # #=> "Invalid Email Address Detected"
73
+ class Address
74
+
75
+ include TextUtils #:nodoc:
76
+
77
+ # Sometimes you need to parse an address, TMail can do it for you and provide you with
78
+ # a fairly robust method of detecting a valid address.
79
+ #
80
+ # Takes in a string, returns a TMail::Address object.
81
+ #
82
+ # Raises a TMail::SyntaxError on invalid email format
83
+ def Address.parse( str )
84
+ Parser.parse :ADDRESS, str
85
+ end
86
+
87
+ def address_group? #:nodoc:
88
+ false
89
+ end
90
+
91
+ # Address.new(local, domain)
92
+ #
93
+ # Accepts:
94
+ #
95
+ # * local - Left of the at symbol
96
+ #
97
+ # * domain - Array of the domain split at the periods.
98
+ #
99
+ # For example:
100
+ #
101
+ # Address.new("mikel", ["lindsaar", "net"])
102
+ # #=> "#<TMail::Address mikel@lindsaar.net>"
103
+ def initialize( local, domain )
104
+ if domain
105
+ domain.each do |s|
106
+ raise SyntaxError, 'empty word in domain' if s.empty?
107
+ end
108
+ end
109
+
110
+ # This is to catch an unquoted "@" symbol in the local part of the
111
+ # address. Handles addresses like <"@"@me.com> and makes sure they
112
+ # stay like <"@"@me.com> (previously were becoming <@@me.com>)
113
+ if local && (local.join == '@' || local.join =~ /\A[^"].*?@.*?[^"]\Z/)
114
+ @local = "\"#{local.join}\""
115
+ else
116
+ @local = local
117
+ end
118
+
119
+ @domain = domain
120
+ @name = nil
121
+ @routes = []
122
+ end
123
+
124
+ # Provides the name or 'phrase' of the email address.
125
+ #
126
+ # For Example:
127
+ #
128
+ # email = TMail::Address.parse("Mikel Lindsaar <mikel@lindsaar.net>")
129
+ # email.name
130
+ # #=> "Mikel Lindsaar"
131
+ def name
132
+ @name
133
+ end
134
+
135
+ # Setter method for the name or phrase of the email
136
+ #
137
+ # For Example:
138
+ #
139
+ # email = TMail::Address.parse("mikel@lindsaar.net")
140
+ # email.name
141
+ # #=> nil
142
+ # email.name = "Mikel Lindsaar"
143
+ # email.to_s
144
+ # #=> "Mikel Lindsaar <mikel@me.com>"
145
+ def name=( str )
146
+ @name = str
147
+ @name = nil if str and str.empty?
148
+ end
149
+
150
+ #:stopdoc:
151
+ alias phrase name
152
+ alias phrase= name=
153
+ #:startdoc:
154
+
155
+ # This is still here from RFC 822, and is now obsolete per RFC2822 Section 4.
156
+ #
157
+ # "When interpreting addresses, the route portion SHOULD be ignored."
158
+ #
159
+ # It is still here, so you can access it.
160
+ #
161
+ # Routes return the route portion at the front of the email address, if any.
162
+ #
163
+ # For Example:
164
+ # email = TMail::Address.parse( "<@sa,@another:Mikel@me.com>")
165
+ # => #<TMail::Address Mikel@me.com>
166
+ # email.to_s
167
+ # => "<@sa,@another:Mikel@me.com>"
168
+ # email.routes
169
+ # => ["sa", "another"]
170
+ def routes
171
+ @routes
172
+ end
173
+
174
+ def inspect #:nodoc:
175
+ "#<#{self.class} #{address()}>"
176
+ end
177
+
178
+ # Returns the local part of the email address
179
+ #
180
+ # For Example:
181
+ #
182
+ # email = TMail::Address.parse("mikel@lindsaar.net")
183
+ # email.local
184
+ # #=> "mikel"
185
+ def local
186
+ return nil unless @local
187
+ return '""' if @local.size == 1 and @local[0].empty?
188
+ # Check to see if it is an array before trying to map it
189
+ if @local.respond_to?(:map)
190
+ @local.map {|i| quote_atom(i) }.join('.')
191
+ else
192
+ quote_atom(@local)
193
+ end
194
+ end
195
+
196
+ # Returns the domain part of the email address
197
+ #
198
+ # For Example:
199
+ #
200
+ # email = TMail::Address.parse("mikel@lindsaar.net")
201
+ # email.local
202
+ # #=> "lindsaar.net"
203
+ def domain
204
+ return nil unless @domain
205
+ join_domain(@domain)
206
+ end
207
+
208
+ # Returns the full specific address itself
209
+ #
210
+ # For Example:
211
+ #
212
+ # email = TMail::Address.parse("mikel@lindsaar.net")
213
+ # email.address
214
+ # #=> "mikel@lindsaar.net"
215
+ def spec
216
+ s = self.local
217
+ d = self.domain
218
+ if s and d
219
+ s + '@' + d
220
+ else
221
+ s
222
+ end
223
+ end
224
+
225
+ alias address spec
226
+
227
+ # Provides == function to the email. Only checks the actual address
228
+ # and ignores the name/phrase component
229
+ #
230
+ # For Example
231
+ #
232
+ # addr1 = TMail::Address.parse("My Address <mikel@lindsaar.net>")
233
+ # #=> "#<TMail::Address mikel@lindsaar.net>"
234
+ # addr2 = TMail::Address.parse("Another <mikel@lindsaar.net>")
235
+ # #=> "#<TMail::Address mikel@lindsaar.net>"
236
+ # addr1 == addr2
237
+ # #=> true
238
+ def ==( other )
239
+ other.respond_to? :spec and self.spec == other.spec
240
+ end
241
+
242
+ alias eql? ==
243
+
244
+ # Provides a unique hash value for this record against the local and domain
245
+ # parts, ignores the name/phrase value
246
+ #
247
+ # email = TMail::Address.parse("mikel@lindsaar.net")
248
+ # email.hash
249
+ # #=> 18767598
250
+ def hash
251
+ @local.hash ^ @domain.hash
252
+ end
253
+
254
+ # Duplicates a TMail::Address object returning the duplicate
255
+ #
256
+ # addr1 = TMail::Address.parse("mikel@lindsaar.net")
257
+ # addr2 = addr1.dup
258
+ # addr1.id == addr2.id
259
+ # #=> false
260
+ def dup
261
+ obj = self.class.new(@local.dup, @domain.dup)
262
+ obj.name = @name.dup if @name
263
+ obj.routes.replace @routes
264
+ obj
265
+ end
266
+
267
+ include StrategyInterface #:nodoc:
268
+
269
+ def accept( strategy, dummy1 = nil, dummy2 = nil ) #:nodoc:
270
+ unless @local
271
+ strategy.meta '<>' # empty return-path
272
+ return
273
+ end
274
+
275
+ spec_p = (not @name and @routes.empty?)
276
+ if @name
277
+ strategy.phrase @name
278
+ strategy.space
279
+ end
280
+ tmp = spec_p ? '' : '<'
281
+ unless @routes.empty?
282
+ tmp << @routes.map {|i| '@' + i }.join(',') << ':'
283
+ end
284
+ tmp << self.spec
285
+ tmp << '>' unless spec_p
286
+ strategy.meta tmp
287
+ strategy.lwsp ''
288
+ end
289
+
290
+ end
291
+
292
+
293
+ class AddressGroup
294
+
295
+ include Enumerable
296
+
297
+ def address_group?
298
+ true
299
+ end
300
+
301
+ def initialize( name, addrs )
302
+ @name = name
303
+ @addresses = addrs
304
+ end
305
+
306
+ attr_reader :name
307
+
308
+ def ==( other )
309
+ other.respond_to? :to_a and @addresses == other.to_a
310
+ end
311
+
312
+ alias eql? ==
313
+
314
+ def hash
315
+ map {|i| i.hash }.hash
316
+ end
317
+
318
+ def []( idx )
319
+ @addresses[idx]
320
+ end
321
+
322
+ def size
323
+ @addresses.size
324
+ end
325
+
326
+ def empty?
327
+ @addresses.empty?
328
+ end
329
+
330
+ def each( &block )
331
+ @addresses.each(&block)
332
+ end
333
+
334
+ def to_a
335
+ @addresses.dup
336
+ end
337
+
338
+ alias to_ary to_a
339
+
340
+ def include?( a )
341
+ @addresses.include? a
342
+ end
343
+
344
+ def flatten
345
+ set = []
346
+ @addresses.each do |a|
347
+ if a.respond_to? :flatten
348
+ set.concat a.flatten
349
+ else
350
+ set.push a
351
+ end
352
+ end
353
+ set
354
+ end
355
+
356
+ def each_address( &block )
357
+ flatten.each(&block)
358
+ end
359
+
360
+ def add( a )
361
+ @addresses.push a
362
+ end
363
+
364
+ alias push add
365
+
366
+ def delete( a )
367
+ @addresses.delete a
368
+ end
369
+
370
+ include StrategyInterface
371
+
372
+ def accept( strategy, dummy1 = nil, dummy2 = nil )
373
+ strategy.phrase @name
374
+ strategy.meta ':'
375
+ strategy.space
376
+ first = true
377
+ each do |mbox|
378
+ if first
379
+ first = false
380
+ else
381
+ strategy.puts_meta ','
382
+ end
383
+ strategy.space
384
+ mbox.accept strategy
385
+ end
386
+ strategy.meta ';'
387
+ strategy.lwsp ''
388
+ end
389
+
390
+ end
391
+
392
+ end # module TMail
@@ -0,0 +1,65 @@
1
+ =begin rdoc
2
+
3
+ = Attachment handling file
4
+
5
+ =end
6
+
7
+ require 'kconv'
8
+ require 'stringio'
9
+
10
+ module TMail
11
+ class Attachment < StringIO
12
+ attr_accessor :original_filename, :content_type
13
+ alias quoted_filename original_filename
14
+ end
15
+
16
+ class Mail
17
+ def has_attachments?
18
+ attachment?(self) || multipart? && parts.any? { |part| attachment?(part) }
19
+ end
20
+
21
+ # Returns true if this part's content main type is text, else returns false.
22
+ # By main type is meant "text/plain" is text. "text/html" is text
23
+ def text_content_type?
24
+ self.header['content-type'] && (self.header['content-type'].main_type == 'text')
25
+ end
26
+
27
+ def inline_attachment?(part)
28
+ part['content-id'] || (part['content-disposition'] && part['content-disposition'].disposition == 'inline' && !part.text_content_type?)
29
+ end
30
+
31
+ def attachment?(part)
32
+ part.disposition_is_attachment? || (!part.content_type.nil? && !part.text_content_type?) unless part.multipart?
33
+ end
34
+
35
+ def attachments
36
+ if multipart?
37
+ parts.collect { |part| attachment(part) }.flatten.compact
38
+ elsif attachment?(self)
39
+ [attachment(self)]
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def attachment(part)
46
+ if part.multipart?
47
+ part.attachments
48
+ elsif attachment?(part)
49
+ content = part.body # unquoted automatically by TMail#body
50
+ file_name = (part['content-location'] && part['content-location'].body) ||
51
+ part.sub_header('content-type', 'name') ||
52
+ part.sub_header('content-disposition', 'filename') ||
53
+ 'noname'
54
+
55
+ return if content.blank?
56
+
57
+ attachment = TMail::Attachment.new(content)
58
+ attachment.original_filename = file_name.strip unless file_name.blank?
59
+ attachment.content_type = part.content_type
60
+ attachment
61
+ end
62
+ end
63
+
64
+ end
65
+ end