actionmailer 1.3.6 → 2.0.0

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 (96) hide show
  1. data/CHANGELOG +40 -28
  2. data/MIT-LICENSE +1 -1
  3. data/README +2 -2
  4. data/Rakefile +4 -3
  5. data/install.rb +1 -1
  6. data/lib/action_mailer.rb +5 -3
  7. data/lib/action_mailer/base.rb +57 -36
  8. data/lib/action_mailer/helpers.rb +4 -4
  9. data/lib/action_mailer/part.rb +2 -5
  10. data/lib/action_mailer/test_case.rb +59 -0
  11. data/lib/action_mailer/test_helper.rb +67 -0
  12. data/lib/action_mailer/vendor.rb +14 -0
  13. data/lib/action_mailer/vendor/{text → text-format-0.6.3/text}/format.rb +0 -0
  14. data/lib/action_mailer/vendor/tmail-1.1.0/tmail.rb +4 -0
  15. data/lib/action_mailer/vendor/tmail-1.1.0/tmail/Makefile +19 -0
  16. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/address.rb +6 -3
  17. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/attachments.rb +10 -2
  18. data/lib/action_mailer/vendor/tmail-1.1.0/tmail/base64.rb +52 -0
  19. data/lib/action_mailer/vendor/tmail-1.1.0/tmail/compat.rb +39 -0
  20. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/config.rb +5 -3
  21. data/lib/action_mailer/vendor/tmail-1.1.0/tmail/core_extensions.rb +67 -0
  22. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/encode.rb +23 -9
  23. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/facade.rb +0 -0
  24. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/header.rb +23 -6
  25. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/info.rb +0 -0
  26. data/lib/action_mailer/vendor/tmail-1.1.0/tmail/interface.rb +540 -0
  27. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/loader.rb +0 -0
  28. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/mail.rb +20 -5
  29. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/mailbox.rb +5 -3
  30. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/mbox.rb +0 -0
  31. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/net.rb +5 -3
  32. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/obsolete.rb +5 -3
  33. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/parser.rb +234 -281
  34. data/lib/action_mailer/vendor/tmail-1.1.0/tmail/parser.y +381 -0
  35. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/port.rb +5 -3
  36. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/quoting.rb +12 -1
  37. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/scanner.rb +5 -3
  38. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/scanner_r.rb +1 -1
  39. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/stringio.rb +6 -4
  40. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/tmail.rb +0 -0
  41. data/lib/action_mailer/vendor/{tmail → tmail-1.1.0/tmail}/utils.rb +50 -7
  42. data/lib/action_mailer/vendor/{tmail/base64.rb → tmail-1.1.0/tmail/version.rb} +7 -40
  43. data/lib/action_mailer/version.rb +3 -3
  44. data/lib/actionmailer.rb +1 -0
  45. data/test/abstract_unit.rb +19 -0
  46. data/test/delivery_method_test.rb +51 -0
  47. data/test/fixtures/first_mailer/share.erb +1 -0
  48. data/test/fixtures/first_mailer/share.rhtml +0 -1
  49. data/test/fixtures/helper_mailer/use_example_helper.erb +1 -0
  50. data/test/fixtures/helper_mailer/use_example_helper.rhtml +0 -0
  51. data/test/fixtures/helper_mailer/use_helper.erb +1 -0
  52. data/test/fixtures/helper_mailer/use_helper.rhtml +0 -1
  53. data/test/fixtures/helper_mailer/use_helper_method.erb +1 -0
  54. data/test/fixtures/helper_mailer/use_helper_method.rhtml +0 -1
  55. data/test/fixtures/helper_mailer/use_mail_helper.erb +5 -0
  56. data/test/fixtures/helper_mailer/use_mail_helper.rhtml +0 -5
  57. data/test/fixtures/helpers/{test_helper.rb → example_helper.rb} +2 -2
  58. data/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb +1 -0
  59. data/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.rhtml +0 -1
  60. data/test/fixtures/raw_base64_decoded_string +0 -0
  61. data/test/fixtures/raw_base64_encoded_string +1 -0
  62. data/test/fixtures/raw_email_with_invalid_characters_in_content_type +104 -0
  63. data/test/fixtures/raw_email_with_nested_attachment +100 -0
  64. data/test/fixtures/second_mailer/share.erb +1 -0
  65. data/test/fixtures/second_mailer/share.rhtml +0 -1
  66. data/test/fixtures/templates/signed_up.erb +3 -0
  67. data/test/fixtures/templates/signed_up.rhtml +0 -3
  68. data/test/fixtures/test_mailer/_subtemplate.text.plain.erb +1 -0
  69. data/test/fixtures/test_mailer/custom_templating_extension.text.html.haml +6 -0
  70. data/test/fixtures/test_mailer/custom_templating_extension.text.plain.haml +6 -0
  71. data/test/fixtures/test_mailer/implicitly_multipart_example.ignored.erb +1 -0
  72. data/test/fixtures/test_mailer/implicitly_multipart_example.ignored.rhtml +0 -1
  73. data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb +10 -0
  74. data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.rhtml +0 -10
  75. data/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.erb +2 -0
  76. data/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.rhtml +0 -2
  77. data/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.erb +1 -0
  78. data/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.rhtml +0 -1
  79. data/test/fixtures/test_mailer/included_subtemplate.text.plain.erb +1 -0
  80. data/test/fixtures/test_mailer/rxml_template.builder +2 -0
  81. data/test/fixtures/test_mailer/rxml_template.rxml +2 -0
  82. data/test/fixtures/test_mailer/signed_up.erb +3 -0
  83. data/test/fixtures/test_mailer/signed_up.rhtml +0 -3
  84. data/test/fixtures/test_mailer/signed_up_with_url.erb +5 -0
  85. data/test/fixtures/test_mailer/signed_up_with_url.rhtml +0 -3
  86. data/test/mail_helper_test.rb +10 -6
  87. data/test/mail_render_test.rb +45 -2
  88. data/test/mail_service_test.rb +150 -27
  89. data/test/quoting_test.rb +57 -3
  90. data/test/test_helper_test.rb +117 -0
  91. data/test/tmail_test.rb +9 -0
  92. data/test/url_test.rb +10 -2
  93. metadata +69 -32
  94. data/lib/action_mailer/vendor/tmail.rb +0 -3
  95. data/test/fixtures/helper_mailer/use_test_helper.rhtml +0 -1
  96. data/test/fixtures/raw_email11 +0 -34
