Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Most of this has been said in one way or another in other replies, but I still sense a bit of confusion, so here goes....

Mail::IMAPClient documentation (and the actual code) say that Rfc2060_datetime returns a date string that is properly formatted for use in various requests to the IMAP server (e.g., delete messages older than N days). It does not report the server's notion of current date and time. The following (untested; I don't have Mail::IMAPClient available to test) should work:

use Mail::IMAPClient; my $now = time(); my $num_days = 5; # season to taste my $timestamp_n_daysago = $now - $num_days * 86400; #86400 secs/day my $zone = '-0400'; # EDT, season to taste, defaults to '+0000' (GMT0 +) my $date = Mail::IMAPClient->Rfc2060_datetime($timestamp_n_daysago, $z +one);
Now $date should be a properly formatted date string for SEARCH, etc. commands to the IMAP server, with the following caveats:
  • it is important that the clock on the local system is set correctly; a few seconds are not crucial, but if the date is off by weeks there could be some ugly surprises... :-)
  • $zone should really be the time zone used by the IMAP server. Many mail servers run with GMT0, but YMMV.
  • computation of $timestamp_ndaysago ignores DST changes and such; a better (i.e., more accurate) solution would use one of the DateTime modules to compute date offsets (all of which is irrelevant if the IMAP server is running it's clock in GMT0);

Update: Now that I'm at $HOME, where I have Mail::IMAPClient and can run the above code, it needs a few tweaks and some additional explanation based on re-reading the docs. First the code:
use strict; use warnings; use Mail::IMAPClient; my $now = time(); my $zone = '-0400'; # EDT, season to taste, defaults to '+0000' (GMT0 +) my $zone_correction = 3600 * $zone / 100; # timezone correction in s +ecs print "zone_correction: $zone_correction\n"; $now += $zone_correction; my $date = Mail::IMAPClient->Rfc2060_datetime($now, $zone); print "date_time now: $date\n"; my $num_days = 5; # season to taste my $timestamp_n_daysago = $now - $num_days * 86400; #86400 secs/day $date = Mail::IMAPClient->Rfc2060_datetime($timestamp_n_daysago, $zone +); print "date_time $num_days days ago: $date\n";

From the shell:

-> date && ./test Wed Sep 24 16:01:32 EDT 2008 zone_correction: -14400 date_time now: 24-Sep-2008 16:01:32 -0400 date_time 5 days ago: 19-Sep-2008 16:01:32 -0400

And by way of additional explanation:

The documentation for Mail::IMAPClient->Rfc2060_datetime says:

The timestamp follows the definition of the output of the platforms specific "time", usually in seconds since Jan 1st 1970. However, you have to correct the number yourself for the zone.
In other words, if I want the resulting string to give the date/time in my current time zone (EDT, which is GMT-0400), I need to adjust the output of time appropriately. Hence the changes to compute a $zone_correction and adjust $now before calling Mail::IMAPClient->Rfc2060_datetime.

In reply to Re: problem in Rfc2080 date of imap server by broomduster
in thread problem in Rfc2080 date of imap server by luckypower

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (4)
    As of 2018-05-22 21:51 GMT
    Find Nodes?
      Voting Booth?