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
@@ -0,0 +1,36 @@
1
+ require 'abstract_controller/collector'
2
+ require 'active_support/core_ext/hash/reverse_merge'
3
+ require 'active_support/core_ext/array/extract_options'
4
+
5
+ module ActionMailer #:nodoc:
6
+ class Collector
7
+ include AbstractController::Collector
8
+ attr_reader :responses
9
+
10
+ def initialize(context, &block)
11
+ @context = context
12
+ @responses = []
13
+ @default_render = block
14
+ @default_formats = context.formats
15
+ end
16
+
17
+ def any(*args, &block)
18
+ options = args.extract_options!
19
+ raise "You have to supply at least one format" if args.empty?
20
+ args.each { |type| send(type, options.dup, &block) }
21
+ end
22
+ alias :all :any
23
+
24
+ def custom(mime, options={}, &block)
25
+ options.reverse_merge!(:content_type => mime.to_s)
26
+ @context.formats = [mime.to_sym]
27
+ options[:body] = if block
28
+ block.call
29
+ else
30
+ @default_render.call
31
+ end
32
+ @responses << options
33
+ @context.formats = @default_formats
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,86 @@
1
+ require 'tmpdir'
2
+
3
+ module ActionMailer
4
+ # This modules handles everything related to the delivery, from registering new
5
+ # delivery methods to configuring the mail object to be sent.
6
+ module DeliveryMethods
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ class_attribute :delivery_methods, :delivery_method
11
+
12
+ # Do not make this inheritable, because we always want it to propagate
13
+ cattr_accessor :raise_delivery_errors
14
+ self.raise_delivery_errors = true
15
+
16
+ cattr_accessor :perform_deliveries
17
+ self.perform_deliveries = true
18
+
19
+ self.delivery_methods = {}.freeze
20
+ self.delivery_method = :smtp
21
+
22
+ add_delivery_method :smtp, Mail::SMTP,
23
+ :address => "localhost",
24
+ :port => 25,
25
+ :domain => 'localhost.localdomain',
26
+ :user_name => nil,
27
+ :password => nil,
28
+ :authentication => nil,
29
+ :enable_starttls_auto => true
30
+
31
+ add_delivery_method :file, Mail::FileDelivery,
32
+ :location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
33
+
34
+ add_delivery_method :sendmail, Mail::Sendmail,
35
+ :location => '/usr/sbin/sendmail',
36
+ :arguments => '-i -t'
37
+
38
+ add_delivery_method :test, Mail::TestMailer
39
+ end
40
+
41
+ module ClassMethods
42
+ # Provides a list of emails that have been delivered by Mail::TestMailer
43
+ delegate :deliveries, :deliveries=, :to => Mail::TestMailer
44
+
45
+ # Adds a new delivery method through the given class using the given symbol
46
+ # as alias and the default options supplied:
47
+ #
48
+ # Example:
49
+ #
50
+ # add_delivery_method :sendmail, Mail::Sendmail,
51
+ # :location => '/usr/sbin/sendmail',
52
+ # :arguments => '-i -t'
53
+ #
54
+ def add_delivery_method(symbol, klass, default_options={})
55
+ class_attribute(:"#{symbol}_settings") unless respond_to?(:"#{symbol}_settings")
56
+ send(:"#{symbol}_settings=", default_options)
57
+ self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze
58
+ end
59
+
60
+ def wrap_delivery_behavior(mail, method=nil) #:nodoc:
61
+ method ||= self.delivery_method
62
+ mail.delivery_handler = self
63
+
64
+ case method
65
+ when NilClass
66
+ raise "Delivery method cannot be nil"
67
+ when Symbol
68
+ if klass = delivery_methods[method.to_sym]
69
+ mail.delivery_method(klass, send(:"#{method}_settings"))
70
+ else
71
+ raise "Invalid delivery method #{method.inspect}"
72
+ end
73
+ else
74
+ mail.delivery_method(method)
75
+ end
76
+
77
+ mail.perform_deliveries = perform_deliveries
78
+ mail.raise_delivery_errors = raise_delivery_errors
79
+ end
80
+ end
81
+
82
+ def wrap_delivery_behavior!(*args) #:nodoc:
83
+ self.class.wrap_delivery_behavior(message, *args)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,139 @@
1
+ module ActionMailer
2
+ # This is the API which is deprecated and is going to be removed on Rails 3.1 release.
3
+ # Part of the old API will be deprecated after 3.1, for a smoother deprecation process.
4
+ # Chech those in OldApi instead.
5
+ module DeprecatedApi #:nodoc:
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ [:charset, :content_type, :mime_version, :implicit_parts_order].each do |method|
10
+ class_eval <<-FILE, __FILE__, __LINE__ + 1
11
+ def self.default_#{method}
12
+ @@default_#{method}
13
+ end
14
+
15
+ def self.default_#{method}=(value)
16
+ ActiveSupport::Deprecation.warn "ActionMailer::Base.default_#{method}=value is deprecated, " <<
17
+ "use default :#{method} => value instead"
18
+ @@default_#{method} = value
19
+ end
20
+
21
+ @@default_#{method} = nil
22
+ FILE
23
+ end
24
+ end
25
+
26
+ module ClassMethods
27
+ # Deliver the given mail object directly. This can be used to deliver
28
+ # a preconstructed mail object, like:
29
+ #
30
+ # email = MyMailer.create_some_mail(parameters)
31
+ # email.set_some_obscure_header "frobnicate"
32
+ # MyMailer.deliver(email)
33
+ def deliver(mail, show_warning=true)
34
+ if show_warning
35
+ ActiveSupport::Deprecation.warn "#{self}.deliver is deprecated, call " <<
36
+ "deliver in the mailer instance instead", caller[0,2]
37
+ end
38
+
39
+ raise "no mail object available for delivery!" unless mail
40
+ wrap_delivery_behavior(mail)
41
+ mail.deliver
42
+ mail
43
+ end
44
+
45
+ def template_root
46
+ self.view_paths && self.view_paths.first
47
+ end
48
+
49
+ def template_root=(root)
50
+ ActiveSupport::Deprecation.warn "template_root= is deprecated, use prepend_view_path instead", caller[0,2]
51
+ self.view_paths = ActionView::Base.process_view_paths(root)
52
+ end
53
+
54
+ def respond_to?(method_symbol, include_private = false)
55
+ matches_dynamic_method?(method_symbol) || super
56
+ end
57
+
58
+ def method_missing(method_symbol, *parameters)
59
+ if match = matches_dynamic_method?(method_symbol)
60
+ case match[1]
61
+ when 'create'
62
+ ActiveSupport::Deprecation.warn "#{self}.create_#{match[2]} is deprecated, " <<
63
+ "use #{self}.#{match[2]} instead", caller[0,2]
64
+ new(match[2], *parameters).message
65
+ when 'deliver'
66
+ ActiveSupport::Deprecation.warn "#{self}.deliver_#{match[2]} is deprecated, " <<
67
+ "use #{self}.#{match[2]}.deliver instead", caller[0,2]
68
+ new(match[2], *parameters).message.deliver
69
+ else super
70
+ end
71
+ else
72
+ super
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def matches_dynamic_method?(method_name)
79
+ method_name = method_name.to_s
80
+ /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
81
+ end
82
+ end
83
+
84
+ # Delivers a Mail object. By default, it delivers the cached mail
85
+ # object (from the <tt>create!</tt> method). If no cached mail object exists, and
86
+ # no alternate has been given as the parameter, this will fail.
87
+ def deliver!(mail = @_message)
88
+ ActiveSupport::Deprecation.warn "Calling deliver in the AM::Base object is deprecated, " <<
89
+ "please call deliver in the Mail instance", caller[0,2]
90
+ self.class.deliver(mail, false)
91
+ end
92
+ alias :deliver :deliver!
93
+
94
+ def render(*args)
95
+ options = args.last.is_a?(Hash) ? args.last : {}
96
+
97
+ if options[:body].is_a?(Hash)
98
+ ActiveSupport::Deprecation.warn(':body in render deprecated. Please use instance ' <<
99
+ 'variables as assigns instead', caller[0,1])
100
+
101
+ options[:body].each { |k,v| instance_variable_set(:"@#{k}", v) }
102
+ end
103
+ super
104
+ end
105
+
106
+ # Render a message but does not set it as mail body. Useful for rendering
107
+ # data for part and attachments.
108
+ #
109
+ # Examples:
110
+ #
111
+ # render_message "special_message"
112
+ # render_message :template => "special_message"
113
+ # render_message :inline => "<%= 'Hi!' %>"
114
+ #
115
+ def render_message(*args)
116
+ ActiveSupport::Deprecation.warn "render_message is deprecated, use render instead", caller[0,2]
117
+ render(*args)
118
+ end
119
+
120
+ private
121
+
122
+ def initialize_defaults(*)
123
+ @charset ||= self.class.default_charset.try(:dup)
124
+ @content_type ||= self.class.default_content_type.try(:dup)
125
+ @implicit_parts_order ||= self.class.default_implicit_parts_order.try(:dup)
126
+ @mime_version ||= self.class.default_mime_version.try(:dup)
127
+ super
128
+ end
129
+
130
+ def create_parts
131
+ if @body.is_a?(Hash) && !@body.empty?
132
+ ActiveSupport::Deprecation.warn "Giving a hash to body is deprecated, please use instance variables instead", caller[0,2]
133
+ @body.each { |k, v| instance_variable_set(:"@#{k}", v) }
134
+ end
135
+ super
136
+ end
137
+
138
+ end
139
+ end
@@ -1,17 +1,29 @@
1
- module MailHelper
2
- # Uses Text::Format to take the text and format it, indented two spaces for
3
- # each line, and wrapped at 72 columns.
4
- def block_format(text)
5
- formatted = text.split(/\n\r\n/).collect { |paragraph|
6
- Text::Format.new(
7
- :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
8
- ).format
9
- }.join("\n")
1
+ module ActionMailer
2
+ module MailHelper
3
+ # Uses Text::Format to take the text and format it, indented two spaces for
4
+ # each line, and wrapped at 72 columns.
5
+ def block_format(text)
6
+ formatted = text.split(/\n\r\n/).collect { |paragraph|
7
+ Text::Format.new(
8
+ :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
9
+ ).format
10
+ }.join("\n")
10
11
 