@@ -0,0 +1,67 @@
1
+ module ActionMailer
2
+ module TestHelper
3
+ # Asserts that the number of emails sent matches the given number.
4
+ #
5
+ # def test_emails
6
+ # assert_emails 0
7
+ # ContactMailer.deliver_contact
8
+ # assert_emails 1
9
+ # ContactMailer.deliver_contact
10
+ # assert_emails 2
11
+ # end
12
+ #
13
+ # If a block is passed, that block should cause the specified number of emails to be sent.
14
+ #
15
+ # def test_emails_again
16
+ # assert_emails 1 do
17
+ # ContactMailer.deliver_contact
18
+ # end
19
+ #
20
+ # assert_emails 2 do
21
+ # ContactMailer.deliver_contact
22
+ # ContactMailer.deliver_contact
23
+ # end
24
+ # end
25
+ def assert_emails(number)
26
+ if block_given?
27
+ original_count = ActionMailer::Base.deliveries.size
28
+ yield
29
+ new_count = ActionMailer::Base.deliveries.size
30
+ assert_equal original_count + number, new_count, "#{number} emails expected, but #{new_count - original_count} were sent"
31
+ else
32
+ assert_equal number, ActionMailer::Base.deliveries.size
33
+ end
34
+ end
35
+
36
+ # Assert that no emails have been sent.
37
+ #
38
+ # def test_emails
39
+ # assert_no_emails
40
+ # ContactMailer.deliver_contact
41
+ # assert_emails 1
42
+ # end
43
+ #
44
+ # If a block is passed, that block should not cause any emails to be sent.
45
+ #
46
+ # def test_emails_again
47
+ # assert_no_emails do
48
+ # # No emails should be sent from this block
49
+ # end
50
+ # end
51
+ #
52
+ # Note: This assertion is simply a shortcut for:
53
+ #
54
+ # assert_emails 0
55
+ def assert_no_emails(&block)
56
+ assert_emails 0, &block
57
+ end
58
+ end
59
+ end
60
+
61
+ module Test
62
+ module Unit
63
+ class TestCase
64
+ include ActionMailer::TestHelper
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,14 @@
1
+ # Prefer gems to the bundled libs.
2
+ require 'rubygems'
3
+
4
+ begin
5
+ gem 'tmail', '~> 1.1.0'
6
+ rescue Gem::LoadError
7
+ $:.unshift "#{File.dirname(__FILE__)}/vendor/tmail-1.1.0"
8
+ end
9
+
10
+ begin
11
+ gem 'text-format', '>= 0.6.3'
12
+ rescue Gem::LoadError
13
+ $:.unshift "#{File.dirname(__FILE__)}/vendor/text-format-0.6.3"
14
+ end
@@ -0,0 +1,4 @@
1
+ require 'tmail/version'
2
+ require 'tmail/mail'
3
+ require 'tmail/mailbox'
4
+ require 'tmail/core_extensions'
@@ -0,0 +1,19 @@
1
+ #
2
+ # lib/tmail/Makefile
3
+ #
4
+
5
+ debug:
6
+ rm -f parser.rb
7
+ make parser.rb DEBUG=true
8
+
9
+ parser.rb: parser.y
10
+ if [ "$(DEBUG)" = true ]; then \
11
+ racc -v -g -o$@ parser.y ;\
12
+ else \
13
+ racc -E -o$@ parser.y ;\
14
+ fi
15
+
16
+ clean:
17
+ rm -f parser.rb parser.output
18
+
19
+ distclean: clean
@@ -1,5 +1,8 @@
1
- #
2
- # address.rb
1
+ =begin rdoc
2
+
3
+ = Address handling class
4
+
5
+ =end
3
6
  #
