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
attachments ?.
-
#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
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/office/email_message.rb', line 48 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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/office/email_message.rb', line 91 def apply_filter filter case filter.kind when ::Office::EmailFilter::KIND_SKIP_INBOX self.remove_tag( WpTag::INBOX ) self.conv.remove_tag( WpTag::INBOX ) when ::Office::EmailFilter::KIND_AUTORESPOND Ish::EmailContext.create({ email_template: ::Tmpl.find_by_slug( filter.email_template_slug ), lead: lead, }) else raise "unknown filter kind: #{filter.kind}" end end |
#company_url ⇒ Object
86 87 88 |
# File 'lib/office/email_message.rb', line 86 def company_url from[0].split('@')[1] end |
#conv ⇒ Object
76 77 78 |
# File 'lib/office/email_message.rb', line 76 def conv email_conversation end |
#lead ⇒ Object
attachments ?
28 29 30 |
# File 'lib/office/email_message.rb', line 28 def lead Lead.find_by email: from end |
#name ⇒ Object
@TODO: reimplement
81 82 83 84 |
# File 'lib/office/email_message.rb', line 81 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
106 107 108 109 110 111 |
# File 'lib/office/email_message.rb', line 106 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
40 41 42 |
# File 'lib/office/email_message.rb', line 40 def received_at date end |
#remove_tag(tag) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/office/email_message.rb', line 60 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
73 |
# File 'lib/office/email_message.rb', line 73 def rmtag tag; remove_tag tag; end |
#wp_term_ids ⇒ Object
Copied to email_conversation
45 |
# File 'lib/office/email_message.rb', line 45 field :wp_term_ids, type: Array, default: [] |