11
- # Make list points stand on their own line
12
- formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
13
- formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
12
+ # Make list points stand on their own line
13
+ formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
14
+ formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
15
+
16
+ formatted
17
+ end
14
18
 
15
- formatted
19
+ # Access the mailer instance.
20
+ def mailer
21
+ @_controller
22
+ end
23
+
24
+ # Access the message instance.
25
+ def message
26
+ @_message
27
+ end
16
28
  end
17
29
  end
@@ -0,0 +1,248 @@
1
+ require 'active_support/core_ext/object/try'
2
+
3
+ module ActionMailer
4
+ module OldApi #:nodoc:
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ extend ActionMailer::AdvAttrAccessor
9
+
10
+ @@protected_instance_variables = %w(@parts)
11
+ cattr_reader :protected_instance_variables
12
+
13
+ # Specify the BCC addresses for the message
14
+ adv_attr_accessor :bcc
15
+
16
+ # Specify the CC addresses for the message.
17
+ adv_attr_accessor :cc
18
+
19
+ # Specify the charset to use for the message. This defaults to the
20
+ # +default_charset+ specified for ActionMailer::Base.
21
+ adv_attr_accessor :charset
22
+
23
+ # Specify the content type for the message. This defaults to <tt>text/plain</tt>
24
+ # in most cases, but can be automatically set in some situations.
25
+ adv_attr_accessor :content_type
26
+
27
+ # Specify the from address for the message.
28
+ adv_attr_accessor :from
29
+
30
+ # Specify the address (if different than the "from" address) to direct
31
+ # replies to this message.
32
+ adv_attr_accessor :reply_to
33
+
34
+ # Specify additional headers to be added to the message.
35
+ adv_attr_accessor :headers
36
+
37
+ # Specify the order in which parts should be sorted, based on content-type.
38
+ # This defaults to the value for the +default_implicit_parts_order+.
39
+ adv_attr_accessor :implicit_parts_order
40
+
41
+ # Defaults to "1.0", but may be explicitly given if needed.
42
+ adv_attr_accessor :mime_version
43
+
44
+ # The recipient addresses for the message, either as a string (for a single
45
+ # address) or an array (for multiple addresses).
46
+ adv_attr_accessor :recipients
47
+
48
+ # The date on which the message was sent. If not set (the default), the
49
+ # header will be set by the delivery agent.
50
+ adv_attr_accessor :sent_on
51
+
52
+ # Specify the subject of the message.
53
+ adv_attr_accessor :subject
54
+
55
+ # Specify the template name to use for current message. This is the "base"
56
+ # template name, without the extension or directory, and may be used to
57
+ # have multiple mailer methods share the same template.
58
+ adv_attr_accessor :template
59
+
60
+ # Override the mailer name, which defaults to an inflected version of the
61
+ # mailer's class name. If you want to use a template in a non-standard
62
+ # location, you can use this to specify that location.
63
+ adv_attr_accessor :mailer_name
64
+
65
+ # Define the body of the message. This is either a Hash (in which case it
66
+ # specifies the variables to pass to the template when it is rendered),
67
+ # or a string, in which case it specifies the actual text of the message.
68
+ adv_attr_accessor :body
69
+
70
+ # Alias controller_path to mailer_name so render :partial in views work.
71
+ alias :controller_path :mailer_name
72
+ end
73
+
74
+ def process(method_name, *args)
75
+ initialize_defaults(method_name)
76
+ super
77
+ unless @mail_was_called
78
+ create_parts
79
+ create_mail
80
+ end
81
+ @_message
82
+ end
83
+
84
+ # Add a part to a multipart message, with the given content-type. The
85
+ # part itself is yielded to the block so that other properties (charset,
86
+ # body, headers, etc.) can be set on it.
87
+ def part(params)
88
+ params = {:content_type => params} if String === params
89
+
90
+ if custom_headers = params.delete(:headers)
91
+ params.merge!(custom_headers)
92
+ end
93
+
94
+ part = Mail::Part.new(params)
95
+
96
+ yield part if block_given?
97
+ @parts << part
98
+ end
99
+
100
+ # Add an attachment to a multipart message. This is simply a part with the
101
+ # content-disposition set to "attachment".
102
+ def attachment(params, &block)
103
+ params = { :content_type => params } if String === params
104
+
105
+ params[:content] ||= params.delete(:data) || params.delete(:body)
106
+
107
+ if params[:filename]
108
+ params = normalize_file_hash(params)
109
+ else
110
+ params = normalize_nonfile_hash(params)
111
+ end
112
+
113
+ part(params, &block)
114
+ end
115
+
116
+ protected
117
+
118
+ def normalize_nonfile_hash(params)
119
+ content_disposition = "attachment;"
120
+
121
+ mime_type = params.delete(:mime_type)
122
+
123
+ if content_type = params.delete(:content_type)
124
+ content_type = "#{mime_type || content_type};"
125
+ end
126
+
127
+ params[:body] = params.delete(:data) if params[:data]
128
+
129
+ { :content_type => content_type,
130
+ :content_disposition => content_disposition }.merge(params)
131
+ end
132
+
133
+ def normalize_file_hash(params)
134
+ filename = File.basename(params.delete(:filename))
135
+ content_disposition = "attachment; filename=\"#{File.basename(filename)}\""
136
+
137
+ mime_type = params.delete(:mime_type)
138
+
139
+ if (content_type = params.delete(:content_type)) && (content_type !~ /filename=/)
140
+ content_type = "#{mime_type || content_type}; filename=\"#{filename}\""
141
+ end
142
+
143
+ params[:body] = params.delete(:data) if params[:data]
144
+
145
+ { :content_type => content_type,
146
+ :content_disposition => content_disposition }.merge(params)
147
+ end
148
+
149
+ def create_mail
150
+ m = @_message
151
+
152
+ quote_fields!({:subject => subject, :to => recipients, :from => from,
153
+ :bcc => bcc, :cc => cc, :reply_to => reply_to}, charset)
154
+
155
+ m.mime_version = mime_version unless mime_version.nil?
156
+ m.date = sent_on.to_time rescue sent_on if sent_on
157
+
158
+ @headers.each { |k, v| m[k] = v }
159
+
160
+ real_content_type, ctype_attrs = parse_content_type
161
+ main_type, sub_type = split_content_type(real_content_type)
162
+
163
+ if @parts.size == 1 && @parts.first.parts.empty?
164
+ m.content_type([main_type, sub_type, ctype_attrs])
165
+ m.body = @parts.first.body.encoded
166
+ else
167
+ @parts.each do |p|
168
+ m.add_part(p)
169
+ end
170
+
171
+ m.body.set_sort_order(@implicit_parts_order)
172
+ m.body.sort_parts!
173
+
174
+ if real_content_type =~ /multipart/
175
+ ctype_attrs.delete "charset"
176
+ m.content_type([main_type, sub_type, ctype_attrs])
177
+ end
178
+ end
179
+
180
+ wrap_delivery_behavior!
181
+ m.content_transfer_encoding = '8bit' unless m.body.only_us_ascii?
182
+
183
+ @_message
184
+ end
185
+
186
+ # Set up the default values for the various instance variables of this
187
+ # mailer. Subclasses may override this method to provide different
188
+ # defaults.
189
+ def initialize_defaults(method_name)
190
+ @charset ||= self.class.default[:charset].try(:dup)
191
+ @content_type ||= self.class.default[:content_type].try(:dup)
192
+ @implicit_parts_order ||= self.class.default[:parts_order].try(:dup)
193
+ @mime_version ||= self.class.default[:mime_version].try(:dup)
194
+
195
+ @mailer_name ||= self.class.mailer_name.dup
196
+ @template ||= method_name
197
+ @mail_was_called = false
198
+
199
+ @parts ||= []
200
+ @headers ||= {}
201
+ @sent_on ||= Time.now
202
+ @body ||= {}
203
+ end
204
+
205
+ def create_parts
206
+ if String === @body
207
+ @parts.unshift create_inline_part(@body)
208
+ elsif @parts.empty? || @parts.all? { |p| p.content_disposition =~ /^attachment/ }
209
+ self.class.view_paths.first.find_all(@template, {}, @mailer_name).each do |template|
210
+ @parts << create_inline_part(render_to_body(:_template => template), template.mime_type)
211
+ end
212
+
213
+ if @parts.size > 1
214
+ @content_type = "multipart/alternative" if @content_type !~ /^multipart/
215
+ end
216
+
217
+ # If this is a multipart e-mail add the mime_version if it is not
218
+ # already set.
219
+ @mime_version ||= "1.0" if !@parts.empty?
220
+ end
221
+ end
222
+
223
+ def create_inline_part(body, mime_type=nil)
224
+ ct = mime_type || "text/plain"
225
+ main_type, sub_type = split_content_type(ct.to_s)
226
+
227
+ Mail::Part.new(
228
+ :content_type => [main_type, sub_type, {:charset => charset}],
229
+ :content_disposition => "inline",
230
+ :body => body
231
+ )
232
+ end
233
+
234
+ def split_content_type(ct)
235
+ ct.to_s.split("/")
236
+ end
237
+
238
+ def parse_content_type(defaults=nil)
239
+ if @content_type.blank?
240
+ [ nil, {} ]
241
+ else
242
+ ctype, *attrs = @content_type.split(/;\s*/)
243
+ attrs = attrs.inject({}) { |h,s| k,v = s.split(/\=/, 2); h[k] = v; h }
244
+ [ctype, {"charset" => @charset}.merge(attrs)]
245
+ end
246
+ end
247
+ end
248
+ end
@@ -1,6 +1,8 @@
1
- # encoding: us-ascii
2
1
  module ActionMailer
