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