Commit 3da52798 3da52798917b92b79751c7eb9a0c1b721f167318 by Sergey Poznyakoff

(fetch_internaldate): Bugfix. Coredumped on invalid dates.

1 parent beea97a5
...@@ -337,17 +337,25 @@ fetch_flags (struct fetch_command *command, char **arg) ...@@ -337,17 +337,25 @@ fetch_flags (struct fetch_command *command, char **arg)
337 static int 337 static int
338 fetch_internaldate (struct fetch_command *command, char **arg ARG_UNUSED) 338 fetch_internaldate (struct fetch_command *command, char **arg ARG_UNUSED)
339 { 339 {
340 char date[128], *p; 340 char date[128];
341 envelope_t env = NULL; 341 envelope_t env = NULL;
342 struct tm tm; 342 struct tm tm, *tmp = NULL;
343 mu_timezone tz; 343 mu_timezone tz;
344 344
345 message_get_envelope (command->msg, &env); 345 message_get_envelope (command->msg, &env);
346 date[0] = '\0'; 346 date[0] = '\0';
347 envelope_date (env, date, sizeof (date), NULL); 347 if (envelope_date (env, date, sizeof (date), NULL) == 0)
348 p = date; 348 {
349 mu_parse_ctime_date_time ((const char **) &p, &tm, &tz); 349 char *p = date;
350 strftime (date, sizeof (date), "%d-%b-%Y %H:%M:%S", &tm); 350 if (mu_parse_ctime_date_time ((const char **) &p, &tm, &tz) == 0)
351 tmp = &tm;
352 }
353 if (!tmp)
354 {
355 time_t t = time(NULL);
356 tmp = localtime(&t);
357 }
358 strftime (date, sizeof (date), "%d-%b-%Y %H:%M:%S", tmp);
351 util_send ("%s", command->name); 359 util_send ("%s", command->name);
352 util_send (" \"%s +0000\"", date); 360 util_send (" \"%s +0000\"", date);
353 return RESP_OK; 361 return RESP_OK;
......