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