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

The attachments related to the current mail.

[show source]
    # File lib/roda/plugins/mailer.rb
218 def mail_attachments
219   @mail_attachments ||= []
220 end