]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 625437 - Use 'Importance' / 'X-Priority' headers in incoming mail to influence...
authorReed Loden <reed@reedloden.com>
Wed, 1 Aug 2012 00:38:02 +0000 (17:38 -0700)
committerReed Loden <reed@reedloden.com>
Wed, 1 Aug 2012 00:38:02 +0000 (17:38 -0700)
[r=LpSolit a=LpSolit]

email_in.pl

index 53b5ac2a888cda3777039475071a3b228cd9c4fd..67a48e789eac978be503d93e3acbdada8877cc50 100755 (executable)
@@ -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) {