annotate lib/tasks/email.rake @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children
rev   line source
Chris@1115 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1115 3 #
Chris@1115 4 # This program is free software; you can redistribute it and/or
Chris@1115 5 # modify it under the terms of the GNU General Public License
Chris@1115 6 # as published by the Free Software Foundation; either version 2
Chris@1115 7 # of the License, or (at your option) any later version.
Chris@1115 8 #
Chris@1115 9 # This program is distributed in the hope that it will be useful,
Chris@1115 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1115 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1115 12 # GNU General Public License for more details.
Chris@1115 13 #
Chris@1115 14 # You should have received a copy of the GNU General Public License
Chris@1115 15 # along with this program; if not, write to the Free Software
Chris@1115 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1115 17
Chris@1115 18 namespace :redmine do
Chris@1115 19 namespace :email do
Chris@1115 20
Chris@1115 21 desc <<-END_DESC
Chris@1115 22 Read an email from standard input.
Chris@1115 23
Chris@1115 24 General options:
Chris@1115 25 unknown_user=ACTION how to handle emails from an unknown user
Chris@1115 26 ACTION can be one of the following values:
Chris@1115 27 ignore: email is ignored (default)
Chris@1115 28 accept: accept as anonymous user
Chris@1115 29 create: create a user account
Chris@1115 30 no_permission_check=1 disable permission checking when receiving
Chris@1115 31 the email
Chris@1295 32 no_account_notice=1 disable new user account notification
Chris@1295 33 default_group=foo,bar adds created user to foo and bar groups
Chris@1115 34
Chris@1115 35 Issue attributes control options:
Chris@1115 36 project=PROJECT identifier of the target project
Chris@1115 37 status=STATUS name of the target status
Chris@1115 38 tracker=TRACKER name of the target tracker
Chris@1115 39 category=CATEGORY name of the target category
Chris@1115 40 priority=PRIORITY name of the target priority
Chris@1115 41 allow_override=ATTRS allow email content to override attributes
Chris@1115 42 specified by previous options
Chris@1115 43 ATTRS is a comma separated list of attributes
Chris@1115 44
Chris@1115 45 Examples:
Chris@1115 46 # No project specified. Emails MUST contain the 'Project' keyword:
Chris@1115 47 rake redmine:email:read RAILS_ENV="production" < raw_email
Chris@1115 48
Chris@1115 49 # Fixed project and default tracker specified, but emails can override
Chris@1115 50 # both tracker and priority attributes:
Chris@1115 51 rake redmine:email:read RAILS_ENV="production" \\
Chris@1115 52 project=foo \\
Chris@1115 53 tracker=bug \\
Chris@1115 54 allow_override=tracker,priority < raw_email
Chris@1115 55 END_DESC
Chris@1115 56
Chris@1115 57 task :read => :environment do
Chris@1115 58 options = { :issue => {} }
Chris@1115 59 %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
Chris@1115 60 options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
Chris@1115 61 options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
Chris@1115 62 options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']
Chris@1295 63 options[:no_account_notice] = ENV['no_account_notice'] if ENV['no_account_notice']
Chris@1295 64 options[:default_group] = ENV['default_group'] if ENV['default_group']
Chris@1115 65
Chris@1115 66 MailHandler.receive(STDIN.read, options)
Chris@1115 67 end
Chris@1115 68
Chris@1115 69 desc <<-END_DESC
Chris@1115 70 Read emails from an IMAP server.
Chris@1115 71
Chris@1115 72 General options:
Chris@1115 73 unknown_user=ACTION how to handle emails from an unknown user
Chris@1115 74 ACTION can be one of the following values:
Chris@1115 75 ignore: email is ignored (default)
Chris@1115 76 accept: accept as anonymous user
Chris@1115 77 create: create a user account
Chris@1115 78 no_permission_check=1 disable permission checking when receiving
Chris@1115 79 the email
Chris@1295 80 no_account_notice=1 disable new user account notification
Chris@1295 81 default_group=foo,bar adds created user to foo and bar groups
Chris@1115 82
Chris@1115 83 Available IMAP options:
Chris@1115 84 host=HOST IMAP server host (default: 127.0.0.1)
Chris@1115 85 port=PORT IMAP server port (default: 143)
Chris@1115 86 ssl=SSL Use SSL? (default: false)
Chris@1115 87 username=USERNAME IMAP account
Chris@1115 88 password=PASSWORD IMAP password
Chris@1115 89 folder=FOLDER IMAP folder to read (default: INBOX)
Chris@1115 90
Chris@1115 91 Issue attributes control options:
Chris@1115 92 project=PROJECT identifier of the target project
Chris@1115 93 status=STATUS name of the target status
Chris@1115 94 tracker=TRACKER name of the target tracker
Chris@1115 95 category=CATEGORY name of the target category
Chris@1115 96 priority=PRIORITY name of the target priority
Chris@1115 97 allow_override=ATTRS allow email content to override attributes
Chris@1115 98 specified by previous options
Chris@1115 99 ATTRS is a comma separated list of attributes
Chris@1115 100
Chris@1115 101 Processed emails control options:
Chris@1115 102 move_on_success=MAILBOX move emails that were successfully received
Chris@1115 103 to MAILBOX instead of deleting them
Chris@1115 104 move_on_failure=MAILBOX move emails that were ignored to MAILBOX
Chris@1115 105
Chris@1115 106 Examples:
Chris@1115 107 # No project specified. Emails MUST contain the 'Project' keyword:
Chris@1115 108
Chris@1115 109 rake redmine:email:receive_imap RAILS_ENV="production" \\
Chris@1115 110 host=imap.foo.bar username=redmine@example.net password=xxx
Chris@1115 111
Chris@1115 112
Chris@1115 113 # Fixed project and default tracker specified, but emails can override
Chris@1115 114 # both tracker and priority attributes:
Chris@1115 115
Chris@1115 116 rake redmine:email:receive_imap RAILS_ENV="production" \\
Chris@1115 117 host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\
Chris@1115 118 project=foo \\
Chris@1115 119 tracker=bug \\
Chris@1115 120 allow_override=tracker,priority
Chris@1115 121 END_DESC
Chris@1115 122
Chris@1115 123 task :receive_imap => :environment do
Chris@1115 124 imap_options = {:host => ENV['host'],
Chris@1115 125 :port => ENV['port'],
Chris@1115 126 :ssl => ENV['ssl'],
Chris@1115 127 :username => ENV['username'],
Chris@1115 128 :password => ENV['password'],
Chris@1115 129 :folder => ENV['folder'],
Chris@1115 130 :move_on_success => ENV['move_on_success'],
Chris@1115 131 :move_on_failure => ENV['move_on_failure']}
Chris@1115 132
Chris@1115 133 options = { :issue => {} }
Chris@1115 134 %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
Chris@1115 135 options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
Chris@1115 136 options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
Chris@1115 137 options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']
Chris@1295 138 options[:no_account_notice] = ENV['no_account_notice'] if ENV['no_account_notice']
Chris@1295 139 options[:default_group] = ENV['default_group'] if ENV['default_group']
Chris@1115 140
Chris@1115 141 Redmine::IMAP.check(imap_options, options)
Chris@1115 142 end
Chris@1115 143
Chris@1115 144 desc <<-END_DESC
Chris@1115 145 Read emails from an POP3 server.
Chris@1115 146
Chris@1115 147 Available POP3 options:
Chris@1115 148 host=HOST POP3 server host (default: 127.0.0.1)
Chris@1115 149 port=PORT POP3 server port (default: 110)
Chris@1115 150 username=USERNAME POP3 account
Chris@1115 151 password=PASSWORD POP3 password
Chris@1115 152 apop=1 use APOP authentication (default: false)
Chris@1115 153 delete_unprocessed=1 delete messages that could not be processed
Chris@1115 154 successfully from the server (default
Chris@1115 155 behaviour is to leave them on the server)
Chris@1115 156
Chris@1115 157 See redmine:email:receive_imap for more options and examples.
Chris@1115 158 END_DESC
Chris@1115 159
Chris@1115 160 task :receive_pop3 => :environment do
Chris@1115 161 pop_options = {:host => ENV['host'],
Chris@1115 162 :port => ENV['port'],
Chris@1115 163 :apop => ENV['apop'],
Chris@1115 164 :username => ENV['username'],
Chris@1115 165 :password => ENV['password'],
Chris@1115 166 :delete_unprocessed => ENV['delete_unprocessed']}
Chris@1115 167
Chris@1115 168 options = { :issue => {} }
Chris@1115 169 %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
Chris@1115 170 options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
Chris@1115 171 options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
Chris@1115 172 options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']
Chris@1295 173 options[:no_account_notice] = ENV['no_account_notice'] if ENV['no_account_notice']
Chris@1295 174 options[:default_group] = ENV['default_group'] if ENV['default_group']
Chris@1115 175
Chris@1115 176 Redmine::POP3.check(pop_options, options)
Chris@1115 177 end
Chris@1115 178
Chris@1115 179 desc "Send a test email to the user with the provided login name"
Chris@1115 180 task :test, [:login] => :environment do |task, args|
Chris@1115 181 include Redmine::I18n
Chris@1115 182 abort l(:notice_email_error, "Please include the user login to test with. Example: rake redmine:email:test[login]") if args[:login].blank?
Chris@1115 183
Chris@1115 184 user = User.find_by_login(args[:login])
Chris@1115 185 abort l(:notice_email_error, "User #{args[:login]} not found") unless user && user.logged?
Chris@1115 186
Chris@1115 187 ActionMailer::Base.raise_delivery_errors = true
Chris@1115 188 begin
Chris@1115 189 Mailer.with_synched_deliveries do
Chris@1115 190 Mailer.test_email(user).deliver
Chris@1115 191 end
Chris@1115 192 puts l(:notice_email_sent, user.mail)
Chris@1115 193 rescue Exception => e
Chris@1115 194 abort l(:notice_email_error, e.message)
Chris@1115 195 end
Chris@1115 196 end
Chris@1115 197 end
Chris@1115 198 end