cinch-imap 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -3
- data/lib/cinch/plugins/imap.rb +22 -5
- metadata +2 -2
data/README.md
CHANGED
@@ -2,12 +2,17 @@ Cinch-Imap
|
|
2
2
|
==========
|
3
3
|
The Cinch Imap Plugin. Poll an IMAP mailbox at a defined interval.
|
4
4
|
|
5
|
-
|
5
|
+
Change Log
|
6
|
+
----------
|
7
|
+
0.0.4
|
8
|
+
- Added from_rewrites configuration option
|
9
|
+
- Added !monitor showconfig command
|
10
|
+
- Added !monitor version command
|
11
|
+
|
12
|
+
0.0.3
|
6
13
|
-------
|
7
|
-
|
8
14
|
- Added configurable prefix based on subject match.
|
9
15
|
- Moved "mark messages read" to a configurable option.
|
10
|
-
- Simplfied from information
|
11
16
|
|
12
17
|
Required Configuration
|
13
18
|
----------------------
|
@@ -52,6 +57,10 @@ Example Configuration
|
|
52
57
|
:port => 993,
|
53
58
|
:ssl => true,
|
54
59
|
:subject_matches => {'ERROR' => '!!', 'SUCCESS' => '..'},
|
60
|
+
:from_rewrites => {
|
61
|
+
'this@suchalong.silly.address' => 'foo',
|
62
|
+
'another@address.that.bugs.me' => 'bugger',
|
63
|
+
},
|
55
64
|
}
|
56
65
|
end
|
57
66
|
|
data/lib/cinch/plugins/imap.rb
CHANGED
@@ -5,27 +5,36 @@ module Cinch
|
|
5
5
|
class Imap
|
6
6
|
include Cinch::Plugin
|
7
7
|
|
8
|
+
VERSION='0.0.4'
|
9
|
+
|
8
10
|
match /monitor (on|off)/
|
9
11
|
match /monitor status/, method: :status
|
12
|
+
match /monitor showconfig/, method: :showconfig
|
10
13
|
match /monitor clear/, method: :clear
|
11
14
|
match /monitor interval (\d+)/, method: :interval
|
15
|
+
match /monitor version/, method: :about
|
12
16
|
match /monitor$/, method: :usage
|
13
17
|
|
14
18
|
def initialize(*args)
|
15
19
|
super
|
16
20
|
@mail_host = config[:host]
|
17
21
|
@mail_user = config[:user]
|
18
|
-
@
|
22
|
+
@mail_password = config[:password]
|
19
23
|
@mail_folder = config[:folder] || 'INBOX'
|
20
24
|
@mail_port = config[:port] || 143
|
21
25
|
@mail_ssl = config[:ssl] || false
|
22
26
|
@mark_as_read = config[:mark_as_read ] || true
|
23
27
|
@interval = config[:interval] || 300
|
24
28
|
@subject_matches = config[:subject_matches] || {}
|
29
|
+
@from_rewrites = config[:from_rewrites] || {}
|
25
30
|
@messages_seen = 0
|
26
31
|
@started = Time.now
|
27
32
|
end
|
28
33
|
|
34
|
+
def about(m)
|
35
|
+
m.reply "Looks like I'm on #{VERSION} #{m.user.nick}"
|
36
|
+
end
|
37
|
+
|
29
38
|
def interval (seconds)
|
30
39
|
@interval = seconds
|
31
40
|
@monitor = @interval > 0
|
@@ -35,6 +44,12 @@ module Cinch
|
|
35
44
|
@messages_seen = 0
|
36
45
|
end
|
37
46
|
|
47
|
+
def showconfig(m)
|
48
|
+
config.each do |k, v|
|
49
|
+
m.reply "#{k} is #{config[k]}" unless k == :password
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
38
53
|
def status(m)
|
39
54
|
now = Time.now
|
40
55
|
days = ((now - @started)/(3600 * 24)).to_i
|
@@ -76,14 +91,16 @@ module Cinch
|
|
76
91
|
|
77
92
|
background_job do
|
78
93
|
imap = Net::IMAP.new(@mail_host, @mail_port, @mail_ssl)
|
79
|
-
imap.login(@mail_user, @
|
94
|
+
imap.login(@mail_user, @mail_password)
|
80
95
|
imap.select(@mail_folder)
|
81
96
|
get_messages(imap) do |from, subj|
|
82
|
-
|
97
|
+
@from_rewrites.each do |k, v|
|
98
|
+
from =~ /#{k}/ ? message_from = "#{v}" : message_from = from
|
99
|
+
end
|
83
100
|
@subject_matches.each do |k, v|
|
84
|
-
|
101
|
+
subj =~ /#{k}/ ? message_prefix = "#{v}" : message_prefix = ''
|
85
102
|
end
|
86
|
-
m.reply
|
103
|
+
m.reply "#{message_prefix} #{message_from} #{subj}"
|
87
104
|
end
|
88
105
|
imap.disconnect
|
89
106
|
end if @monitor
|