Class: BlabberMouth::Adapters::Tmail
- Defined in:
- lib/blabber_mouth/adapters/tmail.rb
Overview
Converts a BlabberMouth object into a TMail object.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#convert ⇒ Object
Converts the BlabberMouth object to a TMail object.
-
#deliverable ⇒ Object
Returns the ready to be delivered encoded String.
-
#transformed ⇒ Object
Returns the underlying TMail object.
Methods inherited from Base
Constructor Details
This class inherits a constructor from BlabberMouth::Adapters::Base
Instance Method Details
#convert ⇒ Object
Converts the BlabberMouth object to a TMail object.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/blabber_mouth/adapters/tmail.rb', line 23 def convert @tmail = TMail::Mail.new @tmail.to = bm_notifier.to @tmail.cc = bm_notifier.cc @tmail.bcc = bm_notifier.bcc @tmail.reply_to = bm_notifier.reply_to @tmail.from = bm_notifier.from @tmail.subject = bm_notifier.subject @tmail.date = bm_notifier.date_sent @tmail.mime_version = bm_notifier.mime_version # set text and html bodies main_body = TMail::Mail.new unless bm_notifier.body(:plain).blank? text = TMail::Mail.new text.content_type = "text/plain" text.body = bm_notifier.body(:plain) main_body.parts << text end unless bm_notifier.body(:html).blank? html = TMail::Mail.new html.content_type = "text/html" html.body = bm_notifier.body(:html) main_body.parts << html end unless main_body.parts.empty? main_body.content_type = "multipart/alternative" if bm_notifier..any? # there's an attachment @tmail.parts << main_body else if main_body.parts.size == 1 @tmail.body = main_body.parts.first.body else @tmail.parts << main_body end end end # set attachments, if any. bm_notifier..each do |at| = TMail::Mail.new .body = Base64.encode64(at.body) .transfer_encoding = "Base64" .content_type = "application/octet-stream" ['Content-Disposition'] = "attachment; filename=#{at.file_name}" @tmail.parts << end @tmail.content_type = bm_notifier.content_type end |
#deliverable ⇒ Object
Returns the ready to be delivered encoded String
18 19 20 |
# File 'lib/blabber_mouth/adapters/tmail.rb', line 18 def deliverable transformed.encoded end |
#transformed ⇒ Object
Returns the underlying TMail object. Raises BlabberMouth::Errors::UnconvertedNotifier if the convert method hasn't been called first.
12 13 14 15 |
# File 'lib/blabber_mouth/adapters/tmail.rb', line 12 def transformed raise BlabberMouth::Errors::UnconvertedNotifier.new if @tmail.nil? @tmail end |