wco_email 0.1.1.86 → 0.1.1.88
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.txt +2 -0
- data/app/controllers/wco_email/contexts_controller.rb +5 -3
- data/config/initializers/00_s3.rb +6 -5
- data/config/initializers/00_s3.rb-example +7 -6
- data/lib/lambda.py +104 -0
- data/lib/tasks/wco_email_tasks.rake +8 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 483d72380237765ec7d468767be2603c78d9fd5d37f3ff3b1411aa453d3ef182
|
4
|
+
data.tar.gz: 984f2df22408001c3409c9710afbc526d7ac6f8225601ed280bdc08179814a00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5b7513165ab4ef1d7dc7a1e515c992e3d2a0dd3ce7ab81b311d4ee85842ec853e64b07693f4716cd4db76170048d87f25bc4210a8f26c82a0f1d79da619a3ea
|
7
|
+
data.tar.gz: 9143705fa7e5ab0167fc990d187c5922fed21af9fc2269cb2f49f39a92c6c13905d1c1b95b8e7477d907eca8211e22c60e2e75d747eb106750acb642e533f26c
|
data/README.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
= Install =
|
3
3
|
|
4
|
+
alias be='bundle exec '
|
4
5
|
alias dc='docker-compose '
|
5
6
|
|
6
7
|
Copy and edit the config file:
|
@@ -26,6 +27,7 @@
|
|
26
27
|
You need a copy of wco_models.git locally ( default location is ~/projects/ruby/wco_models )
|
27
28
|
|
28
29
|
awslocal s3api create-bucket --bucket wco-email-development
|
30
|
+
awslocal s3api create-bucket --bucket wco-email-ses-development
|
29
31
|
|
30
32
|
== Troubleshooting ==
|
31
33
|
|
@@ -47,6 +47,7 @@ class WcoEmail::ContextsController < WcoEmail::ApplicationController
|
|
47
47
|
def index
|
48
48
|
authorize! :index, WcoEmail::Context
|
49
49
|
@ctxs = WcoEmail::Context.all
|
50
|
+
|
50
51
|
if params[:lead_id]
|
51
52
|
@lead = Lead.find params[:lead_id]
|
52
53
|
@ctxs = @ctxs.where( lead_id: @lead.id )
|
@@ -56,14 +57,15 @@ class WcoEmail::ContextsController < WcoEmail::ApplicationController
|
|
56
57
|
@ctxs = @ctxs.where( :sent_at.ne => nil )
|
57
58
|
elsif 'false' == params[:sent]
|
58
59
|
@ctxs = @ctxs.where( sent_at: nil )
|
59
|
-
else
|
60
|
-
|
61
|
-
|
60
|
+
# else
|
61
|
+
# ## default, show notsent.
|
62
|
+
# @ctxs = @ctxs.where( :sent_at.ne => nil )
|
62
63
|
end
|
63
64
|
|
64
65
|
@ctxs = @ctxs.order_by( sent_at: :desc, send_at: :desc
|
65
66
|
).page( params[:ctxs_page]
|
66
67
|
).per( current_profile.per_page )
|
68
|
+
|
67
69
|
end
|
68
70
|
|
69
71
|
def new
|
@@ -1,13 +1,14 @@
|
|
1
|
+
|
1
2
|
::S3_CREDENTIALS ||= {
|
2
3
|
## user:
|
3
4
|
access_key_id: "",
|
4
5
|
secret_access_key: "",
|
5
6
|
bucket: "wco-email-development",
|
6
7
|
region: 'us-east-1',
|
8
|
+
}
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
bucket_ses: "",
|
12
|
-
region_ses: 'us-east-1',
|
10
|
+
::SES_S3_CREDENTIALS ||= {
|
11
|
+
endpoint: "http://localhost:4566/",
|
12
|
+
force_path_style: true,
|
13
13
|
}
|
14
|
+
::SES_S3_BUCKET ||= "wco-email-ses-development"
|
@@ -1,13 +1,14 @@
|
|
1
|
+
|
1
2
|
::S3_CREDENTIALS ||= {
|
2
3
|
## user:
|
3
4
|
access_key_id: "",
|
4
5
|
secret_access_key: "",
|
5
|
-
bucket: "",
|
6
|
+
bucket: "wco-email-development",
|
6
7
|
region: 'us-east-1',
|
8
|
+
}
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
bucket_ses: "",
|
12
|
-
region_ses: 'us-east-1',
|
10
|
+
::SES_S3_CREDENTIALS ||= {
|
11
|
+
endpoint: "http://localhost:4566/",
|
12
|
+
force_path_style: true,
|
13
13
|
}
|
14
|
+
::SES_S3_BUCKET ||= "wco-email-ses-development"
|
data/lib/lambda.py
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
import os
|
3
|
+
import boto3
|
4
|
+
import email
|
5
|
+
import re
|
6
|
+
from botocore.exceptions import ClientError
|
7
|
+
from email.mime.multipart import MIMEMultipart
|
8
|
+
from email.mime.text import MIMEText
|
9
|
+
from email.mime.application import MIMEApplication
|
10
|
+
import requests
|
11
|
+
|
12
|
+
region = os.environ['Region']
|
13
|
+
office_api_endpoint = os.environ.get('POX_ENDPOINT', None) # https://email.wasya.co/email/messages/from-ses
|
14
|
+
office_api_key = os.environ.get('POX_KEY', None)
|
15
|
+
office_api_secret = os.environ.get('POX_SECRET', None)
|
16
|
+
incoming_email_bucket = os.environ['MailS3Bucket']
|
17
|
+
incoming_email_prefix = os.environ.get('MailS3Prefix', None)
|
18
|
+
sender = os.environ['MailSender']
|
19
|
+
recipient = os.environ['MailRecipient']
|
20
|
+
|
21
|
+
def get_message_from_s3(message_id):
|
22
|
+
if incoming_email_prefix:
|
23
|
+
object_path = (incoming_email_prefix + "/" + message_id)
|
24
|
+
else:
|
25
|
+
object_path = message_id
|
26
|
+
|
27
|
+
object_http_path = f"https://s3.console.aws.amazon.com/s3/object/{incoming_email_bucket}/{object_path}?region={region}"
|
28
|
+
|
29
|
+
client_s3 = boto3.client("s3")
|
30
|
+
object_s3 = client_s3.get_object(Bucket=incoming_email_bucket, Key=object_path)
|
31
|
+
file = object_s3['Body'].read()
|
32
|
+
|
33
|
+
file_dict = {
|
34
|
+
"file": file,
|
35
|
+
"path": object_http_path,
|
36
|
+
"object_path": object_path,
|
37
|
+
}
|
38
|
+
return file_dict
|
39
|
+
|
40
|
+
def create_message(file_dict):
|
41
|
+
separator = ";"
|
42
|
+
mailobject = email.message_from_string(file_dict['file'].decode('utf-8'))
|
43
|
+
subject_original = mailobject['Subject']
|
44
|
+
subject = "FW: " + subject_original
|
45
|
+
body_text = ("The attached message was received from "
|
46
|
+
+ separator.join(mailobject.get_all('From'))
|
47
|
+
+ ". This message is archived at " + file_dict['path'])
|
48
|
+
|
49
|
+
# The file name to use for the attached message. Uses regex to remove all
|
50
|
+
# non-alphanumeric characters, and appends a file extension.
|
51
|
+
filename = re.sub('[^0-9a-zA-Z]+', '_', subject_original) + ".eml"
|
52
|
+
|
53
|
+
msg = MIMEMultipart()
|
54
|
+
text_part = MIMEText(body_text, _subtype="html")
|
55
|
+
msg.attach(text_part)
|
56
|
+
|
57
|
+
msg['Subject'] = subject
|
58
|
+
msg['From'] = sender
|
59
|
+
msg['To'] = recipient
|
60
|
+
|
61
|
+
att = MIMEApplication(file_dict["file"], filename)
|
62
|
+
att.add_header("Content-Disposition", 'attachment', filename=filename)
|
63
|
+
|
64
|
+
msg.attach(att)
|
65
|
+
|
66
|
+
message = {
|
67
|
+
"Source": sender,
|
68
|
+
"Destinations": recipient,
|
69
|
+
"Data": msg.as_string()
|
70
|
+
}
|
71
|
+
return message
|
72
|
+
|
73
|
+
def send_email(message):
|
74
|
+
client_ses = boto3.client('ses', region)
|
75
|
+
|
76
|
+
try:
|
77
|
+
response = client_ses.send_raw_email(
|
78
|
+
Source=message['Source'],
|
79
|
+
Destinations=[
|
80
|
+
message['Destinations']
|
81
|
+
],
|
82
|
+
RawMessage={
|
83
|
+
'Data':message['Data']
|
84
|
+
}
|
85
|
+
)
|
86
|
+
except ClientError as e:
|
87
|
+
output = e.response['Error']['Message']
|
88
|
+
else:
|
89
|
+
output = "Email sent! Message ID: " + response['MessageId']
|
90
|
+
|
91
|
+
return output
|
92
|
+
|
93
|
+
def lambda_handler(event, context):
|
94
|
+
|
95
|
+
message_id = event['Records'][0]['ses']['mail']['messageId']
|
96
|
+
print(f"Received message ID {message_id}")
|
97
|
+
|
98
|
+
result = requests.post(office_api_endpoint,
|
99
|
+
data = { 'object_path': f"https://{incoming_email_bucket}.s3.amazonaws.com/{message_id}",
|
100
|
+
'bucket': incoming_email_bucket,
|
101
|
+
'key': office_api_key,
|
102
|
+
'object_key': message_id,
|
103
|
+
'secret': office_api_secret })
|
104
|
+
print(result)
|
@@ -159,6 +159,14 @@ namespace :wco_email do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
|
162
|
+
desc "seed"
|
163
|
+
task :seed => :environment do
|
164
|
+
inbox_tag = Wco::Tag.find_or_create_by({ slug: 'inbox' })
|
165
|
+
stub = WcoEmail::MessageStub.new({ bucket: 'wco-email-ses-development',
|
166
|
+
object_key: '2021-10-18T18_41_17Fanand_phoenixwebgroup_co' })
|
167
|
+
end
|
168
|
+
|
169
|
+
|
162
170
|
|
163
171
|
desc 'send contexts'
|
164
172
|
task send_contexts: :environment do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wco_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1.
|
4
|
+
version: 0.1.1.88
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Pudeyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|
@@ -452,6 +452,7 @@ files:
|
|
452
452
|
- config/initializers/08_integrations.rb-example
|
453
453
|
- config/initializers/assets.rb
|
454
454
|
- config/routes.rb
|
455
|
+
- lib/lambda.py
|
455
456
|
- lib/tasks/bjjcollective/sitemap.rb
|
456
457
|
- lib/tasks/db_tasks.rake
|
457
458
|
- lib/tasks/direct_mail_tasks.rake
|