Feature #4882 » mapi.rb
1 |
require 'win32ole' |
---|---|
2 |
|
3 |
module Redmine |
4 |
module MAPI |
5 |
class << self |
6 |
def check(mapi_options={}, options={}) |
7 |
|
8 |
puts "options: #{options}" if logger && logger.debug? |
9 |
puts "mapi_options: #{mapi_options}" if logger && logger.debug? |
10 |
mapi = WIN32OLE.new('Mapi.Session') |
11 |
|
12 |
WIN32OLE.const_load(mapi) |
13 |
|
14 |
mailbox = 'MS Exchange Settings' |
15 |
logonParam = mailbox |
16 |
mapi.Logon(logonParam) |
17 |
|
18 |
inbox = mapi.inbox |
19 |
|
20 |
messages = inbox.messages |
21 |
|
22 |
messages.each do |msg| |
23 |
# logger.info "Receiving message: #{message.grep(/^Subject: /)}" if logger && logger.debug?
|
24 |
puts "Receiving message: #{msg.Subject}" if logger && logger.info? |
25 |
|
26 |
if MAPIMailHandler.receive(msg, options) |
27 |
logger.info "Message #{msg.Subject} processed -- removing from server." if logger && logger.info? |
28 |
puts "#{msg.Subject}" |
29 |
puts "--> Message processed and deleted from the server" |
30 |
msg.delete |
31 |
else
|
32 |
puts "#{msg.Subject}" |
33 |
puts "--> Message NOT processed -- leaving it on the server" |
34 |
logger.info "ERROR: Message #{msg.Subject} can not be processed, leaving on the server." if logger && logger.info? |
35 |
end
|
36 |
end
|
37 |
end
|
38 |
|
39 |
private
|
40 |
|
41 |
def logger |
42 |
RAILS_DEFAULT_LOGGER
|
43 |
end
|
44 |
end
|
45 |
end
|
46 |
end
|