mail_room 0.4.2 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18fcfd6db34934950b927ff4a8ab959e93e12eed
4
- data.tar.gz: c1b229e83fe719ce86f0f72f1b14f32a7a8b4f3e
3
+ metadata.gz: ceb4dec276d2d4f97fe52bfad9bfe8d6872007dd
4
+ data.tar.gz: 84b9d66207d812a0a086dedab6d8362c2468c3e6
5
5
  SHA512:
6
- metadata.gz: a73241070478126fbd770ae7b3fba7b443c86a732b79f9c3976f7e1296a07cb9262f44eeaf356e0e51f85c793edac2b37d81d0b588d0138e4a0eacf9cc94b2f5
7
- data.tar.gz: 24d8dfc3bbcf59ed3ca84780992a75867af6568d503edfb7b40e4b99560aee3004569156f0cc8d3bde94c51fb87a1444fd373b269fdb730b0f801a5d357ee9ec
6
+ metadata.gz: 1547d51516853487da839d8ff00fe70be46dacb9689b8f47227cc55fbd5399de83a191ecf4e8e844bf86052d6d2406891b327a68e978b7527fca45da9bff4643
7
+ data.tar.gz: 3175e36ca4515ee0e9b1d85301bbdb8cb991b4509330b29efd8a4f3cf294e15f856d07cd8f6ff7e252849175f5a1495d7a9ff46d777afbb87fcabe8267f90acc
data/.travis.yml CHANGED
@@ -5,3 +5,4 @@ rvm:
5
5
  - 2.1.5
6
6
  - 2.2.0
7
7
  script: bundle exec rspec spec
8
+ sudo: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## mail_room 0.5.0 ##
2
+
3
+ * Que delivery method
4
+
5
+ *Tony Pitale <@tpitale>*
6
+
1
7
  ## mail_room 0.4.2 ##
2
8
 
3
9
  * rescue from all IOErrors, not just EOFError
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 POST to a delivery URL whenever a new message is received on the configured mailbox and folder.
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
- # Postback Delivery method
8
- # @author Tony Pitale
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::Mailbox]
24
+ # @param [MailRoom::Delivery::Sidekiq::Options]
25
25
  def initialize(options)
26
26
  @options = options
27
27
  end
@@ -50,6 +50,8 @@ module MailRoom
50
50
  Delivery::LetterOpener
51
51
  when "sidekiq"
52
52
  Delivery::Sidekiq
53
+ when "que"
54
+ Delivery::Que
53
55
  else
54
56
  Delivery::Postback
55
57
  end
@@ -1,4 +1,4 @@
1
1
  module MailRoom
2
2
  # Current version of MailRoom gem
3
- VERSION = "0.4.2"
3
+ VERSION = "0.5.0"
4
4
  end
data/mail_room.gemspec CHANGED
@@ -28,4 +28,5 @@ Gem::Specification.new do |gem|
28
28
  gem.add_development_dependency "mail"
29
29
  gem.add_development_dependency "letter_opener"
30
30
  gem.add_development_dependency "redis"
31
+ gem.add_development_dependency "pg"
31
32
  end
@@ -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.2
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-08-31 00:00:00.000000000 Z
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