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.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_filter(filter) ⇒ Object
-
#churn_subpart(part) ⇒ Object
For recursive parts of type ‘related`.
- #conv ⇒ Object
- #lead ⇒ Object
-
#object_key ⇒ Object
aka ‘filename’, use with bucket name + prefix.
- #preview_str ⇒ Object
- #received_at ⇒ Object
Class Method Details
.strip_emoji(text) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/office/email_message.rb', line 104 def self.strip_emoji(text) text = text.force_encoding('utf-8').encode clean = "" # symbols & pics regex = /[\u{1f300}-\u{1f5ff}]/ clean = text.gsub regex, "" # enclosed chars regex = /[\u{2500}-\u{2BEF}]/ # I changed this to exclude chinese char clean = clean.gsub regex, "" # emoticons regex = /[\u{1f600}-\u{1f64f}]/ clean = clean.gsub regex, "" #dingbats regex = /[\u{2702}-\u{27b0}]/ clean = clean.gsub regex, "" end |
Instance Method Details
#apply_filter(filter) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/office/email_message.rb', line 64 def apply_filter filter case filter.kind when ::Office::EmailFilter::KIND_DESTROY_SCHS conv.add_tag ::WpTag::TRASH conv.remove_tag ::WpTag::INBOX lead.schs.each do |sch| sch.update_attributes({ state: ::Sch::STATE_TRASH }) end when ::Office::EmailFilter::KIND_ADD_TAG conv.add_tag filter.wp_term_id if ::WpTag::TRASH == ::WpTag.find( filter.wp_term_id ).slug conv.remove_tag ::WpTag::INBOX end when ::Office::EmailFilter::KIND_REMOVE_TAG 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 |
#churn_subpart(part) ⇒ Object
For recursive parts of type ‘related`. Content dispositions: “inline; creation-date="Tue, 11 Apr 2023 19:39:42 GMT"; filename=image005.png; modification-date="Tue, 11 Apr 2023 19:47:53 GMT"; size=14916”,
Content Types: “application/pdf; name="Securities Forward Agreement – HaulHub Inc – Victor Pudeyev – 2021-10-26.docx.pdf"” “image/jpeg; name=TX_DL_2.jpg” “image/png; name=image005.png” “multipart/alternative; boundary=000_BL0PR10MB2913C560ADE059F0AB3A6D11829A9BL0PR10MB2913namp”, “text/html; charset=utf-8” “text/plain; charset=UTF-8” “text/calendar; charset=utf-8; method=REQUEST”
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/office/email_message.rb', line 137 def churn_subpart part if part.content_disposition&.include?('attachment') ## @TODO: attachments ! ; else if part.content_type.include?("multipart/related") || part.content_type.include?("multipart/alternative") part.parts.each do |subpart| churn_subpart( subpart ) end else = Office::EmailAttachment.new({ content: part.decoded, content_type: part.content_type, email_message: self, }) .save if part.content_type.include?('text/html') part_html = part.decoded elsif part.content_type.include?("text/plain") part_txt = part.decoded elsif part.content_type.include?("text/calendar") ; elsif part.content_type.include?("application/pdf") ; elsif part.content_type.include?("image/jpeg") ; elsif part.content_type.include?("image/png") ; else puts! part.content_type, '444 No action for a part with this content_type' end end end end |
#conv ⇒ Object
49 50 51 |
# File 'lib/office/email_message.rb', line 49 def conv email_conversation end |
#lead ⇒ Object
30 31 32 |
# File 'lib/office/email_message.rb', line 30 def lead Lead.find_by email: from end |
#object_key ⇒ Object
aka ‘filename’, use with bucket name + prefix. I need this!
19 |
# File 'lib/office/email_message.rb', line 19 field :object_key, type: :string |
#preview_str ⇒ Object
56 57 58 59 60 61 |
# File 'lib/office/email_message.rb', line 56 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
44 45 46 |
# File 'lib/office/email_message.rb', line 44 def received_at date end |