(_mh_message_save): Bugfix
Showing
1 changed file
with
31 additions
and
25 deletions
... | @@ -504,7 +504,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) | ... | @@ -504,7 +504,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) |
504 | char *name = NULL, *buf = NULL, *msg_name; | 504 | char *name = NULL, *buf = NULL, *msg_name; |
505 | size_t n, off = 0; | 505 | size_t n, off = 0; |
506 | size_t bsize; | 506 | size_t bsize; |
507 | size_t nlines; | 507 | size_t nlines, nbytes; |
508 | size_t new_body_start, new_header_lines; | 508 | size_t new_body_start, new_header_lines; |
509 | FILE *fp; | 509 | FILE *fp; |
510 | message_t msg = mhm->message; | 510 | message_t msg = mhm->message; |
... | @@ -517,10 +517,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) | ... | @@ -517,10 +517,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) |
517 | 517 | ||
518 | fp = _mh_tempfile (mhm->mhd, &name); | 518 | fp = _mh_tempfile (mhm->mhd, &name); |
519 | if (!fp) | 519 | if (!fp) |
520 | { | ||
521 | free (mhm); | ||
522 | return errno; | 520 | return errno; |
523 | } | ||
524 | 521 | ||
525 | message_size (msg, &bsize); | 522 | message_size (msg, &bsize); |
526 | 523 | ||
... | @@ -530,41 +527,38 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) | ... | @@ -530,41 +527,38 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) |
530 | break; | 527 | break; |
531 | 528 | ||
532 | if (!bsize) | 529 | if (!bsize) |
533 | { | ||
534 | free (mhm); | ||
535 | return ENOMEM; | 530 | return ENOMEM; |
536 | } | ||
537 | 531 | ||
538 | /* Copy flags */ | 532 | /* Copy flags */ |
539 | message_get_header (msg, &hdr); | 533 | message_get_header (msg, &hdr); |
540 | header_get_stream (hdr, &stream); | 534 | header_get_stream (hdr, &stream); |
541 | off = 0; | 535 | off = 0; |
542 | nlines = 0; | 536 | nlines = nbytes = 0; |
543 | while ((status = stream_readline (stream, buf, bsize, off, &n)) == 0 | 537 | while ((status = stream_readline (stream, buf, bsize, off, &n)) == 0 |
544 | && n != 0) | 538 | && n != 0) |
545 | { | 539 | { |
546 | if (_mh_delim(buf)) | 540 | if (_mh_delim(buf)) |
547 | break; | 541 | break; |
548 | 542 | ||
549 | nlines++; | ||
550 | |||
551 | if (!(strncasecmp (buf, "status:", 7) == 0 | 543 | if (!(strncasecmp (buf, "status:", 7) == 0 |
552 | || strncasecmp (buf, "x-imapbase:", 11) == 0 | 544 | || strncasecmp (buf, "x-imapbase:", 11) == 0 |
553 | || strncasecmp (buf, "x-uid:", 6) == 0 | 545 | || strncasecmp (buf, "x-uid:", 6) == 0 |
554 | || strncasecmp (buf, MU_HEADER_ENV_DATE ":", sizeof (MU_HEADER_ENV_DATE)) == 0 | 546 | || strncasecmp (buf, MU_HEADER_ENV_DATE ":", sizeof (MU_HEADER_ENV_DATE)) == 0 |
555 | || strncasecmp (buf, MU_HEADER_ENV_SENDER ":", sizeof (MU_HEADER_ENV_SENDER)) == 0)) | 547 | || strncasecmp (buf, MU_HEADER_ENV_SENDER ":", sizeof (MU_HEADER_ENV_SENDER)) == 0)) |
556 | fprintf (fp, "%s", buf); | 548 | { |
557 | off += n; | 549 | nlines++; |
550 | nbytes += fprintf (fp, "%s", buf); | ||
558 | } | 551 | } |
559 | 552 | ||
560 | new_header_lines = nlines; | 553 | off += n; |
561 | new_body_start = off; | 554 | } |
562 | 555 | ||
563 | /* Add imapbase */ | 556 | /* Add imapbase */ |
564 | if (!mhd->msg_head || (mhd->msg_head == mhm)) /*FIXME*/ | 557 | if (!mhd->msg_head || (mhd->msg_head == mhm)) /*FIXME*/ |
565 | { | 558 | { |
566 | fprintf (fp, "X-IMAPbase: %lu %u\n", | 559 | nbytes += fprintf (fp, "X-IMAPbase: %lu %u\n", |
567 | (unsigned long) mhd->uidvalidity, (unsigned) _mh_next_seq(mhd)); | 560 | (unsigned long) mhd->uidvalidity, |
561 | (unsigned) _mh_next_seq(mhd)); | ||
568 | nlines++; | 562 | nlines++; |
569 | } | 563 | } |
570 | 564 | ||
... | @@ -575,10 +569,10 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) | ... | @@ -575,10 +569,10 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) |
575 | char *p = buffer; | 569 | char *p = buffer; |
576 | while (isspace (*p)) | 570 | while (isspace (*p)) |
577 | p++; | 571 | p++; |
578 | fprintf (fp, "%s: %s", MU_HEADER_ENV_DATE, p); | 572 | nbytes += fprintf (fp, "%s: %s", MU_HEADER_ENV_DATE, p); |
579 | 573 | ||
580 | if (*p && p[strlen (p) - 1] != '\n') | 574 | if (*p && p[strlen (p) - 1] != '\n') |
581 | fprintf (fp, "\n"); | 575 | nbytes += fprintf (fp, "\n"); |
582 | 576 | ||
583 | nlines++; | 577 | nlines++; |
584 | } | 578 | } |
... | @@ -592,9 +586,16 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) | ... | @@ -592,9 +586,16 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) |
592 | /* Add status */ | 586 | /* Add status */ |
593 | message_get_attribute (msg, &attr); | 587 | message_get_attribute (msg, &attr); |
594 | attribute_to_string (attr, buf, bsize, &n); | 588 | attribute_to_string (attr, buf, bsize, &n); |
595 | fprintf (fp, "%s", buf); | 589 | if (n) |
596 | fprintf (fp, "\n"); | 590 | { |
597 | nlines += 2; | 591 | nbytes += fprintf (fp, "%s", buf); |
592 | nlines++; | ||
593 | } | ||
594 | nbytes += fprintf (fp, "\n"); | ||
595 | nlines++; | ||
596 | |||
597 | new_header_lines = nlines; | ||
598 | new_body_start = nbytes; | ||
598 | 599 | ||
599 | /* Copy message body */ | 600 | /* Copy message body */ |
600 | 601 | ||
... | @@ -610,12 +611,13 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) | ... | @@ -610,12 +611,13 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) |
610 | nlines++; | 611 | nlines++; |
611 | fwrite (buf, 1, n, fp); | 612 | fwrite (buf, 1, n, fp); |
612 | off += n; | 613 | off += n; |
614 | nbytes += n; | ||
613 | } | 615 | } |
614 | 616 | ||
615 | mhm->header_lines = new_header_lines; | 617 | mhm->header_lines = new_header_lines; |
616 | mhm->body_start = new_body_start; | 618 | mhm->body_start = new_body_start; |
617 | mhm->body_lines = nlines; | 619 | mhm->body_lines = nlines; |
618 | mhm->body_end = off; | 620 | mhm->body_end = nbytes; |
619 | 621 | ||
620 | free (buf); | 622 | free (buf); |
621 | fclose (fp); | 623 | fclose (fp); |
... | @@ -1215,14 +1217,18 @@ mh_message_stream_open (struct _mh_message *mhm) | ... | @@ -1215,14 +1217,18 @@ mh_message_stream_open (struct _mh_message *mhm) |
1215 | struct _mh_data *mhd = mhm->mhd; | 1217 | struct _mh_data *mhd = mhm->mhd; |
1216 | char *filename = NULL; | 1218 | char *filename = NULL; |
1217 | int status; | 1219 | int status; |
1218 | 1220 | int flags = MU_STREAM_ALLOW_LINKS; | |
1219 | filename = _mh_message_name (mhm, mhm->deleted); | 1221 | filename = _mh_message_name (mhm, mhm->deleted); |
1220 | 1222 | ||
1221 | if (!filename) | 1223 | if (!filename) |
1222 | return ENOMEM; | 1224 | return ENOMEM; |
1223 | 1225 | ||
1224 | status = file_stream_create (&mhm->stream, filename, | 1226 | /* The message should be at least readable */ |
1225 | mhd->mailbox->flags | MU_STREAM_ALLOW_LINKS); | 1227 | if (mhd->mailbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND)) |
1228 | flags |= MU_STREAM_RDWR; | ||
1229 | else | ||
1230 | flags |= MU_STREAM_READ; | ||
1231 | status = file_stream_create (&mhm->stream, filename, flags); | ||
1226 | 1232 | ||
1227 | free (filename); | 1233 | free (filename); |
1228 | 1234 | ... | ... |
-
Please register or sign in to post a comment