From: Don Armstrong <don@donarmstrong.com>
Date: Wed, 3 Dec 2008 18:40:59 +0000 (-0800)
Subject: Add Date headers if missing (closes: #458757)
X-Git-Tag: release/2.6.0~467^2~4
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=dc85a6466933b3bb0d49508d2b1aecf593ada2f6;p=debbugs.git

Add Date headers if missing (closes: #458757)
---

diff --git a/Debbugs/MIME.pm b/Debbugs/MIME.pm
index 78599747..0d35b0fb 100644
--- a/Debbugs/MIME.pm
+++ b/Debbugs/MIME.pm
@@ -24,6 +24,9 @@ BEGIN {
 use File::Path;
 use MIME::Parser;
 
+use POSIX qw(strftime);
+use List::MoreUtils qw(apply);
+
 # for decode_rfc1522
 use MIME::WordDecoder qw();
 use Encode qw(decode encode encode_utf8 decode_utf8 is_utf8);
@@ -114,13 +117,17 @@ sub parse
 
 =head2 create_mime_message
 
-     create_mime_message([To=>'don@debian.org'],$body,[$attach1, $attach2]);
+     create_mime_message([To=>'don@debian.org'],$body,[$attach1, $attach2],$include_date);
 
 Creates a MIME encoded message with headers given by the first
 argument, and a message given by the second.
 
 Optional attachments can be specified in the third arrayref argument.
 
+Whether to include the date in the header is the final argument; it
+defaults to true, setting the Date header if one is not already
+present.
+
 Headers are passed directly to MIME::Entity::build, the message is the
 first attachment.
 
@@ -132,12 +139,23 @@ MIME::Entity::attach
 =cut
 
 sub create_mime_message{
-     my ($headers,$body,$attachments) = @_;
+     my ($headers,$body,$attachments,$include_date) = @_;
      $attachments = [] if not defined $attachments;
+     $include_date = 1 if not defined $include_date;
 
      die "The first argument to create_mime_message must be an arrayref" unless ref($headers) eq 'ARRAY';
      die "The third argument to create_mime_message must be an arrayref" unless ref($attachments) eq 'ARRAY';
 
+     if ($include_date) {
+	 my %headers = apply {lc($_)} @{$headers};
+	 if (not exists $headers{date}) {
+	     push @{$headers},
+		 ('Date',
+		  strftime("%a, %d %b %Y %H:%M:%S +0000",gmtime)
+		 );
+	 }
+     }
+
      # Build the message
      # MIME::Entity is stupid, and doesn't rfc1522 encode its headers, so we do it for it.
      my $msg = MIME::Entity->build('Content-Type' => 'text/plain; charset=utf-8',
diff --git a/debian/changelog b/debian/changelog
index 865fc141..dd73da4b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -236,6 +236,7 @@ debbugs (2.4.2) UNRELEASED; urgency=low
   * Strip BOM before regexes involving spaces (closes: #488554)
   * Display link to full log again (closes: #507506)
   * Add Last-Modified: header support to mbox download (closes: #456786)
+  * Add Date headers if missing (closes: #458757)
 
   
  -- Colin Watson <cjwatson@debian.org>  Fri, 20 Jun 2003 18:57:25 +0100