Class: Office::EmailMessage
- Inherits:
-
Object
- Object
- Office::EmailMessage
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/office/email_message.rb
Overview
When I receive one.
Instance Method Summary collapse
-
#add_tag(tag) ⇒ Object
Tested manually ok, does not pass the spec.
-
#apply_filter(filter) ⇒ Object
@TODO: move to email_conversation vp 2023-03-24.
- #company_url ⇒ Object
- #conv ⇒ Object
- #lead ⇒ Object
-
#name ⇒ Object
@TODO: reimplement.
-
#object_key ⇒ Object
aka ‘filename’, use with bucket name + prefix.
- #preview_str ⇒ Object
- #received_at ⇒ Object
- #remove_tag(tag) ⇒ Object
- #rmtag(tag) ⇒ Object
-
#wp_term_ids ⇒ Object
Copied to email_conversation.
Instance Method Details
#add_tag(tag) ⇒ Object
Tested manually ok, does not pass the spec. @TODO: hire to make pass spec? vp 2023-03-07
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/office/email_message.rb', line 51 def add_tag tag case tag.class.name when 'WpTag' ; when 'String' tag = WpTag.emailtag(tag) else throw "#add_tag2 expects a WpTag or string (eg WpTag::INBOX) as the only parameter." end self[:wp_term_ids] = ( [ tag.id ] + self[:wp_term_ids] ).uniq self.save! end |
#apply_filter(filter) ⇒ Object
@TODO: move to email_conversation vp 2023-03-24
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/office/email_message.rb', line 94 def apply_filter filter case filter.kind when ::Office::EmailFilter::KIND_DESTROY_SCHS self.conv.add_tag( ::WpTag::TRASH ) self.conv.remove_tag( ::WpTag::INBOX ) tmp_lead = ::Lead.where( email: self.part_txt.split("\n")[1] ).first if tmp_lead tmp_lead.schs.each { |sch| sch.update_attributes({ state: ::Sch::STATE_TRASH }) } end when ::Office::EmailFilter::KIND_ADD_TAG self.conv.add_tag( filter.wp_term_id ) if ::WpTag::TRASH == ::WpTag.find( filter.wp_term_id ).slug self.conv.remove_tag(::WpTag::INBOX ) end when ::Office::EmailFilter::KIND_REMOVE_TAG self.conv.remove_tag( filter.wp_term_id ) when ::Office::EmailFilter::KIND_AUTORESPOND_TMPL Ish::EmailContext.create({ email_template: filter.email_template, lead_id: lead.id, send_at: Time.now + 22.minutes, }) when ::Office::EmailFilter::KIND_AUTORESPOND_EACT ::Sch.create({ email_action: filter.email_action, state: ::Sch::STATE_ACTIVE, lead_id: lead.id, perform_at: Time.now + 22.minutes, }) else raise "unknown filter kind: #{filter.kind}" end end |
#company_url ⇒ Object
89 90 91 |
# File 'lib/office/email_message.rb', line 89 def company_url from[0].split('@')[1] end |
#conv ⇒ Object
79 80 81 |
# File 'lib/office/email_message.rb', line 79 def conv email_conversation end |
#lead ⇒ Object
31 32 33 |
# File 'lib/office/email_message.rb', line 31 def lead Lead.find_by email: from end |
#name ⇒ Object
@TODO: reimplement
84 85 86 87 |
# File 'lib/office/email_message.rb', line 84 def name return 'associate' # from[0].split('@')[0].upcase end |
#object_key ⇒ Object
aka ‘filename’, use with bucket name + prefix
19 |
# File 'lib/office/email_message.rb', line 19 field :object_key, type: :string |
#preview_str ⇒ Object
134 135 136 137 138 139 |
# File 'lib/office/email_message.rb', line 134 def preview_str body = part_html || part_html || 'Neither part_html nor part_txt!' body = ::ActionView::Base.full_sanitizer.sanitize( body ).gsub(/\s+/, ' ') body = body[0..200] body end |
#received_at ⇒ Object
43 44 45 |
# File 'lib/office/email_message.rb', line 43 def received_at date end |
#remove_tag(tag) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/office/email_message.rb', line 63 def remove_tag tag case tag.class.name when 'WpTag' ; when 'String' tag = WpTag.emailtag(tag) else throw "#remove_tag2 expects a WpTag or string (eg WpTag::INBOX) as the only parameter." end self[:wp_term_ids] = self[:wp_term_ids] - [ tag.id ] out = self.save! out end |
#rmtag(tag) ⇒ Object
76 |
# File 'lib/office/email_message.rb', line 76 def rmtag tag; remove_tag tag; end |
#wp_term_ids ⇒ Object
Copied to email_conversation
48 |
# File 'lib/office/email_message.rb', line 48 field :wp_term_ids, type: Array, default: [] |