Class: DraftBox::DeliveryMethod
- Inherits:
-
Object
- Object
- DraftBox::DeliveryMethod
- Defined in:
- lib/draft_box/delivery_method.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(options = {}) ⇒ DeliveryMethod
constructor
A new instance of DeliveryMethod.
Constructor Details
#initialize(options = {}) ⇒ DeliveryMethod
Returns a new instance of DeliveryMethod.
5 6 7 |
# File 'lib/draft_box/delivery_method.rb', line 5 def initialize( = {}) self.settings = end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
3 4 5 |
# File 'lib/draft_box/delivery_method.rb', line 3 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/draft_box/delivery_method.rb', line 9 def deliver!(mail) validate_mail!(mail) # subject: mail.subject # body: mail.body.to_s # from: mail.from # to: mail.to # cc: mail.cc # bcc: mail.bcc # attachments: mail.attachments # Attachment: # filename: attachment.filename # content_type: attachment.content_type # content: attachment.body.to_s ActiveRecord::Base.transaction do email = DraftBox::Email.create!( subject: mail.subject, body: mail.parts.empty? ? mail.body.to_s : mail.parts.find { |p| p.content_type.start_with?('text/html', 'text/plain') }&.body.to_s, from: mail.from.first, to: mail.to, cc: mail.cc, bcc: mail.bcc ) mail..each do || email..create!( filename: .filename, content_type: .content_type, data: .body.to_s ) end end end |