herald 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,55 +0,0 @@
1
- class Herald
2
- class Watcher
3
-
4
- module Imap
5
-
6
- attr_accessor :user, :pass, :host, :mailbox, :last_uid
7
-
8
- # lazy-load net/imap when this Module is used
9
- def self.extended(base)
10
- Herald.lazy_load('net/imap')
11
- Herald.lazy_load('date')
12
- end
13
-
14
- def parse_options(options)
15
- @user = options.delete(:user)
16
- @pass = options.delete(:pass)
17
- @host = options.delete(:host)
18
- @mailbox = options.delete(:mailbox) || "INBOX"
19
- @mailbox.upcase!
20
- # start looking a week ago unless option given
21
- @start_date = options.delete(:start_date) || (Date.today - 7).strftime("%d-%b-%Y")
22
- end
23
-
24
- def prepare; end
25
- def cleanup; end
26
-
27
- def to_s
28
- "Herald IMAP Watcher, Host: #{@host}, Keywords: '#{@keywords}', Timer: #{@timer}, State: #{@keep_alive ? 'Watching' : 'Stopped'}"
29
- end
30
-
31
- private
32
-
33
- def activities
34
- puts "u: #{@user}"
35
- puts "p: #{@pass}"
36
- puts "h: #{@host}"
37
- imap = Net::IMAP.new(@host)
38
- imap.login("LOGIN", @user, @pass)
39
- imap.select(@mailbox)
40
- @last_look = Time.now
41
- # if we have the id of the last email looked at
42
- if @last_uid
43
- search_result = imap.search(["BODY", @keywords, "SINCE", @start_date])
44
- else
45
- search_result = imap.search(["BODY", @keywords, "SINCE", @start_date])
46
- end
47
- puts search_result.inspect
48
- imap.logout
49
- imap.disconnect
50
- end
51
-
52
- end
53
-
54
- end
55
- end