4
7
  #--
5
8
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
@@ -51,6 +54,7 @@ module TMail
51
54
  raise SyntaxError, 'empty word in domain' if s.empty?
52
55
  end
53
56
  end
57
+
54
58
  @local = local
55
59
  @domain = domain
56
60
  @name = nil
@@ -96,7 +100,6 @@ module TMail
96
100
 
97
101
  alias address spec
98
102
 
99
-
100
103
  def ==( other )
101
104
  other.respond_to? :spec and self.spec == other.spec
102
105
  end
@@ -1,3 +1,9 @@
1
+ =begin rdoc
2
+
3
+ = Attachment handling class
4
+
5
+ =end
6
+
1
7
  require 'stringio'
2
8
 
3
9
  module TMail
@@ -18,7 +24,9 @@ module TMail
18
24
  def attachments
19
25
  if multipart?
20
26
  parts.collect { |part|
21
- if attachment?(part)
27
+ if part.multipart?
28
+ part.attachments
29
+ elsif attachment?(part)
22
30
  content = part.body # unquoted automatically by TMail#body
23
31
  file_name = (part['content-location'] &&
24
32
  part['content-location'].body) ||
@@ -32,7 +40,7 @@ module TMail
32
40
  attachment.content_type = part.content_type
33
41
  attachment
34
42
  end
35
- }.compact
43
+ }.flatten.compact
36
44
  end
37
45
  end
38
46
  end
