Commit e5747d36 e5747d3682631aa9380febc0f93943e0722d2986 by Sergey Poznyakoff

(amd_envelope_date): Reformat Delivery-Date value

to standart ctime format. Fix memory leak.
(amd_envelope_sender): Propagate return from header_aget_value()
back to the caller.
1 parent 84f0a1f0
...@@ -1410,7 +1410,7 @@ amd_envelope_date (envelope_t envelope, char *buf, size_t len, ...@@ -1410,7 +1410,7 @@ amd_envelope_date (envelope_t envelope, char *buf, size_t len,
1410 message_t msg = envelope_get_owner (envelope); 1410 message_t msg = envelope_get_owner (envelope);
1411 struct _amd_message *mhm = message_get_owner (msg); 1411 struct _amd_message *mhm = message_get_owner (msg);
1412 header_t hdr = NULL; 1412 header_t hdr = NULL;
1413 char *from; 1413 char *date;
1414 int status; 1414 int status;
1415 1415
1416 if (mhm == NULL) 1416 if (mhm == NULL)
...@@ -1418,24 +1418,37 @@ amd_envelope_date (envelope_t envelope, char *buf, size_t len, ...@@ -1418,24 +1418,37 @@ amd_envelope_date (envelope_t envelope, char *buf, size_t len,
1418 1418
1419 if ((status = message_get_header (msg, &hdr)) != 0) 1419 if ((status = message_get_header (msg, &hdr)) != 0)
1420 return status; 1420 return status;
1421 if (header_aget_value (hdr, MU_HEADER_ENV_DATE, &from) 1421 if (header_aget_value (hdr, MU_HEADER_ENV_DATE, &date))
1422 && header_aget_value (hdr, MU_HEADER_DELIVERY_DATE, &from)) 1422 {
1423 return ENOSYS; 1423 time_t t;
1424 int rc;
1425
1426 if (header_aget_value (hdr, MU_HEADER_DELIVERY_DATE, &date))
1427 return MU_ERR_NOENT;
1428 /* Convert to ctime format */
1429 rc = mu_parse_date (date, &t, NULL); /* FIXME: TZ info is lost */
1430 free (date);
1431 if (rc)
1432 return MU_ERR_NOENT;
1433 date = strdup (ctime (&t));
1434 }
1424 1435
1425 /* Format: "sender date" */ 1436 /* Format: "sender date" */
1426 if (buf && len > 0) 1437 if (buf && len > 0)
1427 { 1438 {
1428 len--; /* Leave space for the null. */ 1439 len--; /* Leave space for the null. */
1429 strncpy (buf, from, len); 1440 strncpy (buf, date, len);
1430 if (strlen (from) < len) 1441 if (strlen (date) < len)
1431 { 1442 {
1432 len = strlen (buf); 1443 len = strlen (buf);
1444 if (buf[len-1] != '\n')
1433 buf[len++] = '\n'; 1445 buf[len++] = '\n';
1434 } 1446 }
1435 buf[len] = '\0'; 1447 buf[len] = '\0';
1436 } 1448 }
1437 else 1449 else
1438 len = 0; 1450 len = 0;
1451 free (date);
1439 1452
1440 if (psize) 1453 if (psize)
1441 *psize = len; 1454 *psize = len;
...@@ -1456,8 +1469,8 @@ amd_envelope_sender (envelope_t envelope, char *buf, size_t len, size_t *psize) ...@@ -1456,8 +1469,8 @@ amd_envelope_sender (envelope_t envelope, char *buf, size_t len, size_t *psize)
1456 1469
1457 if ((status = message_get_header (msg, &hdr)) != 0) 1470 if ((status = message_get_header (msg, &hdr)) != 0)
1458 return status; 1471 return status;
1459 if (header_aget_value (hdr, MU_HEADER_ENV_SENDER, &from)) 1472 if (status = header_aget_value (hdr, MU_HEADER_ENV_SENDER, &from))
1460 return ENOSYS; 1473 return status;
1461 1474
1462 if (buf && len > 0) 1475 if (buf && len > 0)
1463 { 1476 {
......