annotate .svn/pristine/e8/e86b4aa0a3e324955e92b3f7034e99d911b3a474.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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