incoming 0.1.8 → 0.2.0
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 +5 -5
- data/MIT-LICENSE +1 -1
- data/README.md +28 -28
- data/lib/incoming.rb +1 -1
- data/lib/incoming/strategies/sendgrid.rb +3 -2
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8409603277a81970dc527c48ca47f77760c9144cb8669c5076ae35218157df7f
|
4
|
+
data.tar.gz: c91ca767fb8bd056aaf7c653fbcb1aa907038f95478dbb35773cccd3f7b8e511
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9da30c903889786191ae4eac39f106897de8da570721d84bfab38785bd2a9944225a22f815353653aae9a0b384f8d7963d63628a3e168fd3dac60914d917334
|
7
|
+
data.tar.gz: eda688777a0803b9047b0e1864e0d83a18724ab4c769ecc42a40d9fb2f258f8b50cbf551c5a3cdbcc1d2ee975d0826e06b1b45c94e384e238402f30331e383e3
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Brought to you by :zap: **Honeybadger.io**, painless [Rails exception tracking](
|
|
24
24
|
1. Add Incoming! to your Gemfile and run `bundle install`:
|
25
25
|
|
26
26
|
```ruby
|
27
|
-
gem
|
27
|
+
gem "incoming"
|
28
28
|
```
|
29
29
|
|
30
30
|
2. Create a new class to receive emails (see examples below)
|
@@ -32,7 +32,7 @@ Brought to you by :zap: **Honeybadger.io**, painless [Rails exception tracking](
|
|
32
32
|
3. Implement an HTTP endpoint to receive HTTP post hooks, and pass the
|
33
33
|
request to your receiver. (see examples below)
|
34
34
|
|
35
|
-
## SendGrid
|
35
|
+
## SendGrid Example
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
class EmailReceiver < Incoming::Strategies::SendGrid
|
@@ -47,11 +47,11 @@ result = EmailReceiver.receive(req) # => Got message from whoever@wherever.com w
|
|
47
47
|
|
48
48
|
[Sendgrid API reference](http://sendgrid.com/docs/API_Reference/Webhooks/parse.html)
|
49
49
|
|
50
|
-
## Mailgun
|
50
|
+
## Mailgun Example
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
class EmailReceiver < Incoming::Strategies::Mailgun
|
54
|
-
setup :
|
54
|
+
setup api_key: "asdf"
|
55
55
|
|
56
56
|
def receive(mail)
|
57
57
|
%(Got message from #{mail.to.first} with subject "#{mail.subject}")
|
@@ -64,7 +64,7 @@ result = EmailReceiver.receive(req) # => Got message from whoever@wherever.com w
|
|
64
64
|
|
65
65
|
[Mailgun API reference](http://documentation.mailgun.net/user_manual.html#receiving-messages)
|
66
66
|
|
67
|
-
## Postmark
|
67
|
+
## Postmark Example
|
68
68
|
|
69
69
|
```ruby
|
70
70
|
class EmailReceiver < Incoming::Strategies::Postmark
|
@@ -79,7 +79,7 @@ result = EmailReceiver.receive(req) # => Got message from whoever@wherever.com w
|
|
79
79
|
|
80
80
|
[Postmark API reference](http://developer.postmarkapp.com/developer-inbound.html)
|
81
81
|
|
82
|
-
## CloudMailin
|
82
|
+
## CloudMailin Example
|
83
83
|
|
84
84
|
Use the Raw Format when setting up your address target.
|
85
85
|
|
@@ -96,7 +96,7 @@ result = EmailReceiver.receive(req) # => Got message from whoever@wherever.com w
|
|
96
96
|
|
97
97
|
[CloudMailin API reference](http://docs.cloudmailin.com/http_post_formats/)
|
98
98
|
|
99
|
-
## Mandrill
|
99
|
+
## Mandrill Example
|
100
100
|
|
101
101
|
Mandrill is capable of sending multiple events in a single webhook, so
|
102
102
|
the Mandrill strategy works a bit differently than the others. Namely,
|
@@ -112,16 +112,16 @@ class EmailReceiver < Incoming::Strategies::Mandrill
|
|
112
112
|
end
|
113
113
|
|
114
114
|
req = Rack::Request.new(env)
|
115
|
-
result = EmailReceiver.receive(req) # =>
|
115
|
+
result = EmailReceiver.receive(req) # => Got message from whoever@wherever.com with subject "hello world"
|
116
116
|
```
|
117
117
|
|
118
118
|
[Mandrill API reference](http://help.mandrill.com/entries/22092308-What-is-the-format-of-inbound-email-webhooks-)
|
119
119
|
|
120
|
-
## Postfix
|
120
|
+
## Postfix Example
|
121
121
|
|
122
122
|
```ruby
|
123
123
|
class EmailReceiver < Incoming::Strategies::HTTPPost
|
124
|
-
setup :
|
124
|
+
setup secret: "6d7e5337a0cd69f52c3fcf9f5af438b1"
|
125
125
|
|
126
126
|
def receive(mail)
|
127
127
|
%(Got message from #{mail.to.first} with subject "#{mail.subject}")
|
@@ -139,11 +139,11 @@ result = EmailReceiver.receive(req) # => Got message from whoever@wherever.com w
|
|
139
139
|
# /etc/mail/aliases
|
140
140
|
http_post: "|http_post -s 6d7e5337a0cd69f52c3fcf9f5af438b1 http://www.example.com/emails"
|
141
141
|
```
|
142
|
-
## Qmail
|
142
|
+
## Qmail Example:
|
143
143
|
|
144
144
|
```ruby
|
145
145
|
class EmailReceiver < Incoming::Strategies::HTTPPost
|
146
|
-
setup :
|
146
|
+
setup secret: "6d7e5337a0cd69f52c3fcf9f5af438b1"
|
147
147
|
|
148
148
|
def receive(mail)
|
149
149
|
%(Got message from #{mail.to.first} with subject "#{mail.subject}")
|
@@ -172,16 +172,16 @@ example.com:example
|
|
172
172
|
```
|
173
173
|
Now mails to `whoever@example.com` will be posted to the corresponding URL above. To post all mails for `example.com`, just add the above line to `~example/.qmail-default`.
|
174
174
|
|
175
|
-
## Example Rails
|
175
|
+
## Example Rails Controller
|
176
176
|
|
177
177
|
```ruby
|
178
178
|
# app/controllers/emails_controller.rb
|
179
179
|
class EmailsController < ActionController::Base
|
180
180
|
def create
|
181
181
|
if EmailReceiver.receive(request)
|
182
|
-
render :
|
182
|
+
render json: { status: "ok" }
|
183
183
|
else
|
184
|
-
render :
|
184
|
+
render json: { status: "rejected" }, status: 403
|
185
185
|
end
|
186
186
|
end
|
187
187
|
end
|
@@ -190,27 +190,27 @@ end
|
|
190
190
|
```ruby
|
191
191
|
# config/routes.rb
|
192
192
|
Rails.application.routes.draw do
|
193
|
-
post
|
193
|
+
post "/emails" => "emails#create"
|
194
194
|
end
|
195
195
|
```
|
196
196
|
|
197
197
|
```ruby
|
198
198
|
# spec/controllers/emails_controller_spec.rb
|
199
|
-
require
|
199
|
+
require "spec_helper"
|
200
200
|
|
201
|
-
describe EmailsController,
|
202
|
-
it
|
203
|
-
EmailReceiver.
|
201
|
+
describe EmailsController, "#create" do
|
202
|
+
it "responds with success when request is valid" do
|
203
|
+
allow(EmailReceiver).to receive(:receive).and_return(true)
|
204
204
|
post :create
|
205
|
-
response.
|
206
|
-
response.body.
|
205
|
+
expect(response.success?).to eq(true)
|
206
|
+
expect(response.body).to eq(%({"status":"ok"}))
|
207
207
|
end
|
208
208
|
|
209
|
-
it
|
210
|
-
EmailReceiver.
|
209
|
+
it "responds with 403 when request is invalid" do
|
210
|
+
allow(EmailReceiver).to receive(:receive).and_return(false)
|
211
211
|
post :create
|
212
|
-
response.status.
|
213
|
-
response.body.
|
212
|
+
expect(response.status).to eq(403)
|
213
|
+
expect(response.body).to eq(%({"status":"rejected"}))
|
214
214
|
end
|
215
215
|
end
|
216
216
|
```
|
@@ -230,5 +230,5 @@ end
|
|
230
230
|
|
231
231
|
## License
|
232
232
|
|
233
|
-
Incoming! is
|
234
|
-
|
233
|
+
Incoming! is free software, and may be redistributed under the terms specified
|
234
|
+
in the MIT-LICENSE file.
|
data/lib/incoming.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'mail/utilities'
|
2
3
|
|
3
4
|
module Incoming
|
4
5
|
module Strategies
|
@@ -18,7 +19,7 @@ module Incoming
|
|
18
19
|
header params['headers']
|
19
20
|
header['Content-Transfer-Encoding'] = nil
|
20
21
|
|
21
|
-
if encodings['text']
|
22
|
+
if Mail::Utilities.blank?(encodings['text'])
|
22
23
|
body params['text']
|
23
24
|
else
|
24
25
|
body params['text'].force_encoding(encodings['text']).encode('UTF-8')
|
@@ -26,7 +27,7 @@ module Incoming
|
|
26
27
|
|
27
28
|
html_part do
|
28
29
|
content_type 'text/html; charset=UTF-8'
|
29
|
-
if encodings['html']
|
30
|
+
if Mail::Utilities.blank?(encodings['html'])
|
30
31
|
body params['html']
|
31
32
|
else
|
32
33
|
body params['html'].force_encoding(encodings['html']).encode('UTF-8')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: incoming
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Wood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-its
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Incoming! standardizes various mail parse apis, making it a snap to receive
|
70
84
|
emails through HTTP post hooks.
|
71
85
|
email:
|
@@ -105,8 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
119
|
- !ruby/object:Gem::Version
|
106
120
|
version: '0'
|
107
121
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.2.2
|
122
|
+
rubygems_version: 3.0.3
|
110
123
|
signing_key:
|
111
124
|
specification_version: 4
|
112
125
|
summary: Incoming! helps you receive email in your Rack apps.
|