(_mh_message_save): Take into account
trailing newline returned by envelope_date (should it be returned, by the by?) Output a newline to separate the headers from the body. (mh_envelope_date): Make sure the returned value is terminated with a '\n' character (if the buffer space permits).
Showing
1 changed file
with
17 additions
and
5 deletions
... | @@ -540,7 +540,14 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) | ... | @@ -540,7 +540,14 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) |
540 | 540 | ||
541 | message_get_envelope (msg, &env); | 541 | message_get_envelope (msg, &env); |
542 | if (envelope_date (env, buffer, sizeof buffer, &n) == 0 && n > 0) | 542 | if (envelope_date (env, buffer, sizeof buffer, &n) == 0 && n > 0) |
543 | fprintf (fp, "%s: %s\n", MH_ENV_DATE_HEADER, buffer); | 543 | { |
544 | /* NOTE: buffer is terminated with \n */ | ||
545 | char *p = buffer; | ||
546 | while (isspace (*p)) | ||
547 | p++; | ||
548 | fprintf (fp, "%s: %s", MH_ENV_DATE_HEADER, p); | ||
549 | } | ||
550 | |||
544 | if (envelope_sender (env, buffer, sizeof buffer, &n) == 0 && n > 0) | 551 | if (envelope_sender (env, buffer, sizeof buffer, &n) == 0 && n > 0) |
545 | fprintf (fp, "%s: %s\n", MH_ENV_SENDER_HEADER, buffer); | 552 | fprintf (fp, "%s: %s\n", MH_ENV_SENDER_HEADER, buffer); |
546 | 553 | ||
... | @@ -548,6 +555,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) | ... | @@ -548,6 +555,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) |
548 | message_get_attribute (msg, &attr); | 555 | message_get_attribute (msg, &attr); |
549 | attribute_to_string (attr, buf, bsize, &n); | 556 | attribute_to_string (attr, buf, bsize, &n); |
550 | fprintf (fp, "%s", buf); | 557 | fprintf (fp, "%s", buf); |
558 | fprintf (fp, "\n"); | ||
551 | 559 | ||
552 | /* Copy message body */ | 560 | /* Copy message body */ |
553 | 561 | ||
... | @@ -1371,8 +1379,12 @@ mh_envelope_date (envelope_t envelope, char *buf, size_t len, | ... | @@ -1371,8 +1379,12 @@ mh_envelope_date (envelope_t envelope, char *buf, size_t len, |
1371 | { | 1379 | { |
1372 | len--; /* Leave space for the null. */ | 1380 | len--; /* Leave space for the null. */ |
1373 | strncpy (buf, from, len); | 1381 | strncpy (buf, from, len); |
1374 | buf[len] = '\0'; | 1382 | if (strlen (from) < len) |
1383 | { | ||
1375 | len = strlen (buf); | 1384 | len = strlen (buf); |
1385 | buf[len++] = '\n'; | ||
1386 | } | ||
1387 | buf[len] = '\0'; | ||
1376 | } | 1388 | } |
1377 | else | 1389 | else |
1378 | len = 0; | 1390 | len = 0; |
... | @@ -1401,11 +1413,11 @@ mh_envelope_sender (envelope_t envelope, char *buf, size_t len, size_t *psize) | ... | @@ -1401,11 +1413,11 @@ mh_envelope_sender (envelope_t envelope, char *buf, size_t len, size_t *psize) |
1401 | 1413 | ||
1402 | if (buf && len > 0) | 1414 | if (buf && len > 0) |
1403 | { | 1415 | { |
1404 | int slen = strlen (from) + 1; | 1416 | int slen = strlen (from); |
1405 | 1417 | ||
1406 | if (len <= slen) | 1418 | if (len < slen + 1) |
1407 | slen = len - 1; | 1419 | slen = len - 1; |
1408 | memcpy (buf, from, slen - 1); | 1420 | memcpy (buf, from, slen); |
1409 | buf[slen] = 0; | 1421 | buf[slen] = 0; |
1410 | } | 1422 | } |
1411 | else | 1423 | else | ... | ... |
-
Please register or sign in to post a comment