redimap 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +16 -17
- data/README.md +2 -2
- data/bin/redimap +20 -7
- data/lib/redimap.rb +1 -1
- data/lib/redimap/{core.rb → base.rb} +2 -2
- data/lib/redimap/config.rb +9 -9
- data/lib/redimap/imap_conn.rb +0 -2
- data/lib/redimap/redis_conn.rb +26 -25
- data/lib/redimap/version.rb +1 -1
- data/spec/lib/redimap/config_spec.rb +2 -1
- data/spec/lib/redimap/core_spec.rb +1 -0
- data/spec/lib/redimap/imap_conn_spec.rb +8 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6528b99d1b6dcd904c2c60b2e2a292cc6c88210
|
4
|
+
data.tar.gz: 1937d909847c35c540556241434fac179782280d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5138560b0e28a1b78f7cd0abfefd95d19bca1fa73a7ade2ca86cf925f08576daca78e9169e06e024f851c922594bc139275c864dc1b2838c9165a12d66a248b3
|
7
|
+
data.tar.gz: 4279f416c647a13cad78b80e149e4974e1aca47e8ba17fb75413d5ea697f3ce744939b356ff19f110f77df460e69e06a3efd0252a9a05c7e605a36d1107bb1cb
|
data/.gitignore
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/
|
16
|
-
|
17
|
-
tmp
|
1
|
+
/*.gem
|
2
|
+
/*.rbc
|
3
|
+
/.bundle/
|
4
|
+
/.config
|
5
|
+
/.yardoc/
|
6
|
+
/Gemfile.lock
|
7
|
+
/InstalledFiles
|
8
|
+
/_yardoc/
|
9
|
+
/coverage/
|
10
|
+
/doc/
|
11
|
+
/lib/bundler/man/
|
12
|
+
/pkg/
|
13
|
+
/rdoc/
|
14
|
+
/spec/reports/
|
15
|
+
/test/version_tmp/
|
16
|
+
/tmp/
|
data/README.md
CHANGED
@@ -29,9 +29,9 @@ Check and queue new messages and quit:
|
|
29
29
|
|
30
30
|
$ bundle exec redimap
|
31
31
|
|
32
|
-
Check and queue new messages but run for eternity
|
32
|
+
Check and queue new messages but run for eternity:
|
33
33
|
|
34
|
-
$ bundle exec redimap
|
34
|
+
$ bundle exec redimap --eternal
|
35
35
|
|
36
36
|
|
37
37
|
## Contributions
|
data/bin/redimap
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'optparse'
|
4
|
+
|
3
5
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/redimap')
|
4
6
|
|
5
7
|
|
6
|
-
|
8
|
+
# = Parse opts
|
9
|
+
|
10
|
+
options = {}
|
7
11
|
|
8
|
-
|
9
|
-
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: redimap [options]"
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
running = false
|
15
|
+
opts.on("-e", "--eternal", "Run eternally") do |e|
|
16
|
+
options[:eternal] = true
|
15
17
|
end
|
18
|
+
end.parse!
|
19
|
+
|
20
|
+
|
21
|
+
# = Main loop
|
22
|
+
|
23
|
+
loop do
|
24
|
+
Redimap.queue_new_mailboxes_uids
|
25
|
+
|
26
|
+
break unless options[:eternal]
|
27
|
+
|
28
|
+
sleep Redimap.config.polling_interval # Sleep awhile.
|
16
29
|
end
|
data/lib/redimap.rb
CHANGED
@@ -5,10 +5,10 @@ module Redimap
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.configure
|
8
|
-
yield config
|
8
|
+
yield @config
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
11
|
+
def self.queue_new_mailboxes_uids
|
12
12
|
Redimap::ImapConn.new do |imap|
|
13
13
|
Redimap::RedisConn.new do |redis|
|
14
14
|
Redimap.config.imap_mailboxes.each do |mailbox|
|
data/lib/redimap/config.rb
CHANGED
@@ -4,18 +4,18 @@ require 'json'
|
|
4
4
|
module Redimap
|
5
5
|
class Config
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
attr_accessor :imap_host
|
8
|
+
attr_accessor :imap_port
|
9
|
+
attr_accessor :imap_username
|
10
|
+
attr_accessor :imap_password
|
11
11
|
|
12
|
-
|
12
|
+
attr_accessor :imap_mailboxes
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
attr_accessor :redis_url
|
15
|
+
attr_accessor :redis_ns_redimap
|
16
|
+
attr_accessor :redis_ns_queue
|
17
17
|
|
18
|
-
|
18
|
+
attr_accessor :polling_interval
|
19
19
|
|
20
20
|
def initialize
|
21
21
|
@imap_host = ENV['IMAP_HOST']
|
data/lib/redimap/imap_conn.rb
CHANGED
data/lib/redimap/redis_conn.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
require 'redis'
|
2
2
|
require 'json'
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
|
5
6
|
module Redimap
|
6
7
|
class RedisConn
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
attr_accessor :redis
|
9
|
+
@@RESCUE_QUEUE = 'redimap'
|
10
|
+
@@RESCUE_CLASS = 'RedimapJob'
|
12
11
|
|
13
12
|
def initialize
|
14
13
|
@redis = Redis.connect(:url => Redimap.config.redis_url)
|
15
14
|
|
15
|
+
@KEYS = {
|
16
|
+
:redimap_mailboxes => "#{Redimap.config.redis_ns_redimap}:mailboxes",
|
17
|
+
:rescue_queues => "#{Redimap.config.redis_ns_queue}:queues",
|
18
|
+
:rescue_queue_redimap => "#{Redimap.config.redis_ns_queue}:queue:#{@@RESCUE_QUEUE}",
|
19
|
+
}.freeze
|
20
|
+
|
16
21
|
if block_given?
|
17
22
|
yield self
|
18
23
|
|
@@ -27,35 +32,31 @@ module Redimap
|
|
27
32
|
end
|
28
33
|
|
29
34
|
def get_mailbox_uid(mailbox)
|
30
|
-
@redis.hget(
|
31
|
-
"#{Redimap.config.redis_ns_redimap}:mailboxes",
|
32
|
-
mailbox
|
33
|
-
).to_i # Also handles nil.
|
35
|
+
@redis.hget(@KEYS[:redimap_mailboxes], mailbox).to_i # Also handles nil.
|
34
36
|
end
|
35
37
|
|
36
38
|
def set_mailbox_uid(mailbox, uid)
|
37
|
-
@redis.hset(
|
38
|
-
"#{Redimap.config.redis_ns_redimap}:mailboxes",
|
39
|
-
mailbox,
|
40
|
-
uid
|
41
|
-
)
|
39
|
+
@redis.hset(@KEYS[:redimap_mailboxes], mailbox, uid)
|
42
40
|
end
|
43
41
|
|
44
42
|
def queue_mailbox_uid(mailbox, uid)
|
45
|
-
@redis.sadd(
|
46
|
-
"#{Redimap.config.redis_ns_queue}:queues",
|
47
|
-
QUEUE_QUEUE
|
48
|
-
)
|
43
|
+
@redis.sadd(@KEYS[:rescue_queues], @@RESCUE_QUEUE)
|
49
44
|
|
50
|
-
payload
|
51
|
-
|
52
|
-
|
45
|
+
@redis.rpush(@KEYS[:rescue_queue_redimap], payload(mailbox, uid))
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def payload(mailbox, uid)
|
51
|
+
{
|
52
|
+
# resque
|
53
|
+
:class => @@RESCUE_CLASS,
|
54
|
+
:args => [mailbox, uid],
|
55
|
+
# sidekiq (extra)
|
56
|
+
:queue => @@RESCUE_QUEUE,
|
57
|
+
:retry => true,
|
58
|
+
:jid => SecureRandom.hex(12),
|
53
59
|
}.to_json
|
54
|
-
|
55
|
-
@redis.rpush(
|
56
|
-
"#{Redimap.config.redis_ns_queue}:queue:#{QUEUE_QUEUE}",
|
57
|
-
payload
|
58
|
-
)
|
59
60
|
end
|
60
61
|
|
61
62
|
end
|
data/lib/redimap/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
|
3
4
|
describe Redimap::Config do
|
4
5
|
|
5
6
|
context "Defaults" do
|
@@ -29,7 +30,7 @@ describe Redimap::Config do
|
|
29
30
|
@config.redis_ns_queue.should == "resque"
|
30
31
|
end
|
31
32
|
|
32
|
-
it "
|
33
|
+
it "polling_interval should default to 60 seconds" do
|
33
34
|
@config.polling_interval.should == 60
|
34
35
|
end
|
35
36
|
end
|
@@ -2,6 +2,7 @@ require 'net/imap'
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
+
|
5
6
|
describe Redimap::ImapConn do
|
6
7
|
|
7
8
|
before(:each) do
|
@@ -14,7 +15,7 @@ describe Redimap::ImapConn do
|
|
14
15
|
|
15
16
|
context "#initialize" do
|
16
17
|
it "should set imap as Net::IMAP" do
|
17
|
-
Redimap::ImapConn.new.imap.should == @fake_net_imap
|
18
|
+
Redimap::ImapConn.new.instance_variable_get('@imap').should == @fake_net_imap
|
18
19
|
end
|
19
20
|
|
20
21
|
it "should #close when block" do
|
@@ -27,20 +28,22 @@ describe Redimap::ImapConn do
|
|
27
28
|
context "#close" do
|
28
29
|
before(:each) do
|
29
30
|
@imap = Redimap::ImapConn.new
|
31
|
+
|
32
|
+
@imap_imap = @imap.instance_variable_get('@imap')
|
30
33
|
end
|
31
34
|
|
32
35
|
it "should disconnect from IMAP" do
|
33
|
-
@
|
36
|
+
@imap_imap.stub(:logout)
|
34
37
|
|
35
|
-
@
|
38
|
+
@imap_imap.should_receive(:disconnect)
|
36
39
|
|
37
40
|
@imap.close
|
38
41
|
end
|
39
42
|
|
40
43
|
it "should logout from IMAP" do
|
41
|
-
@
|
44
|
+
@imap_imap.stub(:disconnect)
|
42
45
|
|
43
|
-
@
|
46
|
+
@imap_imap.should_receive(:logout)
|
44
47
|
|
45
48
|
@imap.close
|
46
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redimap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tiredpixel
|
@@ -87,8 +87,8 @@ files:
|
|
87
87
|
- Rakefile
|
88
88
|
- bin/redimap
|
89
89
|
- lib/redimap.rb
|
90
|
+
- lib/redimap/base.rb
|
90
91
|
- lib/redimap/config.rb
|
91
|
-
- lib/redimap/core.rb
|
92
92
|
- lib/redimap/imap_conn.rb
|
93
93
|
- lib/redimap/redis_conn.rb
|
94
94
|
- lib/redimap/version.rb
|