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