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 +4 -4
- data/app/jobs/ishapi/email_message_intake_job.rb +27 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc372746027421f9ac7c60e85da6d38c0032e9a8070a8ae3d43e360406896fba
|
4
|
+
data.tar.gz: c55c1545c1f1dd9fb02933362c60129c3856831250e8855042edb3a1eb9260b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
35
|
-
the_mail = Mail.new(
|
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:
|
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
|
-
|
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
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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.
|
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-
|
11
|
+
date: 2023-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|