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



45
46
47
48
49
50
51
52
# File 'lib/office/email_message.rb', line 45

def add_tag tag
  if WpTag == tag.class
    self[:wp_term_ids] = self[:wp_term_ids].push(tag.id).uniq
    self.save!
  else
    throw "#add_tag expects a WpTag as the only parameter."
  end
end

#apply_filter(filter) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/office/email_message.rb', line 77

def apply_filter filter
  case filter.kind
  when ::Office::EmailFilter::KIND_SKIP_INBOX
    self.remove_tag( ::WpTag.email_inbox_tag )
  when ::Office::EmailFilter::KIND_AUTORESPOND
    Ish::EmailContext.create({
      email_template: ::Tmpl.find_by_slug( filter.email_template_slug ),
      lead: lead,
    })
  # when 'autorespond-remind'
  #   Office::EmailAction.create({
  #     tmpl_slug: 'require-sign-nda',
  #     next_in_days: -> { rand(1..5) },
  #     next_at_time: ->{ rand(8..16).hours + rand(1..59).minutes },
  #     next_action: 're-remind-sign-nda',
  #   })
  #   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



73
74
75
# File 'lib/office/email_message.rb', line 73

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

#convObject



63
64
65
# File 'lib/office/email_message.rb', line 63

def conv
  email_conversation
end

#leadObject

attachments ?



26
27
28
# File 'lib/office/email_message.rb', line 26

def lead
  Lead.find_by email: from
end

#nameObject

@TODO: reimplement, look at footer instead.



68
69
70
71
# File 'lib/office/email_message.rb', line 68

def name
  return 'associate'
  # from[0].split('@')[0].upcase
end

#object_keyObject

aka ‘filename’, use with bucket name + prefix



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

field :object_key,  type: :string

#received_atObject



38
39
40
# File 'lib/office/email_message.rb', line 38

def received_at
  date
end

#remove_tag(tag) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/office/email_message.rb', line 53

def remove_tag tag
  if WpTag == tag.class
    self[:wp_term_ids].delete( tag.id )
    self.save!
  else
    throw "#remove_tag expects a WpTag as the only parameter."
  end
end

#wp_term_idsObject

Copied to email_conversation



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

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