set svn:eol-style native lib/tasks/email.rake

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9064 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2012-03-04 10:24:01 +00:00
parent 739820141a
commit c474d59b0b
1 changed files with 186 additions and 186 deletions

View File

@ -1,186 +1,186 @@
# Redmine - project management software # Redmine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang # Copyright (C) 2006-2011 Jean-Philippe Lang
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
namespace :redmine do namespace :redmine do
namespace :email do namespace :email do
desc <<-END_DESC desc <<-END_DESC
Read an email from standard input. Read an email from standard input.
General options: General options:
unknown_user=ACTION how to handle emails from an unknown user unknown_user=ACTION how to handle emails from an unknown user
ACTION can be one of the following values: ACTION can be one of the following values:
ignore: email is ignored (default) ignore: email is ignored (default)
accept: accept as anonymous user accept: accept as anonymous user
create: create a user account create: create a user account
no_permission_check=1 disable permission checking when receiving no_permission_check=1 disable permission checking when receiving
the email the email
Issue attributes control options: Issue attributes control options:
project=PROJECT identifier of the target project project=PROJECT identifier of the target project
status=STATUS name of the target status status=STATUS name of the target status
tracker=TRACKER name of the target tracker tracker=TRACKER name of the target tracker
category=CATEGORY name of the target category category=CATEGORY name of the target category
priority=PRIORITY name of the target priority priority=PRIORITY name of the target priority
allow_override=ATTRS allow email content to override attributes allow_override=ATTRS allow email content to override attributes
specified by previous options specified by previous options
ATTRS is a comma separated list of attributes ATTRS is a comma separated list of attributes
Examples: Examples:
# No project specified. Emails MUST contain the 'Project' keyword: # No project specified. Emails MUST contain the 'Project' keyword:
rake redmine:email:read RAILS_ENV="production" < raw_email rake redmine:email:read RAILS_ENV="production" < raw_email
# Fixed project and default tracker specified, but emails can override # Fixed project and default tracker specified, but emails can override
# both tracker and priority attributes: # both tracker and priority attributes:
rake redmine:email:read RAILS_ENV="production" \\ rake redmine:email:read RAILS_ENV="production" \\
project=foo \\ project=foo \\
tracker=bug \\ tracker=bug \\
allow_override=tracker,priority < raw_email allow_override=tracker,priority < raw_email
END_DESC END_DESC
task :read => :environment do task :read => :environment do
options = { :issue => {} } options = { :issue => {} }
%w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] } %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check'] options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']
MailHandler.receive(STDIN.read, options) MailHandler.receive(STDIN.read, options)
end end
desc <<-END_DESC desc <<-END_DESC
Read emails from an IMAP server. Read emails from an IMAP server.
General options: General options:
unknown_user=ACTION how to handle emails from an unknown user unknown_user=ACTION how to handle emails from an unknown user
ACTION can be one of the following values: ACTION can be one of the following values:
ignore: email is ignored (default) ignore: email is ignored (default)
accept: accept as anonymous user accept: accept as anonymous user
create: create a user account create: create a user account
no_permission_check=1 disable permission checking when receiving no_permission_check=1 disable permission checking when receiving
the email the email
Available IMAP options: Available IMAP options:
host=HOST IMAP server host (default: 127.0.0.1) host=HOST IMAP server host (default: 127.0.0.1)
port=PORT IMAP server port (default: 143) port=PORT IMAP server port (default: 143)
ssl=SSL Use SSL? (default: false) ssl=SSL Use SSL? (default: false)
username=USERNAME IMAP account username=USERNAME IMAP account
password=PASSWORD IMAP password password=PASSWORD IMAP password
folder=FOLDER IMAP folder to read (default: INBOX) folder=FOLDER IMAP folder to read (default: INBOX)
Issue attributes control options: Issue attributes control options:
project=PROJECT identifier of the target project project=PROJECT identifier of the target project
status=STATUS name of the target status status=STATUS name of the target status
tracker=TRACKER name of the target tracker tracker=TRACKER name of the target tracker
category=CATEGORY name of the target category category=CATEGORY name of the target category
priority=PRIORITY name of the target priority priority=PRIORITY name of the target priority
allow_override=ATTRS allow email content to override attributes allow_override=ATTRS allow email content to override attributes
specified by previous options specified by previous options
ATTRS is a comma separated list of attributes ATTRS is a comma separated list of attributes
Processed emails control options: Processed emails control options:
move_on_success=MAILBOX move emails that were successfully received move_on_success=MAILBOX move emails that were successfully received
to MAILBOX instead of deleting them to MAILBOX instead of deleting them
move_on_failure=MAILBOX move emails that were ignored to MAILBOX move_on_failure=MAILBOX move emails that were ignored to MAILBOX
Examples: Examples:
# No project specified. Emails MUST contain the 'Project' keyword: # No project specified. Emails MUST contain the 'Project' keyword:
rake redmine:email:receive_imap RAILS_ENV="production" \\ rake redmine:email:receive_imap RAILS_ENV="production" \\
host=imap.foo.bar username=redmine@example.net password=xxx host=imap.foo.bar username=redmine@example.net password=xxx
# Fixed project and default tracker specified, but emails can override # Fixed project and default tracker specified, but emails can override
# both tracker and priority attributes: # both tracker and priority attributes:
rake redmine:email:receive_imap RAILS_ENV="production" \\ rake redmine:email:receive_imap RAILS_ENV="production" \\
host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\ host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\
project=foo \\ project=foo \\
tracker=bug \\ tracker=bug \\
allow_override=tracker,priority allow_override=tracker,priority
END_DESC END_DESC
task :receive_imap => :environment do task :receive_imap => :environment do
imap_options = {:host => ENV['host'], imap_options = {:host => ENV['host'],
:port => ENV['port'], :port => ENV['port'],
:ssl => ENV['ssl'], :ssl => ENV['ssl'],
:username => ENV['username'], :username => ENV['username'],
:password => ENV['password'], :password => ENV['password'],
:folder => ENV['folder'], :folder => ENV['folder'],
:move_on_success => ENV['move_on_success'], :move_on_success => ENV['move_on_success'],
:move_on_failure => ENV['move_on_failure']} :move_on_failure => ENV['move_on_failure']}
options = { :issue => {} } options = { :issue => {} }
%w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] } %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check'] options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']
Redmine::IMAP.check(imap_options, options) Redmine::IMAP.check(imap_options, options)
end end
desc <<-END_DESC desc <<-END_DESC
Read emails from an POP3 server. Read emails from an POP3 server.
Available POP3 options: Available POP3 options:
host=HOST POP3 server host (default: 127.0.0.1) host=HOST POP3 server host (default: 127.0.0.1)
port=PORT POP3 server port (default: 110) port=PORT POP3 server port (default: 110)
username=USERNAME POP3 account username=USERNAME POP3 account
password=PASSWORD POP3 password password=PASSWORD POP3 password
apop=1 use APOP authentication (default: false) apop=1 use APOP authentication (default: false)
delete_unprocessed=1 delete messages that could not be processed delete_unprocessed=1 delete messages that could not be processed
successfully from the server (default successfully from the server (default
behaviour is to leave them on the server) behaviour is to leave them on the server)
See redmine:email:receive_imap for more options and examples. See redmine:email:receive_imap for more options and examples.
END_DESC END_DESC
task :receive_pop3 => :environment do task :receive_pop3 => :environment do
pop_options = {:host => ENV['host'], pop_options = {:host => ENV['host'],
:port => ENV['port'], :port => ENV['port'],
:apop => ENV['apop'], :apop => ENV['apop'],
:username => ENV['username'], :username => ENV['username'],
:password => ENV['password'], :password => ENV['password'],
:delete_unprocessed => ENV['delete_unprocessed']} :delete_unprocessed => ENV['delete_unprocessed']}
options = { :issue => {} } options = { :issue => {} }
%w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] } %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check'] options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']
Redmine::POP3.check(pop_options, options) Redmine::POP3.check(pop_options, options)
end end
desc "Send a test email to the user with the provided login name" desc "Send a test email to the user with the provided login name"
task :test, [:login] => :environment do |task, args| task :test, [:login] => :environment do |task, args|
include Redmine::I18n include Redmine::I18n
abort l(:notice_email_error, "Please include the user login to test with. Example: rake redmine:email:test[login]") if args[:login].blank? abort l(:notice_email_error, "Please include the user login to test with. Example: rake redmine:email:test[login]") if args[:login].blank?
user = User.find_by_login(args[:login]) user = User.find_by_login(args[:login])
abort l(:notice_email_error, "User #{args[:login]} not found") unless user && user.logged? abort l(:notice_email_error, "User #{args[:login]} not found") unless user && user.logged?
ActionMailer::Base.raise_delivery_errors = true ActionMailer::Base.raise_delivery_errors = true
begin begin
Mailer.deliver_test(User.current) Mailer.deliver_test(User.current)
puts l(:notice_email_sent, user.mail) puts l(:notice_email_sent, user.mail)
rescue Exception => e rescue Exception => e
abort l(:notice_email_error, e.message) abort l(:notice_email_error, e.message)
end end
end end
end end
end end