redimap 0.2.0 → 0.3.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 +4 -4
- data/README.md +3 -2
- data/bin/redimap +4 -0
- data/lib/redimap/base.rb +37 -9
- data/lib/redimap/config.rb +20 -0
- data/lib/redimap/imap_conn.rb +14 -10
- data/lib/redimap/redis_conn.rb +12 -4
- data/lib/redimap/version.rb +1 -1
- data/redimap.gemspec +3 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aae1058590d80f17e8db74f6958c9f6f4298e2f
|
4
|
+
data.tar.gz: 7210171c97d686c2621c0c80c8d95e3e4bb9e7c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d577b5997aaab61c5d2671b500c1f7a537e4b3cd747e659979c369eaf3a69f8504527f69f53ed918ba1c481ddab124b7936cef620cdcc8e24c0882bff4545e33
|
7
|
+
data.tar.gz: 90a755ebb2374c138f8008de02053e5a0a8649b37a0481fbac9559ccaf4146b668e483e99d0e54dcf229621d284d5def22171d7fe4f091f763c076b1a2ab2964
|
data/README.md
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
Redimap provides a simple executable for polling mailboxes
|
4
4
|
within an IMAP account. It keeps track of what it's seen using Redis. For new
|
5
|
-
messages, the mailbox and uid are queued in Redis. The format
|
6
|
-
compatible with Resque.
|
5
|
+
messages, the mailbox and uid are queued in Redis. The queue format should be
|
6
|
+
compatible with [Resque](https://github.com/resque/resque) and
|
7
|
+
[Sidekiq](https://github.com/mperham/sidekiq).
|
7
8
|
|
8
9
|
More sleep lost by [tiredpixel](http://www.tiredpixel.com).
|
9
10
|
|
data/bin/redimap
CHANGED
@@ -4,6 +4,8 @@ require 'optparse'
|
|
4
4
|
|
5
5
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/redimap')
|
6
6
|
|
7
|
+
@logger = Redimap.logger
|
8
|
+
|
7
9
|
|
8
10
|
# = Parse opts
|
9
11
|
|
@@ -25,5 +27,7 @@ loop do
|
|
25
27
|
|
26
28
|
break unless options[:eternal]
|
27
29
|
|
30
|
+
@logger.debug { "Snoring for #{Redimap.config.polling_interval} s" }
|
31
|
+
|
28
32
|
sleep Redimap.config.polling_interval # Sleep awhile.
|
29
33
|
end
|
data/lib/redimap/base.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
|
1
4
|
module Redimap
|
2
5
|
|
3
6
|
def self.config
|
@@ -5,22 +8,47 @@ module Redimap
|
|
5
8
|
end
|
6
9
|
|
7
10
|
def self.configure
|
8
|
-
yield
|
11
|
+
yield self.config
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.logger
|
15
|
+
unless @logger
|
16
|
+
@logger = Logger.new($stdout)
|
17
|
+
|
18
|
+
@logger.level = Logger.const_get(ENV['LOG_LEVEL'] || 'INFO')
|
19
|
+
@logger.progname = :Redimap
|
20
|
+
end
|
21
|
+
|
22
|
+
@logger
|
9
23
|
end
|
10
24
|
|
11
25
|
def self.queue_new_mailboxes_uids
|
26
|
+
@logger = Redimap.logger
|
27
|
+
|
28
|
+
@logger.info { "Queueing new mailboxes UIDs" }
|
29
|
+
|
12
30
|
Redimap::ImapConn.new do |imap|
|
13
31
|
Redimap::RedisConn.new do |redis|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
unseen_uids = imap.read_mailbox(mailbox, last_seen_uid)
|
18
|
-
|
19
|
-
unseen_uids.each do |uid|
|
20
|
-
redis.queue_mailbox_uid(mailbox, uid)
|
32
|
+
begin
|
33
|
+
Redimap.config.imap_mailboxes.each do |mailbox|
|
34
|
+
last_seen_uid = redis.get_mailbox_uid(mailbox)
|
21
35
|
|
22
|
-
|
36
|
+
@logger.debug { "Last saw #{mailbox}##{last_seen_uid}" }
|
37
|
+
|
38
|
+
unseen_uids = imap.read_mailbox(mailbox, last_seen_uid)
|
39
|
+
|
40
|
+
unseen_uids.each do |uid|
|
41
|
+
redis.queue_mailbox_uid(mailbox, uid)
|
42
|
+
|
43
|
+
redis.set_mailbox_uid(mailbox, uid)
|
44
|
+
end
|
45
|
+
|
46
|
+
@logger.info { "Queued #{unseen_uids.count} UIDs from #{mailbox}" }
|
23
47
|
end
|
48
|
+
rescue Net::IMAP::Error, Redis::BaseError => e
|
49
|
+
@logger.error { e.to_s }
|
50
|
+
|
51
|
+
return
|
24
52
|
end
|
25
53
|
end
|
26
54
|
end
|
data/lib/redimap/config.rb
CHANGED
@@ -18,6 +18,8 @@ module Redimap
|
|
18
18
|
attr_accessor :polling_interval
|
19
19
|
|
20
20
|
def initialize
|
21
|
+
@logger = Redimap.logger
|
22
|
+
|
21
23
|
@imap_host = ENV['IMAP_HOST']
|
22
24
|
@imap_port = ENV['IMAP_PORT'] || 993
|
23
25
|
@imap_username = ENV['IMAP_USERNAME']
|
@@ -30,6 +32,24 @@ module Redimap
|
|
30
32
|
@redis_ns_queue = ENV['REDIS_NS_QUEUE'] || "resque"
|
31
33
|
|
32
34
|
@polling_interval = (ENV['POLLING_INTERVAL'] || 60).to_i
|
35
|
+
|
36
|
+
@logger.debug { "Initialized #{to_s}" }
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
{
|
41
|
+
:imap_host => @imap_host,
|
42
|
+
:imap_port => @imap_port,
|
43
|
+
:imap_username => @imap_username,
|
44
|
+
|
45
|
+
:imap_mailboxes => @imap_mailboxes,
|
46
|
+
|
47
|
+
:redis_url => @redis_url,
|
48
|
+
:redis_ns_redimap => @redis_ns_redimap,
|
49
|
+
:redis_ns_queue => @redis_ns_queue,
|
50
|
+
|
51
|
+
:polling_interval => @polling_interval,
|
52
|
+
}
|
33
53
|
end
|
34
54
|
|
35
55
|
end
|
data/lib/redimap/imap_conn.rb
CHANGED
@@ -5,13 +5,19 @@ module Redimap
|
|
5
5
|
class ImapConn
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@
|
9
|
-
:port => Redimap.config.imap_port,
|
10
|
-
:ssl => true
|
11
|
-
})
|
8
|
+
@logger = Redimap.logger
|
12
9
|
|
13
|
-
|
10
|
+
begin
|
11
|
+
@imap = Net::IMAP.new(Redimap.config.imap_host, {
|
12
|
+
:port => Redimap.config.imap_port,
|
13
|
+
:ssl => true
|
14
|
+
})
|
15
|
+
|
14
16
|
@imap.login(Redimap.config.imap_username, Redimap.config.imap_password)
|
17
|
+
rescue Net::IMAP::NoResponseError => e
|
18
|
+
@logger.error { e.to_s }
|
19
|
+
|
20
|
+
return
|
15
21
|
end
|
16
22
|
|
17
23
|
if block_given?
|
@@ -22,11 +28,9 @@ module Redimap
|
|
22
28
|
end
|
23
29
|
|
24
30
|
def close
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@imap.disconnect
|
29
|
-
end
|
31
|
+
@imap.logout
|
32
|
+
|
33
|
+
@imap.disconnect
|
30
34
|
end
|
31
35
|
|
32
36
|
def read_mailbox(mailbox = "INBOX", last_seen_uid = 0)
|
data/lib/redimap/redis_conn.rb
CHANGED
@@ -10,7 +10,17 @@ module Redimap
|
|
10
10
|
@@RESCUE_CLASS = 'RedimapJob'
|
11
11
|
|
12
12
|
def initialize
|
13
|
-
@
|
13
|
+
@logger = Redimap.logger
|
14
|
+
|
15
|
+
begin
|
16
|
+
@redis = Redis.connect(:url => Redimap.config.redis_url)
|
17
|
+
|
18
|
+
@redis.ping
|
19
|
+
rescue Redis::CannotConnectError => e
|
20
|
+
@logger.error { e.to_s }
|
21
|
+
|
22
|
+
return
|
23
|
+
end
|
14
24
|
|
15
25
|
@KEYS = {
|
16
26
|
:redimap_mailboxes => "#{Redimap.config.redis_ns_redimap}:mailboxes",
|
@@ -26,9 +36,7 @@ module Redimap
|
|
26
36
|
end
|
27
37
|
|
28
38
|
def close
|
29
|
-
|
30
|
-
@redis.quit
|
31
|
-
end
|
39
|
+
@redis.quit
|
32
40
|
end
|
33
41
|
|
34
42
|
def get_mailbox_uid(mailbox)
|
data/lib/redimap/version.rb
CHANGED
data/redimap.gemspec
CHANGED
@@ -10,10 +10,10 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["tp@tiredpixel.com"]
|
11
11
|
spec.description = %q{Redimap provides a simple executable for polling mailboxes
|
12
12
|
within an IMAP account. It keeps track of what it's seen using Redis. For new
|
13
|
-
messages, the mailbox and uid are queued in Redis. The format
|
14
|
-
compatible with Resque.}
|
13
|
+
messages, the mailbox and uid are queued in Redis. The queue format should be
|
14
|
+
compatible with Resque and Sidekiq.}
|
15
15
|
spec.summary = %q{Redimap polls IMAP account mailboxes and queues in Redis.}
|
16
|
-
spec.homepage = ""
|
16
|
+
spec.homepage = "https://github.com/tiredpixel/redimap"
|
17
17
|
spec.license = "MIT"
|
18
18
|
|
19
19
|
spec.files = `git ls-files`.split($/)
|
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.3.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-04-
|
11
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -69,8 +69,8 @@ dependencies:
|
|
69
69
|
description: |-
|
70
70
|
Redimap provides a simple executable for polling mailboxes
|
71
71
|
within an IMAP account. It keeps track of what it's seen using Redis. For new
|
72
|
-
messages, the mailbox and uid are queued in Redis. The format
|
73
|
-
compatible with Resque.
|
72
|
+
messages, the mailbox and uid are queued in Redis. The queue format should be
|
73
|
+
compatible with Resque and Sidekiq.
|
74
74
|
email:
|
75
75
|
- tp@tiredpixel.com
|
76
76
|
executables:
|
@@ -97,7 +97,7 @@ files:
|
|
97
97
|
- spec/lib/redimap/core_spec.rb
|
98
98
|
- spec/lib/redimap/imap_conn_spec.rb
|
99
99
|
- spec/spec_helper.rb
|
100
|
-
homepage:
|
100
|
+
homepage: https://github.com/tiredpixel/redimap
|
101
101
|
licenses:
|
102
102
|
- MIT
|
103
103
|
metadata: {}
|