From bb12c359514198c79b91916506c97f350a2b4d36 Mon Sep 17 00:00:00 2001 From: Reed Loden Date: Tue, 31 Jul 2012 17:38:02 -0700 Subject: Bug 625437 - Use 'Importance' / 'X-Priority' headers in incoming mail to influence bug's initial priority [r=LpSolit a=LpSolit] --- email_in.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'email_in.pl') diff --git a/email_in.pl b/email_in.pl index 53b5ac2a8..67a48e789 100755 --- a/email_in.pl +++ b/email_in.pl @@ -30,6 +30,7 @@ use HTML::FormatText::WithLinks; use Pod::Usage; use Encode; use Scalar::Util qw(blessed); +use List::MoreUtils qw(firstidx); use Bugzilla; use Bugzilla::Attachment; @@ -37,6 +38,7 @@ use Bugzilla::Bug; use Bugzilla::BugMail; use Bugzilla::Constants; use Bugzilla::Error; +use Bugzilla::Field; use Bugzilla::Mailer; use Bugzilla::Token; use Bugzilla::User; @@ -133,6 +135,29 @@ sub parse_mail { $fields{'short_desc'} = $summary; } + # The Importance/X-Priority field is only used when creating a new bug. + # 1) If somebody specifies a priority, use it. + # 2) If there is an Importance or X-Priority header, use it as + # something that is relative to the default priority. + # If the value is High or 1, increase the priority by 1. + # If the value is Low or 5, decrease the priority by 1. + # 3) Otherwise, use the default priority. + # Note: this will only work if the 'letsubmitterchoosepriority' + # parameter is enabled. + my $importance = $input_email->header('Importance') + || $input_email->header('X-Priority'); + if (!$fields{'bug_id'} && !$fields{'priority'} && $importance) { + my @legal_priorities = @{get_legal_field_values('priority')}; + my $i = firstidx { $_ eq Bugzilla->params->{'defaultpriority'} } @legal_priorities; + if ($importance =~ /(high|[12])/i) { + $i-- unless $i == 0; + } + elsif ($importance =~ /(low|[45])/i) { + $i++ unless $i == $#legal_priorities; + } + $fields{'priority'} = $legal_priorities[$i]; + } + my $comment = ''; # Get the description, except the signature. foreach my $line (@body_lines) { -- cgit v1.2.3-24-g4f1b