Class: Office::EmailMessage

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/office/email_message.rb

Overview

When I receive one.

Instance Method Summary collapse

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_urlObject



86
87
88
# File 'lib/office/email_message.rb', line 86

def company_url
  from[0].split('@')[1]
end

#convObject



76
77
78
# File 'lib/office/email_message.rb', line 76

def conv
  email_conversation
end

#leadObject

attachments ?



28
29
30
# File 'lib/office/email_message.rb', line 28

def lead
  Lead.find_by email: from
end

#nameObject

@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_keyObject

aka ‘filename’, use with bucket name + prefix



19
# File 'lib/office/email_message.rb', line 19

field :object_key,  type: :string

#preview_strObject



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_atObject



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_idsObject

Copied to email_conversation



45
# File 'lib/office/email_message.rb', line 45

field :wp_term_ids, type: Array, default: []