简体   繁体   中英

Indy10 GMTToLocalDateTime issue

It seems that Indy GMTToLocalDateTime does not ignore comments when decoding date:

TDateTime dtDate1 = GMTToLocalDateTime("12 Mar 2015 14:03:21 -0000");
TDateTime dtDate2 = GMTToLocalDateTime("Thu, 12 Mar 2015 14:03:20 +0000 (GMT)");
TDateTime dtDate3 = GMTToLocalDateTime("Thu, 12 Mar 2015 14:03:20 +0000 (envelope-from <aaa@bbb.ccc>)");
TDateTime dtDate4 = GMTToLocalDateTime("Thu, 12 Mar 2015 14:03:20 +0000 (aaa@bbb.ccc)");

UnicodeString Dt1 = DateTimeToStr(dtDate1);
UnicodeString Dt2 = DateTimeToStr(dtDate2);
UnicodeString Dt3 = DateTimeToStr(dtDate3);
UnicodeString Dt4 = DateTimeToStr(dtDate4);

First 2 are decoded correctly. The last 2 are not. The part in the parenthesis is supposed to be ignored because it is just a comment but it seems that it is not.

Is this a bug in Indy? Also - is there a bug-tracker for Indy (as it appears forums are down)?

GMTToLocalDateTime() (more specifically, RawStrInternetToDateTime() ) is not meant to accept or look for embedded comments. Comments do not belong in the input and must be stripped off beforehand. Embedded comments are a feature of email, but are to be ignored when processing data (see RFC 822 Section 3.4.3).

In this situation, the comments were not stripped by the caller, and the presence of the '.' character in the comments of the last 2 examples was throwing off RawStrInternetToDateTime() when it checks for the presence of a timestamp and whether it uses ':' or '.' as a delimiter between the hour/minutes/seconds.

Indy as a whole is not designed to even recognize, let alone handle, embedded comments in headers. However, in this situation, I have made a small tweak to RawStrInternetToDateTime() so comments will not confuse the timestamp parsing anymore (though it is really the caller's responsibility to strip comments before parsing).

And yes, there are bug trackers for Indy:

http://code.google.com/p/indyproject
(though Google Code is shutting down , so this one will go away eventually).

http://indy.codeplex.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM