This project is read-only.

Date.TryParseExact Problem

Topics: Issues
Nov 20, 2013 at 2:23 PM
I have a problem with the recovery of the correct date of the message.
for all messages that arrive through the day in the format "dd" everything works correctly, but in some messages the day comes in the format "d" and then the "ValidDateTimeFormats" does not contain the correct format.
For example I get from the server the following date: "Fri, Nov 1, 2013 23:13:40"
in this case the "ValidDateTimeFormats" does not contain the correct format, and then the TryParse returns "null".
Adding the format "ddd, d MMM yyyy HH: mm: ss" then the date of the message is retrieved correctly.
If you can bring out a new release so correct solve the problem.
Nov 20, 2013 at 2:33 PM
Hi GDEffe,

thank you for your message! I will include the missing date format in the coming release

Kind regards,

Nov 20, 2013 at 3:32 PM
Edited Nov 20, 2013 at 3:34 PM
Ok, thank you.

but I also have another problem.
the procedure 'parsedate' class HeaderFieldParser does not take care the time zone offset.
if I receive emails from server in my own ZONE come with my own OFFSET and then recovering the correct date and time.
if coming from servers in different ZONE with different OFFSET from mine, recovering from 'parsedate' a date with time different from the real.
to solve the problem in my opinion, just delete this piece:

var num = value.IndexOf (':');

             if (num! = -1)
                 var num2 = value.IndexOfAny (new [] {'', '\ t'}, num);
                 if (num2 == -1)
                     return null;
                 value.Substring value = (0, num2);

             value.Replace value = ('-', '');

and let the TryParseExact also works with the OFFSET.
When will it come out with a release these updates?
Nov 20, 2013 at 4:22 PM
Thank you for taking good care of the code! The update is planned for this weekend, I also include your suggestion about time zones.
Nov 27, 2013 at 10:44 PM
Hi GDEffe,

you can check the latest code in the repository, I added the missing date format. Parsing of timezones is not included yet, but coming in the next few days.


Nov 29, 2013 at 12:55 PM
Hi Pavel,
in the download section there isn't a new revision, even if source code I saw that the parsing has the new date format.
I tried to re-download the library but the problem remains.
maybe you don't have upload the new versione yet?
Nov 29, 2013 at 5:43 PM
Hi GDEffe,

only the code in the repository (see source code section) has been updated. There was no new stable release yet, but it's coming in a few days.

Kind regards,

Dec 3, 2013 at 3:20 PM
ok, I tried the code in the repository (source code section) and date in the new format are retrieved correctly.
as you said, parsing of timezones is not included yet

I noticed, however, that the new 'version' does not separate attachments from embedded resource but also appear in the attachment the Embeddeb resource. is that correct? the old attachment handling, i think was more comfortable.
Dec 3, 2013 at 3:50 PM
Hi GDEffe,

thank you for testing the code!

The attachment handling was not updated yet, as the new code is not stable yet.
At the moment some attachments (e.g the google logo and profile picture in messages from Google+) appear in both, attachments, and embedded resources.
This happens when the body parts are missing the "inline" disposition, however have a ContentId.
I will see to handle these attachments to only appear as embedded resources.

Best regards,

Dec 17, 2013 at 12:08 PM
Hi Pavel,
when the timezone will be updated?
Dec 17, 2013 at 4:54 PM
Hi GDEffe,

I'm sorry, totally forgot about this. I'll set it on high priority and will update the library on weekend.
Dec 27, 2013 at 6:58 AM
not sure it this helps or is part of the issue but if i had a date like so
"Thu, 12 Dec 2013 21:19:31 -0800 (PST)"
the (pst) always caused issues however not all of them had the time zone.
so i put this little bit of code and it seems to work
int ind = s.LastIndexOf(' ');
if((s[ind + 1] >= 'A' && s[ind + 1] <= 'Z') || (s[ind + 1] == '(' || s[ind + 1] == ')'))
              s = s.Substring(0, ind);
DateTime date = DateTime.Parse(s, CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault);
so far no failures yet

hope it helps
Dec 27, 2013 at 3:45 PM
Edited Dec 27, 2013 at 3:47 PM
You may get slightly better performance by doing:
  int ind = s.LastIndexOf(' ');
  if (Char.IsUpper (s, ind + 1) || (s[ind + 1] == '(') || (s[ind + 1]==')')) {
      s = s.Substring (0, ind);

PS: Not sure why "ind + 1" appears oddly in my browser.
Dec 28, 2013 at 3:34 PM
Hi ravib,

thank you for the snippet! I will include it!