Commit 548d003f 548d003fc8be7285726e4d978d2236867dacb55c by Sergey Poznyakoff

(_mh_message_save): Bugfix;

(mh_save_attributes): Implemented
1 parent ca0bf2df
...@@ -64,9 +64,6 @@ ...@@ -64,9 +64,6 @@
64 64
65 #define MAX_OPEN_STREAMS 16 65 #define MAX_OPEN_STREAMS 16
66 66
67 #define MH_ENV_SENDER_HEADER "X-Envelope-Sender"
68 #define MH_ENV_DATE_HEADER "X-Envelope-Date"
69
70 /* Notifications ADD_MESG. */ 67 /* Notifications ADD_MESG. */
71 #define DISPATCH_ADD_MSG(mbox,mhd) \ 68 #define DISPATCH_ADD_MSG(mbox,mhd) \
72 do \ 69 do \
...@@ -508,6 +505,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) ...@@ -508,6 +505,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge)
508 size_t n, off = 0; 505 size_t n, off = 0;
509 size_t bsize; 506 size_t bsize;
510 size_t nlines; 507 size_t nlines;
508 size_t new_body_start, new_header_lines;
511 FILE *fp; 509 FILE *fp;
512 message_t msg = mhm->message; 510 message_t msg = mhm->message;
513 header_t hdr; 511 header_t hdr;
...@@ -517,15 +515,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) ...@@ -517,15 +515,7 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge)
517 char buffer[512]; 515 char buffer[512];
518 envelope_t env = NULL; 516 envelope_t env = NULL;
519 517
520 if (expunge) 518 fp = _mh_tempfile (mhm->mhd, &name);
521 fp = _mh_tempfile (mhm->mhd, &name);
522 else
523 {
524 msg_name = _mh_message_name (mhm, mhm->deleted);
525 fp = fopen (msg_name, "w");
526 free (msg_name);
527 }
528
529 if (!fp) 519 if (!fp)
530 { 520 {
531 free (mhm); 521 free (mhm);
...@@ -561,14 +551,14 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) ...@@ -561,14 +551,14 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge)
561 if (!(strncasecmp (buf, "status:", 7) == 0 551 if (!(strncasecmp (buf, "status:", 7) == 0
562 || strncasecmp (buf, "x-imapbase:", 11) == 0 552 || strncasecmp (buf, "x-imapbase:", 11) == 0
563 || strncasecmp (buf, "x-uid:", 6) == 0 553 || strncasecmp (buf, "x-uid:", 6) == 0
564 || strncasecmp (buf, MH_ENV_DATE_HEADER ":", sizeof (MH_ENV_DATE_HEADER)) == 0 554 || strncasecmp (buf, MU_HEADER_ENV_DATE ":", sizeof (MU_HEADER_ENV_DATE)) == 0
565 || strncasecmp (buf, MH_ENV_SENDER_HEADER ":", sizeof (MH_ENV_SENDER_HEADER)) == 0)) 555 || strncasecmp (buf, MU_HEADER_ENV_SENDER ":", sizeof (MU_HEADER_ENV_SENDER)) == 0))
566 fprintf (fp, "%s", buf); 556 fprintf (fp, "%s", buf);
567 off += n; 557 off += n;
568 } 558 }
569 559
570 mhm->header_lines = nlines; 560 new_header_lines = nlines;
571 mhm->body_start = off; 561 new_body_start = off;
572 562
573 /* Add imapbase */ 563 /* Add imapbase */
574 if (!mhd->msg_head || (mhd->msg_head == mhm)) /*FIXME*/ 564 if (!mhd->msg_head || (mhd->msg_head == mhm)) /*FIXME*/
...@@ -585,13 +575,13 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) ...@@ -585,13 +575,13 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge)
585 char *p = buffer; 575 char *p = buffer;
586 while (isspace (*p)) 576 while (isspace (*p))
587 p++; 577 p++;
588 fprintf (fp, "%s: %s", MH_ENV_DATE_HEADER, p); 578 fprintf (fp, "%s: %s", MU_HEADER_ENV_DATE, p);
589 nlines++; 579 nlines++;
590 } 580 }
591 581
592 if (envelope_sender (env, buffer, sizeof buffer, &n) == 0 && n > 0) 582 if (envelope_sender (env, buffer, sizeof buffer, &n) == 0 && n > 0)
593 { 583 {
594 fprintf (fp, "%s: %s\n", MH_ENV_SENDER_HEADER, buffer); 584 fprintf (fp, "%s: %s\n", MU_HEADER_ENV_SENDER, buffer);
595 nlines++; 585 nlines++;
596 } 586 }
597 587
...@@ -618,19 +608,18 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge) ...@@ -618,19 +608,18 @@ _mh_message_save (struct _mh_data *mhd, struct _mh_message *mhm, int expunge)
618 off += n; 608 off += n;
619 } 609 }
620 610
611 mhm->header_lines = new_header_lines;
612 mhm->body_start = new_body_start;
621 mhm->body_lines = nlines; 613 mhm->body_lines = nlines;
622 mhm->body_end = off; 614 mhm->body_end = off;
623 615
624 free (buf); 616 free (buf);
625 fclose (fp); 617 fclose (fp);
626 618
627 if (expunge) 619 msg_name = _mh_message_name (mhm, mhm->deleted);
628 { 620 rename (name, msg_name);
629 msg_name = _mh_message_name (mhm, mhm->deleted); 621 free (name);
630 rename (name, msg_name); 622 free (msg_name);
631 free (name);
632 free (msg_name);
633 }
634 623
635 return 0; 624 return 0;
636 } 625 }
...@@ -795,9 +784,41 @@ mh_expunge (mailbox_t mailbox) ...@@ -795,9 +784,41 @@ mh_expunge (mailbox_t mailbox)
795 static int 784 static int
796 mh_save_attributes (mailbox_t mailbox) 785 mh_save_attributes (mailbox_t mailbox)
797 { 786 {
798 /*FIXME*/ 787 struct _mh_data *mhd = mailbox->data;
799 (void)mailbox; 788 struct _mh_message *mhm;
800 return ENOSYS; 789
790 if (mhd == NULL)
791 return EINVAL;
792
793 if (mhd->msg_count == 0)
794 return 0;
795
796 /* Find the first dirty(modified) message. */
797 for (mhm = mhd->msg_head; mhm; mhm = mhm->next)
798 {
799 if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED) ||
800 (mhm->attr_flags & MU_ATTRIBUTE_DELETED) ||
801 (mhm->message && message_is_modified (mhm->message)))
802 break;
803 }
804
805 if (!mhm)
806 return 0; /* Nothing changed, just return. */
807
808 while (mhm)
809 {
810 struct _mh_message *next = mhm->next;
811
812 if (mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
813 {
814 _mh_attach_message (mailbox, mhm, NULL);
815 mhm->deleted = mhm->attr_flags & MU_ATTRIBUTE_DELETED;
816 _mh_message_save (mhd, mhm, 0);
817 }
818 mhm = next;
819 }
820
821 return 0;
801 } 822 }
802 823
803 static int 824 static int
...@@ -1441,7 +1462,7 @@ mh_envelope_date (envelope_t envelope, char *buf, size_t len, ...@@ -1441,7 +1462,7 @@ mh_envelope_date (envelope_t envelope, char *buf, size_t len,
1441 1462
1442 if ((status = message_get_header (msg, &hdr)) != 0) 1463 if ((status = message_get_header (msg, &hdr)) != 0)
1443 return status; 1464 return status;
1444 if (header_aget_value (hdr, MH_ENV_DATE_HEADER, &from)) 1465 if (header_aget_value (hdr, MU_HEADER_ENV_DATE, &from))
1445 return ENOSYS; 1466 return ENOSYS;
1446 1467
1447 /* Format: "sender date" */ 1468 /* Format: "sender date" */
...@@ -1478,7 +1499,7 @@ mh_envelope_sender (envelope_t envelope, char *buf, size_t len, size_t *psize) ...@@ -1478,7 +1499,7 @@ mh_envelope_sender (envelope_t envelope, char *buf, size_t len, size_t *psize)
1478 1499
1479 if ((status = message_get_header (msg, &hdr)) != 0) 1500 if ((status = message_get_header (msg, &hdr)) != 0)
1480 return status; 1501 return status;
1481 if (header_aget_value (hdr, MH_ENV_SENDER_HEADER, &from)) 1502 if (header_aget_value (hdr, MU_HEADER_ENV_SENDER, &from))
1482 return ENOSYS; 1503 return ENOSYS;
1483 1504
1484 if (buf && len > 0) 1505 if (buf && len > 0)
......