lib/roda/plugins/mailer.rb in roda-3.62.0 vs lib/roda/plugins/mailer.rb in roda-3.63.0
- old
+ new
@@ -113,10 +113,15 @@
# You can override the default by specifying a :content_type option when
# loading the plugin:
#
# plugin :mailer, content_type: 'text/html'
#
+ # For backwards compatibility reasons, the +r.mail+ method does not do
+ # a terminal match by default if provided arguments (unlike +r.get+ and
+ # +r.post+). You can pass the :terminal option to make +r.mail+ enforce
+ # a terminal match if provided arguments.
+ #
# The mailer plugin does support being used inside a Roda application
# that is handling web requests, where the routing block for mails and
# web requests is shared. However, it's recommended that you create a
# separate Roda application for emails. This can be a subclass of your main
# Roda application if you want your helper methods to automatically be
@@ -161,11 +166,12 @@
# +mail+ or +sendmail+ methods) and the rest of the arguments match
# the request. This yields any of the captures to the block, as well as
# any arguments passed to the +mail+ or +sendmail+ Roda class methods.
def mail(*args)
if @env["REQUEST_METHOD"] == "MAIL"
- if_match(args) do |*vs|
+ # RODA4: Make terminal match the default
+ send(roda_class.opts[:mailer][:terminal] ? :_verb : :if_match, args) do |*vs|
yield(*(vs + @env['roda.mail_args']))
end
end
end
end
@@ -188,12 +194,12 @@
block.call if block
end
if content_type = header_content_type || roda_class.opts[:mailer][:content_type]
if mail.multipart?
- if mail.content_type =~ /multipart\/mixed/ &&
+ if /multipart\/mixed/ =~ mail.content_type &&
mail.parts.length >= 2 &&
- (part = mail.parts.find{|p| !p.attachment && p.content_type == "text/plain"})
+ (part = mail.parts.find{|p| !p.attachment && (p.encoded; /text\/plain/ =~ p.content_type)})
part.content_type = content_type
end
else
mail.content_type = content_type
end