Class: Replyr::ReplyEmail
- Inherits:
-
Object
- Object
- Replyr::ReplyEmail
- Defined in:
- lib/replyr/reply_email.rb
Instance Attribute Summary collapse
-
#attached_files ⇒ Object
Returns the value of attribute attached_files.
-
#body ⇒ Object
Returns the value of attribute body.
-
#from ⇒ Object
Returns the value of attribute from.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#to ⇒ Object
Returns the value of attribute to.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mail) ⇒ ReplyEmail
constructor
A new instance of ReplyEmail.
-
#is_reply_email? ⇒ Boolean
Checks if this incoming mail is a reply email.
- #process ⇒ Object
- #stripped_body ⇒ Object
Constructor Details
#initialize(mail) ⇒ ReplyEmail
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/replyr/reply_email.rb', line 5 def initialize(mail) self.to = mail.to.first self.from = mail.from.first self.subject = mail.subject self.body = mail.multipart? ? mail.text_part.decoded : mail.decoded # Extract Attachments and store as StringIO in attached_files # can later be processed by e.g. carrierwave # self.attached_files = mail..map do || file = StringIO.new(.decoded) file.class.class_eval { attr_accessor :original_filename, :content_type } file.original_filename = .filename file.content_type = .mime_type file end end |
Instance Attribute Details
#attached_files ⇒ Object
Returns the value of attribute attached_files.
3 4 5 |
# File 'lib/replyr/reply_email.rb', line 3 def attached_files @attached_files end |
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/replyr/reply_email.rb', line 3 def body @body end |
#from ⇒ Object
Returns the value of attribute from.
3 4 5 |
# File 'lib/replyr/reply_email.rb', line 3 def from @from end |
#subject ⇒ Object
Returns the value of attribute subject.
3 4 5 |
# File 'lib/replyr/reply_email.rb', line 3 def subject @subject end |
#to ⇒ Object
Returns the value of attribute to.
3 4 5 |
# File 'lib/replyr/reply_email.rb', line 3 def to @to end |
Class Method Details
.process(mail) ⇒ Object
23 24 25 26 |
# File 'lib/replyr/reply_email.rb', line 23 def self.process(mail) reply_mail = new(mail) reply_mail.process end |
Instance Method Details
#is_reply_email? ⇒ Boolean
Checks if this incoming mail is a reply email
30 31 32 |
# File 'lib/replyr/reply_email.rb', line 30 def is_reply_email? to.starts_with?(Replyr.config.prefix) end |
#process ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/replyr/reply_email.rb', line 38 def process if is_reply_email? if reply_address = ReplyAddress.new_from_address(to) reply_address.model.class.handle_reply(reply_token, stripped_body, attached_files) else # no valid reply_address end end end |
#stripped_body ⇒ Object
34 35 36 |
# File 'lib/replyr/reply_email.rb', line 34 def stripped_body EmailReplyParser.parse_reply(body, from).to_s.force_encoding("UTF-8") end |