annotate lib/tasks/email.rake @ 8:0c83d98252d9 yuya

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