cinch-imap 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. data/README.md +50 -43
  2. data/lib/cinch/plugins/imap.rb +9 -8
  3. metadata +3 -3
data/README.md CHANGED
@@ -1,60 +1,67 @@
1
- Cinch-Imap
2
- ===========
3
-
1
+ Cinch-Imap
2
+ ==========
4
3
  The Cinch Imap Plugin. Poll an IMAP mailbox at a defined interval.
5
4
 
6
- Installation
7
- ---------------------
5
+ 0.0.3 Changes
6
+ -------
8
7
 
9
- $ gem install cinch-imap
8
+ - Added configurable prefix based on subject match.
9
+ - Moved "mark messages read" to a configurable option.
10
+ - Simplfied from information
10
11
 
11
- Setup
12
- ----------
12
+ Required Configuration
13
+ ----------------------
13
14
 
14
- #### Options ####
15
+ :host - The IMAP server
16
+ :user - The user id
17
+ :password - The password
15
18
 
16
- * :host - The IMAP server
17
- * :user - The user id
18
- * :password - The password
19
- * :port - The IMAP port. Defaults to 143.
20
- * :ssl - Use ssl? Default is false.
21
- * :interval - Number of seconds between polling. Default is 300.
19
+ Optional Configuration
20
+ ----------------------
22
21
 
23
- #### Commands ####
22
+ :port - The IMAP port. Default to 143.
23
+ :ssl - Use ssl? Default is false.
24
+ :interval - Number of seconds between polling. Default is 300.
25
+ :mark_as_read - Sets the IMAP :Seen flag on polled messages. Default is true.
24
26
 
25
- * !monitor on/off - Enable/Disable IMAP polling
26
- * !monitor status - Issues a status report to the channel
27
- * !monitor clear - Resets the number of "messages seen" to 0
28
- * !monitor interval [n] - Set polling interval to n second
27
+ Commands
28
+ --------
29
+
30
+ !monitor on/off - Enable/Disable IMAP polling
31
+ !monitor status - Issues a status report to the channel
32
+ !monitor clear - Resets the number of "messages seen" to 0
33
+ !monitor interval [n] - Set polling interval to n second
29
34
 
30
- #### Integration with Cinch ####
35
+ Example Configuration
36
+ ---------------------
31
37
 
32
- # mybot.rb
33
- require 'cinch'
34
- require 'cinch/plugins/imap'
38
+ # mybot.rb
39
+ require 'cinch'
40
+ require 'cinch/plugins/imap'
35
41
 
36
- bot = Cinch::Bot.new do
37
- configure do |c|
38
- c.server = "my.ircserver.tld"
39
- c.nick = "cinch"
40
- c.channels = ["#mychannel"]
41
- c.plugins.plugins = [Cinch::Plugins::Imap]
42
- c.plugins.options[Cinch::Plugins::Imap] = {
43
- :host => 'my.imapserver.tld',
44
- :user => 'me@fqdn.tld',
45
- :password => "l3tm3out",
46
- :port => 993,
47
- :ssl => true,
48
- }
49
- end
42
+ bot = Cinch::Bot.new do
43
+ configure do |c|
44
+ c.server = "my.ircserver.tld"
45
+ c.nick = "cinch"
46
+ c.channels = ["#mychannel"]
47
+ c.plugins.plugins = [Cinch::Plugins::Imap]
48
+ c.plugins.options[Cinch::Plugins::Imap] = {
49
+ :host => 'my.imapserver.tld',
50
+ :user => 'me@fqdn.tld',
51
+ :password => "l3tm3out",
52
+ :port => 993,
53
+ :ssl => true,
54
+ :subject_matches => {'ERROR' => '!!', 'SUCCESS' => '..'},
55
+ }
56
+ end
50
57
 
51
- end
58
+ end
52
59
 
53
- bot.start
60
+ bot.start
54
61
 
55
- Finally, run your bot.
62
+ Now, run your bot.
56
63
 
57
- ruby mybot.rb
64
+ ruby mybot.rb
58
65
 
59
66
  WARNING
60
67
  -------
@@ -68,4 +75,4 @@ TODO
68
75
  ----
69
76
 
70
77
  * Figure out how to auto-start this thing
71
- * Support a list of sender addresses to rewrite
78
+ * Support configurable from address rewrites
@@ -19,9 +19,11 @@ module Cinch
19
19
  @mail_folder = config[:folder] || 'INBOX'
20
20
  @mail_port = config[:port] || 143
21
21
  @mail_ssl = config[:ssl] || false
22
+ @mark_as_read = config[:mark_as_read ] || true
23
+ @interval = config[:interval] || 300
24
+ @subject_matches = config[:subject_matches] || {}
22
25
  @messages_seen = 0
23
26
  @started = Time.now
24
- @interval = config[:interval] || 300
25
27
  end
26
28
 
27
29
  def interval (seconds)
@@ -52,9 +54,9 @@ module Cinch
52
54
  name = envelope.from[0].name
53
55
  mailbox = envelope.from[0].mailbox
54
56
  host = envelope.from[0].host
55
- from = name.nil? ? "#{mailbox}@#{host}" : name
57
+ from = name.nil? ? host : name
56
58
  subj = envelope.subject
57
- conn.store(message_id, "+FLAGS", [:Seen])
59
+ conn.store(message_id, "+FLAGS", [:Seen]) if @mark_as_read
58
60
  @messages_seen += 1
59
61
  yield from, subj
60
62
  end
@@ -77,12 +79,11 @@ module Cinch
77
79
  imap.login(@mail_user, @mail_pass)
78
80
  imap.select(@mail_folder)
79
81
  get_messages(imap) do |from, subj|
80
- case subj
81
- when /PROBLEM/
82
- m.reply "[!!] [#{from}] #{subj}"
83
- else
84
- m.reply "[..] [#{from}] #{subj}"
82
+ message = "#{from} #{subj}"
83
+ @subject_matches.each do |k, v|
84
+ message = "#{v} #{message}" if subj =~ /#{k}/
85
85
  end
86
+ m.reply message
86
87
  end
87
88
  imap.disconnect
88
89
  end if @monitor
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - windowsrefund
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-01 00:00:00 -05:00
17
+ date: 2011-02-02 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency