1
|
# redMine - project management software
|
2
|
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
3
|
#
|
4
|
# This program is free software; you can redistribute it and/or
|
5
|
# modify it under the terms of the GNU General Public License
|
6
|
# as published by the Free Software Foundation; either version 2
|
7
|
# of the License, or (at your option) any later version.
|
8
|
#
|
9
|
# This program is distributed in the hope that it will be useful,
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
# GNU General Public License for more details.
|
13
|
#
|
14
|
# You should have received a copy of the GNU General Public License
|
15
|
# along with this program; if not, write to the Free Software
|
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
|
18
|
require 'net/pop'
|
19
|
|
20
|
module Redmine
|
21
|
module POP3
|
22
|
class << self
|
23
|
def check(pop_options={}, options={})
|
24
|
host = pop_options[:host] || '127.0.0.1'
|
25
|
port = pop_options[:port] || '110'
|
26
|
|
27
|
pop = Net::POP3.new(host,port)
|
28
|
pop.start(pop_options[:username], pop_options[:password]) do |pop_session|
|
29
|
pop_session.each_mail do |msg|
|
30
|
message = msg.pop
|
31
|
logger.debug "Receiving message: #{message.grep(/^Subject: /)}" if logger && logger.debug?
|
32
|
if MailHandler.receive(message, options)
|
33
|
logger.info "Message #{message.grep(/^Subject: /)} processed -- removing from server." if logger && logger.info?
|
34
|
puts "#{message.grep(/^Subject: /)}"
|
35
|
puts "--> Message processed and deleted from the server"
|
36
|
msg.delete
|
37
|
else
|
38
|
puts "#{message.grep(/^Subject: /)}"
|
39
|
puts "--> Message NOT processed -- leaving it on the server"
|
40
|
logger.info "ERROR: Message #{message.grep(/^Subject: /)} can not be processed, leaving on the server." if logger && logger.info?
|
41
|
end
|
42
|
|
43
|
end
|
44
|
end
|
45
|
|
46
|
end
|
47
|
|
48
|
private
|
49
|
|
50
|
def logger
|
51
|
RAILS_DEFAULT_LOGGER
|
52
|
end
|
53
|
end
|
54
|
end
|
55
|
end
|