--- /dev/null
+# Redmine - project management software
+# Copyright (C) 2006-2010 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require 'net/pop'
+
+module Redmine
+ module POP3
+ class << self
+ def check(pop_options={}, options={})
+ host = pop_options[:host] || '127.0.0.1'
+ port = pop_options[:port] || '110'
+ apop = (pop_options[:apop].to_s == '1')
+ delete_unprocessed = (pop_options[:delete_unprocessed].to_s == '1')
+
+ pop = Net::POP3.APOP(apop).new(host,port)
+ puts "Connecting to #{host}..."
+ pop.start(pop_options[:username], pop_options[:password]) do |pop_session|
+ if pop_session.mails.empty?
+ puts "No email to process"
+ else
+ puts "#{pop_session.mails.size} email(s) to process..."
+ pop_session.each_mail do |msg|
+ message = msg.pop
+ message_id = (message =~ /^Message-ID: (.*)/ ? $1 : '').strip
+ if MailHandler.receive(message, options)
+ msg.delete
+ puts "--> Message #{message_id} processed and deleted from the server"
+ else
+ if delete_unprocessed
+ msg.delete
+ puts "--> Message #{message_id} NOT processed and deleted from the server"
+ else
+ puts "--> Message #{message_id} NOT processed and left on the server"
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
\r
Redmine::IMAP.check(imap_options, options)\r
end\r
+ \r
+ desc <<-END_DESC\r
+Read emails from an POP3 server.\r
+\r
+Available POP3 options:\r
+ host=HOST POP3 server host (default: 127.0.0.1)\r
+ port=PORT POP3 server port (default: 110)\r
+ username=USERNAME POP3 account\r
+ password=PASSWORD POP3 password\r
+ apop=1 use APOP authentication (default: false)\r
+ delete_unprocessed=1 delete messages that could not be processed\r
+ successfully from the server (default\r
+ behaviour is to leave them on the server)\r
+\r
+See redmine:email:receive_imap for more options and examples.\r
+END_DESC\r
+ \r
+ task :receive_pop3 => :environment do\r
+ pop_options = {:host => ENV['host'],\r
+ :port => ENV['port'],\r
+ :apop => ENV['apop'],\r
+ :username => ENV['username'],\r
+ :password => ENV['password'],\r
+ :delete_unprocessed => ENV['delete_unprocessed']}\r
+ \r
+ options = { :issue => {} }\r
+ %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }\r
+ options[:allow_override] = ENV['allow_override'] if ENV['allow_override']\r
+ options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']\r
+ options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']\r
+ \r
+ Redmine::POP3.check(pop_options, options)\r
+ end\r
end\r
end\r