ish_models 0.0.33.302 → 0.0.33.303

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2466c302497d9d68bbea639194f985dd4b34d8bbd8ef5aaecebbef7f1e3650ed
4
- data.tar.gz: '087e0d9cd4469555e510cb4b1da335b77a8f44a1dd59be0fbf9edf2cfcb790be'
3
+ metadata.gz: 8b412037faff703b47b7fa0233f65fdba3a6c1172323c19fbc60ec719c180fa9
4
+ data.tar.gz: 0c68af161d244280a3cd3a109f5b880dc778c5e2ca03338222a4a1262b1461f8
5
5
  SHA512:
6
- metadata.gz: 65078192596ea0469d46fa671c0e373c6c7628f01a6ed9da023a0c82dfce4c417f387bcdc1768b148093dbb231b806acf4220db497263db7b64cd1f6b18ebc6b
7
- data.tar.gz: bc05a572fb9b7da56d41a1103b67b51af8bcf9cff27b0c82d0324081efc65c1c85fc7b0478635d3314d1097dbdc9bb0c0cd0ca117622a8d19cba8a40ec4cee2e
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'
@@ -135,23 +135,13 @@ class Office::EmailMessage
135
135
  # "text/calendar; charset=utf-8; method=REQUEST"
136
136
  def churn_subpart part
137
137
  if part.content_disposition&.include?('attachment')
138
- ## @TODO: attachments !
139
- ;
138
+ save_attachment( part, filename: "subpart-attachment" )
140
139
  else
141
- if part.content_type.include?("multipart/related") ||
142
- part.content_type.include?("multipart/alternative")
143
-
140
+ if part.content_type.include?("multipart")
144
141
  part.parts.each do |subpart|
145
142
  churn_subpart( subpart )
146
143
  end
147
144
  else
148
- # attachment = Office::EmailAttachment.new({
149
- # content: part.decoded,
150
- # content_type: part.content_type,
151
- # email_message: self,
152
- # })
153
- # attachment.save
154
-
155
145
  if part.content_type.include?('text/html')
156
146
  self.part_html = part.decoded
157
147
 
@@ -159,15 +149,19 @@ class Office::EmailMessage
159
149
  self.part_txt = part.decoded
160
150
 
161
151
  elsif part.content_type.include?("text/calendar")
162
- ;
152
+ save_attachment( part, filename: 'subpart-calendar.ics' )
153
+
163
154
  elsif part.content_type.include?("application/pdf")
164
- ;
155
+ save_attachment( part, filename: 'subpart.pdf' )
156
+
165
157
  elsif part.content_type.include?("image/jpeg")
166
- ;
158
+ save_attachment( part, filename: 'subpart.jpg' )
159
+
167
160
  elsif part.content_type.include?("image/png")
168
- ;
161
+ save_attachment( part, filename: 'subpart.png' )
169
162
 
170
163
  else
164
+ save_attachment( part, filename: 'subpart-unspecified' )
171
165
  self.logs.push "444 No action for a part with content_type #{part.content_type}"
172
166
 
173
167
  end
@@ -175,6 +169,49 @@ class Office::EmailMessage
175
169
  end
176
170
  end
177
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
178
215
 
179
216
  def body_sanitized
180
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.302
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