@@ -0,0 +1,52 @@
1
+ # = TITLE:
2
+ #
3
+ # Base64
4
+ #
5
+ # = COPYRIGHT:
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
+ module TMail
33
+
34
+ module Base64
35
+
36
+ module_function
37
+
38
+ def folding_encode( str, eol = "\n", limit = 60 )
39
+ [str].pack('m')
40
+ end
41
+
42
+ def encode( str )
43
+ [str].pack('m').tr( "\r\n", '' )
44
+ end
45
+
46
+ def decode( str, strict = false )
47
+ str.unpack('m').first
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,39 @@
1
+ unless Enumerable.method_defined?(:map)
2
+ module Enumerable
3
+ alias map collect
4
+ end
5
+ end
6
+
7
+ unless Enumerable.method_defined?(:select)
8
+ module Enumerable
9
+ alias select find_all
10
+ end
11
+ end
12
+
13
+ unless Enumerable.method_defined?(:reject)
14
+ module Enumerable
15
+ def reject
16
+ result = []
17
+ each do |i|
18
+ result.push i unless yield(i)
19
+ end
20
+ result
21
+ end
22
+ end
23
+ end
24
+
25
+ unless Enumerable.method_defined?(:sort_by)
26
+ module Enumerable
27
+ def sort_by
28
+ map {|i| [yield(i), i] }.sort.map {|val, i| i }
29
+ end
30
+ end
31
+ end
32
+
33
+ unless File.respond_to?(:read)
34
+ def File.read(fname)
35
+ File.open(fname) {|f|
36
+ return f.read
37
+ }
38
+ end
39
+ end
@@ -1,6 +1,8 @@
1
- #
2
- # config.rb
3
- #
1
+ =begin rdoc
2
+
3
+ = Configuration Class
4
+
5
+ =end
4
6
  #--
5
7
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
6
8
  #
@@ -0,0 +1,67 @@
1
+ =begin rdoc
2
+
3
+ = Ruby on Rails Core Extensions
4
+
5
+ provides .blank?
6
+
7
+ =end
8
+ unless Object.respond_to?(:blank?) #:nodoc:
9
+ # Check first to see if we are in a Rails environment, no need to
10
+ # define these methods if we are
11
+ class Object
12
+ # An object is blank if it's nil, empty, or a whitespace string.
13
+ # For example, "", " ", nil, [], and {} are blank.
14
+ #
15
+ # This simplifies
16
+ # if !address.nil? && !address.empty?
17
+ # to
18
+ # if !address.blank?
19
+ def blank?
20
+ if respond_to?(:empty?) && respond_to?(:strip)
21
+ empty? or strip.empty?
22
+ elsif respond_to?(:empty?)
23
+ empty?
24
+ else
25
+ !self
26
+ end
27
+ end
28
+ end
29
+
30
+ class NilClass #:nodoc:
31
+ def blank?
32
+ true
33
+ end
34
+ end
35
+
36
+ class FalseClass #:nodoc:
37
+ def blank?
38
+ true
39
+ end
40
+ end
41
+
42
+ class TrueClass #:nodoc:
43
+ def blank?
44
+ false
45
+ end
46
+ end
47
+
48
+ class Array #:nodoc:
49
+ alias_method :blank?, :empty?
50
+ end
51
+
52
+ class Hash #:nodoc:
53
+ alias_method :blank?, :empty?
54
+ end
55
+
56
+ class String #:nodoc:
57
+ def blank?
58
+ empty? || strip.empty?
59
+ end
60
+ end
61
+
62
+ class Numeric #:nodoc:
63
+ def blank?
64
+ false
65
+ end
66
+ end
67
+ end
@@ -1,6 +1,8 @@
1
- #
2
- # encode.rb
3
- #
1
+ =begin rdoc
2
+
3
+ = Text Encoding class
4
+
5
+ =end
4
6
  #--
5
7
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
6
8
  #
@@ -50,23 +52,25 @@ module TMail
50
52
  end
51
53
  end
52
54
  module_function :create_dest
53
-
55
+
54
56
  def encoded( eol = "\r\n", charset = 'j', dest = nil )
55
57
  accept_strategy Encoder, eol, charset, dest
56
58
  end
57
-
59
+
58
60
  def decoded( eol = "\n", charset = 'e', dest = nil )
