eMail Headers: RFC2822 and ISO8601 date formats in Perl

In eMail headers, the Creation Date of message has to be present in order to visualize correctly the message itself in recipient’s client.

This piece of code can helps the definition of eMail Headers (for example for use in Perl BOTs Sending eMail messages).

#!/usr/bin/perl -w
 
use strict;
use POSIX qw(strftime);
 
my $now = time();
 
#####################
# ISO8601 Date Format
#####################
 
# Extracting TimeZone
my $timezone = strftime("%z", localtime($now));
$timezone =~ s/(\d{2})(\d{2})/$1:$2/;
 
# Printing Date
print strftime("%Y-%m-%dT%H:%M:%S", localtime($now)) . $tz . "\n";
 
 
###################################################################
# RFC822 (actually RFC2822, as the year has 4 digits) Date Format
###################################################################
 
print strftime("%a, %d %b %Y %H:%M:%S %z", localtime($now)) . "\n";

Comments are closed.