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