61
+ # Turn the E-Mail into a string and return it with all
62
+ # encoded characters decoded. alias for to_s
59
63
  accept_strategy Decoder, eol, charset, dest
60
64
  end
61
-
65
+
62
66
  alias to_s decoded
63
-
67
+
64
68
  def accept_strategy( klass, eol, charset, dest = nil )
65
69
  dest ||= ''
66
- accept klass.new(create_dest(dest), charset, eol)
70
+ accept klass.new( create_dest(dest), charset, eol )
67
71
  dest
68
72
  end
69
-
73
+
70
74
  end
71
75
 
72
76
 
@@ -141,6 +145,7 @@ module TMail
141
145
  end
142
146
 
143
147
  def kv_pair( k, v )
148
+ v = dquote(v) unless token_safe?(v)
144
149
  @f << k << '=' << v
145
150
  end
146
151
 
@@ -190,9 +195,18 @@ module TMail
190
195
  @f = StrategyInterface.create_dest(dest)
191
196
  @opt = OPTIONS[$KCODE]
192
197
  @eol = eol
198
+ @preserve_quotes = true
193
199
  reset
194
200
  end
195
201
 
202
+ def preserve_quotes=( bool )
203
+ @preserve_quotes
204
+ end
205
+
206
+ def preserve_quotes
207
+ @preserve_quotes
208
+ end
209
+
196
210
  def normalize_encoding( str )
197
211
  if @opt
198
212
  then NKF.nkf(@opt, str)
@@ -1,5 +1,10 @@
1
- #
2
- # header.rb
1
+ =begin rdoc
2
+
3
+ = Header handling class
4
+
5
+ =end
6
+ # RFC #822 ftp://ftp.isi.edu/in-notes/rfc822.txt
7
+ #
3
8
  #
4
9
  #--
5
10
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
@@ -76,6 +81,7 @@ module TMail
76
81
 
77
82
  @illegal = false
78
83
  @parsed = false
84
+
79
85
  if intern
80
86
  @parsed = true
81
87
  parse_init
@@ -129,7 +135,7 @@ module TMail
129
135
 
130
136
  include StrategyInterface
131
137
 
132
- def accept( strategy, dummy1 = nil, dummy2 = nil )
138
+ def accept( strategy )
133
139
  ensure_parsed
134
140
  do_accept strategy
135
141
  strategy.terminate
@@ -207,6 +213,7 @@ module TMail
207
213
  end
208
214
 
209
215
  def do_parse
216
+ quote_boundary
210
217
  obj = Parser.parse(self.class::PARSE_TYPE, @body, @comments)
211
218
  set obj if obj
212
219
  end
@@ -739,12 +746,17 @@ module TMail
739
746
 
740
747
  def params
741
748
  ensure_parsed
749
+ unless @params.blank?
750
+ @params.each do |k, v|
751
+ @params[k] = unquote(v)
752
+ end
753
+ end
742
754
  @params
743
755
  end
744
756
 
745
757
  def []( key )
746
758
  ensure_parsed
747
- @params and @params[key]
759
+ @params and unquote(@params[key])
748
760
  end
749
761
 
750
762
  def []=( key, val )
@@ -835,12 +847,17 @@ module TMail
835
847
 
836
848
  def params
837
849
  ensure_parsed
850
+ unless @params.blank?
851
+ @params.each do |k, v|
852
+ @params[k] = unquote(v)
853
+ end
854
+ end
838
855
  @params
839
856
  end
840
857
 
841
858
  def []( key )
842
859
  ensure_parsed
843
- @params and @params[key]
860
+ @params and unquote(@params[key])
844
861
  end
845
862
 
846
863
  def []=( key, val )
@@ -867,7 +884,7 @@ module TMail
867
884
  @params.each do |k,v|
868
885
  strategy.meta ';'
869
886
  strategy.space
870
- strategy.kv_pair k, v
887
+ strategy.kv_pair k, unquote(v)
871
888
  end
872
889
  end
873
890