Chris@0
|
1 # Redmine - project management software
|
Chris@441
|
2 # Copyright (C) 2006-2011 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@441
|
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@441
|
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@441
|
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@441
|
61
|
Chris@0
|
62 MailHandler.receive(STDIN.read, options)
|
Chris@0
|
63 end
|
Chris@441
|
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@441
|
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@441
|
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@441
|
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@441
|
99
|
Chris@0
|
100 Examples:
|
Chris@0
|
101 # No project specified. Emails MUST contain the 'Project' keyword:
|
Chris@441
|
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@441
|
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@441
|
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@441
|
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@441
|
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@441
|
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@441
|
165
|
Chris@0
|
166 Redmine::POP3.check(pop_options, options)
|
Chris@0
|
167 end
|
Chris@441
|
168
|
chris@37
|
169 desc "Send a test email to the user with the provided login name"
|
chris@37
|
170 task :test, :login, :needs => :environment do |task, args|
|
chris@37
|
171 include Redmine::I18n
|
Chris@441
|
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@37
|
173
|
chris@37
|
174 user = User.find_by_login(args[:login])
|
Chris@441
|
175 abort l(:notice_email_error, "User #{args[:login]} not found") unless user && user.logged?
|
Chris@441
|
176
|
chris@37
|
177 ActionMailer::Base.raise_delivery_errors = true
|
chris@37
|
178 begin
|
chris@37
|
179 Mailer.deliver_test(User.current)
|
chris@37
|
180 puts l(:notice_email_sent, user.mail)
|
chris@37
|
181 rescue Exception => e
|
chris@37
|
182 abort l(:notice_email_error, e.message)
|
chris@37
|
183 end
|
chris@37
|
184 end
|
Chris@0
|
185 end
|
Chris@0
|
186 end
|