ish_models 0.0.33.302 → 0.0.33.304

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: 2466c302497d9d68bbea639194f985dd4b34d8bbd8ef5aaecebbef7f1e3650ed
4
- data.tar.gz: '087e0d9cd4469555e510cb4b1da335b77a8f44a1dd59be0fbf9edf2cfcb790be'
3
+ metadata.gz: '069e59f9305d7133032ef2b6776d9cefd59f376d40774828a21b5b95c5acd7b9'
4
+ data.tar.gz: a556f13344b589b0add0b7c0f81408f0c9c55a89f902cfa855b7b29171182769
5
5
  SHA512:
6
- metadata.gz: 65078192596ea0469d46fa671c0e373c6c7628f01a6ed9da023a0c82dfce4c417f387bcdc1768b148093dbb231b806acf4220db497263db7b64cd1f6b18ebc6b
7
- data.tar.gz: bc05a572fb9b7da56d41a1103b67b51af8bcf9cff27b0c82d0324081efc65c1c85fc7b0478635d3314d1097dbdc9bb0c0cd0ca117622a8d19cba8a40ec4cee2e
6
+ metadata.gz: a9ab4766a82cd464fef564632d3fade497a5bb4542d0c472c2089fcf99cd657462d68b0c463b5800486d47a51613c2952d290b78fba7adcc080d713a508d119e
7
+ data.tar.gz: d21d6f7d92307efd7338bd86dd3b1fc1f0f3c9bc254c7b2ee00da15c5cf8193c1ac4aa5ea46d47d21f02fae2c1283b69553ac37f84f38ce1ae5d9615e1b0ff17
@@ -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: self.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: self,
190
+ filename: filename,
191
+ })
192
+ begin
193
+ attachment.save
194
+ rescue Encoding::UndefinedConversionError
195
+ self.logs.push "Could not save an attachment"
196
+ self.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: self,
205
+ filename: filename,
206
+ object: File.open("/tmp/#{filename}"),
207
+ })
208
+ if !asset3d.save
209
+ self.logs.push "Could not save an asset3d"
210
+ self.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.304
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