redimap 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -22
- data/bin/redimap +16 -27
- data/lib/redimap.rb +61 -1
- data/lib/redimap/config.rb +1 -4
- data/lib/redimap/imap_conn.rb +1 -3
- data/lib/redimap/redis_conn.rb +5 -7
- data/lib/redimap/version.rb +1 -1
- data/redimap.gemspec +0 -1
- data/test/redimap.rb +4 -0
- data/test/redimap/config.rb +52 -0
- data/test/redimap/imap_conn.rb +115 -0
- data/test/redimap/redis_conn.rb +127 -0
- data/test/redimap/version.rb +12 -0
- metadata +12 -25
- data/lib/redimap/base.rb +0 -59
- data/spec/lib/redimap/config_spec.rb +0 -97
- data/spec/lib/redimap/core_spec.rb +0 -12
- data/spec/lib/redimap/imap_conn_spec.rb +0 -52
- data/spec/spec_helper.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c929905574855a252e70b27eebd917bbc2e2d5f
|
4
|
+
data.tar.gz: 14cdb430a27e403bad32c1a0345ab614143fc908
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3466b8be78651950fca40f63dac8db31213410178e7441330df2c241d136ccc85eb1cfe6179802403eab16f2d76942305fe2a6786667ecd45d3a15cd98fcf1b
|
7
|
+
data.tar.gz: 4025d34af7d0e5c956ef1669cb2ae446e6647e72b266d00ee802173b54f40f21316c2902277d2d9dcc25ade2198517a7d15cc0c95881ee77f8b2b4e106137bb8
|
data/README.md
CHANGED
@@ -26,29 +26,9 @@ Most settings have defaults, but it is necessary to at least set up IMAP.
|
|
26
26
|
|
27
27
|
Check and queue new messages and quit:
|
28
28
|
|
29
|
-
$ bundle exec redimap --host mail.example.com --
|
29
|
+
$ bundle exec redimap --imap-host mail.example.com --imap-username a@example.com --imap-password helpimacarrot
|
30
30
|
|
31
|
-
|
32
|
-
options override environment variables. Note that environment variables are in
|
33
|
-
lowercase, and are named differently to command-line parameters.
|
34
|
-
|
35
|
-
$ imap_host=mail.example.com imap_user=a@example.com imap_password=helpimacarrot bundle exec redimap
|
36
|
-
|
37
|
-
The complete list of available environment variables is:
|
38
|
-
|
39
|
-
eternal
|
40
|
-
log_level
|
41
|
-
imap_host
|
42
|
-
imap_port
|
43
|
-
imap_username
|
44
|
-
imap_password
|
45
|
-
imap_mailboxes
|
46
|
-
redis_url
|
47
|
-
redis_ns_redimap
|
48
|
-
redis_ns_queue
|
49
|
-
polling_interval
|
50
|
-
|
51
|
-
Use `--eternal` or `eternal=1` to run eternally.
|
31
|
+
Use `--eternal` to run eternally.
|
52
32
|
|
53
33
|
|
54
34
|
## Contributions
|
@@ -60,6 +40,17 @@ doing or planning to do, or if you get stuck on something, then just wave. :)
|
|
60
40
|
|
61
41
|
Do whatever makes you happy. We'll probably still like you. :)
|
62
42
|
|
43
|
+
Tests are written using [minitest](https://github.com/seattlerb/minitest), which
|
44
|
+
is included by default in Ruby 1.9 onwards. To run all tests in a pretty way:
|
45
|
+
|
46
|
+
ruby -rminitest/pride test/redimap.rb
|
47
|
+
|
48
|
+
Or, if you're of that turn of mind, use [TURN](https://github.com/TwP/turn)
|
49
|
+
(`gem install turn`):
|
50
|
+
|
51
|
+
turn test/redimap.rb
|
52
|
+
|
53
|
+
|
63
54
|
## Blessing
|
64
55
|
|
65
56
|
May you find peace, and help others to do likewise.
|
data/bin/redimap
CHANGED
@@ -67,7 +67,7 @@ OptionParser.new do |opts|
|
|
67
67
|
opts.separator "Other:"
|
68
68
|
|
69
69
|
opts.on("-v", "--[no-]verbose", "Be somewhat verbose") do |o|
|
70
|
-
options[:
|
70
|
+
options[:verbose] = o
|
71
71
|
end
|
72
72
|
|
73
73
|
opts.on_tail("--help", "Show this message") do
|
@@ -85,31 +85,20 @@ end.parse!
|
|
85
85
|
# = Configure
|
86
86
|
|
87
87
|
Redimap.configure do |c|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
ENV[e_k].to_i
|
103
|
-
when 'imap_mailboxes'
|
104
|
-
ENV[e_k].split(',')
|
105
|
-
else
|
106
|
-
ENV[e_k]
|
107
|
-
end if ENV[e_k] # Read env var if set, parsing as for params.
|
108
|
-
|
109
|
-
e_v = options[e_k.to_sym] if options[e_k.to_sym] # Override from params.
|
110
|
-
|
111
|
-
c.instance_variable_set("@#{e_k}", e_v) if e_v # Only set extant settings.
|
112
|
-
end
|
88
|
+
c.log_level = 'DEBUG' if options[:verbose]
|
89
|
+
|
90
|
+
c.imap_host = options[:imap_host] if options[:imap_host]
|
91
|
+
c.imap_port = options[:imap_port] if options[:imap_port]
|
92
|
+
c.imap_username = options[:imap_username] if options[:imap_username]
|
93
|
+
c.imap_password = options[:imap_password] if options[:imap_password]
|
94
|
+
|
95
|
+
c.imap_mailboxes = options[:imap_mailboxes] if options[:imap_mailboxes]
|
96
|
+
|
97
|
+
c.redis_url = options[:redis_url] if options[:redis_url]
|
98
|
+
c.redis_ns_redimap = options[:redis_ns_redimap] if options[:redis_ns_redimap]
|
99
|
+
c.redis_ns_queue = options[:redis_ns_queue] if options[:redis_ns_queue]
|
100
|
+
|
101
|
+
c.polling_interval = options[:polling_interval] if options[:polling_interval]
|
113
102
|
end
|
114
103
|
|
115
104
|
@logger = Redimap.logger
|
@@ -120,7 +109,7 @@ end
|
|
120
109
|
loop do
|
121
110
|
Redimap.queue_new_mailboxes_uids
|
122
111
|
|
123
|
-
break unless
|
112
|
+
break unless options[:eternal]
|
124
113
|
|
125
114
|
@logger.debug { "Snoring for #{Redimap.config.polling_interval} s" }
|
126
115
|
|
data/lib/redimap.rb
CHANGED
@@ -1,5 +1,65 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
require_relative 'redimap/version'
|
2
4
|
require_relative 'redimap/config'
|
3
|
-
|
5
|
+
|
4
6
|
require_relative 'redimap/imap_conn'
|
5
7
|
require_relative 'redimap/redis_conn'
|
8
|
+
|
9
|
+
|
10
|
+
module Redimap
|
11
|
+
|
12
|
+
extend self
|
13
|
+
|
14
|
+
def config
|
15
|
+
@config ||= Redimap::Config.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield config
|
20
|
+
|
21
|
+
Redimap.logger.debug { "Configured #{Redimap.config.to_s}" }
|
22
|
+
end
|
23
|
+
|
24
|
+
def logger
|
25
|
+
unless @logger
|
26
|
+
@logger = Logger.new($stdout)
|
27
|
+
|
28
|
+
@logger.level = Logger.const_get(Redimap.config.log_level)
|
29
|
+
@logger.progname = :Redimap
|
30
|
+
end
|
31
|
+
|
32
|
+
@logger
|
33
|
+
end
|
34
|
+
|
35
|
+
def queue_new_mailboxes_uids
|
36
|
+
Redimap.logger.info { "Queueing new mailboxes UIDs" }
|
37
|
+
|
38
|
+
Redimap::ImapConn.new do |imap|
|
39
|
+
Redimap::RedisConn.new do |redis|
|
40
|
+
begin
|
41
|
+
Redimap.config.imap_mailboxes.each do |mailbox|
|
42
|
+
last_seen_uid = redis.get_mailbox_uid(mailbox)
|
43
|
+
|
44
|
+
Redimap.logger.debug { "Last saw #{mailbox}##{last_seen_uid}" }
|
45
|
+
|
46
|
+
unseen_uids = imap.read_mailbox(mailbox, last_seen_uid)
|
47
|
+
|
48
|
+
unseen_uids.each do |uid|
|
49
|
+
redis.queue_mailbox_uid(mailbox, uid)
|
50
|
+
|
51
|
+
redis.set_mailbox_uid(mailbox, uid)
|
52
|
+
end
|
53
|
+
|
54
|
+
Redimap.logger.info { "Queued #{unseen_uids.count} UIDs from #{mailbox}" }
|
55
|
+
end
|
56
|
+
rescue Net::IMAP::Error, Redis::BaseError => e
|
57
|
+
Redimap.logger.error { e.to_s }
|
58
|
+
|
59
|
+
return
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/lib/redimap/config.rb
CHANGED
data/lib/redimap/imap_conn.rb
CHANGED
@@ -5,8 +5,6 @@ module Redimap
|
|
5
5
|
class ImapConn
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@logger = Redimap.logger
|
9
|
-
|
10
8
|
begin
|
11
9
|
@imap = Net::IMAP.new(Redimap.config.imap_host, {
|
12
10
|
:port => Redimap.config.imap_port,
|
@@ -15,7 +13,7 @@ module Redimap
|
|
15
13
|
|
16
14
|
@imap.login(Redimap.config.imap_username, Redimap.config.imap_password)
|
17
15
|
rescue Net::IMAP::NoResponseError => e
|
18
|
-
|
16
|
+
Redimap.logger.error { e.to_s }
|
19
17
|
|
20
18
|
return
|
21
19
|
end
|
data/lib/redimap/redis_conn.rb
CHANGED
@@ -10,22 +10,20 @@ module Redimap
|
|
10
10
|
@@RESCUE_CLASS = 'RedimapJob'
|
11
11
|
|
12
12
|
def initialize
|
13
|
-
@logger = Redimap.logger
|
14
|
-
|
15
13
|
begin
|
16
14
|
@redis = Redis.connect(:url => Redimap.config.redis_url)
|
17
15
|
|
18
16
|
@redis.ping
|
19
17
|
rescue Redis::CannotConnectError => e
|
20
|
-
|
18
|
+
Redimap.logger.error { e.to_s }
|
21
19
|
|
22
20
|
return
|
23
21
|
end
|
24
22
|
|
25
23
|
@KEYS = {
|
26
24
|
:redimap_mailboxes => "#{Redimap.config.redis_ns_redimap}:mailboxes",
|
27
|
-
:
|
28
|
-
:
|
25
|
+
:resque_queues => "#{Redimap.config.redis_ns_queue}:queues",
|
26
|
+
:resque_queue_redimap => "#{Redimap.config.redis_ns_queue}:queue:#{@@RESCUE_QUEUE}",
|
29
27
|
}.freeze
|
30
28
|
|
31
29
|
if block_given?
|
@@ -48,9 +46,9 @@ module Redimap
|
|
48
46
|
end
|
49
47
|
|
50
48
|
def queue_mailbox_uid(mailbox, uid)
|
51
|
-
@redis.sadd(@KEYS[:
|
49
|
+
@redis.sadd(@KEYS[:resque_queues], @@RESCUE_QUEUE)
|
52
50
|
|
53
|
-
@redis.rpush(@KEYS[:
|
51
|
+
@redis.rpush(@KEYS[:resque_queue_redimap], payload(mailbox, uid))
|
54
52
|
end
|
55
53
|
|
56
54
|
private
|
data/lib/redimap/version.rb
CHANGED
data/redimap.gemspec
CHANGED
data/test/redimap.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative '../../lib/redimap/config'
|
4
|
+
|
5
|
+
|
6
|
+
describe Redimap::Config do
|
7
|
+
|
8
|
+
describe "default" do
|
9
|
+
before do
|
10
|
+
@config = Redimap::Config.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets log_level to INFO" do
|
14
|
+
@config.log_level.must_equal 'INFO'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets imap_port to 993" do
|
18
|
+
@config.imap_port.must_equal 993
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets imap_mailboxes to INBOX" do
|
22
|
+
@config.imap_mailboxes.must_equal ['INBOX']
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets redis_url to redis://127.0.0.1:6379/0" do
|
26
|
+
@config.redis_url.must_equal 'redis://127.0.0.1:6379/0'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets redis_ns_redimap to redimap" do
|
30
|
+
@config.redis_ns_redimap.must_equal 'redimap'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets redis_ns_queue to resque" do
|
34
|
+
@config.redis_ns_queue.must_equal 'resque'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets polling_interval to 60" do
|
38
|
+
@config.polling_interval.must_equal 60
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#to_s" do
|
43
|
+
before do
|
44
|
+
@config = Redimap::Config.new
|
45
|
+
end
|
46
|
+
|
47
|
+
it "stringifies hash of config" do
|
48
|
+
@config.to_s.must_equal '{:log_level=>"INFO", :imap_host=>nil, :imap_port=>993, :imap_username=>nil, :imap_mailboxes=>["INBOX"], :redis_url=>"redis://127.0.0.1:6379/0", :redis_ns_redimap=>"redimap", :redis_ns_queue=>"resque", :polling_interval=>60}'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative '../../lib/redimap'
|
4
|
+
require_relative '../../lib/redimap/imap_conn'
|
5
|
+
|
6
|
+
|
7
|
+
describe Redimap::ImapConn do
|
8
|
+
|
9
|
+
def imap_conn_new
|
10
|
+
@net_imap = Minitest::Mock.new
|
11
|
+
@net_imap.expect(:login, nil, [nil, nil])
|
12
|
+
|
13
|
+
Net::IMAP.stub(:new, @net_imap) do
|
14
|
+
@imap_conn = Redimap::ImapConn.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#initialize" do
|
19
|
+
before do
|
20
|
+
@config = Redimap::Config.new
|
21
|
+
|
22
|
+
@net_imap = Minitest::Mock.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it "connects with correct imap_username,imap_password" do
|
26
|
+
@net_imap.expect(:login, nil, ["schoenberg@example.com", "DerKrankeMond"])
|
27
|
+
|
28
|
+
@config.imap_username = "schoenberg@example.com"
|
29
|
+
@config.imap_password = "DerKrankeMond"
|
30
|
+
|
31
|
+
Net::IMAP.stub(:new, @net_imap) do
|
32
|
+
Redimap.stub(:config, @config) do
|
33
|
+
@imap_conn = Redimap::ImapConn.new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
@net_imap.verify
|
38
|
+
end
|
39
|
+
|
40
|
+
it "connects with correct imap_host" do
|
41
|
+
@net_imap.expect(:login, nil, [nil, nil])
|
42
|
+
|
43
|
+
@config.imap_host = 'arnold.example.com'
|
44
|
+
|
45
|
+
Net::IMAP.stub(:new, lambda { |imap_host, params|
|
46
|
+
imap_host.must_equal('arnold.example.com')
|
47
|
+
|
48
|
+
@net_imap
|
49
|
+
}) do
|
50
|
+
Redimap.stub(:config, @config) do
|
51
|
+
@imap_conn = Redimap::ImapConn.new
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "connects with correct imap_port,ssl" do
|
57
|
+
@net_imap.expect(:login, nil, [nil, nil])
|
58
|
+
|
59
|
+
@config.imap_port = 666
|
60
|
+
|
61
|
+
Net::IMAP.stub(:new, lambda { |imap_host, params|
|
62
|
+
params.must_equal({ :port => 666, :ssl => true })
|
63
|
+
|
64
|
+
@net_imap
|
65
|
+
}) do
|
66
|
+
Redimap.stub(:config, @config) do
|
67
|
+
@imap_conn = Redimap::ImapConn.new
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#close" do
|
74
|
+
before do
|
75
|
+
imap_conn_new
|
76
|
+
end
|
77
|
+
|
78
|
+
it "disconnects from mailbox" do
|
79
|
+
@net_imap.expect(:logout, nil)
|
80
|
+
@net_imap.expect(:disconnect, nil)
|
81
|
+
|
82
|
+
@imap_conn.close
|
83
|
+
|
84
|
+
@net_imap.verify
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#read_mailbox" do
|
89
|
+
before do
|
90
|
+
imap_conn_new
|
91
|
+
end
|
92
|
+
|
93
|
+
it "gets all INBOX uids when default" do
|
94
|
+
@net_imap.expect(:select, nil, ['INBOX'])
|
95
|
+
@net_imap.expect(:uid_search, [1, 2, 3], ['1:*'])
|
96
|
+
|
97
|
+
@imap_conn.read_mailbox.must_equal [1, 2, 3]
|
98
|
+
end
|
99
|
+
|
100
|
+
it "gets all Sent uids when mailbox:Sent" do
|
101
|
+
@net_imap.expect(:select, nil, ['Sent'])
|
102
|
+
@net_imap.expect(:uid_search, [1, 2, 3], ['1:*'])
|
103
|
+
|
104
|
+
@imap_conn.read_mailbox('Sent').must_equal [1, 2, 3]
|
105
|
+
end
|
106
|
+
|
107
|
+
it "gets new Sent uids when mailbox:Sent,last_seen_uid:2" do
|
108
|
+
@net_imap.expect(:select, nil, ['Sent'])
|
109
|
+
@net_imap.expect(:uid_search, [1, 2, 3], ['3:*'])
|
110
|
+
|
111
|
+
@imap_conn.read_mailbox('Sent', 2).must_equal [3]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require_relative '../../lib/redimap'
|
6
|
+
require_relative '../../lib/redimap/redis_conn'
|
7
|
+
|
8
|
+
|
9
|
+
describe Redimap::RedisConn do
|
10
|
+
|
11
|
+
def redis_conn_new
|
12
|
+
@redis = Minitest::Mock.new
|
13
|
+
@redis.expect(:ping, nil)
|
14
|
+
|
15
|
+
Redis.stub(:connect, @redis) do
|
16
|
+
@redis_conn = Redimap::RedisConn.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#initialize" do
|
21
|
+
before do
|
22
|
+
@config = Redimap::Config.new
|
23
|
+
|
24
|
+
@redis = Minitest::Mock.new
|
25
|
+
@redis.expect(:ping, nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "connects with correct url" do
|
29
|
+
@config.redis_url = 'redis://bminor.example.com:6379/7'
|
30
|
+
|
31
|
+
Redis.stub(:connect, lambda { |params|
|
32
|
+
params.must_equal({ :url => 'redis://bminor.example.com:6379/7' })
|
33
|
+
|
34
|
+
@redis
|
35
|
+
}) do
|
36
|
+
Redimap.stub(:config, @config) do
|
37
|
+
@redis_conn = Redimap::RedisConn.new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sets up KEYS semi-constants" do
|
43
|
+
@config.redis_ns_redimap = 'reetabix'
|
44
|
+
@config.redis_ns_queue = 'magicmango'
|
45
|
+
|
46
|
+
Redimap.stub(:config, @config) do
|
47
|
+
redis_conn_new
|
48
|
+
end
|
49
|
+
|
50
|
+
@redis_conn.instance_variable_get("@KEYS").must_equal({
|
51
|
+
:redimap_mailboxes => 'reetabix:mailboxes',
|
52
|
+
:resque_queues => 'magicmango:queues',
|
53
|
+
:resque_queue_redimap => 'magicmango:queue:redimap',
|
54
|
+
})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#close" do
|
59
|
+
before do
|
60
|
+
redis_conn_new
|
61
|
+
end
|
62
|
+
|
63
|
+
it "disconnects" do
|
64
|
+
@redis.expect(:quit, nil)
|
65
|
+
|
66
|
+
@redis_conn.close
|
67
|
+
|
68
|
+
@redis.verify
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#get_mailbox_uid" do
|
73
|
+
before do
|
74
|
+
redis_conn_new
|
75
|
+
end
|
76
|
+
|
77
|
+
it "gets uid for mailbox when existing" do
|
78
|
+
@redis.expect(:hget, 17, ['redimap:mailboxes', 'Badger'])
|
79
|
+
|
80
|
+
@redis_conn.get_mailbox_uid('Badger').must_equal(17)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "gets uid for mailbox when new" do
|
84
|
+
@redis.expect(:hget, nil, ['redimap:mailboxes', 'Badger'])
|
85
|
+
|
86
|
+
@redis_conn.get_mailbox_uid('Badger').must_equal(0)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#set_mailbox_uid" do
|
91
|
+
before do
|
92
|
+
redis_conn_new
|
93
|
+
end
|
94
|
+
|
95
|
+
it "sets uid for mailbox" do
|
96
|
+
@redis.expect(:hset, nil, ['redimap:mailboxes', 'Ferret', 99])
|
97
|
+
|
98
|
+
@redis_conn.set_mailbox_uid('Ferret', 99)
|
99
|
+
|
100
|
+
@redis.verify
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#queue_mailbox_uid" do
|
105
|
+
before do
|
106
|
+
redis_conn_new
|
107
|
+
end
|
108
|
+
|
109
|
+
it "adds queue to set of queues and pushes job onto queue" do
|
110
|
+
@redis.expect(:sadd, nil, ['resque:queues', 'redimap'])
|
111
|
+
@redis.expect(:rpush, nil, ['resque:queue:redimap', {
|
112
|
+
'class' => 'RedimapJob',
|
113
|
+
'args' => ['Hedgehog', 49],
|
114
|
+
'queue' => 'redimap',
|
115
|
+
'retry' => true,
|
116
|
+
'jid' => 'ohsorandom',
|
117
|
+
}.to_json])
|
118
|
+
|
119
|
+
SecureRandom.stub(:hex, 'ohsorandom') do
|
120
|
+
@redis_conn.queue_mailbox_uid('Hedgehog', 49)
|
121
|
+
end
|
122
|
+
|
123
|
+
@redis.verify
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redimap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tiredpixel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
description: |-
|
70
56
|
Redimap provides a simple executable for polling mailboxes
|
71
57
|
within an IMAP account. It keeps track of what it's seen using Redis. For new
|
@@ -87,16 +73,16 @@ files:
|
|
87
73
|
- Rakefile
|
88
74
|
- bin/redimap
|
89
75
|
- lib/redimap.rb
|
90
|
-
- lib/redimap/base.rb
|
91
76
|
- lib/redimap/config.rb
|
92
77
|
- lib/redimap/imap_conn.rb
|
93
78
|
- lib/redimap/redis_conn.rb
|
94
79
|
- lib/redimap/version.rb
|
95
80
|
- redimap.gemspec
|
96
|
-
-
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
81
|
+
- test/redimap.rb
|
82
|
+
- test/redimap/config.rb
|
83
|
+
- test/redimap/imap_conn.rb
|
84
|
+
- test/redimap/redis_conn.rb
|
85
|
+
- test/redimap/version.rb
|
100
86
|
homepage: https://github.com/tiredpixel/redimap
|
101
87
|
licenses:
|
102
88
|
- MIT
|
@@ -122,7 +108,8 @@ signing_key:
|
|
122
108
|
specification_version: 4
|
123
109
|
summary: Redimap polls IMAP account mailboxes and queues in Redis.
|
124
110
|
test_files:
|
125
|
-
-
|
126
|
-
-
|
127
|
-
-
|
128
|
-
-
|
111
|
+
- test/redimap.rb
|
112
|
+
- test/redimap/config.rb
|
113
|
+
- test/redimap/imap_conn.rb
|
114
|
+
- test/redimap/redis_conn.rb
|
115
|
+
- test/redimap/version.rb
|
data/lib/redimap/base.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
|
4
|
-
module Redimap
|
5
|
-
|
6
|
-
def self.config
|
7
|
-
@config ||= Redimap::Config.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.configure
|
11
|
-
yield self.config
|
12
|
-
|
13
|
-
Redimap.logger.debug { "Configured #{Redimap.config.to_s}" }
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.logger
|
17
|
-
unless @logger
|
18
|
-
@logger = Logger.new($stdout)
|
19
|
-
|
20
|
-
@logger.level = Logger.const_get(Redimap.config.log_level)
|
21
|
-
@logger.progname = :Redimap
|
22
|
-
end
|
23
|
-
|
24
|
-
@logger
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.queue_new_mailboxes_uids
|
28
|
-
@logger = Redimap.logger
|
29
|
-
|
30
|
-
@logger.info { "Queueing new mailboxes UIDs" }
|
31
|
-
|
32
|
-
Redimap::ImapConn.new do |imap|
|
33
|
-
Redimap::RedisConn.new do |redis|
|
34
|
-
begin
|
35
|
-
Redimap.config.imap_mailboxes.each do |mailbox|
|
36
|
-
last_seen_uid = redis.get_mailbox_uid(mailbox)
|
37
|
-
|
38
|
-
@logger.debug { "Last saw #{mailbox}##{last_seen_uid}" }
|
39
|
-
|
40
|
-
unseen_uids = imap.read_mailbox(mailbox, last_seen_uid)
|
41
|
-
|
42
|
-
unseen_uids.each do |uid|
|
43
|
-
redis.queue_mailbox_uid(mailbox, uid)
|
44
|
-
|
45
|
-
redis.set_mailbox_uid(mailbox, uid)
|
46
|
-
end
|
47
|
-
|
48
|
-
@logger.info { "Queued #{unseen_uids.count} UIDs from #{mailbox}" }
|
49
|
-
end
|
50
|
-
rescue Net::IMAP::Error, Redis::BaseError => e
|
51
|
-
@logger.error { e.to_s }
|
52
|
-
|
53
|
-
return
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe Redimap::Config do
|
5
|
-
|
6
|
-
context "Defaults" do
|
7
|
-
it "log_level should default to INFO" do
|
8
|
-
Redimap.config.log_level.should == "INFO"
|
9
|
-
end
|
10
|
-
|
11
|
-
it "imap_port should default to 993" do
|
12
|
-
Redimap.config.imap_port.should == 993
|
13
|
-
end
|
14
|
-
|
15
|
-
it "imap_mailboxes should default to [INBOX]" do
|
16
|
-
Redimap.config.imap_mailboxes.should == ['INBOX']
|
17
|
-
end
|
18
|
-
|
19
|
-
it "redis_url should default to redis://127.0.0.1:6379/0" do
|
20
|
-
Redimap.config.redis_url.should == "redis://127.0.0.1:6379/0"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "redis_ns_redimap should default to redimap" do
|
24
|
-
Redimap.config.redis_ns_redimap.should == "redimap"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "redis_ns_queue should default to resque" do
|
28
|
-
Redimap.config.redis_ns_queue.should == "resque"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "polling_interval should default to 60 seconds" do
|
32
|
-
Redimap.config.polling_interval.should == 60
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "Non-defaults" do
|
37
|
-
before(:each) do
|
38
|
-
Redimap.configure do |c|
|
39
|
-
c.log_level = "WARN"
|
40
|
-
|
41
|
-
c.imap_host = "imap.carrot.localhost"
|
42
|
-
c.imap_port = 666
|
43
|
-
c.imap_username = "Pachelbel"
|
44
|
-
c.imap_password = "Canon"
|
45
|
-
|
46
|
-
c.imap_mailboxes = ['INBOX', 'SENT']
|
47
|
-
|
48
|
-
c.redis_url = "redis://127.0.0.1:6379/1"
|
49
|
-
c.redis_ns_redimap = "brekyread"
|
50
|
-
c.redis_ns_queue = "sidekiq"
|
51
|
-
|
52
|
-
c.polling_interval = 300
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
it "log_level should get set" do
|
57
|
-
Redimap.config.log_level.should == "WARN"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "imap_host should get set" do
|
61
|
-
Redimap.config.imap_host.should == "imap.carrot.localhost"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "imap_port should get set" do
|
65
|
-
Redimap.config.imap_port.should == 666
|
66
|
-
end
|
67
|
-
|
68
|
-
it "imap_username should get set" do
|
69
|
-
Redimap.config.imap_username.should == "Pachelbel"
|
70
|
-
end
|
71
|
-
|
72
|
-
it "imap_password should get set" do
|
73
|
-
Redimap.config.imap_password.should == "Canon"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "imap_mailboxes should get set" do
|
77
|
-
Redimap.config.imap_mailboxes.should == ['INBOX', 'SENT']
|
78
|
-
end
|
79
|
-
|
80
|
-
it "redis_url should get set" do
|
81
|
-
Redimap.config.redis_url.should == "redis://127.0.0.1:6379/1"
|
82
|
-
end
|
83
|
-
|
84
|
-
it "redis_ns_redimap should get set" do
|
85
|
-
Redimap.config.redis_ns_redimap.should == "brekyread"
|
86
|
-
end
|
87
|
-
|
88
|
-
it "redis_ns_queue should get set" do
|
89
|
-
Redimap.config.redis_ns_queue.should == "sidekiq"
|
90
|
-
end
|
91
|
-
|
92
|
-
it "polling_interval should get set" do
|
93
|
-
Redimap.config.polling_interval.should == 300
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'net/imap'
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
|
6
|
-
describe Redimap::ImapConn do
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
@fake_net_imap = double(Net::IMAP)
|
10
|
-
|
11
|
-
Net::IMAP.stub(:new).and_return(@fake_net_imap)
|
12
|
-
|
13
|
-
@fake_net_imap.stub(:login)
|
14
|
-
end
|
15
|
-
|
16
|
-
context "#initialize" do
|
17
|
-
it "should set imap as Net::IMAP" do
|
18
|
-
Redimap::ImapConn.new.instance_variable_get('@imap').should == @fake_net_imap
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should #close when block" do
|
22
|
-
Redimap::ImapConn.new do |imap|
|
23
|
-
imap.should_receive(:close)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "#close" do
|
29
|
-
before(:each) do
|
30
|
-
@imap = Redimap::ImapConn.new
|
31
|
-
|
32
|
-
@imap_imap = @imap.instance_variable_get('@imap')
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should disconnect from IMAP" do
|
36
|
-
@imap_imap.stub(:logout)
|
37
|
-
|
38
|
-
@imap_imap.should_receive(:disconnect)
|
39
|
-
|
40
|
-
@imap.close
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should logout from IMAP" do
|
44
|
-
@imap_imap.stub(:disconnect)
|
45
|
-
|
46
|
-
@imap_imap.should_receive(:logout)
|
47
|
-
|
48
|
-
@imap.close
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|