]> git.donarmstrong.com Git - debbugs.git/commitdiff
Add Date headers if missing (closes: #458757)
authorDon Armstrong <don@donarmstrong.com>
Wed, 3 Dec 2008 18:40:59 +0000 (10:40 -0800)
committerDon Armstrong <don@donarmstrong.com>
Wed, 3 Dec 2008 18:40:59 +0000 (10:40 -0800)
Debbugs/MIME.pm
debian/changelog

index 785997477ce9a3e2af44051f6a76595d02e61155..0d35b0fb85e8b259fdf37d3faad373dc5f51087f 100644 (file)
@@ -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',
index 865fc14150ddaca567ba602aea107f53c7e0a449..dd73da4b1e097cac08c6670aa448b9e1cf91a831 100644 (file)
@@ -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