Commit 9bb7be19 9bb7be1916bab7ef490980694e2bfc7a6898c52a by Alain Magloire

Put more headers in the cache, (ugly).

1 parent 419da3f7
...@@ -67,6 +67,14 @@ attribute_is_modified (attribute_t attr) ...@@ -67,6 +67,14 @@ attribute_is_modified (attribute_t attr)
67 } 67 }
68 68
69 int 69 int
70 attribute_clear_modified (attribute_t attr)
71 {
72 if (attr)
73 attr->flags &= ~MU_ATTRIBUTE_MODIFIED;
74 return 0;
75 }
76
77 int
70 attribute_get_flags (attribute_t attr, int *pflags) 78 attribute_get_flags (attribute_t attr, int *pflags)
71 { 79 {
72 if (attr == NULL) 80 if (attr == NULL)
......
...@@ -76,6 +76,22 @@ body_get_owner (body_t body) ...@@ -76,6 +76,22 @@ body_get_owner (body_t body)
76 return (body) ? body->owner : NULL; 76 return (body) ? body->owner : NULL;
77 } 77 }
78 78
79 /* FIXME: not implemented. */
80 int
81 body_is_modified (body_t body)
82 {
83 (void)body;
84 return 0;
85 }
86
87 /* FIXME: not implemented. */
88 int
89 body_clear_modified (body_t body)
90 {
91 (void)body;
92 return 0;
93 }
94
79 int 95 int
80 body_get_filename (body_t body, char *filename, size_t len, size_t *pn) 96 body_get_filename (body_t body, char *filename, size_t len, size_t *pn)
81 { 97 {
......
...@@ -97,6 +97,14 @@ header_is_modified (header_t header) ...@@ -97,6 +97,14 @@ header_is_modified (header_t header)
97 return (header) ? (header->flags & HEADER_MODIFIED) : 0; 97 return (header) ? (header->flags & HEADER_MODIFIED) : 0;
98 } 98 }
99 99
100 int
101 header_clear_modified (header_t header)
102 {
103 if (header)
104 header->flags &= ~HEADER_MODIFIED;
105 return 0;
106 }
107
100 /* Parsing is done in a rather simple fashion, meaning we just consider an 108 /* Parsing is done in a rather simple fashion, meaning we just consider an
101 entry to be a field-name an a field-value. So they maybe duplicate of 109 entry to be a field-name an a field-value. So they maybe duplicate of
102 field-name like "Received" they are just put in the array, see _get_value() 110 field-name like "Received" they are just put in the array, see _get_value()
......
...@@ -58,28 +58,42 @@ struct _mbox_data; ...@@ -58,28 +58,42 @@ struct _mbox_data;
58 typedef struct _mbox_data* mbox_data_t; 58 typedef struct _mbox_data* mbox_data_t;
59 typedef struct _mbox_message* mbox_message_t; 59 typedef struct _mbox_message* mbox_message_t;
60 60
61 /* These represent the header field-name that we are caching for speed. */ 61 /* Below are the headers field-names that we are caching for speed, it is
62 #define HDRSIZE 9 62 more or less the list of headers in ENVELOPE command from IMAP. */
63 #define HDRSIZE 15
64
63 const char *fhdr_table[] = 65 const char *fhdr_table[] =
64 { 66 {
65 #define HFROM 0 67 #define H_BCC 0
66 "From", 68 "Bcc",
67 #define HTO 1 69 #define H_CC 1
68 "To",
69 #define HCC 2
70 "Cc", 70 "Cc",
71 #define HSUBJECT 3 71 #define H_CONTENT_LANGUAGE 2
72 "Subject", 72 "Content-Language",
73 #define HDATE 4 73 #define H_CONTENT_TRANSFER_ENCODING 3
74 "Date", 74 "Content-Transfer-Encoding",
75 #define HX_IMAPBASE 5 75 #define H_CONTENT_TYPE 4
76 "X-IMAPbase",
77 #define HX_UIDL 6
78 "X-UIDL",
79 #define HX_UID 7
80 "X-UID",
81 #define HCONTENT_TYPE 8
82 "Content-Type", 76 "Content-Type",
77 #define H_DATE 5
78 "Date",
79 #define H_FROM 6
80 "From",
81 #define H_IN_REPLY_TO 7
82 "In-Reply-To",
83 #define H_MESSAGE_ID 8
84 "Message-ID",
85 #define H_REFERENCE 9
86 "Reply-To",
87 #define H_REPLY_TO 10
88 "Reply-To",
89 #define H_SENDER 11
90 "Sender",
91 #define H_SUBJECT 12
92 "Subject",
93 #define H_TO 13
94 "To",
95 #define H_X_UIDL 14
96 "X-UIDL"
83 }; 97 };
84 98
85 /* Keep the positions of where the headers and bodies start and end. 99 /* Keep the positions of where the headers and bodies start and end.
...@@ -146,6 +160,7 @@ struct _mbox_data ...@@ -146,6 +160,7 @@ struct _mbox_data
146 static int mbox_open __P ((mailbox_t, int)); 160 static int mbox_open __P ((mailbox_t, int));
147 static int mbox_close __P ((mailbox_t)); 161 static int mbox_close __P ((mailbox_t));
148 static int mbox_get_message __P ((mailbox_t, size_t, message_t *)); 162 static int mbox_get_message __P ((mailbox_t, size_t, message_t *));
163 //static int mbox_get_message_by_uid __P ((mailbox_t, size_t, message_t *));
149 static int mbox_append_message __P ((mailbox_t, message_t)); 164 static int mbox_append_message __P ((mailbox_t, message_t));
150 static int mbox_messages_count __P ((mailbox_t, size_t *)); 165 static int mbox_messages_count __P ((mailbox_t, size_t *));
151 static int mbox_messages_recent __P ((mailbox_t, size_t *)); 166 static int mbox_messages_recent __P ((mailbox_t, size_t *));
...@@ -637,8 +652,23 @@ mbox_expunge (mailbox_t mailbox) ...@@ -637,8 +652,23 @@ mbox_expunge (mailbox_t mailbox)
637 continue; 652 continue;
638 } 653 }
639 654
640 if (mum->message) 655 /* Do the expensive mbox_append_message0() only if mark dirty. */
656 if ((mum->attr_flags & MU_ATTRIBUTE_MODIFIED) ||
657 (mum->message && message_is_modified (mum->message)))
658 {
659 /* The message was not instanciated, probably the dirty flag was
660 set by mbox_scan(), create one here. */
661 if (mum->message == 0)
641 { 662 {
663 message_t msg;
664 status = mbox_get_message (mailbox, i, &msg);
665 if (status != 0)
666 {
667 fprintf (stderr, "Error expunge:%d: %s", __LINE__,
668 strerror (status));
669 goto bailout0;
670 }
671 }
642 status = mbox_append_message0 (tmpmailbox, mum->message, 672 status = mbox_append_message0 (tmpmailbox, mum->message,
643 &total, 1, (i == save_imapbase)); 673 &total, 1, (i == save_imapbase));
644 if (status != 0) 674 if (status != 0)
...@@ -647,6 +677,9 @@ mbox_expunge (mailbox_t mailbox) ...@@ -647,6 +677,9 @@ mbox_expunge (mailbox_t mailbox)
647 strerror (status)); 677 strerror (status));
648 goto bailout0; 678 goto bailout0;
649 } 679 }
680 /* Clear the dirty bit. */
681 mum->attr_flags &= ~MU_ATTRIBUTE_MODIFIED;
682 message_clear_modified (mum->message);
650 } 683 }
651 else 684 else
652 { 685 {
...@@ -811,12 +844,24 @@ mbox_expunge (mailbox_t mailbox) ...@@ -811,12 +844,24 @@ mbox_expunge (mailbox_t mailbox)
811 } 844 }
812 else 845 else
813 { 846 {
847 for (i = 0; i < HDRSIZE; i++)
848 if (mum->fhdr[i])
849 {
850 free (mum->fhdr[i]);
851 mum->fhdr[i] = NULL;
852 }
814 memset (mum, 0, sizeof (*mum)); 853 memset (mum, 0, sizeof (*mum));
815 } 854 }
816 } 855 }
817 mum->header_from = mum->header_from_end = 0; 856 mum->header_from = mum->header_from_end = 0;
818 mum->body = mum->body_end = 0; 857 mum->body = mum->body_end = 0;
819 mum->header_lines = mum->body_lines = 0; 858 mum->header_lines = mum->body_lines = 0;
859 for (i = 0; i < HDRSIZE; i++)
860 if (mum->fhdr[i])
861 {
862 free (mum->fhdr[i]);
863 mum->fhdr[i] = NULL;
864 }
820 } 865 }
821 monitor_unlock (mailbox->monitor); 866 monitor_unlock (mailbox->monitor);
822 /* This is should reset the messages_count, the last argument 0 means 867 /* This is should reset the messages_count, the last argument 0 means
...@@ -1387,7 +1432,7 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize, ...@@ -1387,7 +1432,7 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize,
1387 { 1432 {
1388 char *s; 1433 char *s;
1389 size_t len = 0; 1434 size_t len = 0;
1390 envelope_t envelope; 1435 envelope_t envelope = NULL;
1391 message_get_envelope (msg, &envelope); 1436 message_get_envelope (msg, &envelope);
1392 status = envelope_sender (envelope, mud->sender, 128, &len); 1437 status = envelope_sender (envelope, mud->sender, 128, &len);
1393 if (status != 0) 1438 if (status != 0)
...@@ -1414,7 +1459,7 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize, ...@@ -1414,7 +1459,7 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize,
1414 { 1459 {
1415 char *s; 1460 char *s;
1416 size_t len = 0; 1461 size_t len = 0;
1417 envelope_t envelope; 1462 envelope_t envelope = NULL;
1418 char buffer[1024]; 1463 char buffer[1024];
1419 message_get_envelope (msg, &envelope); 1464 message_get_envelope (msg, &envelope);
1420 status = envelope_date (envelope, mud->date, 128, &len); 1465 status = envelope_date (envelope, mud->date, 128, &len);
...@@ -1464,8 +1509,8 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize, ...@@ -1464,8 +1509,8 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize,
1464 { 1509 {
1465 char buffer[1024]; 1510 char buffer[1024];
1466 size_t nread = 0; 1511 size_t nread = 0;
1467 stream_t is; 1512 stream_t is = NULL;
1468 header_t header; 1513 header_t header = NULL;
1469 message_get_header (msg, &header); 1514 message_get_header (msg, &header);
1470 header_get_stream (header, &is); 1515 header_get_stream (header, &is);
1471 do 1516 do
...@@ -1572,8 +1617,8 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize, ...@@ -1572,8 +1617,8 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize,
1572 { 1617 {
1573 char buffer[1024]; 1618 char buffer[1024];
1574 size_t nread = 0; 1619 size_t nread = 0;
1575 stream_t is; 1620 stream_t is = NULL;
1576 body_t body; 1621 body_t body = NULL;
1577 message_get_body (msg, &body); 1622 message_get_body (msg, &body);
1578 body_get_stream (body, &is); 1623 body_get_stream (body, &is);
1579 do 1624 do
...@@ -1616,7 +1661,7 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize, ...@@ -1616,7 +1661,7 @@ mbox_append_message0 (mailbox_t mailbox, message_t msg, off_t *psize,
1616 /* Append the Message. */ 1661 /* Append the Message. */
1617 char buffer[1024]; 1662 char buffer[1024];
1618 size_t nread = 0; 1663 size_t nread = 0;
1619 stream_t is; 1664 stream_t is = NULL;
1620 message_get_stream (msg, &is); 1665 message_get_stream (msg, &is);
1621 do 1666 do
1622 { 1667 {
......
...@@ -162,10 +162,26 @@ message_is_modified (message_t msg) ...@@ -162,10 +162,26 @@ message_is_modified (message_t msg)
162 int mod = 0; 162 int mod = 0;
163 mod |= header_is_modified (msg->header); 163 mod |= header_is_modified (msg->header);
164 mod |= attribute_is_modified (msg->attribute); 164 mod |= attribute_is_modified (msg->attribute);
165 mod |= body_is_modified (msg->body);
165 return mod; 166 return mod;
166 } 167 }
167 168
168 int 169 int
170 message_clear_modified (message_t msg)
171 {
172 if (msg)
173 {
174 if (msg->header)
175 header_clear_modified (msg->header);
176 if (msg->attribute)
177 attribute_clear_modified (msg->attribute);
178 if (msg->body)
179 body_clear_modified (msg->body);
180 }
181 return 0;
182 }
183
184 int
169 message_set_mailbox (message_t msg, mailbox_t mailbox) 185 message_set_mailbox (message_t msg, mailbox_t mailbox)
170 { 186 {
171 if (msg == NULL) 187 if (msg == NULL)
......