-
Notifications
You must be signed in to change notification settings - Fork 0
/
owa-growl.rb
executable file
·46 lines (37 loc) · 1.18 KB
/
owa-growl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
require 'highline/import'
require 'mechanize'
require 'ruby-growl'
# Configuration
GROWL_HOST = 'localhost'
GROWL_NOTIFICATION_TITLE = 'New Email in Outlook Web Access'
FOLDERS_URL = 'YOUR_URL_TO_THE_FOLDERS_PAGE_IN_OWA'
SLEEP_DURATION = 300
if ARGV[0] == "start" || ARGV[0] == "run"
# Get the required user input before we start the loop
GROWL_PASSWORD = ask('Growl password: ') { |q| q.echo = "*" }
OWA_USERNAME = ask('Email username: ')
OWA_PASSWORD = ask('Email password: ') { |q| q.echo = "*" }
end
Daemons.run_proc('owa-growl') do
loop do
agent = WWW::Mechanize.new
agent.auth(OWA_USERNAME, OWA_PASSWORD)
page = agent.get(FOLDERS_URL)
new_email_count = 0
elements = page.search("/html/body//i")
elements.each do |element|
match = /\((\d+)\)/.match(element.inner_html)
unless match.nil?
new_email_count += match[1].to_i
end
end
if new_email_count > 0
g = Growl.new GROWL_HOST, 'owa-growl', ["owa"], nil, GROWL_PASSWORD
g.notify "owa", GROWL_NOTIFICATION_TITLE, "Email count: #{new_email_count}"
end
sleep SLEEP_DURATION
end
end