module Roda::RodaPlugins::Mailer::ResponseMethods

  1. lib/roda/plugins/mailer.rb

Methods

Public Instance

  1. finish
  2. mail
  3. mail_attachments

Attributes

mail [RW]

The mail object related to the current request.

Public Instance methods

finish()

If the related request was an email request, add any response headers to the email, as well as adding the response body to the email. Return the email unless no body was set for it, which would indicate that the routing tree did not handle the request.

[show source]
    # File lib/roda/plugins/mailer.rb
193 def finish
194   if m = mail
195     header_content_type = @headers.delete(RodaResponseHeaders::CONTENT_TYPE)
196     m.headers(@headers)
197     m.body(@body.join) unless @body.empty?
198     mail_attachments.each do |a, block|
199       m.add_file(*a)
200       block.call if block
201     end
202 
203     if content_type = header_content_type || roda_class.opts[:mailer][:content_type]
204       if mail.multipart?
205         if /multipart\/mixed/ =~ mail.content_type &&
206            mail.parts.length >= 2 &&
207            (part = mail.parts.find{|p| !p.attachment && (p.encoded; /text\/plain/ =~ p.content_type)})
208           part.content_type = content_type
209         end
210       else
211         mail.content_type = content_type
212       end
213     end
214 
215     unless m.body.to_s.empty? && m.parts.empty? && @body.empty?
216       m
217     end
218   else
219     super
220   end
221 end
mail_attachments()

The attachments related to the current mail.

[show source]
    # File lib/roda/plugins/mailer.rb
224 def mail_attachments
225   @mail_attachments ||= []
226 end