ishapi 0.1.8.303 → 0.1.8.305

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: deb042effc76a3bac981e7d95c5ccbac9c1fe067b5afb6799f273a2fb061ba67
4
- data.tar.gz: a497b8b725895391c965abe2680adb51d739958ca36172615263aa3fd6b83703
3
+ metadata.gz: fc372746027421f9ac7c60e85da6d38c0032e9a8070a8ae3d43e360406896fba
4
+ data.tar.gz: c55c1545c1f1dd9fb02933362c60129c3856831250e8855042edb3a1eb9260b2
5
5
  SHA512:
6
- metadata.gz: 206d685ea05a79c226a49d888e1ba2ced49e5ff32343999fe1a00e42c65eb8f139e17cc1dcb2bd6d0e7acbb83c257ef55205d75f318631c353a3aef22b6db143
7
- data.tar.gz: ceebf0b9f54feb97eeac59cc655d65c12fc10957431d4821bf472e18822d97d80be31b0407f914a2a94e63119c62a5cf8a743e9f96556f088c481e90fbad3eff
6
+ metadata.gz: cd966429e4ddadd59d1464c3fb93161d5f232db3045a3af8b474bf8d56275f689745c509360b6ab42e5a11ac50d693c73ea4c99b21b0acd07b8723b05b4d2bdb
7
+ data.tar.gz: 108f40bb94ade6afededba38d9c0e9edef891b2e746bb16108a8719669d056e1b6b40d5bb3a21289ed8dac022c73c3015a7bc796596678b8c1db105e4948750b
@@ -10,11 +10,15 @@ class Ishapi::EmailMessageIntakeJob < Ishapi::ApplicationJob
10
10
  queue_as :default
11
11
 
12
12
  =begin
13
- object_key = 'bg57j6u0j38b5ts86635fkqtjlucn5tvrm2hea81'
13
+
14
+ object_key = 'n0v5mg6q1t4fjjnfh8vj8a96t85rp9la2ud0gdg1'
14
15
  MsgStub.where({ object_key: object_key }).delete
15
16
 
16
- stub = MsgStub.create({ object_key: object_key })
17
+ stub = MsgStub.create!({ object_key: object_key })
17
18
  id = stub.id
19
+
20
+ Ishapi::EmailMessageIntakeJob.perform_now( stub.id.to_s )
21
+
18
22
  =end
19
23
  def perform id
20
24
  stub = ::Office::EmailMessageStub.find id
@@ -25,14 +29,15 @@ class Ishapi::EmailMessageIntakeJob < Ishapi::ApplicationJob
25
29
  raise "This stub has already been processed: #{stub.id.to_s}."
26
30
  return
27
31
  end
32
+
28
33
  client = Aws::S3::Client.new({
29
34
  region: ::S3_CREDENTIALS[:region_ses],
30
35
  access_key_id: ::S3_CREDENTIALS[:access_key_id_ses],
31
36
  secret_access_key: ::S3_CREDENTIALS[:secret_access_key_ses],
32
37
  })
33
38
 
34
- _mail = client.get_object( bucket: ::S3_CREDENTIALS[:bucket_ses], key: stub.object_key ).body.read
35
- the_mail = Mail.new(_mail)
39
+ raw = client.get_object( bucket: ::S3_CREDENTIALS[:bucket_ses], key: stub.object_key ).body.read
40
+ the_mail = Mail.new( raw )
36
41
  message_id = the_mail.header['message-id'].decoded
37
42
  in_reply_to_id = the_mail.header['in-reply-to']&.to_s
38
43
  email_inbox_tag_id = WpTag.emailtag(WpTag::INBOX).id
@@ -47,7 +52,7 @@ class Ishapi::EmailMessageIntakeJob < Ishapi::ApplicationJob
47
52
 
48
53
  @message = ::Office::EmailMessage.where( message_id: message_id ).first
49
54
  @message ||= ::Office::EmailMessage.create({
50
- raw: _mail,
55
+ raw: raw,
51
56
 
52
57
  message_id: message_id,
53
58
  in_reply_to_id: in_reply_to_id,
@@ -70,13 +75,7 @@ class Ishapi::EmailMessageIntakeJob < Ishapi::ApplicationJob
70
75
  # bccs: the_mail.bcc,
71
76
  })
72
77
  if !@message.persisted?
73
- puts! @message.errors.full_messages, "Could not create email_message"
74
- end
75
- if the_mail.body.preamble.present?
76
- @message.preamble = the_mail.body.preamble
77
- end
78
- if the_mail.body.epilogue.present?
79
- @message.epilogue = the_mail.body.epilogue
78
+ throw "Could not create email_message: #{@message.errors.full_messages.join(', ')} ."
80
79
  end
81
80
 
82
81
  ## Parts
@@ -93,29 +92,32 @@ class Ishapi::EmailMessageIntakeJob < Ishapi::ApplicationJob
93
92
  elsif the_mail.content_type.blank?
94
93
  @message.part_txt = body
95
94
  else
96
- throw "mail body of unknown type: #{the_mail.content_type}"
95
+ @message.logs.push "mail body of unknown type: #{the_mail.content_type}"
97
96
  end
98
97
  end
99
98
 
100
99
  ## Attachments
101
100
  the_mail.attachments.each do |att|
102
- photo = Photo.new({
103
- content_type: att.content_type.split(';')[0],
104
- original_filename: att.content_type_parameters[:name],
105
- image_data: att.body.encoded,
106
- email_message_id: @message.id,
107
- })
108
- photo.decode_base64_image
109
- if photo.save
110
- ;
111
- else
101
+ content_type = att.content_type.split(';')[0]
102
+ if content_type.include? 'image'
103
+ photo = Photo.new({
104
+ content_type: content_type,
105
+ original_filename: att.content_type_parameters[:name],
106
+ image_data: att.body.encoded,
107
+ email_message_id: @message.id,
108
+ })
109
+ photo.decode_base64_image
110
+ photo.save
111
+ elsif att.filename
112
112
  attachment = Office::EmailAttachment.new({
113
- content: att.decoded,
113
+ content: att.body.decoded,
114
114
  content_type: att.content_type,
115
115
  email_message: @message,
116
116
  filename: att.filename,
117
117
  })
118
118
  attachment.save
119
+ else
120
+ @message.logs.push "Could not save an attachment!"
119
121
  end
120
122
  end
121
123
 
@@ -152,6 +154,7 @@ class Ishapi::EmailMessageIntakeJob < Ishapi::ApplicationJob
152
154
  state: Conv::STATE_UNREAD,
153
155
  latest_at: the_mail.date || Time.now.to_datetime,
154
156
  from_emails: ( conv.from_emails + the_mail.from ).uniq,
157
+ preview: @message.body_sanitized[0...200],
155
158
  })
156
159
  conv.add_tag( ::WpTag::INBOX )
157
160
  conv_lead_tie = Office::EmailConversationLead.find_or_create_by({
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ishapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.303
4
+ version: 0.1.8.305
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-15 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails