ish_models 0.0.33.301 → 0.0.33.303

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4efc52be97806ddfc99cbb6fa6cc0c183e51a0f32384d789906a98793906616d
4
- data.tar.gz: '084169118e8a9e6c4ef65f07ab3c5cfbc79c77136f6d3974adc1f29b1a0157f0'
3
+ metadata.gz: 8b412037faff703b47b7fa0233f65fdba3a6c1172323c19fbc60ec719c180fa9
4
+ data.tar.gz: 0c68af161d244280a3cd3a109f5b880dc778c5e2ca03338222a4a1262b1461f8
5
5
  SHA512:
6
- metadata.gz: 0bd8bf92613eb20ab1518dc9fabe62dba096000845dc691b39946cff8a4b4578905e0ee5f57121394fede7539326d0c1df56ff783356614dbdde250f0ab07c84
7
- data.tar.gz: a3aa5e12b8ada259599b578f67dabfab9c0e2e283fa00d03f03e5cefc9e3f2e7fcfae14a912cfabdcba0cd7f786b1442a9b7851fe4400f52ce9015dff2b33934
6
+ metadata.gz: 7199e68751b9367d9b6ca3a6c9967d8ae0aea6515869f820e34b8c7283b80939e004622f666fdf08ddc13418d7a6b2480af2dea9a399f7171d8933d3911bbd20
7
+ data.tar.gz: 1a1518f3581dd67a240cb4e333f35ba405523777f048b21e5e91bb432c84d1ed11cf4ca5832234abd213300f99eb8eaec6f81ce2900f604b56eb17f81a66322a
@@ -8,6 +8,8 @@ class ::Gameui::Asset3d
8
8
  include Mongoid::Paperclip
9
9
  include Ish::Utils
10
10
 
11
+ field :filename
12
+
11
13
  belongs_to :marker, class_name: 'Gameui::Marker', optional: true
12
14
  belongs_to :invoice, class_name: 'Ish::Invoice', optional: true
13
15
  belongs_to :email_message, class_name: 'Office::EmailMessage', optional: true, inverse_of: :asset3ds
@@ -2,7 +2,7 @@
2
2
  ##
3
3
  ## for alerting
4
4
  ##
5
- class Iro::OptionWatch
5
+ class Iro::Alert
6
6
  include Mongoid::Document
7
7
  include Mongoid::Timestamps
8
8
  store_in collection: 'iro_option_watches'
data/lib/ish_models.rb CHANGED
@@ -40,7 +40,7 @@ require 'gameui/asset3d'
40
40
  require 'gameui/map'
41
41
  require 'gameui/marker'
42
42
 
43
- require 'iro/option_watch'
43
+ # require 'iro/alert'
44
44
 
45
45
  require 'ish/cache_key'
46
46
  require 'ish/crawler'
@@ -100,6 +100,7 @@ class Office::EmailMessage
100
100
 
101
101
  ## From: https://stackoverflow.com/questions/24672834/how-do-i-remove-emoji-from-string/24673322
102
102
  def self.strip_emoji(text)
103
+ text = '' if text.blank?
103
104
  text = text.force_encoding('utf-8').encode
104
105
  clean = ""
105
106
 
@@ -134,23 +135,13 @@ class Office::EmailMessage
134
135
  # "text/calendar; charset=utf-8; method=REQUEST"
135
136
  def churn_subpart part
136
137
  if part.content_disposition&.include?('attachment')
137
- ## @TODO: attachments !
138
- ;
138
+ save_attachment( part, filename: "subpart-attachment" )
139
139
  else
140
- if part.content_type.include?("multipart/related") ||
141
- part.content_type.include?("multipart/alternative")
142
-
140
+ if part.content_type.include?("multipart")
143
141
  part.parts.each do |subpart|
144
142
  churn_subpart( subpart )
145
143
  end
146
144
  else
147
- # attachment = Office::EmailAttachment.new({
148
- # content: part.decoded,
149
- # content_type: part.content_type,
150
- # email_message: self,
151
- # })
152
- # attachment.save
153
-
154
145
  if part.content_type.include?('text/html')
155
146
  self.part_html = part.decoded
156
147
 
@@ -158,15 +149,19 @@ class Office::EmailMessage
158
149
  self.part_txt = part.decoded
159
150
 
160
151
  elsif part.content_type.include?("text/calendar")
161
- ;
152
+ save_attachment( part, filename: 'subpart-calendar.ics' )
153
+
162
154
  elsif part.content_type.include?("application/pdf")
163
- ;
155
+ save_attachment( part, filename: 'subpart.pdf' )
156
+
164
157
  elsif part.content_type.include?("image/jpeg")
165
- ;
158
+ save_attachment( part, filename: 'subpart.jpg' )
159
+
166
160
  elsif part.content_type.include?("image/png")
167
- ;
161
+ save_attachment( part, filename: 'subpart.png' )
168
162
 
169
163
  else
164
+ save_attachment( part, filename: 'subpart-unspecified' )
170
165
  self.logs.push "444 No action for a part with content_type #{part.content_type}"
171
166
 
172
167
  end
@@ -174,6 +169,49 @@ class Office::EmailMessage
174
169
  end
175
170
  end
176
171
 
172
+ def save_attachment att, filename: "no-filename-specified"
173
+ content_type = att.content_type.split(';')[0]
174
+ if content_type.include? 'image'
175
+ photo = Photo.new({
176
+ content_type: content_type,
177
+ email_message_id: @message.id,
178
+ image_data: att.body.encoded,
179
+ original_filename: att.content_type_parameters[:name],
180
+ })
181
+ photo.decode_base64_image
182
+ photo.save
183
+ else
184
+
185
+ filename = CGI.escape( att.filename || filename )
186
+ attachment = Office::EmailAttachment.new({
187
+ content: att.body.decoded,
188
+ content_type: att.content_type,
189
+ email_message: @message,
190
+ filename: filename,
191
+ })
192
+ begin
193
+ attachment.save
194
+ rescue Encoding::UndefinedConversionError
195
+ @message.logs.push "Could not save an attachment"
196
+ @message.save
197
+ end
198
+
199
+ sio = StringIO.new att.body.decoded
200
+ File.open("/tmp/#{filename}", 'w:UTF-8:ASCII-8BIT') do |f|
201
+ f.puts(sio.read)
202
+ end
203
+ asset3d = ::Gameui::Asset3d.new({
204
+ email_message: @message,
205
+ filename: filename,
206
+ object: File.open("/tmp/#{filename}"),
207
+ })
208
+ if !asset3d.save
209
+ @message.logs.push "Could not save an asset3d"
210
+ @message.save
211
+ end
212
+
213
+ end
214
+ end
177
215
 
178
216
  def body_sanitized
179
217
  ActionView::Base.full_sanitizer.sanitize( part_html||'' ).squish
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33.301
4
+ version: 0.0.33.303
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
@@ -191,7 +191,7 @@ files:
191
191
  - lib/gameui/map.rb
192
192
  - lib/gameui/map_bookmark.rb
193
193
  - lib/gameui/marker.rb
194
- - lib/iro/option_watch.rb
194
+ - lib/iro/alert.rb-bk
195
195
  - lib/ish/cache_key.rb
196
196
  - lib/ish/configuration.rb
197
197
  - lib/ish/crawler.rb