mail_room 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/README.md +39 -1
- data/lib/mail_room/delivery/que.rb +61 -0
- data/lib/mail_room/delivery/sidekiq.rb +3 -3
- data/lib/mail_room/mailbox.rb +2 -0
- data/lib/mail_room/version.rb +1 -1
- data/mail_room.gemspec +1 -0
- data/spec/lib/delivery/que_spec.rb +45 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceb4dec276d2d4f97fe52bfad9bfe8d6872007dd
|
4
|
+
data.tar.gz: 84b9d66207d812a0a086dedab6d8362c2468c3e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1547d51516853487da839d8ff00fe70be46dacb9689b8f47227cc55fbd5399de83a191ecf4e8e844bf86052d6d2406891b327a68e978b7527fca45da9bff4643
|
7
|
+
data.tar.gz: 3175e36ca4515ee0e9b1d85301bbdb8cb991b4509330b29efd8a4f3cf294e15f856d07cd8f6ff7e252849175f5a1495d7a9ff46d777afbb87fcabe8267f90acc
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# mail_room #
|
2
2
|
|
3
|
-
mail_room is a configuration based process that will idle on IMAP connections and
|
3
|
+
mail_room is a configuration based process that will idle on IMAP connections and execute a delivery method when a new message is received. Examples of delivery methods include:
|
4
|
+
|
5
|
+
* POST to a delivery URL (Postback)
|
6
|
+
* Queue a job to Sidekiq or Que for later processing (Sidekiq or Que)
|
7
|
+
* Log the message or open with LetterOpener (Logger or LetterOpener)
|
4
8
|
|
5
9
|
[![Build Status](https://travis-ci.org/tpitale/mail_room.png?branch=master)](https://travis-ci.org/tpitale/mail_room)
|
6
10
|
[![Code Climate](https://codeclimate.com/github/tpitale/mail_room.png)](https://codeclimate.com/github/tpitale/mail_room)
|
@@ -123,6 +127,40 @@ class EmailReceiverWorker
|
|
123
127
|
end
|
124
128
|
```
|
125
129
|
|
130
|
+
### que ###
|
131
|
+
|
132
|
+
Deliver the message by pushing it onto the configured Que queue to be handled by a custom worker.
|
133
|
+
|
134
|
+
Requires `pg` gem to be installed.
|
135
|
+
|
136
|
+
Configured with `:delivery_method: que`.
|
137
|
+
|
138
|
+
Delivery options:
|
139
|
+
- **host**: The postgresql server host to connect with. Use the database you use with Que.
|
140
|
+
Required, defaults to `localhost`.
|
141
|
+
- **port**: The postgresql server port to connect with. Use the database you use with Que.
|
142
|
+
Required, defaults to `5432`.
|
143
|
+
- **database**: The postgresql database to use. Use the database you use with Que.
|
144
|
+
Required.
|
145
|
+
- **queue**: The Que queue the job is pushed onto. Make sure Que actually reads off this queue.
|
146
|
+
Required, defaults to `default`.
|
147
|
+
- **job_class**: The worker class that will handle the message.
|
148
|
+
Required.
|
149
|
+
- **priority**: The priority you want this job to run at.
|
150
|
+
Required, defaults to `100`, lowest Que default priority.
|
151
|
+
|
152
|
+
An example worker implementation looks like this:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
class EmailReceiverJob < Que::Job
|
156
|
+
def run(message)
|
157
|
+
mail = Mail::Message.new(message)
|
158
|
+
|
159
|
+
puts "New mail from #{mail.from.first}: #{mail.subject}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
126
164
|
### logger ###
|
127
165
|
|
128
166
|
Configured with `:delivery_method: logger`.
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'pg'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module MailRoom
|
5
|
+
module Delivery
|
6
|
+
# Que Delivery method
|
7
|
+
# @author Tony Pitale
|
8
|
+
class Que
|
9
|
+
Options = Struct.new(:host, :port, :database, :username, :password, :queue, :priority, :job_class) do
|
10
|
+
def initialize(mailbox)
|
11
|
+
host = mailbox.delivery_options[:host] || "localhost"
|
12
|
+
port = mailbox.delivery_options[:port] || 5432
|
13
|
+
database = mailbox.delivery_options[:database]
|
14
|
+
username = mailbox.delivery_options[:username]
|
15
|
+
password = mailbox.delivery_options[:password]
|
16
|
+
|
17
|
+
queue = mailbox.delivery_options[:queue] || ''
|
18
|
+
priority = mailbox.delivery_options[:priority] || 100 # lowest priority for Que
|
19
|
+
job_class = mailbox.delivery_options[:job_class]
|
20
|
+
|
21
|
+
super(host, port, database, username, password, queue, priority, job_class)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :options
|
26
|
+
|
27
|
+
# Build a new delivery, hold the mailbox configuration
|
28
|
+
# @param [MailRoom::Delivery::Que::Options]
|
29
|
+
def initialize(options)
|
30
|
+
@options = options
|
31
|
+
end
|
32
|
+
|
33
|
+
# deliver the message by pushing it onto the configured Sidekiq queue
|
34
|
+
# @param message [String] the email message as a string, RFC822 format
|
35
|
+
def deliver(message)
|
36
|
+
queue_job(message)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def connection
|
41
|
+
PG.connect(connection_options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def connection_options
|
45
|
+
{
|
46
|
+
host: options.host,
|
47
|
+
port: options.port,
|
48
|
+
dbname: options.database,
|
49
|
+
user: options.username,
|
50
|
+
password: options.password
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def queue_job(*args)
|
55
|
+
sql = "INSERT INTO que_jobs (priority, job_class, queue, args) VALUES ($1, $2, $3, $4)"
|
56
|
+
|
57
|
+
connection.exec(sql, [options.priority, options.job_class, options.queue, JSON.dump(args)])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -4,8 +4,8 @@ require "json"
|
|
4
4
|
|
5
5
|
module MailRoom
|
6
6
|
module Delivery
|
7
|
-
#
|
8
|
-
# @author
|
7
|
+
# Sidekiq Delivery method
|
8
|
+
# @author Douwe Maan
|
9
9
|
class Sidekiq
|
10
10
|
Options = Struct.new(:redis_url, :namespace, :queue, :worker) do
|
11
11
|
def initialize(mailbox)
|
@@ -21,7 +21,7 @@ module MailRoom
|
|
21
21
|
attr_accessor :options
|
22
22
|
|
23
23
|
# Build a new delivery, hold the mailbox configuration
|
24
|
-
# @param [MailRoom::
|
24
|
+
# @param [MailRoom::Delivery::Sidekiq::Options]
|
25
25
|
def initialize(options)
|
26
26
|
@options = options
|
27
27
|
end
|
data/lib/mail_room/mailbox.rb
CHANGED
data/lib/mail_room/version.rb
CHANGED
data/mail_room.gemspec
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mail_room/delivery/que'
|
3
|
+
|
4
|
+
describe MailRoom::Delivery::Que do
|
5
|
+
describe '#deliver' do
|
6
|
+
let(:mailbox) {MailRoom::Mailbox.new({
|
7
|
+
delivery_options: {
|
8
|
+
database: 'delivery_test',
|
9
|
+
username: 'postgres',
|
10
|
+
password: '',
|
11
|
+
queue: 'default',
|
12
|
+
priority: 5,
|
13
|
+
job_class: 'ParseMailJob'
|
14
|
+
}
|
15
|
+
})}
|
16
|
+
|
17
|
+
let(:connection) {stub}
|
18
|
+
let(:options) {MailRoom::Delivery::Que::Options.new(mailbox)}
|
19
|
+
|
20
|
+
it 'stores the message in que_jobs table' do
|
21
|
+
PG.stubs(:connect).returns(connection)
|
22
|
+
connection.stubs(:exec)
|
23
|
+
|
24
|
+
MailRoom::Delivery::Que.new(options).deliver('email')
|
25
|
+
|
26
|
+
expect(PG).to have_received(:connect).with({
|
27
|
+
host: 'localhost',
|
28
|
+
port: 5432,
|
29
|
+
dbname: 'delivery_test',
|
30
|
+
user: 'postgres',
|
31
|
+
password: ''
|
32
|
+
})
|
33
|
+
|
34
|
+
expect(connection).to have_received(:exec).with(
|
35
|
+
"INSERT INTO que_jobs (priority, job_class, queue, args) VALUES ($1, $2, $3, $4)",
|
36
|
+
[
|
37
|
+
5,
|
38
|
+
'ParseMailJob',
|
39
|
+
'default',
|
40
|
+
JSON.dump(['email'])
|
41
|
+
]
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_room
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pg
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: mail_room will proxy email (gmail) from IMAP to a delivery method
|
140
154
|
email:
|
141
155
|
- tpitale@gmail.com
|
@@ -162,6 +176,7 @@ files:
|
|
162
176
|
- lib/mail_room/delivery/logger.rb
|
163
177
|
- lib/mail_room/delivery/noop.rb
|
164
178
|
- lib/mail_room/delivery/postback.rb
|
179
|
+
- lib/mail_room/delivery/que.rb
|
165
180
|
- lib/mail_room/delivery/sidekiq.rb
|
166
181
|
- lib/mail_room/mailbox.rb
|
167
182
|
- lib/mail_room/mailbox_handler.rb
|
@@ -175,6 +190,7 @@ files:
|
|
175
190
|
- spec/lib/delivery/letter_opener_spec.rb
|
176
191
|
- spec/lib/delivery/logger_spec.rb
|
177
192
|
- spec/lib/delivery/postback_spec.rb
|
193
|
+
- spec/lib/delivery/que_spec.rb
|
178
194
|
- spec/lib/mailbox_handler_spec.rb
|
179
195
|
- spec/lib/mailbox_spec.rb
|
180
196
|
- spec/lib/mailbox_watcher_spec.rb
|
@@ -211,6 +227,7 @@ test_files:
|
|
211
227
|
- spec/lib/delivery/letter_opener_spec.rb
|
212
228
|
- spec/lib/delivery/logger_spec.rb
|
213
229
|
- spec/lib/delivery/postback_spec.rb
|
230
|
+
- spec/lib/delivery/que_spec.rb
|
214
231
|
- spec/lib/mailbox_handler_spec.rb
|
215
232
|
- spec/lib/mailbox_spec.rb
|
216
233
|
- spec/lib/mailbox_watcher_spec.rb
|