Class: Replyr::Email
- Inherits:
-
Object
- Object
- Replyr::Email
- Defined in:
- lib/replyr/email.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#files ⇒ Object
Returns the value of attribute files.
-
#from ⇒ Object
Returns the value of attribute from.
-
#mail ⇒ Object
Returns the value of attribute mail.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#to ⇒ Object
Returns the value of attribute to.
Class Method Summary collapse
Instance Method Summary collapse
- #failed_permanently? ⇒ Boolean
-
#initialize(mail) ⇒ Email
constructor
A new instance of Email.
- #is_bounce_email? ⇒ Boolean
-
#is_reply_email? ⇒ Boolean
Checks if this incoming mail is a reply email.
- #process ⇒ Object
- #stripped_body ⇒ Object
Constructor Details
#initialize(mail) ⇒ Email
Returns a new instance of Email.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/replyr/email.rb', line 5 def initialize(mail) self.mail = 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 files # can later be processed by e.g. carrierwave # self.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
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/replyr/email.rb', line 3 def body @body end |
#files ⇒ Object
Returns the value of attribute files.
3 4 5 |
# File 'lib/replyr/email.rb', line 3 def files @files end |
#from ⇒ Object
Returns the value of attribute from.
3 4 5 |
# File 'lib/replyr/email.rb', line 3 def from @from end |
#mail ⇒ Object
Returns the value of attribute mail.
3 4 5 |
# File 'lib/replyr/email.rb', line 3 def mail @mail end |
#subject ⇒ Object
Returns the value of attribute subject.
3 4 5 |
# File 'lib/replyr/email.rb', line 3 def subject @subject end |
#to ⇒ Object
Returns the value of attribute to.
3 4 5 |
# File 'lib/replyr/email.rb', line 3 def to @to end |
Class Method Details
.process(mail) ⇒ Object
24 25 26 27 |
# File 'lib/replyr/email.rb', line 24 def self.process(mail) reply_mail = new(mail) reply_mail.process end |
Instance Method Details
#failed_permanently? ⇒ Boolean
43 44 45 |
# File 'lib/replyr/email.rb', line 43 def failed_permanently? !mail.retryable? || false end |
#is_bounce_email? ⇒ Boolean
39 40 41 |
# File 'lib/replyr/email.rb', line 39 def is_bounce_email? mail.bounced? || false end |
#is_reply_email? ⇒ Boolean
Checks if this incoming mail is a reply email
31 32 33 |
# File 'lib/replyr/email.rb', line 31 def is_reply_email? to.starts_with?(Replyr.config.reply_prefix) end |
#process ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/replyr/email.rb', line 47 def process if is_bounce_email? if bounce_address = BounceAddress.new_from_address(to) bounce_address.model.handle_bounce(mail.final_recipient) true else false end elsif is_reply_email? if reply_address = ReplyAddress.new_from_address(to) reply_address.model.handle_reply(reply_address.user, stripped_body, files) true else false end end end |
#stripped_body ⇒ Object
35 36 37 |
# File 'lib/replyr/email.rb', line 35 def stripped_body EmailReplyParser.parse_reply(body, from).to_s.force_encoding("UTF-8") end |