3
2
  module Quoting #:nodoc:
3
+ # TODO extract this into Mail itself.
4
+ #
5
+ #
4
6
  # Convert the given text into quoted printable format, with an instruction
5
7
  # that the text be eventually interpreted in the given charset.
6
8
  def quoted_printable(text, charset)
@@ -44,7 +46,7 @@ module ActionMailer
44
46
  # "to", "from", "cc", "bcc" and "reply-to" headers.
45
47
  def quote_address_if_necessary(address, charset)
46
48
  if Array === address
47
- address.map { |a| quote_address_if_necessary(a, charset) }
49
+ address.map { |a| quote_address_if_necessary(a, charset) }.join(", ")
48
50
  elsif address =~ /^(\S.*)\s+(<.*>)$/
49
51
  address = $2
50
52
  phrase = quote_if_necessary($1.gsub(/^['"](.*)['"]$/, '\1'), charset)
@@ -0,0 +1,25 @@
1
+ require "action_mailer"
2
+ require "rails"
3
+
4
+ module ActionMailer
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :action_mailer
7
+
8
+ require "action_mailer/railties/subscriber"
9
+ subscriber ActionMailer::Railties::Subscriber.new
10
+
11
+ initializer "action_mailer.logger" do
12
+ ActionMailer::Base.logger ||= Rails.logger
13
+ end
14
+
15
+ initializer "action_mailer.set_configs" do |app|
16
+ app.config.action_mailer.each do |k,v|
17
+ ActionMailer::Base.send "#{k}=", v
18
+ end
19
+ end
20
+
21
+ initializer "action_mailer.url_for" do |app|
22
+ ActionMailer::Base.send(:include, ActionController::UrlFor) if defined?(ActionController)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module ActionMailer
2
+ module Railties
3
+ class Subscriber < Rails::Subscriber
4
+ def deliver(event)
5
+ recipients = Array(event.payload[:to]).join(', ')
6
+ info("\nSent mail to #{recipients} (%1.fms)" % event.duration)
7
+ debug(event.payload[:mail])
8
+ end
9
+
10
+ def receive(event)
11
+ info("\nReceived mail (%.1fms)" % event.duration)
12
+ debug(event.payload[:mail])
13
+ end
14
+
15
+ def logger
16
+ ActionMailer::Base.logger
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,3 @@
1
- require 'active_support/test_case'
2
-
3
1
  module ActionMailer
4
2
  class NonInferrableMailerError < ::StandardError
5
3
  def initialize(name)
@@ -39,12 +37,12 @@ module ActionMailer
39
37
  def initialize_test_deliveries
40
38
  ActionMailer::Base.delivery_method = :test
41
39
  ActionMailer::Base.perform_deliveries = true
42
- ActionMailer::Base.deliveries = []
40
+ ActionMailer::Base.deliveries.clear
43
41
  end
44
42
 
45
43
  def set_expected_mail
46
- @expected = TMail::Mail.new
47
- @expected.set_content_type "text", "plain", { "charset" => charset }
44
+ @expected = Mail.new
45
+ @expected.content_type ["text", "plain", { "charset" => charset }]
48
46
  @expected.mime_version = '1.0'
49
47
  end
50
48
 
@@ -58,7 +56,7 @@ module ActionMailer
58
56
  end
59
57
 
60
58
  def read_fixture(action)
61
- IO.readlines(File.join(RAILS_ROOT, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
59
+ IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
62
60
  end
63
61
  end
64
62
  end
@@ -58,7 +58,6 @@ module ActionMailer
58
58
  end
59
59
  end
60
60
 
61
- # TODO: Deprecate this
62
61
  module Test
63
62
  module Unit
64
63
  class TestCase
@@ -0,0 +1,34 @@
1
+ module Mail
2
+ class Message
3
+
4
+ def set_content_type(*args)
5
+ ActiveSupport::Deprecation.warn('Message#set_content_type is deprecated, please just call ' <<
6
+ 'Message#content_type with the same arguments', caller[0,2])
7
+ content_type(*args)
8
+ end
9
+
10
+ alias :old_transfer_encoding :transfer_encoding
11
+ def transfer_encoding(value = nil)
12
+ if value
13
+ ActiveSupport::Deprecation.warn('Message#transfer_encoding is deprecated, please call ' <<
14
+ 'Message#content_transfer_encoding with the same arguments', caller[0,2])
15
+ content_transfer_encoding(value)
16
+ else
17
+ old_transfer_encoding
18
+ end
19
+ end
20
+
21
+ def transfer_encoding=(value)
22
+ ActiveSupport::Deprecation.warn('Message#transfer_encoding= is deprecated, please call ' <<
23
+ 'Message#content_transfer_encoding= with the same arguments', caller[0,2])
24
+ self.content_transfer_encoding = value
25
+ end
26
+
27
+ def original_filename
28
+ ActiveSupport::Deprecation.warn('Message#original_filename is deprecated, ' <<
29
+ 'please call Message#filename', caller[0,2])
30
+ filename
31
+ end
32
+
33
+ end
34
+ end