griddler 1.3.1 → 1.5.2
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 +4 -4
- data/README.md +10 -3
- data/Rakefile +0 -1
- data/app/controllers/griddler/emails_controller.rb +5 -3
- data/lib/griddler/configuration.rb +5 -0
- data/lib/griddler/email.rb +51 -2
- data/lib/griddler/email_parser.rb +5 -2
- data/lib/griddler/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 638ce28e726a636413b01cc51837099ec9b828a6
|
4
|
+
data.tar.gz: feca8309eed5360ae57a59846d98b0f163bfe169
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a91bba6d57fbd43ad02cbec2ac3dbbdfe9bf0cadcb3259e471a753292e20560f587a45aeeece4dce1bc2a8f3938842a1950ed7982ef48dae0503c7067fc2ee76
|
7
|
+
data.tar.gz: 494bac5827de8abeea296d31f8ca81159fbc847fc89a8d0a9a1a7636579d915d577cf91bfe08f0edce51d76f51215e76c7e31e5afe26a0f488e589c840333fef
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Tutorials
|
|
14
14
|
---------
|
15
15
|
|
16
16
|
* SendGrid wrote a
|
17
|
-
[great tutorial](
|
17
|
+
[great tutorial](https://sendgrid.com/blog/receiving-email-in-your-rails-app-with-griddler/)
|
18
18
|
on integrating Griddler with your application.
|
19
19
|
* We have our own blog post on the subject over at
|
20
20
|
[Giant Robots](https://robots.thoughtbot.com/griddler-is-better-than-ever).
|
@@ -53,6 +53,7 @@ Defaults are shown below with sample overrides following. In
|
|
53
53
|
```ruby
|
54
54
|
Griddler.configure do |config|
|
55
55
|
config.processor_class = EmailProcessor # CommentViaEmail
|
56
|
+
config.email_class = Griddler::Email # MyEmail
|
56
57
|
config.processor_method = :process # :create_comment (A method on CommentViaEmail)
|
57
58
|
config.reply_delimiter = '-- REPLY ABOVE THIS LINE --'
|
58
59
|
config.email_service = :sendgrid # :cloudmailin, :postmark, :mandrill, :mailgun
|
@@ -62,8 +63,9 @@ end
|
|
62
63
|
| Option | Meaning
|
63
64
|
| ------ | -------
|
64
65
|
| `processor_class` | The class Griddler will use to handle your incoming emails.
|
66
|
+
| `email_class` | The class Griddler will use to represent an incoming e-mail. It must support an initializer that receives a hash as the only argument. We recommend inheriting it from Griddler::Email or checking this class to see all the methods it responds to.
|
65
67
|
| `processor_method` | The method Griddler will call on the processor class when handling your incoming emails.
|
66
|
-
| `reply_delimiter` | The string searched for that will split your body.
|
68
|
+
| `reply_delimiter` | The string searched for that will split your body. You can also supply an array of string - useful if you need translated versions of the delimiter
|
67
69
|
| `email_service` | Tells Griddler which email service you are using. The supported email service options are `:sendgrid` (the default), `:cloudmailin` (expects multipart format), `:postmark`, `:mandrill` and `:mailgun`. You will also need to have an appropriate [adapter] gem included in your Gemfile.
|
68
70
|
|
69
71
|
By default Griddler will look for a class named `EmailProcessor`. The class is
|
@@ -107,6 +109,7 @@ Griddler::Email attributes
|
|
107
109
|
| `#attachments` | An array of `File` objects containing any attachments.
|
108
110
|
| `#headers` | A hash of headers parsed by `Mail::Header`, unless they are already formatted as a hash when received from the adapter in which case the original hash is returned.
|
109
111
|
| `#raw_headers` | The raw headers included in the message.
|
112
|
+
| `#to_h` | A hash of the above attributes.
|
110
113
|
|
111
114
|
### Email Addresses
|
112
115
|
|
@@ -165,16 +168,20 @@ adapter gem in addition to `griddler`.
|
|
165
168
|
| Service | Adapter
|
166
169
|
| ------- | -------
|
167
170
|
| sendgrid | [griddler-sendgrid]
|
171
|
+
| cloudmailin | [griddler-cloudmailin]
|
168
172
|
| mandrill | [griddler-mandrill]
|
169
173
|
| mailgun | [griddler-mailgun]
|
170
174
|
| postmark | [griddler-postmark]
|
171
175
|
| sparkpost | [griddler-sparkpost]
|
176
|
+
| ses (amazon)| [griddler-ses]
|
172
177
|
|
173
178
|
[griddler-sendgrid]: https://github.com/thoughtbot/griddler-sendgrid
|
179
|
+
[griddler-cloudmailin]: https://github.com/thoughtbot/griddler-cloudmailin
|
174
180
|
[griddler-mandrill]: https://github.com/wingrunr21/griddler-mandrill
|
175
181
|
[griddler-mailgun]: https://github.com/bradpauly/griddler-mailgun
|
176
182
|
[griddler-postmark]: https://github.com/r38y/griddler-postmark
|
177
183
|
[griddler-sparkpost]: https://github.com/PrestoDoctor/griddler-sparkpost
|
184
|
+
[griddler-ses]: https://github.com/85x14/griddler-ses
|
178
185
|
|
179
186
|
Writing an Adapter
|
180
187
|
------------------
|
@@ -210,6 +217,6 @@ Griddler was written by Caleb Thompson and Joel Oliveira.
|
|
210
217
|
|
211
218
|
Thanks to our [contributors](https://github.com/thoughtbot/griddler/contributors)!
|
212
219
|
|
213
|
-

|
214
221
|
|
215
222
|
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
data/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
class Griddler::EmailsController < ActionController::Base
|
2
|
+
skip_before_action :verify_authenticity_token, raise: false
|
3
|
+
|
2
4
|
def create
|
3
5
|
normalized_params.each do |p|
|
4
|
-
process_email
|
6
|
+
process_email email_class.new(p)
|
5
7
|
end
|
6
8
|
|
7
9
|
head :ok
|
@@ -9,9 +11,9 @@ class Griddler::EmailsController < ActionController::Base
|
|
9
11
|
|
10
12
|
private
|
11
13
|
|
12
|
-
delegate :processor_class, :processor_method, :email_service, to: :griddler_configuration
|
14
|
+
delegate :processor_class, :email_class, :processor_method, :email_service, to: :griddler_configuration
|
13
15
|
|
14
|
-
private :processor_class, :processor_method, :email_service
|
16
|
+
private :processor_class, :email_class, :processor_method, :email_service
|
15
17
|
|
16
18
|
def normalized_params
|
17
19
|
Array.wrap(email_service.normalize_params(params))
|
@@ -17,6 +17,7 @@ module Griddler
|
|
17
17
|
|
18
18
|
class Configuration
|
19
19
|
attr_accessor :processor_method, :reply_delimiter
|
20
|
+
attr_writer :email_class
|
20
21
|
|
21
22
|
def processor_class
|
22
23
|
@processor_class ||=
|
@@ -36,6 +37,10 @@ module Griddler
|
|
36
37
|
@processor_class = klass.to_s
|
37
38
|
end
|
38
39
|
|
40
|
+
def email_class
|
41
|
+
@email_class ||= Griddler::Email
|
42
|
+
end
|
43
|
+
|
39
44
|
def processor_method
|
40
45
|
@processor_method ||= :process
|
41
46
|
end
|
data/lib/griddler/email.rb
CHANGED
@@ -3,8 +3,24 @@ require 'htmlentities'
|
|
3
3
|
module Griddler
|
4
4
|
class Email
|
5
5
|
include ActionView::Helpers::SanitizeHelper
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
attr_reader :to,
|
8
|
+
:from,
|
9
|
+
:cc,
|
10
|
+
:bcc,
|
11
|
+
:original_recipient,
|
12
|
+
:reply_to,
|
13
|
+
:subject,
|
14
|
+
:body,
|
15
|
+
:raw_body,
|
16
|
+
:raw_text,
|
17
|
+
:raw_html,
|
18
|
+
:headers,
|
19
|
+
:raw_headers,
|
20
|
+
:attachments,
|
21
|
+
:vendor_specific,
|
22
|
+
:spam_report,
|
23
|
+
:charsets
|
8
24
|
|
9
25
|
def initialize(params)
|
10
26
|
@params = params
|
@@ -22,10 +38,43 @@ module Griddler
|
|
22
38
|
|
23
39
|
@cc = recipients(:cc)
|
24
40
|
@bcc = recipients(:bcc)
|
41
|
+
@original_recipient = extract_address(params[:original_recipient])
|
42
|
+
@reply_to = extract_address(params[:reply_to])
|
25
43
|
|
26
44
|
@raw_headers = params[:headers]
|
27
45
|
|
28
46
|
@attachments = params[:attachments]
|
47
|
+
|
48
|
+
@vendor_specific = params.fetch(:vendor_specific, {})
|
49
|
+
|
50
|
+
@spam_report = params[:spam_report]
|
51
|
+
|
52
|
+
@charsets = params[:charsets]
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_h
|
56
|
+
@to_h ||= {
|
57
|
+
to: to,
|
58
|
+
from: from,
|
59
|
+
cc: cc,
|
60
|
+
bcc: bcc,
|
61
|
+
subject: subject,
|
62
|
+
body: body,
|
63
|
+
raw_body: raw_body,
|
64
|
+
raw_text: raw_text,
|
65
|
+
raw_html: raw_html,
|
66
|
+
headers: headers,
|
67
|
+
raw_headers: raw_headers,
|
68
|
+
attachments: attachments,
|
69
|
+
vendor_specific: vendor_specific,
|
70
|
+
spam_score: spam_score,
|
71
|
+
spam_report: spam_report,
|
72
|
+
charsets: charsets,
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def spam_score
|
77
|
+
@spam_report[:score] if @spam_report
|
29
78
|
end
|
30
79
|
|
31
80
|
private
|
@@ -81,10 +81,13 @@ module Griddler::EmailParser
|
|
81
81
|
/^[[:space:]]*[-]+[[:space:]]*Original Message[[:space:]]*[-]+[[:space:]]*$/i,
|
82
82
|
/^[[:space:]]*--[[:space:]]*$/,
|
83
83
|
/^[[:space:]]*\>?[[:space:]]*On.*\r?\n?.*wrote:\r?\n?$/,
|
84
|
-
/^On.*<\n?.*>.*\n?wrote
|
84
|
+
/^On.*<\r?\n?.*>.*\r?\n?wrote:\r?\n?$/,
|
85
85
|
/On.*wrote:/,
|
86
86
|
/\*?From:.*$/i,
|
87
|
-
/^[[:space:]]*\d{4}[-\/]\d{1,2}[-\/]\d{1,2}[[:space:]].*[[:space:]]<.*>?$/i
|
87
|
+
/^[[:space:]]*\d{4}[-\/]\d{1,2}[-\/]\d{1,2}[[:space:]].*[[:space:]]<.*>?$/i,
|
88
|
+
/(_)*\n[[:space:]]*De :.*\n[[:space:]]*Envoyé :.*\n[[:space:]]*À :.*\n[[:space:]]*Objet :.*\n$/i, # French Outlook
|
89
|
+
/^[[:space:]]*\>?[[:space:]]*Le.*<\n?.*>.*\n?a[[:space:]]?\n?écrit :$/, # French
|
90
|
+
/^[[:space:]]*\>?[[:space:]]*El.*<\n?.*>.*\n?escribió:$/ # Spanish
|
88
91
|
]
|
89
92
|
end
|
90
93
|
|
data/lib/griddler/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: griddler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Thompson
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2018-05-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -122,7 +122,8 @@ files:
|
|
122
122
|
- lib/griddler/testing.rb
|
123
123
|
- lib/griddler/version.rb
|
124
124
|
homepage: http://thoughtbot.com
|
125
|
-
licenses:
|
125
|
+
licenses:
|
126
|
+
- MIT
|
126
127
|
metadata: {}
|
127
128
|
post_install_message:
|
128
129
|
rdoc_options: []
|
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
142
|
version: '0'
|
142
143
|
requirements: []
|
143
144
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.5.
|
145
|
+
rubygems_version: 2.5.2
|
145
146
|
signing_key:
|
146
147
|
specification_version: 4
|
147
148
|
summary: SendGrid Parse API client Rails Engine
|