Module: Roda::RodaPlugins::Mailer::ResponseMethods

Defined in:
lib/roda/plugins/mailer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mailObject

The mail object related to the current request.



181
182
183
# File 'lib/roda/plugins/mailer.rb', line 181

def mail
  @mail
end

Instance Method Details

#finishObject

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.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/roda/plugins/mailer.rb', line 187

def finish
  if m = mail
    header_content_type = @headers.delete(RodaResponseHeaders::CONTENT_TYPE)
    m.headers(@headers)
    m.body(@body.join) unless @body.empty?
    mail_attachments.each do |a, block|
      m.add_file(*a)
      block.call if block
    end

    if content_type = header_content_type || roda_class.opts[:mailer][:content_type]
      if mail.multipart?
        if /multipart\/mixed/ =~ mail.content_type &&
           mail.parts.length >= 2 &&
           (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
    end

    unless m.body.to_s.empty? && m.parts.empty? && @body.empty?
      m
    end
  else
    super
  end
end

#mail_attachmentsObject

The attachments related to the current mail.



218
219
220
# File 'lib/roda/plugins/mailer.rb', line 218

def mail_attachments
  @mail_attachments ||= []
end