[Debtags-commits] [svn] r1359 - central-database/trunk/email

Erich Schubert erich at costa.debian.org
Sun Sep 18 01:05:40 UTC 2005


Author: erich
Date: Sun Sep 18 01:05:39 2005
New Revision: 1359

Modified:
   central-database/trunk/email/update-tags.pl
Log:
the email interface will now set a date header in replies

Modified: central-database/trunk/email/update-tags.pl
==============================================================================
--- central-database/trunk/email/update-tags.pl	(original)
+++ central-database/trunk/email/update-tags.pl	Sun Sep 18 01:05:39 2005
@@ -3,9 +3,51 @@
 use MIME::Parser;
 use English;
 use DBI;
+use POSIX;
 
 require '../config.pl';
 
+#### This code is from Amavisd, which is also GPL.
+#
+# Given a Unix time, return the local time zone offset at that time
+# as a string +HHMM or -HHMM, appropriate for the RFC2822 date format.
+# Works also for non-full-hour zone offsets.   (c) Mark Martinec, GPL
+#
+sub get_zone_offset($) {
+	my($t) = @_;
+	my($d) = 0;   # local zone offset in seconds
+	for (1..3) {  # match the date (with a safety loop limit just in case)
+		my($r) = sprintf("%04d%02d%02d", (localtime($t))[5,4,3]) cmp
+		         sprintf("%04d%02d%02d", (gmtime($t+$d))[5,4,3]);
+		if ($r == 0) { last } else { $d += $r*24*3600 };
+	}
+	my($sl,$su) = (0,0);
+	for ((localtime($t))[2,1,0]) { $sl = $sl*60 + $_ };
+	for ((gmtime($t+$d))[2,1,0]) { $su = $su*60 + $_ };
+	$d += $sl-$su;           # add HMS difference (in seconds)
+	my($sign) = $d >= 0 ? '+' : '-';   $d = -$d if $d<0;
+	$d = int(($d+30)/60.0);  # give minutes, rounded
+	sprintf("%s%02d%02d", $sign, int($d/60), $d%60);
+}
+
+# Given a Unix time, provide date-time timestamp as specified in RFC 2822,
+# to be used in headers such as 'Date:' and 'Received:'
+#
+sub rfc2822_timestamp(;$) {
+	my($t) = @_ ? shift : time;
+	my(@lt) = localtime($t);
+	# can't use %z because some systems do not support it (is treated as %Z)
+	my($old_locale) = setlocale(LC_TIME, "C");
+	my($zone_name) = strftime("%Z", @lt);
+	my($s) = strftime("%a, %e %b %Y %H:%M:%S ", @lt);
+	$s .= get_zone_offset($t);
+	$s .= " (" . $zone_name . ")"  if $zone_name !~ /^\s*$(?!\n)/;
+	setlocale(LC_CTYPE, $old_locale);
+	$s;
+};
+
+#### Back to DebTags code.
+
 # create parser
 my $parser = new MIME::Parser;
 # keep in memory
@@ -54,6 +96,7 @@
 EOF
 		my $reply = MIME::Entity->build(From => '....EMAIL....',
 			To => $from, Subject => 'Results from the debtags submission',
+			Date => rfc2822_timestamp(),
 			Data => $replym, Type => 'text/plain');
 		if ($replylines ne "") {
 			$reply->attach(Data => $replylines, Type => 'text/plain');
@@ -73,6 +116,7 @@
 EOF
 		my $reply = MIME::Entity->build(From => '....EMAIL....',
 			To => $from, Subject => 'Results from the debtags submission',
+			Date => rfc2822_timestamp(),
 			Data => $replym, Type => 'text/plain');
 		$reply->smtpsend();
 	}



More information about the Debtags-commits mailing list