(mh_scan0): Implemented EVT_MESSAGE_ADD notification.
Showing
1 changed file
with
34 additions
and
11 deletions
... | @@ -58,7 +58,7 @@ | ... | @@ -58,7 +58,7 @@ |
58 | #include <mailutils/property.h> | 58 | #include <mailutils/property.h> |
59 | #include <mailutils/stream.h> | 59 | #include <mailutils/stream.h> |
60 | #include <mailutils/url.h> | 60 | #include <mailutils/url.h> |
61 | 61 | #include <mailutils/observer.h> | |
62 | #include <mailbox0.h> | 62 | #include <mailbox0.h> |
63 | #include <registrar0.h> | 63 | #include <registrar0.h> |
64 | 64 | ||
... | @@ -67,6 +67,24 @@ | ... | @@ -67,6 +67,24 @@ |
67 | #define MH_ENV_SENDER_HEADER "X-Envelope-Sender" | 67 | #define MH_ENV_SENDER_HEADER "X-Envelope-Sender" |
68 | #define MH_ENV_DATE_HEADER "X-Envelope-Date" | 68 | #define MH_ENV_DATE_HEADER "X-Envelope-Date" |
69 | 69 | ||
70 | /* Notifications ADD_MESG. */ | ||
71 | #define DISPATCH_ADD_MSG(mbox,mhd) \ | ||
72 | do \ | ||
73 | { \ | ||
74 | int bailing = 0; \ | ||
75 | monitor_unlock (mbox->monitor); \ | ||
76 | if (mbox->observable) \ | ||
77 | bailing = observable_notify (mbox->observable, MU_EVT_MESSAGE_ADD); \ | ||
78 | if (bailing != 0) \ | ||
79 | { \ | ||
80 | if (pcount) \ | ||
81 | *pcount = (mhd)->msg_count; \ | ||
82 | locker_unlock (mbox->locker); \ | ||
83 | return EINTR; \ | ||
84 | } \ | ||
85 | monitor_wrlock (mbox->monitor); \ | ||
86 | } while (0); | ||
87 | |||
70 | /* Note: In this particular implementation the message sequence number | 88 | /* Note: In this particular implementation the message sequence number |
71 | serves also as its UID. This allows to avoid many problems related | 89 | serves also as its UID. This allows to avoid many problems related |
72 | to keeping the uids in the headers of the messages. */ | 90 | to keeping the uids in the headers of the messages. */ |
... | @@ -128,7 +146,8 @@ static int mh_save_attributes __P ((mailbox_t)); | ... | @@ -128,7 +146,8 @@ static int mh_save_attributes __P ((mailbox_t)); |
128 | static int mh_uidvalidity __P ((mailbox_t, unsigned long *)); | 146 | static int mh_uidvalidity __P ((mailbox_t, unsigned long *)); |
129 | static int mh_uidnext __P ((mailbox_t, size_t *)); | 147 | static int mh_uidnext __P ((mailbox_t, size_t *)); |
130 | static int mh_scan __P ((mailbox_t, size_t, size_t *)); | 148 | static int mh_scan __P ((mailbox_t, size_t, size_t *)); |
131 | static int mh_scan0 __P ((mailbox_t mailbox, size_t msgno, size_t *pcount)); | 149 | static int mh_scan0 __P ((mailbox_t mailbox, size_t msgno, size_t *pcount, |
150 | int do_notify)); | ||
132 | static int mh_is_updated __P ((mailbox_t)); | 151 | static int mh_is_updated __P ((mailbox_t)); |
133 | static int mh_get_size __P ((mailbox_t, off_t *)); | 152 | static int mh_get_size __P ((mailbox_t, off_t *)); |
134 | 153 | ||
... | @@ -441,7 +460,7 @@ mh_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg) | ... | @@ -441,7 +460,7 @@ mh_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg) |
441 | /* If we did not start a scanning yet do it now. */ | 460 | /* If we did not start a scanning yet do it now. */ |
442 | if (mhd->msg_count == 0) | 461 | if (mhd->msg_count == 0) |
443 | { | 462 | { |
444 | status = mh_scan0 (mailbox, 1, NULL); | 463 | status = mh_scan0 (mailbox, 1, NULL, 0); |
445 | if (status != 0) | 464 | if (status != 0) |
446 | return status; | 465 | return status; |
447 | } | 466 | } |
... | @@ -609,7 +628,7 @@ mh_append_message (mailbox_t mailbox, message_t msg) | ... | @@ -609,7 +628,7 @@ mh_append_message (mailbox_t mailbox, message_t msg) |
609 | /* If we did not start a scanning yet do it now. */ | 628 | /* If we did not start a scanning yet do it now. */ |
610 | if (mhd->msg_count == 0) | 629 | if (mhd->msg_count == 0) |
611 | { | 630 | { |
612 | status = mh_scan0 (mailbox, 1, NULL); | 631 | status = mh_scan0 (mailbox, 1, NULL, 0); |
613 | if (status != 0) | 632 | if (status != 0) |
614 | return status; | 633 | return status; |
615 | } | 634 | } |
... | @@ -633,7 +652,7 @@ mh_messages_count (mailbox_t mailbox, size_t *pcount) | ... | @@ -633,7 +652,7 @@ mh_messages_count (mailbox_t mailbox, size_t *pcount) |
633 | return EINVAL; | 652 | return EINVAL; |
634 | 653 | ||
635 | if (!mh_is_updated (mailbox)) | 654 | if (!mh_is_updated (mailbox)) |
636 | return mh_scan0 (mailbox, mhd->msg_count, pcount); | 655 | return mh_scan0 (mailbox, mhd->msg_count, pcount, 0); |
637 | 656 | ||
638 | if (pcount) | 657 | if (pcount) |
639 | *pcount = mhd->msg_count; | 658 | *pcount = mhd->msg_count; |
... | @@ -654,7 +673,7 @@ mh_messages_recent (mailbox_t mailbox, size_t *pcount) | ... | @@ -654,7 +673,7 @@ mh_messages_recent (mailbox_t mailbox, size_t *pcount) |
654 | /* If we did not start a scanning yet do it now. */ | 673 | /* If we did not start a scanning yet do it now. */ |
655 | if (mhd->msg_count == 0) | 674 | if (mhd->msg_count == 0) |
656 | { | 675 | { |
657 | int status = mh_scan0 (mailbox, 1, NULL); | 676 | int status = mh_scan0 (mailbox, 1, NULL, 0); |
658 | if (status != 0) | 677 | if (status != 0) |
659 | return status; | 678 | return status; |
660 | } | 679 | } |
... | @@ -679,7 +698,7 @@ mh_message_unseen (mailbox_t mailbox, size_t *pmsgno) | ... | @@ -679,7 +698,7 @@ mh_message_unseen (mailbox_t mailbox, size_t *pmsgno) |
679 | /* If we did not start a scanning yet do it now. */ | 698 | /* If we did not start a scanning yet do it now. */ |
680 | if (mhd->msg_count == 0) | 699 | if (mhd->msg_count == 0) |
681 | { | 700 | { |
682 | int status = mh_scan0 (mailbox, 1, NULL); | 701 | int status = mh_scan0 (mailbox, 1, NULL, 0); |
683 | if (status != 0) | 702 | if (status != 0) |
684 | return status; | 703 | return status; |
685 | } | 704 | } |
... | @@ -767,7 +786,7 @@ mh_uidvalidity (mailbox_t mailbox, unsigned long *puidvalidity) | ... | @@ -767,7 +786,7 @@ mh_uidvalidity (mailbox_t mailbox, unsigned long *puidvalidity) |
767 | /* If we did not start a scanning yet do it now. */ | 786 | /* If we did not start a scanning yet do it now. */ |
768 | if (mhd->msg_count == 0) | 787 | if (mhd->msg_count == 0) |
769 | { | 788 | { |
770 | status = mh_scan0 (mailbox, 1, NULL); | 789 | status = mh_scan0 (mailbox, 1, NULL, 0); |
771 | if (status != 0) | 790 | if (status != 0) |
772 | return status; | 791 | return status; |
773 | } | 792 | } |
... | @@ -786,7 +805,7 @@ mh_uidnext (mailbox_t mailbox, size_t *puidnext) | ... | @@ -786,7 +805,7 @@ mh_uidnext (mailbox_t mailbox, size_t *puidnext) |
786 | /* If we did not start a scanning yet do it now. */ | 805 | /* If we did not start a scanning yet do it now. */ |
787 | if (mhd->msg_count == 0) | 806 | if (mhd->msg_count == 0) |
788 | { | 807 | { |
789 | status = mh_scan0 (mailbox, 1, NULL); | 808 | status = mh_scan0 (mailbox, 1, NULL, 0); |
790 | if (status != 0) | 809 | if (status != 0) |
791 | return status; | 810 | return status; |
792 | } | 811 | } |
... | @@ -933,7 +952,7 @@ mh_scan_message (struct _mh_message *mhm) | ... | @@ -933,7 +952,7 @@ mh_scan_message (struct _mh_message *mhm) |
933 | 952 | ||
934 | /* Scan the mailbox */ | 953 | /* Scan the mailbox */ |
935 | static int | 954 | static int |
936 | mh_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount) | 955 | mh_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notify) |
937 | { | 956 | { |
938 | struct _mh_data *mhd = mailbox->data; | 957 | struct _mh_data *mhd = mailbox->data; |
939 | DIR *dir; | 958 | DIR *dir; |
... | @@ -1005,6 +1024,10 @@ mh_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount) | ... | @@ -1005,6 +1024,10 @@ mh_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount) |
1005 | /* This scans the message */ | 1024 | /* This scans the message */ |
1006 | mh_message_stream_open (msg); | 1025 | mh_message_stream_open (msg); |
1007 | mh_message_stream_close (msg); | 1026 | mh_message_stream_close (msg); |
1027 | |||
1028 | /* Notify */ | ||
1029 | if (do_notify) | ||
1030 | DISPATCH_ADD_MSG(mailbox, mhd); | ||
1008 | } | 1031 | } |
1009 | else | 1032 | else |
1010 | { | 1033 | { |
... | @@ -1049,7 +1072,7 @@ mh_scan (mailbox_t mailbox, size_t msgno, size_t *pcount) | ... | @@ -1049,7 +1072,7 @@ mh_scan (mailbox_t mailbox, size_t msgno, size_t *pcount) |
1049 | struct _mh_data *mhd = mailbox->data; | 1072 | struct _mh_data *mhd = mailbox->data; |
1050 | 1073 | ||
1051 | if (! mh_is_updated (mailbox)) | 1074 | if (! mh_is_updated (mailbox)) |
1052 | return mh_scan0 (mailbox, msgno, pcount); | 1075 | return mh_scan0 (mailbox, msgno, pcount, 1); |
1053 | 1076 | ||
1054 | if (pcount) | 1077 | if (pcount) |
1055 | *pcount = mhd->msg_count; | 1078 | *pcount = mhd->msg_count; | ... | ... |
-
Please register or sign in to post a comment