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

The attachments related to the current mail.

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