annotate .svn/pristine/04/049234b460fae5eb30eba8a2487d0eac09c6701f.svn-base @ 1494:e248c7af89ec redmine-2.4

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