tadman has asked for the wisdom of the Perl Monks concerning the following question:

I've been using Mail::Mailer in SMTP mode, not unlike many examples, but what I have found is that there is no Date: header entry created for you by default. This can cause the e-mail to end up sorted incorrectly as being very old, for example 1904 on a Macintosh computer, or 1970 under UNIX.

Of course, you can get something close using:
my $date = scalar localtime(time);
Which is:
Thu Aug 30 12:54:57 2001
What's the easiest way to get an RFC822, or RFC2822, compliant Date: header such as:
Thu, 30 Aug 2001 13:09:26 -0400

Replies are listed 'Best First'.
Re: RFC-Compliant Date String for Mail::Mailer
by count0 (Friar) on Aug 30, 2001 at 21:42 UTC
    It's probaby easiest to just use the POSIX strftime();
    Here is an example:
    use POSIX qw(strftime); my $time = strftime("%a, %d %b %Y %H:%M:%S %z", localtime time);
(crazyinsomniac) Re: RFC-Compliant Date String for Mail::Mailer
by crazyinsomniac (Prior) on Aug 30, 2001 at 21:57 UTC
    Does this qualify? (ok, now?)
    #Thu Aug 30 18:03:31 2001 my @gmt= split ' ', scalar(gmtime); print my $gmtime = "$gmt[0], ".( join ' ', (@gmt)[2,1,3,4]).' 0000'; #Thu, 30 Aug 2001 13:09:26 0000

    You should by all means use POSIX like count0 (smarter).

     
    ___crazyinsomniac_______________________________________
    Disclaimer: Don't blame. It came from inside the void

    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

(dkubb) Re: (1) RFC-Compliant Date String for Mail::Mailer
by dkubb (Deacon) on Dec 05, 2001 at 09:04 UTC

    An easy way to generate an RFC-compliant Date header string is to use time2str() from Date::Format:

    use Date::Format qw(time2str); my $date = time2str('%a, %d %b %Y %H:%M:%S %z', time));