From 40efaae6d5a2f48734caf4cdabd9537f923c0f47 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 6 Jul 2008 16:26:25 +0000 Subject: Mail handler: more control over issue attributes (#1110). Tracker, category and priority attributes can be specified in command line arguments and/or individually specified as overridable by email body keywords. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1643 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/tasks/email.rake | 76 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/lib/tasks/email.rake b/lib/tasks/email.rake index 01407c36d..daf0aa9bb 100644 --- a/lib/tasks/email.rake +++ b/lib/tasks/email.rake @@ -21,16 +21,31 @@ namespace :redmine do desc <<-END_DESC Read an email from standard input. -Available options: - * project => identifier of the project the issue should be added to - -Example: - rake redmine:email:receive project=foo RAILS_ENV="production" +Issue attributes control options: + project=PROJECT identifier of the target project + tracker=TRACKER name of the target tracker + category=CATEGORY name of the target category + priority=PRIORITY name of the target priority + allow_override=ATTRS allow email content to override attributes + specified by previous options + ATTRS is a comma separated list of attributes + +Examples: + # No project specified. Emails MUST contain the 'Project' keyword: + rake redmine:email:read RAILS_ENV="production" < raw_email + + # Fixed project and default tracker specified, but emails can override + # both tracker and priority attributes: + rake redmine:email:read RAILS_ENV="production" \\ + project=foo \\ + tracker=bug \\ + allow_override=tracker,priority < raw_email END_DESC - task :receive => :environment do - options = {} - options[:project] = ENV['project'] if ENV['project'] + task :read => :environment do + options = { :issue => {} } + %w(project 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'] MailHandler.receive(STDIN.read, options) end @@ -39,17 +54,37 @@ END_DESC Read emails from an IMAP server. Available IMAP options: - * host => IMAP server host (default: 127.0.0.1) - * port => IMAP server port (default: 143) - * ssl => Use SSL? (default: false) - * username => IMAP account - * password => IMAP password - * folder => IMAP folder to read (default: INBOX) -Other options: - * project => identifier of the project the issue should be added to + host=HOST IMAP server host (default: 127.0.0.1) + port=PORT IMAP server port (default: 143) + ssl=SSL Use SSL? (default: false) + username=USERNAME IMAP account + password=PASSWORD IMAP password + folder=FOLDER IMAP folder to read (default: INBOX) + +Issue attributes control options: + project=PROJECT identifier of the target project + tracker=TRACKER name of the target tracker + category=CATEGORY name of the target category + priority=PRIORITY name of the target priority + allow_override=ATTRS allow email content to override attributes + specified by previous options + ATTRS is a comma separated list of attributes + +Examples: + # No project specified. Emails MUST contain the 'Project' keyword: + + rake redmine:email:receive_iamp RAILS_ENV="production" \\ + host=imap.foo.bar username=redmine@somenet.foo password=xxx + + + # Fixed project and default tracker specified, but emails can override + # both tracker and priority attributes: -Example: - rake redmine:email:receive_iamp host=imap.foo.bar username=redmine@somenet.foo password=xxx project=foo RAILS_ENV="production" + rake redmine:email:receive_iamp RAILS_ENV="production" \\ + host=imap.foo.bar username=redmine@somenet.foo password=xxx ssl=1 \\ + project=foo \\ + tracker=bug \\ + allow_override=tracker,priority END_DESC task :receive_imap => :environment do @@ -60,8 +95,9 @@ END_DESC :password => ENV['password'], :folder => ENV['folder']} - options = {} - options[:project] = ENV['project'] if ENV['project'] + options = { :issue => {} } + %w(project 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'] Redmine::IMAP.check(imap_options, options) end -- cgit v1.2.3