Commit 3160d750 3160d75010b83bb73df5fc19ddc2b95fdca5f6c9 by Sergey Poznyakoff

Remove rudimentary header caching

1 parent 100441be
...@@ -30,31 +30,6 @@ ...@@ -30,31 +30,6 @@
30 30
31 static void mbox_destroy (mu_mailbox_t); 31 static void mbox_destroy (mu_mailbox_t);
32 32
33 /* Below are the headers field-names that we are caching for speed, it is
34 more or less the list of headers in ENVELOPE command from IMAP.
35
36 NOTE: These are indexed with H_.* macros defined in mbox0.h. Keep them
37 in sync if you add or remove something. */
38
39 const char *fhdr_table[HDRSIZE] =
40 {
41 "Bcc",
42 "Cc",
43 "Content-Language",
44 "Content-Transfer-Encoding",
45 "Content-Type",
46 "Date",
47 "From",
48 "In-Reply-To",
49 "Message-ID",
50 "Reference",
51 "Reply-To",
52 "Sender",
53 "Subject",
54 "To",
55 "X-UIDL"
56 };
57
58 /* Mailbox concrete implementation. */ 33 /* Mailbox concrete implementation. */
59 static int mbox_open (mu_mailbox_t, int); 34 static int mbox_open (mu_mailbox_t, int);
60 static int mbox_close (mu_mailbox_t); 35 static int mbox_close (mu_mailbox_t);
...@@ -186,11 +161,7 @@ mbox_destroy (mu_mailbox_t mailbox) ...@@ -186,11 +161,7 @@ mbox_destroy (mu_mailbox_t mailbox)
186 mbox_message_t mum = mud->umessages[i]; 161 mbox_message_t mum = mud->umessages[i];
187 if (mum) 162 if (mum)
188 { 163 {
189 size_t j;
190 mu_message_destroy (&(mum->message), mum); 164 mu_message_destroy (&(mum->message), mum);
191 for (j = 0; j < HDRSIZE; j++)
192 if (mum->fhdr[j])
193 free (mum->fhdr[j]);
194 free (mum); 165 free (mum);
195 } 166 }
196 } 167 }
...@@ -299,11 +270,7 @@ mbox_close (mu_mailbox_t mailbox) ...@@ -299,11 +270,7 @@ mbox_close (mu_mailbox_t mailbox)
299 /* Destroy the attach messages. */ 270 /* Destroy the attach messages. */
300 if (mum) 271 if (mum)
301 { 272 {
302 size_t j;
303 mu_message_destroy (&(mum->message), mum); 273 mu_message_destroy (&(mum->message), mum);
304 for (j = 0; j < HDRSIZE; j++)
305 if (mum->fhdr[j])
306 free (mum->fhdr[j]);
307 free (mum); 274 free (mum);
308 } 275 }
309 } 276 }
...@@ -768,12 +735,6 @@ mbox_expunge0 (mu_mailbox_t mailbox, int remove_deleted) ...@@ -768,12 +735,6 @@ mbox_expunge0 (mu_mailbox_t mailbox, int remove_deleted)
768 mum->body = mum->body_end = 0; 735 mum->body = mum->body_end = 0;
769 mum->header_lines = mum->body_lines = 0; 736 mum->header_lines = mum->body_lines = 0;
770 #endif 737 #endif
771 for (i = 0; i < HDRSIZE; i++)
772 if (mum->fhdr[i])
773 {
774 free (mum->fhdr[i]);
775 mum->fhdr[i] = NULL;
776 }
777 memset (mum, 0, sizeof (*mum)); 738 memset (mum, 0, sizeof (*mum));
778 /* We are not free()ing the useless mum, but instead 739 /* We are not free()ing the useless mum, but instead
779 we put it back in the pool, to be reuse. */ 740 we put it back in the pool, to be reuse. */
...@@ -785,24 +746,12 @@ mbox_expunge0 (mu_mailbox_t mailbox, int remove_deleted) ...@@ -785,24 +746,12 @@ mbox_expunge0 (mu_mailbox_t mailbox, int remove_deleted)
785 } 746 }
786 else 747 else
787 { 748 {
788 for (i = 0; i < HDRSIZE; i++)
789 if (mum->fhdr[i])
790 {
791 free (mum->fhdr[i]);
792 mum->fhdr[i] = NULL;
793 }
794 memset (mum, 0, sizeof (*mum)); 749 memset (mum, 0, sizeof (*mum));
795 } 750 }
796 } 751 }
797 mum->header_from = mum->header_from_end = 0; 752 mum->header_from = mum->header_from_end = 0;
798 mum->body = mum->body_end = 0; 753 mum->body = mum->body_end = 0;
799 mum->header_lines = mum->body_lines = 0; 754 mum->header_lines = mum->body_lines = 0;
800 for (i = 0; i < HDRSIZE; i++)
801 if (mum->fhdr[i])
802 {
803 free (mum->fhdr[i]);
804 mum->fhdr[i] = NULL;
805 }
806 } 755 }
807 mu_monitor_unlock (mailbox->monitor); 756 mu_monitor_unlock (mailbox->monitor);
808 /* This is should reset the messages_count, the last argument 0 means 757 /* This is should reset the messages_count, the last argument 0 means
...@@ -964,58 +913,11 @@ mbox_header_fill (mu_header_t header, char *buffer, size_t len, ...@@ -964,58 +913,11 @@ mbox_header_fill (mu_header_t header, char *buffer, size_t len,
964 { 913 {
965 mu_message_t msg = mu_header_get_owner (header); 914 mu_message_t msg = mu_header_get_owner (header);
966 mbox_message_t mum = mu_message_get_owner (msg); 915 mbox_message_t mum = mu_message_get_owner (msg);
967 size_t j;
968 /* Since we are filling the header there is no need for the cache headers
969 discard them. */
970 for (j = 0; j < HDRSIZE; j++)
971 {
972 if (mum->fhdr[j])
973 {
974 free (mum->fhdr[j]);
975 mum->fhdr[j] = NULL;
976 }
977 }
978 return mbox_readstream (mum, buffer, len, off, pnread, 0, 916 return mbox_readstream (mum, buffer, len, off, pnread, 0,
979 mum->header_from_end, mum->body); 917 mum->header_from_end, mum->body);
980 } 918 }
981 919
982 static int 920 static int
983 mbox_header_get_fvalue (mu_header_t header, const char *name, char *buffer,
984 size_t buflen, size_t *pnread)
985 {
986 size_t i, fv_len = 0;
987 mu_message_t msg = mu_header_get_owner (header);
988 mbox_message_t mum = mu_message_get_owner (msg);
989 int err = MU_ERR_NOENT;
990 for (i = 0; i < HDRSIZE; i++)
991 {
992 if (*name == *(fhdr_table[i]) && strcasecmp (fhdr_table[i], name) == 0)
993 {
994 if (mum->fhdr[i])
995 {
996 fv_len = strlen (mum->fhdr[i]);
997 if (buffer && buflen > 0)
998 {
999 /* For the null. */
1000 buflen--;
1001 fv_len = (fv_len < buflen) ? fv_len : buflen;
1002 memcpy (buffer, mum->fhdr[i], fv_len);
1003 buffer[fv_len] = '\0';
1004 }
1005 err = 0;
1006 }
1007 else
1008 err = MU_ERR_NOENT;
1009 break;
1010 }
1011 }
1012
1013 if (pnread)
1014 *pnread = fv_len;
1015 return err;
1016 }
1017
1018 static int
1019 mbox_header_size (mu_header_t header, size_t *psize) 921 mbox_header_size (mu_header_t header, size_t *psize)
1020 { 922 {
1021 mu_message_t msg = mu_header_get_owner (header); 923 mu_message_t msg = mu_header_get_owner (header);
...@@ -1218,7 +1120,6 @@ mbox_get_message (mu_mailbox_t mailbox, size_t msgno, mu_message_t *pmsg) ...@@ -1218,7 +1120,6 @@ mbox_get_message (mu_mailbox_t mailbox, size_t msgno, mu_message_t *pmsg)
1218 return status; 1120 return status;
1219 } 1121 }
1220 mu_header_set_fill (header, mbox_header_fill, msg); 1122 mu_header_set_fill (header, mbox_header_fill, msg);
1221 mu_header_set_get_fvalue (header, mbox_header_get_fvalue, msg);
1222 mu_header_set_size (header, mbox_header_size, msg); 1123 mu_header_set_size (header, mbox_header_size, msg);
1223 mu_header_set_lines (header, mbox_header_lines, msg); 1124 mu_header_set_lines (header, mbox_header_lines, msg);
1224 mu_message_set_header (msg, header, mum); 1125 mu_message_set_header (msg, header, mum);
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2003, 2005 Free Software Foundation, Inc. 2 Copyright (C) 2003, 2005, 2007 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -66,24 +66,6 @@ ...@@ -66,24 +66,6 @@
66 #include <mailutils/stream.h> 66 #include <mailutils/stream.h>
67 #include <mailutils/url.h> 67 #include <mailutils/url.h>
68 68
69 #define H_BCC 0
70 #define H_CC 1
71 #define H_CONTENT_LANGUAGE 2
72 #define H_CONTENT_TRANSFER_ENCODING 3
73 #define H_CONTENT_TYPE 4
74 #define H_DATE 5
75 #define H_FROM 6
76 #define H_IN_REPLY_TO 7
77 #define H_MESSAGE_ID 8
78 #define H_REFERENCE 9
79 #define H_REPLY_TO 10
80 #define H_SENDER 11
81 #define H_SUBJECT 12
82 #define H_TO 13
83 #define H_X_UIDL 14
84
85 #define HDRSIZE 15
86
87 struct _mbox_message; 69 struct _mbox_message;
88 struct _mbox_data; 70 struct _mbox_data;
89 71
...@@ -100,11 +82,6 @@ struct _mbox_message ...@@ -100,11 +82,6 @@ struct _mbox_message
100 off_t body; 82 off_t body;
101 off_t body_end; 83 off_t body_end;
102 84
103 /* Fast header retrieve, we save here the most common headers. This will
104 speed the header search. The entire headers are copied, when modified,
105 by the mu_header_t object, we do not have to worry about updating them. */
106 char *fhdr[HDRSIZE];
107
108 size_t uid; /* IMAP uid. */ 85 size_t uid; /* IMAP uid. */
109 86
110 int attr_flags; /* The attr_flags contains the "Status:" attribute */ 87 int attr_flags; /* The attr_flags contains the "Status:" attribute */
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2003, 2005,
3 2007 Free Software Foundation, Inc.
3 4
4 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -404,100 +405,6 @@ do { \ ...@@ -404,100 +405,6 @@ do { \
404 i = 10 * i + (*a - '0'); \ 405 i = 10 * i + (*a - '0'); \
405 } while (0) 406 } while (0)
406 407
407 /* Save/concatenate the field-value in the fast header(fhd) field.
408 Notice that care is taken to preserve the intermediate newlines
409 in the folded headers. However, the final newline is always
410 removed. */
411 #define FAST_HEADER(field,buf,n) \
412 do { \
413 int i = 0; \
414 char *s = field; \
415 char *p = buf; \
416 if (s) \
417 while (*s++) i++; \
418 else \
419 { \
420 p = memchr (buf, ':', n); \
421 if (p) p++; \
422 } \
423 if (p) \
424 { \
425 int l; \
426 char *tmp; \
427 buf[n - 1] = '\0'; \
428 if (!field) \
429 SKIPSPACE(p); \
430 l = n - (p - buf); \
431 tmp = realloc (field, (l + (i ? i + 1 : 0) + 1) * sizeof (char)); \
432 if (tmp) \
433 { \
434 field = tmp; \
435 if (i) field[i++] = '\n'; \
436 memcpy (field + i, p, l); \
437 } \
438 } \
439 } while (0)
440
441 #define FAST_H_BCC(mum,save_field,buf,n) \
442 FAST_HEADER(mum->fhdr[H_BCC],buf,n); \
443 save_field = &(mum->fhdr[H_BCC])
444
445 #define FAST_H_CC(mum,save_field,buf,n) \
446 FAST_HEADER(mum->fhdr[H_CC],buf,n); \
447 save_field = &(mum->fhdr[H_CC])
448
449 #define FAST_H_CONTENT_LANGUAGE(mum,save_field,buf,n) \
450 FAST_HEADER(mum->fhdr[H_CONTENT_LANGUAGE],buf,n); \
451 save_field = &(mum->fhdr[H_CONTENT_LANGUAGE])
452
453 #define FAST_H_CONTENT_TRANSFER_ENCODING(mum,save_field,buf,n) \
454 FAST_HEADER(mum->fhdr[H_CONTENT_TRANSFER_ENCODING],buf,n); \
455 save_field = &(mum->fhdr[H_CONTENT_TRANSFER_ENCODING])
456
457 #define FAST_H_CONTENT_TYPE(mum,save_field,buf,n) \
458 FAST_HEADER(mum->fhdr[H_CONTENT_TYPE],buf,n); \
459 save_field = &(mum->fhdr[H_CONTENT_TYPE])
460
461 #define FAST_H_DATE(mum,save_field,buf,n) \
462 FAST_HEADER(mum->fhdr[H_DATE],buf,n); \
463 save_field = &(mum->fhdr[H_DATE])
464
465 #define FAST_H_FROM(mum,save_field,buf,n) \
466 FAST_HEADER(mum->fhdr[H_FROM],buf,n); \
467 save_field = &(mum->fhdr[H_FROM])
468
469 #define FAST_H_IN_REPLY_TO(mum,save_field,buf,n) \
470 FAST_HEADER(mum->fhdr[H_IN_REPLY_TO],buf,n); \
471 save_field = &(mum->fhdr[H_IN_REPLY_TO])
472
473 #define FAST_H_MESSAGE_ID(mum,save_field,buf,n) \
474 FAST_HEADER(mum->fhdr[H_MESSAGE_ID],buf,n); \
475 save_field = &(mum->fhdr[H_MESSAGE_ID])
476
477 #define FAST_H_REFERENCE(mum,save_field,buf,n) \
478 FAST_HEADER(mum->fhdr[H_REFERENCE],buf,n); \
479 save_field = &(mum->fhdr[H_REFERENCE])
480
481 #define FAST_H_REPLY_TO(mum,save_field,buf,n) \
482 FAST_HEADER(mum->fhdr[H_REPLY_TO],buf,n); \
483 save_field = &(mum->fhdr[H_REPLY_TO])
484
485 #define FAST_H_SENDER(mum,save_field,buf,n) \
486 FAST_HEADER(mum->fhdr[H_SENDER],buf,n); \
487 save_field = &(mum->fhdr[H_SENDER])
488
489 #define FAST_H_SUBJECT(mum,save_field,buf,n) \
490 FAST_HEADER(mum->fhdr[H_SUBJECT],buf,n); \
491 save_field = &(mum->fhdr[H_SUBJECT])
492
493 #define FAST_H_TO(mum,save_field,buf,n) \
494 FAST_HEADER(mum->fhdr[H_TO],buf,n); \
495 save_field = &(mum->fhdr[H_TO])
496
497 #define FAST_H_X_UIDL(mum,save_field,buf,n) \
498 FAST_HEADER(mum->fhdr[H_X_UIDL],buf,n); \
499 save_field = &(mum->fhdr[H_X_UIDL])
500
501 /* Notifications ADD_MESG. */ 408 /* Notifications ADD_MESG. */
502 #define DISPATCH_ADD_MSG(mbox,mud) \ 409 #define DISPATCH_ADD_MSG(mbox,mud) \
503 do \ 410 do \
...@@ -585,7 +492,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif) ...@@ -585,7 +492,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
585 int newline; 492 int newline;
586 size_t n = 0; 493 size_t n = 0;
587 mu_stream_t stream; 494 mu_stream_t stream;
588 char **sfield = NULL;
589 size_t min_uid = 0; 495 size_t min_uid = 0;
590 int zn, isfrom = 0; 496 int zn, isfrom = 0;
591 char *temp; 497 char *temp;
...@@ -629,18 +535,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif) ...@@ -629,18 +535,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
629 else 535 else
630 mud->messages_count = 0; 536 mud->messages_count = 0;
631 537
632 #if 0
633 {
634 size_t j, k;
635 for (j = 0; j < mud->umessages_count; j++)
636 {
637 mum = mud->umessages[j];
638 for (k = 0; k < HDRSIZE; k++)
639 if (mum->fhdr[k])
640 free (mum->fhdr[k]);
641 }
642 }
643 #endif
644 newline = 1; 538 newline = 1;
645 errno = lines = inheader = inbody = 0; 539 errno = lines = inheader = inbody = 0;
646 540
...@@ -667,7 +561,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif) ...@@ -667,7 +561,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
667 /* New message. */ 561 /* New message. */
668 if (isfrom) 562 if (isfrom)
669 { 563 {
670 size_t j;
671 /* Signal the end of the body. */ 564 /* Signal the end of the body. */
672 if (mum && !mum->body_end) 565 if (mum && !mum->body_end)
673 { 566 {
...@@ -697,13 +590,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif) ...@@ -697,13 +590,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
697 mum->body_end = mum->body = 0; 590 mum->body_end = mum->body = 0;
698 mum->attr_flags = 0; 591 mum->attr_flags = 0;
699 lines = 0; 592 lines = 0;
700 sfield = NULL;
701 for (j = 0; j < HDRSIZE; j++)
702 if (mum->fhdr[j])
703 {
704 free (mum->fhdr[j]);
705 mum->fhdr[j] = NULL;
706 }
707 } 593 }
708 else if (ISSTATUS(buf)) 594 else if (ISSTATUS(buf))
709 { 595 {
...@@ -711,96 +597,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif) ...@@ -711,96 +597,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
711 ATTRIBUTE_SET(buf, mum, 'o', 'O', MU_ATTRIBUTE_SEEN); 597 ATTRIBUTE_SET(buf, mum, 'o', 'O', MU_ATTRIBUTE_SEEN);
712 ATTRIBUTE_SET(buf, mum, 'a', 'A', MU_ATTRIBUTE_ANSWERED); 598 ATTRIBUTE_SET(buf, mum, 'a', 'A', MU_ATTRIBUTE_ANSWERED);
713 ATTRIBUTE_SET(buf, mum, 'd', 'D', MU_ATTRIBUTE_DELETED); 599 ATTRIBUTE_SET(buf, mum, 'd', 'D', MU_ATTRIBUTE_DELETED);
714 sfield = NULL;
715 }
716 else if (ISBCC(buf))
717 {
718 FAST_H_BCC(mum, sfield, buf, n);
719 }
720 else if (ISCC(buf))
721 {
722 FAST_H_CC(mum, sfield, buf, n);
723 }
724 else if (ISCONTENT_LANGUAGE(buf))
725 {
726 FAST_H_CONTENT_LANGUAGE(mum, sfield, buf, n);
727 }
728 else if (ISCONTENT_TRANSFER_ENCODING(buf))
729 {
730 FAST_H_CONTENT_TRANSFER_ENCODING(mum, sfield, buf, n);
731 }
732 else if (ISCONTENT_TYPE(buf))
733 {
734 FAST_H_CONTENT_TYPE(mum, sfield, buf, n);
735 }
736 else if (ISDATE(buf))
737 {
738 FAST_H_DATE(mum, sfield, buf, n);
739 }
740 else if (ISFROM(buf))
741 {
742 FAST_H_FROM(mum, sfield, buf, n);
743 }
744 else if (ISIN_REPLY_TO(buf))
745 {
746 FAST_H_IN_REPLY_TO(mum, sfield, buf, n);
747 }
748 else if (ISMESSAGE_ID(buf))
749 {
750 FAST_H_MESSAGE_ID(mum, sfield, buf, n);
751 }
752 else if (ISREFERENCE(buf))
753 {
754 FAST_H_REFERENCE(mum, sfield, buf, n);
755 }
756 else if (ISREPLY_TO(buf))
757 {
758 FAST_H_REPLY_TO(mum, sfield, buf, n);
759 }
760 else if (ISSENDER(buf))
761 {
762 FAST_H_SENDER (mum, sfield, buf, n);
763 }
764 else if (ISSUBJECT(buf))
765 {
766 FAST_H_SUBJECT (mum, sfield, buf, n);
767 }
768 else if (ISTO(buf))
769 {
770 FAST_H_TO (mum, sfield, buf, n);
771 }
772 else if (ISX_UIDL(buf))
773 {
774 FAST_H_X_UIDL (mum, sfield, buf, n);
775 }
776 else if (ISX_IMAPBASE(buf))
777 {
778 char *s = memchr (buf, ':', n);
779 if (s)
780 {
781 s++;
782 ATOI(s, mud->uidvalidity);
783 ATOI(s, mud->uidnext);
784 }
785 }
786 else if (ISX_UID(buf))
787 {
788 char *s = memchr (buf, ':', n);
789 if (s)
790 {
791 s++;
792 ATOI(s, mum->uid);
793 }
794 }
795 else if (sfield && (buf[0] == ' ' || buf[0] == '\t'))
796 {
797 char *save = *sfield;
798 FAST_HEADER (save, buf, n);
799 *sfield = save;
800 }
801 else
802 {
803 sfield = NULL;
804 } 600 }
805 } 601 }
806 602
......