Class Mack::Notifier::Adapters::Tmail
In: lib/mack-notifier/adapters/tmail.rb
Parent: Mack::Notifier::Adapters::Base

Converts a Mack::Notifier object into a TMail object.

Methods

Public Instance methods

Converts the Mack::Notifier object to a TMail object.

[Source]

    # File lib/mack-notifier/adapters/tmail.rb, line 23
23:         def convert
24:           @tmail = TMail::Mail.new 
25:           @tmail.to =           mack_notifier.to
26:           @tmail.cc =           mack_notifier.cc
27:           @tmail.bcc =          mack_notifier.bcc
28:           @tmail.reply_to =     mack_notifier.reply_to
29:           @tmail.from =         mack_notifier.from
30:           @tmail.subject =      mack_notifier.subject
31:           @tmail.date =         mack_notifier.date_sent
32:           @tmail.mime_version = mack_notifier.mime_version
33: 
34:           # set text and html bodies
35:           main_body = TMail::Mail.new
36:           unless mack_notifier.body(:plain).blank?
37:             text = TMail::Mail.new
38:             text.content_type = "text/plain"
39:             text.body = mack_notifier.body(:plain)
40:             main_body.parts << text
41:           end
42:           unless mack_notifier.body(:html).blank?
43:             html = TMail::Mail.new
44:             html.content_type = "text/html"
45:             html.body = mack_notifier.body(:html)
46:             main_body.parts << html
47:           end
48: 
49:           unless main_body.parts.empty?
50:             main_body.content_type = "multipart/alternative"
51:             if mack_notifier.attachments.any? # there's an attachment
52:               @tmail.parts << main_body
53:             else
54:               if main_body.parts.size == 1
55:                 @tmail.body = main_body.parts.first.body
56:               else
57:                 @tmail.parts << main_body
58:               end
59:             end
60:           end
61: 
62:           # set attachments, if any.
63:           mack_notifier.attachments.each do |at|
64:             attachment = TMail::Mail.new
65:             attachment.body = Base64.encode64(at.body)
66:             attachment.transfer_encoding = "Base64"
67:             attachment.content_type = "application/octet-stream"
68:             attachment['Content-Disposition'] = "attachment; filename=#{at.file_name}"
69:             @tmail.parts << attachment
70:           end
71:           
72:           @tmail.content_type = mack_notifier.content_type
73:         end

Returns the ready to be delivered encoded String

[Source]

    # File lib/mack-notifier/adapters/tmail.rb, line 18
18:         def deliverable
19:           transformed.encoded
20:         end

Returns the underlying TMail object. Raises Mack::Errors::UnconvertedNotifier if the convert method hasn‘t been called first.

[Source]

    # File lib/mack-notifier/adapters/tmail.rb, line 12
12:         def transformed
13:           raise Mack::Errors::UnconvertedNotifier.new if @tmail.nil?
14:           @tmail
15:         end

[Validate]