@@ -0,0 +1,46 | |||||
|
1 | Return-Path: <jsmith@somenet.foo> | |||
|
2 | Received: from osiris ([127.0.0.1]) | |||
|
3 | by OSIRIS | |||
|
4 | with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 | |||
|
5 | Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> | |||
|
6 | From: "John Smith" <jsmith@somenet.foo> | |||
|
7 | To: <redmine@somenet.foo> | |||
|
8 | Subject: New ticket on a given project | |||
|
9 | Date: Sun, 22 Jun 2008 12:28:07 +0200 | |||
|
10 | MIME-Version: 1.0 | |||
|
11 | Content-Type: text/plain; | |||
|
12 | format=flowed; | |||
|
13 | charset="iso-8859-1"; | |||
|
14 | reply-type=original | |||
|
15 | Content-Transfer-Encoding: 7bit | |||
|
16 | X-Priority: 3 | |||
|
17 | X-MSMail-Priority: Normal | |||
|
18 | X-Mailer: Microsoft Outlook Express 6.00.2900.2869 | |||
|
19 | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 | |||
|
20 | ||||
|
21 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet | |||
|
22 | turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus | |||
|
23 | blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti | |||
|
24 | sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In | |||
|
25 | in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras | |||
|
26 | sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum | |||
|
27 | id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus | |||
|
28 | eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique | |||
|
29 | sed, mauris. Pellentesque habitant morbi tristique senectus et netus et | |||
|
30 | malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse | |||
|
31 | platea dictumst. | |||
|
32 | ||||
|
33 | Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque | |||
|
34 | sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem. | |||
|
35 | Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et, | |||
|
36 | dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed, | |||
|
37 | massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo | |||
|
38 | pulvinar dui, a gravida orci mi eget odio. Nunc a lacus. | |||
|
39 | ||||
|
40 | Project: onlinestore | |||
|
41 | Tracker: Feature request | |||
|
42 | category: Stock management | |||
|
43 | priority: foo | |||
|
44 | done ratio: x | |||
|
45 | start date: some day | |||
|
46 | due date: never |
@@ -218,7 +218,7 class MailHandler < ActionMailer::Base | |||||
218 | @keywords[attr] |
|
218 | @keywords[attr] | |
219 | else |
|
219 | else | |
220 | @keywords[attr] = begin |
|
220 | @keywords[attr] = begin | |
221 | if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && (v = extract_keyword!(plain_text_body, attr)) |
|
221 | if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && (v = extract_keyword!(plain_text_body, attr, options[:format])) | |
222 | v |
|
222 | v | |
223 | elsif !@@handler_options[:issue][attr].blank? |
|
223 | elsif !@@handler_options[:issue][attr].blank? | |
224 | @@handler_options[:issue][attr] |
|
224 | @@handler_options[:issue][attr] | |
@@ -229,7 +229,7 class MailHandler < ActionMailer::Base | |||||
229 |
|
229 | |||
230 | # Destructively extracts the value for +attr+ in +text+ |
|
230 | # Destructively extracts the value for +attr+ in +text+ | |
231 | # Returns nil if no matching keyword found |
|
231 | # Returns nil if no matching keyword found | |
232 | def extract_keyword!(text, attr) |
|
232 | def extract_keyword!(text, attr, format=nil) | |
233 | keys = [attr.to_s.humanize] |
|
233 | keys = [attr.to_s.humanize] | |
234 | if attr.is_a?(Symbol) |
|
234 | if attr.is_a?(Symbol) | |
235 | keys << l("field_#{attr}", :default => '', :locale => user.language) if user |
|
235 | keys << l("field_#{attr}", :default => '', :locale => user.language) if user | |
@@ -237,7 +237,8 class MailHandler < ActionMailer::Base | |||||
237 | end |
|
237 | end | |
238 | keys.reject! {|k| k.blank?} |
|
238 | keys.reject! {|k| k.blank?} | |
239 | keys.collect! {|k| Regexp.escape(k)} |
|
239 | keys.collect! {|k| Regexp.escape(k)} | |
240 | text.gsub!(/^(#{keys.join('|')})[ \t]*:[ \t]*(.+)\s*$/i, '') |
|
240 | format ||= '.+' | |
|
241 | text.gsub!(/^(#{keys.join('|')})[ \t]*:[ \t]*(#{format})\s*$/i, '') | |||
241 | $2 && $2.strip |
|
242 | $2 && $2.strip | |
242 | end |
|
243 | end | |
243 |
|
244 | |||
@@ -259,10 +260,10 class MailHandler < ActionMailer::Base | |||||
259 | 'category_id' => (k = get_keyword(:category)) && issue.project.issue_categories.find_by_name(k).try(:id), |
|
260 | 'category_id' => (k = get_keyword(:category)) && issue.project.issue_categories.find_by_name(k).try(:id), | |
260 | 'assigned_to_id' => (k = get_keyword(:assigned_to, :override => true)) && find_user_from_keyword(k).try(:id), |
|
261 | 'assigned_to_id' => (k = get_keyword(:assigned_to, :override => true)) && find_user_from_keyword(k).try(:id), | |
261 | 'fixed_version_id' => (k = get_keyword(:fixed_version, :override => true)) && issue.project.shared_versions.find_by_name(k).try(:id), |
|
262 | 'fixed_version_id' => (k = get_keyword(:fixed_version, :override => true)) && issue.project.shared_versions.find_by_name(k).try(:id), | |
262 | 'start_date' => get_keyword(:start_date, :override => true), |
|
263 | 'start_date' => get_keyword(:start_date, :override => true, :format => '\d{4}-\d{2}-\d{2}'), | |
263 | 'due_date' => get_keyword(:due_date, :override => true), |
|
264 | 'due_date' => get_keyword(:due_date, :override => true, :format => '\d{4}-\d{2}-\d{2}'), | |
264 | 'estimated_hours' => get_keyword(:estimated_hours, :override => true), |
|
265 | 'estimated_hours' => get_keyword(:estimated_hours, :override => true), | |
265 |
'done_ratio' => get_keyword(:done_ratio, :override => true) |
|
266 | 'done_ratio' => get_keyword(:done_ratio, :override => true, :format => '(\d|10)?0') | |
266 | }.delete_if {|k, v| v.blank? } |
|
267 | }.delete_if {|k, v| v.blank? } | |
267 | end |
|
268 | end | |
268 |
|
269 |
@@ -229,6 +229,18 class MailHandlerTest < ActiveSupport::TestCase | |||||
229 | assert_equal false, submit_email('ticket_without_from_header.eml') |
|
229 | assert_equal false, submit_email('ticket_without_from_header.eml') | |
230 | end |
|
230 | end | |
231 |
|
231 | |||
|
232 | def test_add_issue_with_invalid_attributes | |||
|
233 | issue = submit_email('ticket_with_invalid_attributes.eml', :allow_override => 'tracker,category,priority') | |||
|
234 | assert issue.is_a?(Issue) | |||
|
235 | assert !issue.new_record? | |||
|
236 | issue.reload | |||
|
237 | assert_nil issue.start_date | |||
|
238 | assert_nil issue.due_date | |||
|
239 | assert_equal 0, issue.done_ratio | |||
|
240 | assert_equal 'Normal', issue.priority.to_s | |||
|
241 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | |||
|
242 | end | |||
|
243 | ||||
232 | def test_add_issue_with_localized_attributes |
|
244 | def test_add_issue_with_localized_attributes | |
233 | User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr' |
|
245 | User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr' | |
234 | issue = submit_email('ticket_with_localized_attributes.eml', :allow_override => 'tracker,category,priority') |
|
246 | issue = submit_email('ticket_with_localized_attributes.eml', :allow_override => 'tracker,category,priority') |
General Comments 0
You need to be logged in to leave comments.
Login now