[Dovecot] SORT(DATE) and missing Date headers

Kyle Wheeler kyle-dovecot at memoryhole.net
Tue Oct 2 17:49:12 EEST 2007


On Tuesday, September 25 at 06:26 PM, quoth Timo Sirainen:
>> That's not *quite* what I meant. ARRIVAL is "when did this mail get 
>> here", while DATE is supposed to be "when was this mail sent". My 
>> thought here is that "when was this mail sent" can be approximated 
>> in the absence of a Date header by checking the earliest timestamp 
>> in the Received headers.
>
>So, something like:
>
>const char *const *headers = mail_get_headers(mail, "Received");
>if (headers != NULL && headers[0] != NULL) {
>  while (headers[1] != NULL) headers++;
>  // do your Received header parsing magic for headers[0]
>}

Aha! That's perfect! (and so simple!)

If anyone in the future is interested in the code for this, here's 
what I did that works for me. This goes in all three places that 
mail_get_date() is used in the code:

t = mail_get_date(mail, NULL);
if (t == (time_t)-1 || t == 0) {
     const char *const *headers = mail_get_headers(mail, "Received");
     if (headers != NULL && headers[0] != NULL) {
         while (headers[1] != NULL) headers++; // find the last one
         /* find the semicolon */
         const char * curs = headers[0];
         while (curs[0] != ';' && curs[0] != 0) {
             if (curs[0] == '(')
                 while (curs[0] != ')' && curs[0] != 0) curs++;
             curs++;
         if (curs[0] == ';') {
             curs++;
             if (curs[0] != 0) {
                 int tz;
                 message_date_parse((const unsigned char *)curs,
                         strlen(curs), &t, &tz);
             }
         }
     }
}

Thanks, Timo!

~Kyle
-- 
Coffee is the common man's gold, and like gold, it brings to every 
person the feeling of luxury and nobility.
                                                  -- Sheik Abd-al-Kadir
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://dovecot.org/pipermail/dovecot/attachments/20071002/a1807b93/attachment.bin 


More information about the dovecot mailing list