38 files changed, 703 insertions, 40 deletions
diff --git a/kmicromail/libetpan/generic/imapdriver.c b/kmicromail/libetpan/generic/imapdriver.c index 0d63319..b3e5982 100644 --- a/kmicromail/libetpan/generic/imapdriver.c +++ b/kmicromail/libetpan/generic/imapdriver.c | |||
@@ -87,32 +87,34 @@ static int imapdriver_messages_number(mailsession * session, char * mb, | |||
87 | uint32_t * result); | 87 | uint32_t * result); |
88 | 88 | ||
89 | static int imapdriver_recent_number(mailsession * session, char * mb, | 89 | static int imapdriver_recent_number(mailsession * session, char * mb, |
90 | uint32_t * result); | 90 | uint32_t * result); |
91 | 91 | ||
92 | static int imapdriver_unseen_number(mailsession * session, char * mb, | 92 | static int imapdriver_unseen_number(mailsession * session, char * mb, |
93 | uint32_t * result); | 93 | uint32_t * result); |
94 | 94 | ||
95 | static int imapdriver_list_folders(mailsession * session, char * mb, | 95 | static int imapdriver_list_folders(mailsession * session, char * mb, |
96 | struct mail_list ** result); | 96 | struct mail_list ** result); |
97 | static int imapdriver_lsub_folders(mailsession * session, char * mb, | 97 | static int imapdriver_lsub_folders(mailsession * session, char * mb, |
98 | struct mail_list ** result); | 98 | struct mail_list ** result); |
99 | static int imapdriver_subscribe_folder(mailsession * session, char * mb); | 99 | static int imapdriver_subscribe_folder(mailsession * session, char * mb); |
100 | static int imapdriver_unsubscribe_folder(mailsession * session, char * mb); | 100 | static int imapdriver_unsubscribe_folder(mailsession * session, char * mb); |
101 | static int imapdriver_append_message(mailsession * session, | 101 | static int imapdriver_append_message(mailsession * session, |
102 | char * message, size_t size); | 102 | char * message, size_t size); |
103 | static int imapdriver_append_message_flags(mailsession * session, | ||
104 | char * message, size_t size, struct mail_flags * flags); | ||
103 | static int imapdriver_copy_message(mailsession * session, | 105 | static int imapdriver_copy_message(mailsession * session, |
104 | uint32_t num, char * mb); | 106 | uint32_t num, char * mb); |
105 | 107 | ||
106 | static int imapdriver_get_messages_list(mailsession * session, | 108 | static int imapdriver_get_messages_list(mailsession * session, |
107 | struct mailmessage_list ** result); | 109 | struct mailmessage_list ** result); |
108 | 110 | ||
109 | static int | 111 | static int |
110 | imapdriver_get_envelopes_list(mailsession * session, | 112 | imapdriver_get_envelopes_list(mailsession * session, |
111 | struct mailmessage_list * env_list); | 113 | struct mailmessage_list * env_list); |
112 | 114 | ||
113 | 115 | ||
114 | #if 0 | 116 | #if 0 |
115 | static int imapdriver_search_messages(mailsession * session, char * charset, | 117 | static int imapdriver_search_messages(mailsession * session, char * charset, |
116 | struct mail_search_key * key, | 118 | struct mail_search_key * key, |
117 | struct mail_search_result ** result); | 119 | struct mail_search_result ** result); |
118 | #endif | 120 | #endif |
@@ -144,32 +146,33 @@ static mailsession_driver local_imap_session_driver = { | |||
144 | .sess_delete_folder = imapdriver_delete_folder, | 146 | .sess_delete_folder = imapdriver_delete_folder, |
145 | .sess_rename_folder = imapdriver_rename_folder, | 147 | .sess_rename_folder = imapdriver_rename_folder, |
146 | .sess_check_folder = imapdriver_check_folder, | 148 | .sess_check_folder = imapdriver_check_folder, |
147 | .sess_examine_folder = imapdriver_examine_folder, | 149 | .sess_examine_folder = imapdriver_examine_folder, |
148 | .sess_select_folder = imapdriver_select_folder, | 150 | .sess_select_folder = imapdriver_select_folder, |
149 | .sess_expunge_folder = imapdriver_expunge_folder, | 151 | .sess_expunge_folder = imapdriver_expunge_folder, |
150 | .sess_status_folder = imapdriver_status_folder, | 152 | .sess_status_folder = imapdriver_status_folder, |
151 | .sess_messages_number = imapdriver_messages_number, | 153 | .sess_messages_number = imapdriver_messages_number, |
152 | .sess_recent_number = imapdriver_recent_number, | 154 | .sess_recent_number = imapdriver_recent_number, |
153 | .sess_unseen_number = imapdriver_unseen_number, | 155 | .sess_unseen_number = imapdriver_unseen_number, |
154 | .sess_list_folders = imapdriver_list_folders, | 156 | .sess_list_folders = imapdriver_list_folders, |
155 | .sess_lsub_folders = imapdriver_lsub_folders, | 157 | .sess_lsub_folders = imapdriver_lsub_folders, |
156 | .sess_subscribe_folder = imapdriver_subscribe_folder, | 158 | .sess_subscribe_folder = imapdriver_subscribe_folder, |
157 | .sess_unsubscribe_folder = imapdriver_unsubscribe_folder, | 159 | .sess_unsubscribe_folder = imapdriver_unsubscribe_folder, |
158 | 160 | ||
159 | .sess_append_message = imapdriver_append_message, | 161 | .sess_append_message = imapdriver_append_message, |
162 | .sess_append_message_flags = imapdriver_append_message_flags, | ||
160 | .sess_copy_message = imapdriver_copy_message, | 163 | .sess_copy_message = imapdriver_copy_message, |
161 | .sess_move_message = NULL, | 164 | .sess_move_message = NULL, |
162 | 165 | ||
163 | .sess_get_messages_list = imapdriver_get_messages_list, | 166 | .sess_get_messages_list = imapdriver_get_messages_list, |
164 | .sess_get_envelopes_list = imapdriver_get_envelopes_list, | 167 | .sess_get_envelopes_list = imapdriver_get_envelopes_list, |
165 | .sess_remove_message = NULL, | 168 | .sess_remove_message = NULL, |
166 | #if 0 | 169 | #if 0 |
167 | .sess_search_messages = imapdriver_search_messages, | 170 | .sess_search_messages = imapdriver_search_messages, |
168 | #endif | 171 | #endif |
169 | 172 | ||
170 | .sess_get_message = imapdriver_get_message, | 173 | .sess_get_message = imapdriver_get_message, |
171 | .sess_get_message_by_uid = imapdriver_get_message_by_uid, | 174 | .sess_get_message_by_uid = imapdriver_get_message_by_uid, |
172 | }; | 175 | }; |
173 | 176 | ||
174 | mailsession_driver * imap_session_driver = &local_imap_session_driver; | 177 | mailsession_driver * imap_session_driver = &local_imap_session_driver; |
175 | 178 | ||
@@ -758,32 +761,57 @@ static int imapdriver_unsubscribe_folder(mailsession * session, char * mb) | |||
758 | } | 761 | } |
759 | 762 | ||
760 | /* messages operations */ | 763 | /* messages operations */ |
761 | 764 | ||
762 | static int imapdriver_append_message(mailsession * session, | 765 | static int imapdriver_append_message(mailsession * session, |
763 | char * message, size_t size) | 766 | char * message, size_t size) |
764 | { | 767 | { |
765 | int r; | 768 | int r; |
766 | 769 | ||
767 | r = mailimap_append_simple(get_imap_session(session), | 770 | r = mailimap_append_simple(get_imap_session(session), |
768 | get_data(session)->imap_mailbox, | 771 | get_data(session)->imap_mailbox, |
769 | message, size); | 772 | message, size); |
770 | 773 | ||
771 | return imap_error_to_mail_error(r); | 774 | return imap_error_to_mail_error(r); |
772 | } | 775 | } |
773 | 776 | ||
777 | static int imapdriver_append_message_flags(mailsession * session, | ||
778 | char * message, size_t size, struct mail_flags * flags) | ||
779 | { | ||
780 | struct mailimap_flag_list * flag_list; | ||
781 | int r; | ||
782 | |||
783 | if (flags != NULL) { | ||
784 | r = imap_flags_to_imap_flags(flags, &flag_list); | ||
785 | if (r != MAIL_NO_ERROR) | ||
786 | return r; | ||
787 | } | ||
788 | else { | ||
789 | flag_list = NULL; | ||
790 | } | ||
791 | |||
792 | r = mailimap_append(get_imap_session(session), | ||
793 | get_data(session)->imap_mailbox, | ||
794 | flag_list, NULL, message, size); | ||
795 | |||
796 | if (flag_list != NULL) | ||
797 | mailimap_flag_list_free(flag_list); | ||
798 | |||
799 | return imap_error_to_mail_error(r); | ||
800 | } | ||
801 | |||
774 | static int imapdriver_copy_message(mailsession * session, | 802 | static int imapdriver_copy_message(mailsession * session, |
775 | uint32_t num, char * mb) | 803 | uint32_t num, char * mb) |
776 | { | 804 | { |
777 | int r; | 805 | int r; |
778 | struct mailimap_set * set; | 806 | struct mailimap_set * set; |
779 | int res; | 807 | int res; |
780 | 808 | ||
781 | set = mailimap_set_new_single(num); | 809 | set = mailimap_set_new_single(num); |
782 | if (set == NULL) { | 810 | if (set == NULL) { |
783 | res = MAIL_ERROR_MEMORY; | 811 | res = MAIL_ERROR_MEMORY; |
784 | goto err; | 812 | goto err; |
785 | } | 813 | } |
786 | 814 | ||
787 | r = mailimap_uid_copy(get_imap_session(session), set, mb); | 815 | r = mailimap_uid_copy(get_imap_session(session), set, mb); |
788 | 816 | ||
789 | mailimap_set_free(set); | 817 | mailimap_set_free(set); |
diff --git a/kmicromail/libetpan/generic/imapdriver_cached.c b/kmicromail/libetpan/generic/imapdriver_cached.c index e6af8e8..04044ae 100644 --- a/kmicromail/libetpan/generic/imapdriver_cached.c +++ b/kmicromail/libetpan/generic/imapdriver_cached.c | |||
@@ -92,32 +92,34 @@ static int imapdriver_cached_messages_number(mailsession * session, | |||
92 | char * mb, | 92 | char * mb, |
93 | uint32_t * result); | 93 | uint32_t * result); |
94 | static int imapdriver_cached_recent_number(mailsession * session, char * mb, | 94 | static int imapdriver_cached_recent_number(mailsession * session, char * mb, |
95 | uint32_t * result); | 95 | uint32_t * result); |
96 | static int imapdriver_cached_unseen_number(mailsession * session, char * mb, | 96 | static int imapdriver_cached_unseen_number(mailsession * session, char * mb, |
97 | uint32_t * result); | 97 | uint32_t * result); |
98 | static int imapdriver_cached_list_folders(mailsession * session, char * mb, | 98 | static int imapdriver_cached_list_folders(mailsession * session, char * mb, |
99 | struct mail_list ** result); | 99 | struct mail_list ** result); |
100 | static int imapdriver_cached_lsub_folders(mailsession * session, char * mb, | 100 | static int imapdriver_cached_lsub_folders(mailsession * session, char * mb, |
101 | struct mail_list ** result); | 101 | struct mail_list ** result); |
102 | static int imapdriver_cached_subscribe_folder(mailsession * session, | 102 | static int imapdriver_cached_subscribe_folder(mailsession * session, |
103 | char * mb); | 103 | char * mb); |
104 | static int imapdriver_cached_unsubscribe_folder(mailsession * session, | 104 | static int imapdriver_cached_unsubscribe_folder(mailsession * session, |
105 | char * mb); | 105 | char * mb); |
106 | static int imapdriver_cached_append_message(mailsession * session, | 106 | static int imapdriver_cached_append_message(mailsession * session, |
107 | char * message, size_t size); | 107 | char * message, size_t size); |
108 | static int imapdriver_cached_append_message_flags(mailsession * session, | ||
109 | char * message, size_t size, struct mail_flags * flags); | ||
108 | static int imapdriver_cached_copy_message(mailsession * session, | 110 | static int imapdriver_cached_copy_message(mailsession * session, |
109 | uint32_t num, char * mb); | 111 | uint32_t num, char * mb); |
110 | 112 | ||
111 | static int imapdriver_cached_get_messages_list(mailsession * session, | 113 | static int imapdriver_cached_get_messages_list(mailsession * session, |
112 | struct mailmessage_list ** | 114 | struct mailmessage_list ** |
113 | result); | 115 | result); |
114 | static int | 116 | static int |
115 | imapdriver_cached_get_envelopes_list(mailsession * session, | 117 | imapdriver_cached_get_envelopes_list(mailsession * session, |
116 | struct mailmessage_list * env_list); | 118 | struct mailmessage_list * env_list); |
117 | static int imapdriver_cached_remove_message(mailsession * session, | 119 | static int imapdriver_cached_remove_message(mailsession * session, |
118 | uint32_t num); | 120 | uint32_t num); |
119 | 121 | ||
120 | #if 0 | 122 | #if 0 |
121 | static int imapdriver_cached_search_messages(mailsession * session, | 123 | static int imapdriver_cached_search_messages(mailsession * session, |
122 | char * charset, | 124 | char * charset, |
123 | struct mail_search_key * key, | 125 | struct mail_search_key * key, |
@@ -152,32 +154,33 @@ static mailsession_driver local_imap_cached_session_driver = { | |||
152 | .sess_delete_folder = imapdriver_cached_delete_folder, | 154 | .sess_delete_folder = imapdriver_cached_delete_folder, |
153 | .sess_rename_folder = imapdriver_cached_rename_folder, | 155 | .sess_rename_folder = imapdriver_cached_rename_folder, |
154 | .sess_check_folder = imapdriver_cached_check_folder, | 156 | .sess_check_folder = imapdriver_cached_check_folder, |
155 | .sess_examine_folder = imapdriver_cached_examine_folder, | 157 | .sess_examine_folder = imapdriver_cached_examine_folder, |
156 | .sess_select_folder = imapdriver_cached_select_folder, | 158 | .sess_select_folder = imapdriver_cached_select_folder, |
157 | .sess_expunge_folder = imapdriver_cached_expunge_folder, | 159 | .sess_expunge_folder = imapdriver_cached_expunge_folder, |
158 | .sess_status_folder = imapdriver_cached_status_folder, | 160 | .sess_status_folder = imapdriver_cached_status_folder, |
159 | .sess_messages_number = imapdriver_cached_messages_number, | 161 | .sess_messages_number = imapdriver_cached_messages_number, |
160 | .sess_recent_number = imapdriver_cached_recent_number, | 162 | .sess_recent_number = imapdriver_cached_recent_number, |
161 | .sess_unseen_number = imapdriver_cached_unseen_number, | 163 | .sess_unseen_number = imapdriver_cached_unseen_number, |
162 | .sess_list_folders = imapdriver_cached_list_folders, | 164 | .sess_list_folders = imapdriver_cached_list_folders, |
163 | .sess_lsub_folders = imapdriver_cached_lsub_folders, | 165 | .sess_lsub_folders = imapdriver_cached_lsub_folders, |
164 | .sess_subscribe_folder = imapdriver_cached_subscribe_folder, | 166 | .sess_subscribe_folder = imapdriver_cached_subscribe_folder, |
165 | .sess_unsubscribe_folder = imapdriver_cached_unsubscribe_folder, | 167 | .sess_unsubscribe_folder = imapdriver_cached_unsubscribe_folder, |
166 | 168 | ||
167 | .sess_append_message = imapdriver_cached_append_message, | 169 | .sess_append_message = imapdriver_cached_append_message, |
170 | .sess_append_message_flags = imapdriver_cached_append_message_flags, | ||
168 | .sess_copy_message = imapdriver_cached_copy_message, | 171 | .sess_copy_message = imapdriver_cached_copy_message, |
169 | .sess_move_message = NULL, | 172 | .sess_move_message = NULL, |
170 | 173 | ||
171 | .sess_get_messages_list = imapdriver_cached_get_messages_list, | 174 | .sess_get_messages_list = imapdriver_cached_get_messages_list, |
172 | .sess_get_envelopes_list = imapdriver_cached_get_envelopes_list, | 175 | .sess_get_envelopes_list = imapdriver_cached_get_envelopes_list, |
173 | .sess_remove_message = imapdriver_cached_remove_message, | 176 | .sess_remove_message = imapdriver_cached_remove_message, |
174 | #if 0 | 177 | #if 0 |
175 | .sess_search_messages = imapdriver_cached_search_messages, | 178 | .sess_search_messages = imapdriver_cached_search_messages, |
176 | #endif | 179 | #endif |
177 | 180 | ||
178 | .sess_get_message = imapdriver_cached_get_message, | 181 | .sess_get_message = imapdriver_cached_get_message, |
179 | .sess_get_message_by_uid = imapdriver_cached_get_message_by_uid, | 182 | .sess_get_message_by_uid = imapdriver_cached_get_message_by_uid, |
180 | }; | 183 | }; |
181 | 184 | ||
182 | mailsession_driver * imap_cached_session_driver = | 185 | mailsession_driver * imap_cached_session_driver = |
183 | &local_imap_cached_session_driver; | 186 | &local_imap_cached_session_driver; |
@@ -763,32 +766,45 @@ static int imapdriver_cached_unsubscribe_folder(mailsession * session, | |||
763 | 766 | ||
764 | return r; | 767 | return r; |
765 | } | 768 | } |
766 | 769 | ||
767 | static int imapdriver_cached_append_message(mailsession * session, | 770 | static int imapdriver_cached_append_message(mailsession * session, |
768 | char * message, size_t size) | 771 | char * message, size_t size) |
769 | { | 772 | { |
770 | int r; | 773 | int r; |
771 | 774 | ||
772 | r = mailsession_append_message(get_ancestor(session), message, size); | 775 | r = mailsession_append_message(get_ancestor(session), message, size); |
773 | 776 | ||
774 | check_for_uid_cache(session); | 777 | check_for_uid_cache(session); |
775 | 778 | ||
776 | return r; | 779 | return r; |
777 | } | 780 | } |
778 | 781 | ||
782 | static int imapdriver_cached_append_message_flags(mailsession * session, | ||
783 | char * message, size_t size, struct mail_flags * flags) | ||
784 | { | ||
785 | int r; | ||
786 | |||
787 | r = mailsession_append_message_flags(get_ancestor(session), | ||
788 | message, size, flags); | ||
789 | |||
790 | check_for_uid_cache(session); | ||
791 | |||
792 | return r; | ||
793 | } | ||
794 | |||
779 | static int imapdriver_cached_copy_message(mailsession * session, | 795 | static int imapdriver_cached_copy_message(mailsession * session, |
780 | uint32_t num, char * mb) | 796 | uint32_t num, char * mb) |
781 | { | 797 | { |
782 | int r; | 798 | int r; |
783 | 799 | ||
784 | r = mailsession_copy_message(get_ancestor(session), num, mb); | 800 | r = mailsession_copy_message(get_ancestor(session), num, mb); |
785 | 801 | ||
786 | check_for_uid_cache(session); | 802 | check_for_uid_cache(session); |
787 | 803 | ||
788 | return r; | 804 | return r; |
789 | } | 805 | } |
790 | 806 | ||
791 | static int cmp_uid(uint32_t ** pa, uint32_t ** pb) | 807 | static int cmp_uid(uint32_t ** pa, uint32_t ** pb) |
792 | { | 808 | { |
793 | uint32_t * a; | 809 | uint32_t * a; |
794 | uint32_t * b; | 810 | uint32_t * b; |
diff --git a/kmicromail/libetpan/generic/imapdriver_cached_message.c b/kmicromail/libetpan/generic/imapdriver_cached_message.c index c0542a3..c4357a3 100644 --- a/kmicromail/libetpan/generic/imapdriver_cached_message.c +++ b/kmicromail/libetpan/generic/imapdriver_cached_message.c | |||
@@ -199,33 +199,33 @@ static void generate_key_from_mime_section(char * key, size_t size, | |||
199 | snprintf(s, 20, ".%u", * (uint32_t *) clist_content(cur)); | 199 | snprintf(s, 20, ".%u", * (uint32_t *) clist_content(cur)); |
200 | if (mmap_string_append(gstr, s) == NULL) | 200 | if (mmap_string_append(gstr, s) == NULL) |
201 | goto free_str; | 201 | goto free_str; |
202 | } | 202 | } |
203 | 203 | ||
204 | snprintf(key, size, "%s", gstr->str); | 204 | snprintf(key, size, "%s", gstr->str); |
205 | 205 | ||
206 | mmap_string_free(gstr); | 206 | mmap_string_free(gstr); |
207 | mailmime_section_free(part); | 207 | mailmime_section_free(part); |
208 | 208 | ||
209 | return; | 209 | return; |
210 | 210 | ||
211 | free_str: | 211 | free_str: |
212 | mmap_string_free(gstr); | 212 | mmap_string_free(gstr); |
213 | free_section: | 213 | free_section: |
214 | mailmime_section_free(part); | 214 | mailmime_section_free(part); |
215 | err: | 215 | err:; |
216 | } | 216 | } |
217 | 217 | ||
218 | static void generate_key_from_section(char * key, size_t size, | 218 | static void generate_key_from_section(char * key, size_t size, |
219 | mailmessage * msg_info, | 219 | mailmessage * msg_info, |
220 | struct mailmime * mime, int type) | 220 | struct mailmime * mime, int type) |
221 | { | 221 | { |
222 | char section_str[PATH_MAX]; | 222 | char section_str[PATH_MAX]; |
223 | 223 | ||
224 | generate_key_from_mime_section(section_str, PATH_MAX, mime); | 224 | generate_key_from_mime_section(section_str, PATH_MAX, mime); |
225 | 225 | ||
226 | switch (type) { | 226 | switch (type) { |
227 | case IMAP_SECTION_MESSAGE: | 227 | case IMAP_SECTION_MESSAGE: |
228 | snprintf(key, size, "%s-%s", msg_info->msg_uid, section_str); | 228 | snprintf(key, size, "%s-%s", msg_info->msg_uid, section_str); |
229 | break; | 229 | break; |
230 | case IMAP_SECTION_HEADER: | 230 | case IMAP_SECTION_HEADER: |
231 | snprintf(key, size, "%s-%s-header", msg_info->msg_uid, section_str); | 231 | snprintf(key, size, "%s-%s-header", msg_info->msg_uid, section_str); |
diff --git a/kmicromail/libetpan/generic/imapdriver_tools.c b/kmicromail/libetpan/generic/imapdriver_tools.c index 3d737f3..de4008f 100644 --- a/kmicromail/libetpan/generic/imapdriver_tools.c +++ b/kmicromail/libetpan/generic/imapdriver_tools.c | |||
@@ -3094,42 +3094,41 @@ static int imap_flags_to_flags(struct mailimap_msg_att_dynamic * att_dyn, | |||
3094 | */ | 3094 | */ |
3095 | if ((flags->fl_flags & MAIL_FLAG_SEEN) && (flags->fl_flags & MAIL_FLAG_NEW)) { | 3095 | if ((flags->fl_flags & MAIL_FLAG_SEEN) && (flags->fl_flags & MAIL_FLAG_NEW)) { |
3096 | flags->fl_flags &= ~MAIL_FLAG_NEW; | 3096 | flags->fl_flags &= ~MAIL_FLAG_NEW; |
3097 | } | 3097 | } |
3098 | } | 3098 | } |
3099 | 3099 | ||
3100 | * result = flags; | 3100 | * result = flags; |
3101 | 3101 | ||
3102 | return MAIL_NO_ERROR; | 3102 | return MAIL_NO_ERROR; |
3103 | 3103 | ||
3104 | free: | 3104 | free: |
3105 | mail_flags_free(flags); | 3105 | mail_flags_free(flags); |
3106 | err: | 3106 | err: |
3107 | return MAIL_ERROR_MEMORY; | 3107 | return MAIL_ERROR_MEMORY; |
3108 | } | 3108 | } |
3109 | 3109 | ||
3110 | static int flags_to_imap_flags(struct mail_flags * flags, | 3110 | int imap_flags_to_imap_flags(struct mail_flags * flags, |
3111 | struct mailimap_store_att_flags ** result) | 3111 | struct mailimap_flag_list ** result) |
3112 | { | 3112 | { |
3113 | struct mailimap_flag * flag; | 3113 | struct mailimap_flag * flag; |
3114 | struct mailimap_flag_list * flag_list; | 3114 | struct mailimap_flag_list * flag_list; |
3115 | struct mailimap_store_att_flags * att_flags; | ||
3116 | int res; | 3115 | int res; |
3117 | clistiter * cur; | 3116 | clistiter * cur; |
3118 | int r; | 3117 | int r; |
3119 | 3118 | ||
3120 | flag_list = mailimap_flag_list_new_empty(); | 3119 | flag_list = mailimap_flag_list_new_empty(); |
3121 | if (flag_list == NULL) { | 3120 | if (flag_list == NULL) { |
3122 | res = MAIL_ERROR_MEMORY; | 3121 | res = MAIL_ERROR_MEMORY; |
3123 | goto err; | 3122 | goto err; |
3124 | } | 3123 | } |
3125 | 3124 | ||
3126 | if ((flags->fl_flags & MAIL_FLAG_DELETED) != 0) { | 3125 | if ((flags->fl_flags & MAIL_FLAG_DELETED) != 0) { |
3127 | flag = mailimap_flag_new_deleted(); | 3126 | flag = mailimap_flag_new_deleted(); |
3128 | if (flag == NULL) { | 3127 | if (flag == NULL) { |
3129 | res = MAIL_ERROR_MEMORY; | 3128 | res = MAIL_ERROR_MEMORY; |
3130 | goto free_flag_list; | 3129 | goto free_flag_list; |
3131 | } | 3130 | } |
3132 | r = mailimap_flag_list_add(flag_list, flag); | 3131 | r = mailimap_flag_list_add(flag_list, flag); |
3133 | if (r != MAILIMAP_NO_ERROR) { | 3132 | if (r != MAILIMAP_NO_ERROR) { |
3134 | mailimap_flag_free(flag); | 3133 | mailimap_flag_free(flag); |
3135 | res = MAIL_ERROR_MEMORY; | 3134 | res = MAIL_ERROR_MEMORY; |
@@ -3226,43 +3225,68 @@ static int flags_to_imap_flags(struct mail_flags * flags, | |||
3226 | goto free_flag_list; | 3225 | goto free_flag_list; |
3227 | } | 3226 | } |
3228 | flag = mailimap_flag_new_flag_keyword(flag_str); | 3227 | flag = mailimap_flag_new_flag_keyword(flag_str); |
3229 | if (flag == NULL) { | 3228 | if (flag == NULL) { |
3230 | free(flag_str); | 3229 | free(flag_str); |
3231 | res = MAIL_ERROR_MEMORY; | 3230 | res = MAIL_ERROR_MEMORY; |
3232 | goto free_flag_list; | 3231 | goto free_flag_list; |
3233 | } | 3232 | } |
3234 | r = mailimap_flag_list_add(flag_list, flag); | 3233 | r = mailimap_flag_list_add(flag_list, flag); |
3235 | if (r != MAILIMAP_NO_ERROR) { | 3234 | if (r != MAILIMAP_NO_ERROR) { |
3236 | mailimap_flag_free(flag); | 3235 | mailimap_flag_free(flag); |
3237 | res = MAIL_ERROR_MEMORY; | 3236 | res = MAIL_ERROR_MEMORY; |
3238 | goto free_flag_list; | 3237 | goto free_flag_list; |
3239 | } | 3238 | } |
3240 | } | 3239 | } |
3241 | } | 3240 | } |
3241 | |||
3242 | * result = flag_list; | ||
3243 | |||
3244 | return MAIL_NO_ERROR; | ||
3245 | |||
3246 | free_flag_list: | ||
3247 | mailimap_flag_list_free(flag_list); | ||
3248 | err: | ||
3249 | return res; | ||
3250 | } | ||
3242 | 3251 | ||
3252 | static int flags_to_imap_flags(struct mail_flags * flags, | ||
3253 | struct mailimap_store_att_flags ** result) | ||
3254 | { | ||
3255 | struct mailimap_flag_list * flag_list; | ||
3256 | struct mailimap_store_att_flags * att_flags; | ||
3257 | int res; | ||
3258 | int r; | ||
3259 | |||
3260 | r = imap_flags_to_imap_flags(flags, | ||
3261 | &flag_list); | ||
3262 | if (r != MAIL_NO_ERROR) { | ||
3263 | res = r; | ||
3264 | goto err; | ||
3265 | } | ||
3266 | |||
3243 | att_flags = mailimap_store_att_flags_new_set_flags_silent(flag_list); | 3267 | att_flags = mailimap_store_att_flags_new_set_flags_silent(flag_list); |
3244 | if (att_flags == NULL) { | 3268 | if (att_flags == NULL) { |
3245 | res = MAIL_ERROR_MEMORY; | 3269 | res = MAIL_ERROR_MEMORY; |
3246 | goto free_flag_list; | 3270 | goto free_flag_list; |
3247 | } | 3271 | } |
3248 | 3272 | ||
3249 | * result = att_flags; | 3273 | * result = att_flags; |
3250 | 3274 | ||
3251 | return MAIL_NO_ERROR; | 3275 | return MAIL_NO_ERROR; |
3252 | 3276 | ||
3253 | free_flag_list: | 3277 | free_flag_list: |
3254 | mailimap_flag_list_free(flag_list); | 3278 | mailimap_flag_list_free(flag_list); |
3255 | err: | 3279 | err: |
3256 | return res; | 3280 | return res; |
3257 | } | 3281 | } |
3258 | 3282 | ||
3259 | 3283 | ||
3260 | static int | 3284 | static int |
3261 | imap_fetch_result_to_flags(clist * fetch_result, uint32_t index, | 3285 | imap_fetch_result_to_flags(clist * fetch_result, uint32_t index, |
3262 | struct mail_flags ** result) | 3286 | struct mail_flags ** result) |
3263 | { | 3287 | { |
3264 | clistiter * cur; | 3288 | clistiter * cur; |
3265 | int r; | 3289 | int r; |
3266 | 3290 | ||
3267 | for(cur = clist_begin(fetch_result) ; cur != NULL ; | 3291 | for(cur = clist_begin(fetch_result) ; cur != NULL ; |
3268 | cur = clist_next(cur)) { | 3292 | cur = clist_next(cur)) { |
diff --git a/kmicromail/libetpan/generic/imapdriver_tools.h b/kmicromail/libetpan/generic/imapdriver_tools.h index 6582a31..59c993e 100644 --- a/kmicromail/libetpan/generic/imapdriver_tools.h +++ b/kmicromail/libetpan/generic/imapdriver_tools.h | |||
@@ -93,21 +93,24 @@ int imap_get_messages_list(mailimap * imap, | |||
93 | mailsession * session, mailmessage_driver * driver, | 93 | mailsession * session, mailmessage_driver * driver, |
94 | uint32_t first_index, | 94 | uint32_t first_index, |
95 | struct mailmessage_list ** result); | 95 | struct mailmessage_list ** result); |
96 | 96 | ||
97 | int | 97 | int |
98 | imapdriver_get_cached_envelope(struct mail_cache_db * cache_db, | 98 | imapdriver_get_cached_envelope(struct mail_cache_db * cache_db, |
99 | MMAPString * mmapstr, | 99 | MMAPString * mmapstr, |
100 | mailsession * session, mailmessage * msg, | 100 | mailsession * session, mailmessage * msg, |
101 | struct mailimf_fields ** result); | 101 | struct mailimf_fields ** result); |
102 | 102 | ||
103 | int | 103 | int |
104 | imapdriver_write_cached_envelope(struct mail_cache_db * cache_db, | 104 | imapdriver_write_cached_envelope(struct mail_cache_db * cache_db, |
105 | MMAPString * mmapstr, | 105 | MMAPString * mmapstr, |
106 | mailsession * session, mailmessage * msg, | 106 | mailsession * session, mailmessage * msg, |
107 | struct mailimf_fields * fields); | 107 | struct mailimf_fields * fields); |
108 | 108 | ||
109 | int imap_flags_to_imap_flags(struct mail_flags * flags, | ||
110 | struct mailimap_flag_list ** result); | ||
111 | |||
109 | #ifdef __cplusplus | 112 | #ifdef __cplusplus |
110 | } | 113 | } |
111 | #endif | 114 | #endif |
112 | 115 | ||
113 | #endif | 116 | #endif |
diff --git a/kmicromail/libetpan/generic/imapstorage.c b/kmicromail/libetpan/generic/imapstorage.c index e8683d8..972b6dd 100644 --- a/kmicromail/libetpan/generic/imapstorage.c +++ b/kmicromail/libetpan/generic/imapstorage.c | |||
@@ -58,33 +58,33 @@ static void imap_mailstorage_uninitialize(struct mailstorage * storage); | |||
58 | static mailstorage_driver imap_mailstorage_driver = { | 58 | static mailstorage_driver imap_mailstorage_driver = { |
59 | .sto_name = "imap", | 59 | .sto_name = "imap", |
60 | .sto_connect = imap_mailstorage_connect, | 60 | .sto_connect = imap_mailstorage_connect, |
61 | .sto_get_folder_session = imap_mailstorage_get_folder_session, | 61 | .sto_get_folder_session = imap_mailstorage_get_folder_session, |
62 | .sto_uninitialize = imap_mailstorage_uninitialize, | 62 | .sto_uninitialize = imap_mailstorage_uninitialize, |
63 | }; | 63 | }; |
64 | 64 | ||
65 | int imap_mailstorage_init(struct mailstorage * storage, | 65 | int imap_mailstorage_init(struct mailstorage * storage, |
66 | char * imap_servername, uint16_t imap_port, | 66 | char * imap_servername, uint16_t imap_port, |
67 | char * imap_command, | 67 | char * imap_command, |
68 | int imap_connection_type, int imap_auth_type, | 68 | int imap_connection_type, int imap_auth_type, |
69 | char * imap_login, char * imap_password, | 69 | char * imap_login, char * imap_password, |
70 | int imap_cached, char * imap_cache_directory) | 70 | int imap_cached, char * imap_cache_directory) |
71 | { | 71 | { |
72 | struct imap_mailstorage * imap_storage; | 72 | struct imap_mailstorage * imap_storage; |
73 | 73 | ||
74 | imap_storage = malloc(sizeof(struct imap_mailstorage)); | 74 | imap_storage = malloc(sizeof(* imap_storage)); |
75 | if (imap_storage == NULL) | 75 | if (imap_storage == NULL) |
76 | goto err; | 76 | goto err; |
77 | 77 | ||
78 | imap_storage->imap_servername = strdup(imap_servername); | 78 | imap_storage->imap_servername = strdup(imap_servername); |
79 | if (imap_storage->imap_servername == NULL) | 79 | if (imap_storage->imap_servername == NULL) |
80 | goto free; | 80 | goto free; |
81 | 81 | ||
82 | imap_storage->imap_connection_type = imap_connection_type; | 82 | imap_storage->imap_connection_type = imap_connection_type; |
83 | 83 | ||
84 | if (imap_port == 0) { | 84 | if (imap_port == 0) { |
85 | switch (imap_connection_type) { | 85 | switch (imap_connection_type) { |
86 | case CONNECTION_TYPE_PLAIN: | 86 | case CONNECTION_TYPE_PLAIN: |
87 | case CONNECTION_TYPE_TRY_STARTTLS: | 87 | case CONNECTION_TYPE_TRY_STARTTLS: |
88 | case CONNECTION_TYPE_STARTTLS: | 88 | case CONNECTION_TYPE_STARTTLS: |
89 | case CONNECTION_TYPE_COMMAND: | 89 | case CONNECTION_TYPE_COMMAND: |
90 | case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: | 90 | case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: |
diff --git a/kmicromail/libetpan/generic/maildirdriver.c b/kmicromail/libetpan/generic/maildirdriver.c index 7830ceb..5f21422 100644 --- a/kmicromail/libetpan/generic/maildirdriver.c +++ b/kmicromail/libetpan/generic/maildirdriver.c | |||
@@ -72,32 +72,35 @@ static int expunge_folder(mailsession * session); | |||
72 | static int status_folder(mailsession * session, char * mb, | 72 | static int status_folder(mailsession * session, char * mb, |
73 | uint32_t * result_messages, uint32_t * result_recent, | 73 | uint32_t * result_messages, uint32_t * result_recent, |
74 | uint32_t * result_unseen); | 74 | uint32_t * result_unseen); |
75 | 75 | ||
76 | static int recent_number(mailsession * session, char * mb, | 76 | static int recent_number(mailsession * session, char * mb, |
77 | uint32_t * result); | 77 | uint32_t * result); |
78 | 78 | ||
79 | static int unseen_number(mailsession * session, char * mb, | 79 | static int unseen_number(mailsession * session, char * mb, |
80 | uint32_t * result); | 80 | uint32_t * result); |
81 | 81 | ||
82 | static int messages_number(mailsession * session, char * mb, | 82 | static int messages_number(mailsession * session, char * mb, |
83 | uint32_t * result); | 83 | uint32_t * result); |
84 | 84 | ||
85 | static int append_message(mailsession * session, | 85 | static int append_message(mailsession * session, |
86 | char * message, size_t size); | 86 | char * message, size_t size); |
87 | 87 | ||
88 | static int append_message_flags(mailsession * session, | ||
89 | char * message, size_t size, struct mail_flags * flags); | ||
90 | |||
88 | static int get_messages_list(mailsession * session, | 91 | static int get_messages_list(mailsession * session, |
89 | struct mailmessage_list ** result); | 92 | struct mailmessage_list ** result); |
90 | 93 | ||
91 | static int get_envelopes_list(mailsession * session, | 94 | static int get_envelopes_list(mailsession * session, |
92 | struct mailmessage_list * env_list); | 95 | struct mailmessage_list * env_list); |
93 | 96 | ||
94 | static int check_folder(mailsession * session); | 97 | static int check_folder(mailsession * session); |
95 | 98 | ||
96 | static int get_message_by_uid(mailsession * session, | 99 | static int get_message_by_uid(mailsession * session, |
97 | const char * uid, mailmessage ** result); | 100 | const char * uid, mailmessage ** result); |
98 | 101 | ||
99 | static mailsession_driver local_maildir_session_driver = { | 102 | static mailsession_driver local_maildir_session_driver = { |
100 | .sess_name = "maildir", | 103 | .sess_name = "maildir", |
101 | 104 | ||
102 | .sess_initialize = initialize, | 105 | .sess_initialize = initialize, |
103 | .sess_uninitialize = uninitialize, | 106 | .sess_uninitialize = uninitialize, |
@@ -116,32 +119,33 @@ static mailsession_driver local_maildir_session_driver = { | |||
116 | .sess_delete_folder = NULL, | 119 | .sess_delete_folder = NULL, |
117 | .sess_rename_folder = NULL, | 120 | .sess_rename_folder = NULL, |
118 | .sess_check_folder = check_folder, | 121 | .sess_check_folder = check_folder, |
119 | .sess_examine_folder = NULL, | 122 | .sess_examine_folder = NULL, |
120 | .sess_select_folder = NULL, | 123 | .sess_select_folder = NULL, |
121 | .sess_expunge_folder = expunge_folder, | 124 | .sess_expunge_folder = expunge_folder, |
122 | .sess_status_folder = status_folder, | 125 | .sess_status_folder = status_folder, |
123 | .sess_messages_number = messages_number, | 126 | .sess_messages_number = messages_number, |
124 | .sess_recent_number = recent_number, | 127 | .sess_recent_number = recent_number, |
125 | .sess_unseen_number = unseen_number, | 128 | .sess_unseen_number = unseen_number, |
126 | .sess_list_folders = NULL, | 129 | .sess_list_folders = NULL, |
127 | .sess_lsub_folders = NULL, | 130 | .sess_lsub_folders = NULL, |
128 | .sess_subscribe_folder = NULL, | 131 | .sess_subscribe_folder = NULL, |
129 | .sess_unsubscribe_folder = NULL, | 132 | .sess_unsubscribe_folder = NULL, |
130 | 133 | ||
131 | .sess_append_message = append_message, | 134 | .sess_append_message = append_message, |
135 | .sess_append_message_flags = append_message_flags, | ||
132 | .sess_copy_message = NULL, | 136 | .sess_copy_message = NULL, |
133 | .sess_move_message = NULL, | 137 | .sess_move_message = NULL, |
134 | 138 | ||
135 | .sess_get_messages_list = get_messages_list, | 139 | .sess_get_messages_list = get_messages_list, |
136 | .sess_get_envelopes_list = get_envelopes_list, | 140 | .sess_get_envelopes_list = get_envelopes_list, |
137 | .sess_remove_message = NULL, | 141 | .sess_remove_message = NULL, |
138 | #if 0 | 142 | #if 0 |
139 | .sess_search_messages = maildriver_generic_search_messages, | 143 | .sess_search_messages = maildriver_generic_search_messages, |
140 | #endif | 144 | #endif |
141 | 145 | ||
142 | .sess_get_message = NULL, | 146 | .sess_get_message = NULL, |
143 | .sess_get_message_by_uid = get_message_by_uid, | 147 | .sess_get_message_by_uid = get_message_by_uid, |
144 | }; | 148 | }; |
145 | 149 | ||
146 | mailsession_driver * maildir_session_driver = &local_maildir_session_driver; | 150 | mailsession_driver * maildir_session_driver = &local_maildir_session_driver; |
147 | 151 | ||
@@ -342,44 +346,91 @@ static int recent_number(mailsession * session, char * mb, | |||
342 | 346 | ||
343 | r = status_folder(session, mb, &messages, &recent, &unseen); | 347 | r = status_folder(session, mb, &messages, &recent, &unseen); |
344 | if (r != MAIL_NO_ERROR) | 348 | if (r != MAIL_NO_ERROR) |
345 | return r; | 349 | return r; |
346 | 350 | ||
347 | * result = recent; | 351 | * result = recent; |
348 | 352 | ||
349 | return MAIL_NO_ERROR; | 353 | return MAIL_NO_ERROR; |
350 | } | 354 | } |
351 | 355 | ||
352 | 356 | ||
353 | /* messages operations */ | 357 | /* messages operations */ |
354 | 358 | ||
355 | static int append_message(mailsession * session, | 359 | static int append_message(mailsession * session, |
356 | char * message, size_t size) | 360 | char * message, size_t size) |
357 | { | 361 | { |
362 | #if 0 | ||
358 | struct maildir * md; | 363 | struct maildir * md; |
359 | int r; | 364 | int r; |
360 | 365 | ||
361 | md = get_maildir_session(session); | 366 | md = get_maildir_session(session); |
362 | if (md == NULL) | 367 | if (md == NULL) |
363 | return MAIL_ERROR_BAD_STATE; | 368 | return MAIL_ERROR_BAD_STATE; |
364 | 369 | ||
365 | r = maildir_message_add(md, message, size); | 370 | r = maildir_message_add(md, message, size); |
366 | if (r != MAILDIR_NO_ERROR) | 371 | if (r != MAILDIR_NO_ERROR) |
367 | return maildirdriver_maildir_error_to_mail_error(r); | 372 | return maildirdriver_maildir_error_to_mail_error(r); |
368 | 373 | ||
369 | return MAIL_NO_ERROR; | 374 | return MAIL_NO_ERROR; |
375 | #endif | ||
376 | |||
377 | return append_message_flags(session, message, size, NULL); | ||
378 | } | ||
379 | |||
380 | static int append_message_flags(mailsession * session, | ||
381 | char * message, size_t size, struct mail_flags * flags) | ||
382 | { | ||
383 | struct maildir * md; | ||
384 | int r; | ||
385 | char uid[PATH_MAX]; | ||
386 | struct maildir_msg * md_msg; | ||
387 | chashdatum key; | ||
388 | chashdatum value; | ||
389 | uint32_t md_flags; | ||
390 | |||
391 | md = get_maildir_session(session); | ||
392 | if (md == NULL) | ||
393 | return MAIL_ERROR_BAD_STATE; | ||
394 | |||
395 | r = maildir_message_add_uid(md, message, size, | ||
396 | uid, sizeof(uid)); | ||
397 | if (r != MAILDIR_NO_ERROR) | ||
398 | return maildirdriver_maildir_error_to_mail_error(r); | ||
399 | |||
400 | if (flags == NULL) | ||
401 | goto exit; | ||
402 | |||
403 | key.data = uid; | ||
404 | key.len = strlen(uid); | ||
405 | r = chash_get(md->mdir_msg_hash, &key, &value); | ||
406 | if (r < 0) | ||
407 | goto exit; | ||
408 | |||
409 | md_msg = value.data; | ||
410 | |||
411 | md_flags = maildirdriver_flags_to_maildir_flags(flags->fl_flags); | ||
412 | |||
413 | r = maildir_message_change_flags(md, uid, md_flags); | ||
414 | if (r != MAILDIR_NO_ERROR) | ||
415 | goto exit; | ||
416 | |||
417 | return MAIL_NO_ERROR; | ||
418 | |||
419 | exit: | ||
420 | return MAIL_NO_ERROR; | ||
370 | } | 421 | } |
371 | 422 | ||
372 | static int get_messages_list(mailsession * session, | 423 | static int get_messages_list(mailsession * session, |
373 | struct mailmessage_list ** result) | 424 | struct mailmessage_list ** result) |
374 | { | 425 | { |
375 | struct maildir * md; | 426 | struct maildir * md; |
376 | int r; | 427 | int r; |
377 | struct mailmessage_list * env_list; | 428 | struct mailmessage_list * env_list; |
378 | int res; | 429 | int res; |
379 | 430 | ||
380 | md = get_maildir_session(session); | 431 | md = get_maildir_session(session); |
381 | if (md == NULL) | 432 | if (md == NULL) |
382 | return MAIL_ERROR_BAD_STATE; | 433 | return MAIL_ERROR_BAD_STATE; |
383 | 434 | ||
384 | r = maildir_update(md); | 435 | r = maildir_update(md); |
385 | if (r != MAILDIR_NO_ERROR) { | 436 | if (r != MAILDIR_NO_ERROR) { |
diff --git a/kmicromail/libetpan/generic/maildirdriver_cached.c b/kmicromail/libetpan/generic/maildirdriver_cached.c index 503d1c9..8a5e206 100644 --- a/kmicromail/libetpan/generic/maildirdriver_cached.c +++ b/kmicromail/libetpan/generic/maildirdriver_cached.c | |||
@@ -73,32 +73,35 @@ static int expunge_folder(mailsession * session); | |||
73 | static int status_folder(mailsession * session, char * mb, | 73 | static int status_folder(mailsession * session, char * mb, |
74 | uint32_t * result_messages, uint32_t * result_recent, | 74 | uint32_t * result_messages, uint32_t * result_recent, |
75 | uint32_t * result_unseen); | 75 | uint32_t * result_unseen); |
76 | 76 | ||
77 | static int recent_number(mailsession * session, char * mb, | 77 | static int recent_number(mailsession * session, char * mb, |
78 | uint32_t * result); | 78 | uint32_t * result); |
79 | 79 | ||
80 | static int unseen_number(mailsession * session, char * mb, | 80 | static int unseen_number(mailsession * session, char * mb, |
81 | uint32_t * result); | 81 | uint32_t * result); |
82 | 82 | ||
83 | static int messages_number(mailsession * session, char * mb, | 83 | static int messages_number(mailsession * session, char * mb, |
84 | uint32_t * result); | 84 | uint32_t * result); |
85 | 85 | ||
86 | static int append_message(mailsession * session, | 86 | static int append_message(mailsession * session, |
87 | char * message, size_t size); | 87 | char * message, size_t size); |
88 | 88 | ||
89 | static int append_message_flags(mailsession * session, | ||
90 | char * message, size_t size, struct mail_flags * flags); | ||
91 | |||
89 | static int get_messages_list(mailsession * session, | 92 | static int get_messages_list(mailsession * session, |
90 | struct mailmessage_list ** result); | 93 | struct mailmessage_list ** result); |
91 | 94 | ||
92 | static int get_envelopes_list(mailsession * session, | 95 | static int get_envelopes_list(mailsession * session, |
93 | struct mailmessage_list * env_list); | 96 | struct mailmessage_list * env_list); |
94 | 97 | ||
95 | static int check_folder(mailsession * session); | 98 | static int check_folder(mailsession * session); |
96 | 99 | ||
97 | static int get_message(mailsession * session, | 100 | static int get_message(mailsession * session, |
98 | uint32_t num, mailmessage ** result); | 101 | uint32_t num, mailmessage ** result); |
99 | 102 | ||
100 | static int get_message_by_uid(mailsession * session, | 103 | static int get_message_by_uid(mailsession * session, |
101 | const char * uid, mailmessage ** result); | 104 | const char * uid, mailmessage ** result); |
102 | 105 | ||
103 | static mailsession_driver local_maildir_cached_session_driver = { | 106 | static mailsession_driver local_maildir_cached_session_driver = { |
104 | .sess_name = "maildir-cached", | 107 | .sess_name = "maildir-cached", |
@@ -120,32 +123,33 @@ static mailsession_driver local_maildir_cached_session_driver = { | |||
120 | .sess_delete_folder = NULL, | 123 | .sess_delete_folder = NULL, |
121 | .sess_rename_folder = NULL, | 124 | .sess_rename_folder = NULL, |
122 | .sess_check_folder = check_folder, | 125 | .sess_check_folder = check_folder, |
123 | .sess_examine_folder = NULL, | 126 | .sess_examine_folder = NULL, |
124 | .sess_select_folder = NULL, | 127 | .sess_select_folder = NULL, |
125 | .sess_expunge_folder = expunge_folder, | 128 | .sess_expunge_folder = expunge_folder, |
126 | .sess_status_folder = status_folder, | 129 | .sess_status_folder = status_folder, |
127 | .sess_messages_number = messages_number, | 130 | .sess_messages_number = messages_number, |
128 | .sess_recent_number = recent_number, | 131 | .sess_recent_number = recent_number, |
129 | .sess_unseen_number = unseen_number, | 132 | .sess_unseen_number = unseen_number, |
130 | .sess_list_folders = NULL, | 133 | .sess_list_folders = NULL, |
131 | .sess_lsub_folders = NULL, | 134 | .sess_lsub_folders = NULL, |
132 | .sess_subscribe_folder = NULL, | 135 | .sess_subscribe_folder = NULL, |
133 | .sess_unsubscribe_folder = NULL, | 136 | .sess_unsubscribe_folder = NULL, |
134 | 137 | ||
135 | .sess_append_message = append_message, | 138 | .sess_append_message = append_message, |
139 | .sess_append_message_flags = append_message_flags, | ||
136 | .sess_copy_message = NULL, | 140 | .sess_copy_message = NULL, |
137 | .sess_move_message = NULL, | 141 | .sess_move_message = NULL, |
138 | 142 | ||
139 | .sess_get_messages_list = get_messages_list, | 143 | .sess_get_messages_list = get_messages_list, |
140 | .sess_get_envelopes_list = get_envelopes_list, | 144 | .sess_get_envelopes_list = get_envelopes_list, |
141 | .sess_remove_message = NULL, | 145 | .sess_remove_message = NULL, |
142 | #if 0 | 146 | #if 0 |
143 | .sess_search_messages = maildriver_generic_search_messages, | 147 | .sess_search_messages = maildriver_generic_search_messages, |
144 | #endif | 148 | #endif |
145 | 149 | ||
146 | .sess_get_message = get_message, | 150 | .sess_get_message = get_message, |
147 | .sess_get_message_by_uid = get_message_by_uid, | 151 | .sess_get_message_by_uid = get_message_by_uid, |
148 | }; | 152 | }; |
149 | 153 | ||
150 | mailsession_driver * maildir_cached_session_driver = | 154 | mailsession_driver * maildir_cached_session_driver = |
151 | &local_maildir_cached_session_driver; | 155 | &local_maildir_cached_session_driver; |
@@ -441,35 +445,109 @@ static int messages_number(mailsession * session, char * mb, | |||
441 | static int unseen_number(mailsession * session, char * mb, | 445 | static int unseen_number(mailsession * session, char * mb, |
442 | uint32_t * result) | 446 | uint32_t * result) |
443 | { | 447 | { |
444 | return mailsession_unseen_number(get_ancestor(session), mb, result); | 448 | return mailsession_unseen_number(get_ancestor(session), mb, result); |
445 | } | 449 | } |
446 | 450 | ||
447 | static int recent_number(mailsession * session, char * mb, | 451 | static int recent_number(mailsession * session, char * mb, |
448 | uint32_t * result) | 452 | uint32_t * result) |
449 | { | 453 | { |
450 | return mailsession_recent_number(get_ancestor(session), mb, result); | 454 | return mailsession_recent_number(get_ancestor(session), mb, result); |
451 | } | 455 | } |
452 | 456 | ||
453 | 457 | ||
454 | static int append_message(mailsession * session, | 458 | static int append_message(mailsession * session, |
455 | char * message, size_t size) | 459 | char * message, size_t size) |
456 | { | 460 | { |
461 | #if 0 | ||
457 | return mailsession_append_message(get_ancestor(session), message, size); | 462 | return mailsession_append_message(get_ancestor(session), message, size); |
463 | #endif | ||
464 | return append_message_flags(session, message, size, NULL); | ||
458 | } | 465 | } |
459 | 466 | ||
467 | static int append_message_flags(mailsession * session, | ||
468 | char * message, size_t size, struct mail_flags * flags) | ||
469 | { | ||
470 | struct maildir * md; | ||
471 | int r; | ||
472 | char uid[PATH_MAX]; | ||
473 | struct maildir_msg * md_msg; | ||
474 | chashdatum key; | ||
475 | chashdatum value; | ||
476 | uint32_t md_flags; | ||
477 | struct mail_cache_db * cache_db_flags; | ||
478 | char filename_flags[PATH_MAX]; | ||
479 | MMAPString * mmapstr; | ||
480 | struct maildir_cached_session_state_data * data; | ||
481 | |||
482 | md = get_maildir_session(session); | ||
483 | if (md == NULL) | ||
484 | return MAIL_ERROR_BAD_STATE; | ||
485 | |||
486 | r = maildir_message_add_uid(md, message, size, | ||
487 | uid, sizeof(uid)); | ||
488 | if (r != MAILDIR_NO_ERROR) | ||
489 | return maildirdriver_maildir_error_to_mail_error(r); | ||
490 | |||
491 | if (flags == NULL) | ||
492 | goto exit; | ||
493 | |||
494 | data = get_cached_data(session); | ||
495 | |||
496 | snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", | ||
497 | data->md_flags_directory, MAIL_DIR_SEPARATOR, data->md_quoted_mb, | ||
498 | MAIL_DIR_SEPARATOR, FLAGS_NAME); | ||
499 | |||
500 | r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); | ||
501 | if (r < 0) | ||
502 | goto exit; | ||
503 | |||
504 | mmapstr = mmap_string_new(""); | ||
505 | if (mmapstr == NULL) | ||
506 | goto close_db_flags; | ||
507 | |||
508 | r = write_cached_flags(cache_db_flags, mmapstr, | ||
509 | uid, flags); | ||
510 | |||
511 | mmap_string_free(mmapstr); | ||
512 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
513 | |||
514 | if (r != MAIL_NO_ERROR) | ||
515 | goto exit; | ||
516 | |||
517 | key.data = uid; | ||
518 | key.len = strlen(uid); | ||
519 | r = chash_get(md->mdir_msg_hash, &key, &value); | ||
520 | if (r < 0) | ||
521 | goto exit; | ||
522 | |||
523 | md_msg = value.data; | ||
524 | |||
525 | md_flags = maildirdriver_flags_to_maildir_flags(flags->fl_flags); | ||
526 | |||
527 | r = maildir_message_change_flags(md, uid, md_flags); | ||
528 | if (r != MAILDIR_NO_ERROR) | ||
529 | goto exit; | ||
530 | |||
531 | return MAIL_NO_ERROR; | ||
532 | |||
533 | close_db_flags: | ||
534 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
535 | exit: | ||
536 | return MAIL_NO_ERROR; | ||
537 | } | ||
460 | 538 | ||
461 | #define UID_NAME "uid.db" | 539 | #define UID_NAME "uid.db" |
462 | 540 | ||
463 | static int uid_clean_up(struct mail_cache_db * uid_db, | 541 | static int uid_clean_up(struct mail_cache_db * uid_db, |
464 | struct mailmessage_list * env_list) | 542 | struct mailmessage_list * env_list) |
465 | { | 543 | { |
466 | chash * hash_exist; | 544 | chash * hash_exist; |
467 | int res; | 545 | int res; |
468 | int r; | 546 | int r; |
469 | unsigned int i; | 547 | unsigned int i; |
470 | chashdatum key; | 548 | chashdatum key; |
471 | chashdatum value; | 549 | chashdatum value; |
472 | char key_str[PATH_MAX]; | 550 | char key_str[PATH_MAX]; |
473 | 551 | ||
474 | /* flush cache */ | 552 | /* flush cache */ |
475 | 553 | ||
diff --git a/kmicromail/libetpan/generic/maildirdriver_cached_message.c b/kmicromail/libetpan/generic/maildirdriver_cached_message.c index 51866aa..34de351 100644 --- a/kmicromail/libetpan/generic/maildirdriver_cached_message.c +++ b/kmicromail/libetpan/generic/maildirdriver_cached_message.c | |||
@@ -26,72 +26,77 @@ | |||
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "maildirdriver_message.h" | 36 | #include "maildirdriver_message.h" |
37 | 37 | ||
38 | #include "mailmessage_tools.h" | 38 | #include "mailmessage_tools.h" |
39 | #include "maildirdriver.h" | 39 | #include "maildirdriver.h" |
40 | #include "maildir.h" | 40 | #include "maildir.h" |
41 | #include "generic_cache.h" | 41 | #include "generic_cache.h" |
42 | #include "mail_cache_db.h" | ||
43 | #include "maildirdriver_tools.h" | ||
42 | 44 | ||
43 | #include <unistd.h> | 45 | #include <unistd.h> |
44 | #include <sys/mman.h> | 46 | #include <sys/mman.h> |
45 | #include <sys/types.h> | 47 | #include <sys/types.h> |
46 | #include <sys/stat.h> | 48 | #include <sys/stat.h> |
47 | #include <fcntl.h> | 49 | #include <fcntl.h> |
48 | #include <string.h> | 50 | #include <string.h> |
49 | #include <stdlib.h> | 51 | #include <stdlib.h> |
50 | 52 | ||
53 | static int get_flags(mailmessage * msg_info, | ||
54 | struct mail_flags ** result); | ||
55 | |||
51 | static int prefetch(mailmessage * msg_info); | 56 | static int prefetch(mailmessage * msg_info); |
52 | 57 | ||
53 | static void prefetch_free(struct generic_message_t * msg); | 58 | static void prefetch_free(struct generic_message_t * msg); |
54 | 59 | ||
55 | static int initialize(mailmessage * msg_info); | 60 | static int initialize(mailmessage * msg_info); |
56 | 61 | ||
57 | static void check(mailmessage * msg_info); | 62 | static void check(mailmessage * msg_info); |
58 | 63 | ||
59 | static mailmessage_driver local_maildir_cached_message_driver = { | 64 | static mailmessage_driver local_maildir_cached_message_driver = { |
60 | .msg_name = "maildir-cached", | 65 | .msg_name = "maildir-cached", |
61 | 66 | ||
62 | .msg_initialize = initialize, | 67 | .msg_initialize = initialize, |
63 | .msg_uninitialize = mailmessage_generic_uninitialize, | 68 | .msg_uninitialize = mailmessage_generic_uninitialize, |
64 | 69 | ||
65 | .msg_flush = mailmessage_generic_flush, | 70 | .msg_flush = mailmessage_generic_flush, |
66 | .msg_check = check, | 71 | .msg_check = check, |
67 | 72 | ||
68 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, | 73 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, |
69 | 74 | ||
70 | .msg_fetch = mailmessage_generic_fetch, | 75 | .msg_fetch = mailmessage_generic_fetch, |
71 | .msg_fetch_header = mailmessage_generic_fetch_header, | 76 | .msg_fetch_header = mailmessage_generic_fetch_header, |
72 | .msg_fetch_body = mailmessage_generic_fetch_header, | 77 | .msg_fetch_body = mailmessage_generic_fetch_header, |
73 | .msg_fetch_size = NULL, | 78 | .msg_fetch_size = NULL, |
74 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, | 79 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, |
75 | .msg_fetch_section = mailmessage_generic_fetch_section, | 80 | .msg_fetch_section = mailmessage_generic_fetch_section, |
76 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, | 81 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, |
77 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, | 82 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, |
78 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, | 83 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, |
79 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, | 84 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, |
80 | 85 | ||
81 | .msg_get_flags = NULL, | 86 | .msg_get_flags = get_flags, |
82 | }; | 87 | }; |
83 | 88 | ||
84 | mailmessage_driver * maildir_cached_message_driver = | 89 | mailmessage_driver * maildir_cached_message_driver = |
85 | &local_maildir_cached_message_driver; | 90 | &local_maildir_cached_message_driver; |
86 | 91 | ||
87 | struct maildir_msg_data { | 92 | struct maildir_msg_data { |
88 | int fd; | 93 | int fd; |
89 | }; | 94 | }; |
90 | 95 | ||
91 | #if 0 | 96 | #if 0 |
92 | static inline struct maildir_cached_session_state_data * | 97 | static inline struct maildir_cached_session_state_data * |
93 | get_cached_session_data(mailmessage * msg) | 98 | get_cached_session_data(mailmessage * msg) |
94 | { | 99 | { |
95 | return msg->session->data; | 100 | return msg->session->data; |
96 | } | 101 | } |
97 | 102 | ||
@@ -233,16 +238,97 @@ static int initialize(mailmessage * msg_info) | |||
233 | msg->msg_prefetch_free = prefetch_free; | 238 | msg->msg_prefetch_free = prefetch_free; |
234 | 239 | ||
235 | return MAIL_NO_ERROR; | 240 | return MAIL_NO_ERROR; |
236 | } | 241 | } |
237 | 242 | ||
238 | static void check(mailmessage * msg_info) | 243 | static void check(mailmessage * msg_info) |
239 | { | 244 | { |
240 | int r; | 245 | int r; |
241 | 246 | ||
242 | if (msg_info->msg_flags != NULL) { | 247 | if (msg_info->msg_flags != NULL) { |
243 | r = mail_flags_store_set(get_session_ancestor_data(msg_info)->md_flags_store, msg_info); | 248 | r = mail_flags_store_set(get_session_ancestor_data(msg_info)->md_flags_store, msg_info); |
244 | 249 | ||
245 | r = mail_flags_store_set(get_cached_session_data(msg_info)->md_flags_store, msg_info); | 250 | r = mail_flags_store_set(get_cached_session_data(msg_info)->md_flags_store, msg_info); |
246 | /* ignore errors */ | 251 | /* ignore errors */ |
247 | } | 252 | } |
248 | } | 253 | } |
254 | |||
255 | #define FLAGS_NAME "flags.db" | ||
256 | |||
257 | static int get_flags(mailmessage * msg_info, | ||
258 | struct mail_flags ** result) | ||
259 | { | ||
260 | struct mail_cache_db * cache_db_flags; | ||
261 | chashdatum key; | ||
262 | chashdatum value; | ||
263 | struct maildir * md; | ||
264 | struct mail_flags * flags; | ||
265 | struct maildir_cached_session_state_data * data; | ||
266 | struct maildir_msg * md_msg; | ||
267 | int r; | ||
268 | uint32_t driver_flags; | ||
269 | char filename_flags[PATH_MAX]; | ||
270 | char keyname[PATH_MAX]; | ||
271 | MMAPString * mmapstr; | ||
272 | |||
273 | if (msg_info->msg_flags != NULL) { | ||
274 | * result = msg_info->msg_flags; | ||
275 | return MAIL_NO_ERROR; | ||
276 | } | ||
277 | |||
278 | data = get_cached_session_data(msg_info); | ||
279 | flags = mail_flags_store_get(data->md_flags_store, | ||
280 | msg_info->msg_index); | ||
281 | if (flags != NULL) { | ||
282 | msg_info->msg_flags = flags; | ||
283 | * result = msg_info->msg_flags; | ||
284 | return MAIL_NO_ERROR; | ||
285 | } | ||
286 | |||
287 | snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", | ||
288 | data->md_flags_directory, MAIL_DIR_SEPARATOR, data->md_quoted_mb, | ||
289 | MAIL_DIR_SEPARATOR, FLAGS_NAME); | ||
290 | |||
291 | r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); | ||
292 | if (r < 0) | ||
293 | return MAIL_ERROR_FILE; | ||
294 | |||
295 | snprintf(keyname, PATH_MAX, "%s-flags", msg_info->msg_uid); | ||
296 | |||
297 | mmapstr = mmap_string_new(""); | ||
298 | if (mmapstr == NULL) { | ||
299 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
300 | return MAIL_ERROR_MEMORY; | ||
301 | } | ||
302 | |||
303 | r = generic_cache_flags_read(cache_db_flags, mmapstr, keyname, &flags); | ||
304 | mmap_string_free(mmapstr); | ||
305 | |||
306 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
307 | |||
308 | if (r != MAIL_NO_ERROR) { | ||
309 | flags = mail_flags_new_empty(); | ||
310 | if (flags == NULL) | ||
311 | return MAIL_ERROR_MEMORY; | ||
312 | } | ||
313 | |||
314 | md = get_maildir_session(msg_info); | ||
315 | if (md == NULL) | ||
316 | return MAIL_ERROR_BAD_STATE; | ||
317 | |||
318 | key.data = msg_info->msg_uid; | ||
319 | key.len = strlen(msg_info->msg_uid); | ||
320 | r = chash_get(md->mdir_msg_hash, &key, &value); | ||
321 | if (r < 0) | ||
322 | return MAIL_ERROR_MSG_NOT_FOUND; | ||
323 | |||
324 | md_msg = value.data; | ||
325 | |||
326 | driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags); | ||
327 | |||
328 | flags->fl_flags = driver_flags; | ||
329 | msg_info->msg_flags = flags; | ||
330 | |||
331 | * result = msg_info->msg_flags; | ||
332 | |||
333 | return MAIL_NO_ERROR; | ||
334 | } | ||
diff --git a/kmicromail/libetpan/generic/maildirdriver_message.c b/kmicromail/libetpan/generic/maildirdriver_message.c index 7cf9dd1..613fc39 100644 --- a/kmicromail/libetpan/generic/maildirdriver_message.c +++ b/kmicromail/libetpan/generic/maildirdriver_message.c | |||
@@ -21,77 +21,81 @@ | |||
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "maildirdriver_message.h" | 36 | #include "maildirdriver_message.h" |
37 | #include "maildirdriver_tools.h" | ||
37 | 38 | ||
38 | #include "mailmessage_tools.h" | 39 | #include "mailmessage_tools.h" |
39 | #include "maildirdriver.h" | 40 | #include "maildirdriver.h" |
40 | #include "maildir.h" | 41 | #include "maildir.h" |
41 | #include "generic_cache.h" | 42 | #include "generic_cache.h" |
42 | 43 | ||
43 | #include <unistd.h> | 44 | #include <unistd.h> |
44 | #include <sys/mman.h> | 45 | #include <sys/mman.h> |
45 | #include <sys/types.h> | 46 | #include <sys/types.h> |
46 | #include <sys/stat.h> | 47 | #include <sys/stat.h> |
47 | #include <fcntl.h> | 48 | #include <fcntl.h> |
48 | #include <string.h> | 49 | #include <string.h> |
49 | #include <stdlib.h> | 50 | #include <stdlib.h> |
50 | 51 | ||
52 | static int get_flags(mailmessage * msg_info, | ||
53 | struct mail_flags ** result); | ||
54 | |||
51 | static int prefetch(mailmessage * msg_info); | 55 | static int prefetch(mailmessage * msg_info); |
52 | 56 | ||
53 | static void prefetch_free(struct generic_message_t * msg); | 57 | static void prefetch_free(struct generic_message_t * msg); |
54 | 58 | ||
55 | static int initialize(mailmessage * msg_info); | 59 | static int initialize(mailmessage * msg_info); |
56 | 60 | ||
57 | static void check(mailmessage * msg_info); | 61 | static void check(mailmessage * msg_info); |
58 | 62 | ||
59 | static mailmessage_driver local_maildir_message_driver = { | 63 | static mailmessage_driver local_maildir_message_driver = { |
60 | .msg_name = "maildir", | 64 | .msg_name = "maildir", |
61 | 65 | ||
62 | .msg_initialize = initialize, | 66 | .msg_initialize = initialize, |
63 | .msg_uninitialize = mailmessage_generic_uninitialize, | 67 | .msg_uninitialize = mailmessage_generic_uninitialize, |
64 | 68 | ||
65 | .msg_flush = mailmessage_generic_flush, | 69 | .msg_flush = mailmessage_generic_flush, |
66 | .msg_check = check, | 70 | .msg_check = check, |
67 | 71 | ||
68 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, | 72 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, |
69 | 73 | ||
70 | .msg_fetch = mailmessage_generic_fetch, | 74 | .msg_fetch = mailmessage_generic_fetch, |
71 | .msg_fetch_header = mailmessage_generic_fetch_header, | 75 | .msg_fetch_header = mailmessage_generic_fetch_header, |
72 | .msg_fetch_body = mailmessage_generic_fetch_header, | 76 | .msg_fetch_body = mailmessage_generic_fetch_header, |
73 | .msg_fetch_size = NULL, | 77 | .msg_fetch_size = NULL, |
74 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, | 78 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, |
75 | .msg_fetch_section = mailmessage_generic_fetch_section, | 79 | .msg_fetch_section = mailmessage_generic_fetch_section, |
76 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, | 80 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, |
77 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, | 81 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, |
78 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, | 82 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, |
79 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, | 83 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, |
80 | 84 | ||
81 | .msg_get_flags = NULL, | 85 | .msg_get_flags = get_flags, |
82 | }; | 86 | }; |
83 | 87 | ||
84 | mailmessage_driver * maildir_message_driver = &local_maildir_message_driver; | 88 | mailmessage_driver * maildir_message_driver = &local_maildir_message_driver; |
85 | 89 | ||
86 | struct maildir_msg_data { | 90 | struct maildir_msg_data { |
87 | int fd; | 91 | int fd; |
88 | }; | 92 | }; |
89 | 93 | ||
90 | static inline struct maildir_session_state_data * | 94 | static inline struct maildir_session_state_data * |
91 | get_session_data(mailmessage * msg) | 95 | get_session_data(mailmessage * msg) |
92 | { | 96 | { |
93 | return msg->msg_session->sess_data; | 97 | return msg->msg_session->sess_data; |
94 | } | 98 | } |
95 | 99 | ||
96 | static struct maildir * get_maildir_session(mailmessage * msg) | 100 | static struct maildir * get_maildir_session(mailmessage * msg) |
97 | { | 101 | { |
@@ -184,16 +188,68 @@ static int initialize(mailmessage * msg_info) | |||
184 | msg->msg_prefetch = prefetch; | 188 | msg->msg_prefetch = prefetch; |
185 | msg->msg_prefetch_free = prefetch_free; | 189 | msg->msg_prefetch_free = prefetch_free; |
186 | 190 | ||
187 | return MAIL_NO_ERROR; | 191 | return MAIL_NO_ERROR; |
188 | } | 192 | } |
189 | 193 | ||
190 | static void check(mailmessage * msg_info) | 194 | static void check(mailmessage * msg_info) |
191 | { | 195 | { |
192 | int r; | 196 | int r; |
193 | 197 | ||
194 | if (msg_info->msg_flags != NULL) { | 198 | if (msg_info->msg_flags != NULL) { |
195 | r = mail_flags_store_set(get_session_data(msg_info)->md_flags_store, | 199 | r = mail_flags_store_set(get_session_data(msg_info)->md_flags_store, |
196 | msg_info); | 200 | msg_info); |
197 | /* ignore errors */ | 201 | /* ignore errors */ |
198 | } | 202 | } |
199 | } | 203 | } |
204 | |||
205 | static int get_flags(mailmessage * msg_info, | ||
206 | struct mail_flags ** result) | ||
207 | { | ||
208 | chashdatum key; | ||
209 | chashdatum value; | ||
210 | struct maildir * md; | ||
211 | struct mail_flags * flags; | ||
212 | struct maildir_session_state_data * data; | ||
213 | struct maildir_msg * md_msg; | ||
214 | int r; | ||
215 | uint32_t driver_flags; | ||
216 | clist * ext; | ||
217 | |||
218 | if (msg_info->msg_flags != NULL) { | ||
219 | * result = msg_info->msg_flags; | ||
220 | return MAIL_NO_ERROR; | ||
221 | } | ||
222 | |||
223 | data = get_session_data(msg_info); | ||
224 | flags = mail_flags_store_get(data->md_flags_store, | ||
225 | msg_info->msg_index); | ||
226 | if (flags != NULL) { | ||
227 | msg_info->msg_flags = flags; | ||
228 | * result = msg_info->msg_flags; | ||
229 | return MAIL_NO_ERROR; | ||
230 | } | ||
231 | |||
232 | md = get_maildir_session(msg_info); | ||
233 | if (md == NULL) | ||
234 | return MAIL_ERROR_BAD_STATE; | ||
235 | |||
236 | key.data = msg_info->msg_uid; | ||
237 | key.len = strlen(msg_info->msg_uid); | ||
238 | r = chash_get(md->mdir_msg_hash, &key, &value); | ||
239 | if (r < 0) | ||
240 | return MAIL_ERROR_MSG_NOT_FOUND; | ||
241 | |||
242 | md_msg = value.data; | ||
243 | |||
244 | driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags); | ||
245 | |||
246 | ext = clist_new(); | ||
247 | if (ext == NULL) | ||
248 | return MAIL_ERROR_MEMORY; | ||
249 | |||
250 | msg_info->msg_flags = mail_flags_new(driver_flags, ext); | ||
251 | |||
252 | * result = msg_info->msg_flags; | ||
253 | |||
254 | return MAIL_NO_ERROR; | ||
255 | } | ||
diff --git a/kmicromail/libetpan/generic/maildirstorage.c b/kmicromail/libetpan/generic/maildirstorage.c index 7e6b461..e37f591 100644 --- a/kmicromail/libetpan/generic/maildirstorage.c +++ b/kmicromail/libetpan/generic/maildirstorage.c | |||
@@ -20,65 +20,66 @@ | |||
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "maildirstorage.h" | ||
36 | #include "mailstorage.h" | 37 | #include "mailstorage.h" |
37 | 38 | ||
38 | #include "mail.h" | 39 | #include "mail.h" |
39 | #include "mailmessage.h" | 40 | #include "mailmessage.h" |
40 | #include "maildirdriver.h" | 41 | #include "maildirdriver.h" |
41 | #include "maildirdriver_cached.h" | 42 | #include "maildirdriver_cached.h" |
42 | #include "maildriver.h" | 43 | #include "maildriver.h" |
43 | 44 | ||
44 | #include <stdlib.h> | 45 | #include <stdlib.h> |
45 | #include <string.h> | 46 | #include <string.h> |
46 | 47 | ||
47 | /* maildir storage */ | 48 | /* maildir storage */ |
48 | 49 | ||
49 | static int maildir_mailstorage_connect(struct mailstorage * storage); | 50 | static int maildir_mailstorage_connect(struct mailstorage * storage); |
50 | static int | 51 | static int |
51 | maildir_mailstorage_get_folder_session(struct mailstorage * storage, | 52 | maildir_mailstorage_get_folder_session(struct mailstorage * storage, |
52 | char * pathname, mailsession ** result); | 53 | char * pathname, mailsession ** result); |
53 | static void maildir_mailstorage_uninitialize(struct mailstorage * storage); | 54 | static void maildir_mailstorage_uninitialize(struct mailstorage * storage); |
54 | 55 | ||
55 | static mailstorage_driver maildir_mailstorage_driver = { | 56 | static mailstorage_driver maildir_mailstorage_driver = { |
56 | .sto_name = "maildir", | 57 | .sto_name = "maildir", |
57 | .sto_connect = maildir_mailstorage_connect, | 58 | .sto_connect = maildir_mailstorage_connect, |
58 | .sto_get_folder_session = maildir_mailstorage_get_folder_session, | 59 | .sto_get_folder_session = maildir_mailstorage_get_folder_session, |
59 | .sto_uninitialize = maildir_mailstorage_uninitialize, | 60 | .sto_uninitialize = maildir_mailstorage_uninitialize, |
60 | }; | 61 | }; |
61 | 62 | ||
62 | int maildir_mailstorage_init(struct mailstorage * storage, | 63 | int maildir_mailstorage_init(struct mailstorage * storage, |
63 | char * md_pathname, int md_cached, | 64 | char * md_pathname, int md_cached, |
64 | char * md_cache_directory, char * md_flags_directory) | 65 | char * md_cache_directory, char * md_flags_directory) |
65 | { | 66 | { |
66 | struct maildir_mailstorage * maildir_storage; | 67 | struct maildir_mailstorage * maildir_storage; |
67 | 68 | ||
68 | maildir_storage = malloc(sizeof(struct maildir_mailstorage)); | 69 | maildir_storage = malloc(sizeof(* maildir_storage)); |
69 | if (maildir_storage == NULL) | 70 | if (maildir_storage == NULL) |
70 | goto err; | 71 | goto err; |
71 | 72 | ||
72 | maildir_storage->md_pathname = strdup(md_pathname); | 73 | maildir_storage->md_pathname = strdup(md_pathname); |
73 | if (maildir_storage->md_pathname == NULL) | 74 | if (maildir_storage->md_pathname == NULL) |
74 | goto free; | 75 | goto free; |
75 | 76 | ||
76 | maildir_storage->md_cached = md_cached; | 77 | maildir_storage->md_cached = md_cached; |
77 | 78 | ||
78 | if (md_cached && (md_cache_directory != NULL) && | 79 | if (md_cached && (md_cache_directory != NULL) && |
79 | (md_flags_directory != NULL)) { | 80 | (md_flags_directory != NULL)) { |
80 | maildir_storage->md_cache_directory = strdup(md_cache_directory); | 81 | maildir_storage->md_cache_directory = strdup(md_cache_directory); |
81 | if (maildir_storage->md_cache_directory == NULL) | 82 | if (maildir_storage->md_cache_directory == NULL) |
82 | goto free_pathname; | 83 | goto free_pathname; |
83 | 84 | ||
84 | maildir_storage->md_flags_directory = strdup(md_flags_directory); | 85 | maildir_storage->md_flags_directory = strdup(md_flags_directory); |
diff --git a/kmicromail/libetpan/generic/maildirstorage.h b/kmicromail/libetpan/generic/maildirstorage.h index d17ea2c..73d7b20 100644 --- a/kmicromail/libetpan/generic/maildirstorage.h +++ b/kmicromail/libetpan/generic/maildirstorage.h | |||
@@ -31,33 +31,33 @@ | |||
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #ifndef MAILDIRSTORAGE_H | 36 | #ifndef MAILDIRSTORAGE_H |
37 | 37 | ||
38 | #define MAILDIRSTORAGE_H | 38 | #define MAILDIRSTORAGE_H |
39 | 39 | ||
40 | #include <libetpan/maildirdriver_types.h> | 40 | #include <libetpan/maildirdriver_types.h> |
41 | 41 | ||
42 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
43 | extern "C" { | 43 | extern "C" { |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | /* | 46 | /* |
47 | maildir_mailstorage_init is the constructor for a mbox storage. | 47 | maildir_mailstorage_init is the constructor for a maildir storage. |
48 | 48 | ||
49 | @param storage this is the storage to initialize. | 49 | @param storage this is the storage to initialize. |
50 | 50 | ||
51 | @param pathname is the directory that contains the mailbox. | 51 | @param pathname is the directory that contains the mailbox. |
52 | 52 | ||
53 | @param cached if this value is != 0, a persistant cache will be | 53 | @param cached if this value is != 0, a persistant cache will be |
54 | stored on local system. | 54 | stored on local system. |
55 | 55 | ||
56 | @param cache_directory is the location of the cache | 56 | @param cache_directory is the location of the cache |
57 | 57 | ||
58 | @param flags_directory is the location of the flags | 58 | @param flags_directory is the location of the flags |
59 | */ | 59 | */ |
60 | 60 | ||
61 | int maildir_mailstorage_init(struct mailstorage * storage, | 61 | int maildir_mailstorage_init(struct mailstorage * storage, |
62 | char * md_pathname, int md_cached, | 62 | char * md_pathname, int md_cached, |
63 | char * md_cache_directory, char * md_flags_directory); | 63 | char * md_cache_directory, char * md_flags_directory); |
diff --git a/kmicromail/libetpan/generic/maildriver.c b/kmicromail/libetpan/generic/maildriver.c index 01e3e34..1fc478a 100644 --- a/kmicromail/libetpan/generic/maildriver.c +++ b/kmicromail/libetpan/generic/maildriver.c | |||
@@ -269,32 +269,42 @@ int mailsession_unsubscribe_folder(mailsession * session, char * mb) | |||
269 | return MAIL_ERROR_NOT_IMPLEMENTED; | 269 | return MAIL_ERROR_NOT_IMPLEMENTED; |
270 | 270 | ||
271 | return session->sess_driver->sess_unsubscribe_folder(session, mb); | 271 | return session->sess_driver->sess_unsubscribe_folder(session, mb); |
272 | } | 272 | } |
273 | 273 | ||
274 | /* message */ | 274 | /* message */ |
275 | 275 | ||
276 | int mailsession_append_message(mailsession * session, | 276 | int mailsession_append_message(mailsession * session, |
277 | char * message, size_t size) | 277 | char * message, size_t size) |
278 | { | 278 | { |
279 | if (session->sess_driver->sess_append_message == NULL) | 279 | if (session->sess_driver->sess_append_message == NULL) |
280 | return MAIL_ERROR_NOT_IMPLEMENTED; | 280 | return MAIL_ERROR_NOT_IMPLEMENTED; |
281 | 281 | ||
282 | return session->sess_driver->sess_append_message(session, message, size); | 282 | return session->sess_driver->sess_append_message(session, message, size); |
283 | } | 283 | } |
284 | 284 | ||
285 | int mailsession_append_message_flags(mailsession * session, | ||
286 | char * message, size_t size, struct mail_flags * flags) | ||
287 | { | ||
288 | if (session->sess_driver->sess_append_message_flags == NULL) | ||
289 | return MAIL_ERROR_NOT_IMPLEMENTED; | ||
290 | |||
291 | return session->sess_driver->sess_append_message_flags(session, | ||
292 | message, size, flags); | ||
293 | } | ||
294 | |||
285 | int mailsession_copy_message(mailsession * session, | 295 | int mailsession_copy_message(mailsession * session, |
286 | uint32_t num, char * mb) | 296 | uint32_t num, char * mb) |
287 | { | 297 | { |
288 | if (session->sess_driver->sess_copy_message == NULL) | 298 | if (session->sess_driver->sess_copy_message == NULL) |
289 | return MAIL_ERROR_NOT_IMPLEMENTED; | 299 | return MAIL_ERROR_NOT_IMPLEMENTED; |
290 | 300 | ||
291 | return session->sess_driver->sess_copy_message(session, num, mb); | 301 | return session->sess_driver->sess_copy_message(session, num, mb); |
292 | } | 302 | } |
293 | 303 | ||
294 | int mailsession_move_message(mailsession * session, | 304 | int mailsession_move_message(mailsession * session, |
295 | uint32_t num, char * mb) | 305 | uint32_t num, char * mb) |
296 | { | 306 | { |
297 | if (session->sess_driver->sess_move_message == NULL) { | 307 | if (session->sess_driver->sess_move_message == NULL) { |
298 | int r; | 308 | int r; |
299 | 309 | ||
300 | if ((session->sess_driver->sess_copy_message == NULL) && | 310 | if ((session->sess_driver->sess_copy_message == NULL) && |
diff --git a/kmicromail/libetpan/generic/maildriver.h b/kmicromail/libetpan/generic/maildriver.h index 7da9aea..c773190 100644 --- a/kmicromail/libetpan/generic/maildriver.h +++ b/kmicromail/libetpan/generic/maildriver.h | |||
@@ -387,32 +387,35 @@ int mailsession_unsubscribe_folder(mailsession * session, char * mb); | |||
387 | 387 | ||
388 | /* | 388 | /* |
389 | mailsession_append_message adds a RFC 2822 message to the current | 389 | mailsession_append_message adds a RFC 2822 message to the current |
390 | given mailbox | 390 | given mailbox |
391 | 391 | ||
392 | @param session the session | 392 | @param session the session |
393 | @param message is a string that contains the RFC 2822 message | 393 | @param message is a string that contains the RFC 2822 message |
394 | @param size this is the size of the message | 394 | @param size this is the size of the message |
395 | 395 | ||
396 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 396 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
397 | on error | 397 | on error |
398 | */ | 398 | */ |
399 | 399 | ||
400 | int mailsession_append_message(mailsession * session, | 400 | int mailsession_append_message(mailsession * session, |
401 | char * message, size_t size); | 401 | char * message, size_t size); |
402 | 402 | ||
403 | int mailsession_append_message_flags(mailsession * session, | ||
404 | char * message, size_t size, struct mail_flags * flags); | ||
405 | |||
403 | /* | 406 | /* |
404 | NOTE: some drivers does not implement this | 407 | NOTE: some drivers does not implement this |
405 | 408 | ||
406 | mailsession_copy_message copies a message whose number is given to | 409 | mailsession_copy_message copies a message whose number is given to |
407 | a given mailbox. The mailbox must be accessible from the same session. | 410 | a given mailbox. The mailbox must be accessible from the same session. |
408 | 411 | ||
409 | @param session the session | 412 | @param session the session |
410 | @param num the message number | 413 | @param num the message number |
411 | @param mb the destination mailbox | 414 | @param mb the destination mailbox |
412 | 415 | ||
413 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 416 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
414 | on error | 417 | on error |
415 | */ | 418 | */ |
416 | 419 | ||
417 | int mailsession_copy_message(mailsession * session, | 420 | int mailsession_copy_message(mailsession * session, |
418 | uint32_t num, char * mb); | 421 | uint32_t num, char * mb); |
diff --git a/kmicromail/libetpan/generic/maildriver_types.h b/kmicromail/libetpan/generic/maildriver_types.h index 3ff9440..9eab4d6 100644 --- a/kmicromail/libetpan/generic/maildriver_types.h +++ b/kmicromail/libetpan/generic/maildriver_types.h | |||
@@ -494,32 +494,34 @@ struct mailsession_driver { | |||
494 | uint32_t * result); | 494 | uint32_t * result); |
495 | int (* sess_unseen_number)(mailsession * session, char * mb, | 495 | int (* sess_unseen_number)(mailsession * session, char * mb, |
496 | uint32_t * result); | 496 | uint32_t * result); |
497 | 497 | ||
498 | int (* sess_list_folders)(mailsession * session, char * mb, | 498 | int (* sess_list_folders)(mailsession * session, char * mb, |
499 | struct mail_list ** result); | 499 | struct mail_list ** result); |
500 | int (* sess_lsub_folders)(mailsession * session, char * mb, | 500 | int (* sess_lsub_folders)(mailsession * session, char * mb, |
501 | struct mail_list ** result); | 501 | struct mail_list ** result); |
502 | 502 | ||
503 | int (* sess_subscribe_folder)(mailsession * session, char * mb); | 503 | int (* sess_subscribe_folder)(mailsession * session, char * mb); |
504 | int (* sess_unsubscribe_folder)(mailsession * session, char * mb); | 504 | int (* sess_unsubscribe_folder)(mailsession * session, char * mb); |
505 | 505 | ||
506 | /* messages operations */ | 506 | /* messages operations */ |
507 | 507 | ||
508 | int (* sess_append_message)(mailsession * session, | 508 | int (* sess_append_message)(mailsession * session, |
509 | char * message, size_t size); | 509 | char * message, size_t size); |
510 | int (* sess_append_message_flags)(mailsession * session, | ||
511 | char * message, size_t size, struct mail_flags * flags); | ||
510 | int (* sess_copy_message)(mailsession * session, | 512 | int (* sess_copy_message)(mailsession * session, |
511 | uint32_t num, char * mb); | 513 | uint32_t num, char * mb); |
512 | int (* sess_move_message)(mailsession * session, | 514 | int (* sess_move_message)(mailsession * session, |
513 | uint32_t num, char * mb); | 515 | uint32_t num, char * mb); |
514 | 516 | ||
515 | int (* sess_get_message)(mailsession * session, | 517 | int (* sess_get_message)(mailsession * session, |
516 | uint32_t num, mailmessage ** result); | 518 | uint32_t num, mailmessage ** result); |
517 | 519 | ||
518 | int (* sess_get_message_by_uid)(mailsession * session, | 520 | int (* sess_get_message_by_uid)(mailsession * session, |
519 | const char * uid, mailmessage ** result); | 521 | const char * uid, mailmessage ** result); |
520 | 522 | ||
521 | int (* sess_get_messages_list)(mailsession * session, | 523 | int (* sess_get_messages_list)(mailsession * session, |
522 | struct mailmessage_list ** result); | 524 | struct mailmessage_list ** result); |
523 | int (* sess_get_envelopes_list)(mailsession * session, | 525 | int (* sess_get_envelopes_list)(mailsession * session, |
524 | struct mailmessage_list * env_list); | 526 | struct mailmessage_list * env_list); |
525 | int (* sess_remove_message)(mailsession * session, uint32_t num); | 527 | int (* sess_remove_message)(mailsession * session, uint32_t num); |
diff --git a/kmicromail/libetpan/generic/mailfolder.c b/kmicromail/libetpan/generic/mailfolder.c index 2ddc37d..89ba891 100644 --- a/kmicromail/libetpan/generic/mailfolder.c +++ b/kmicromail/libetpan/generic/mailfolder.c | |||
@@ -19,32 +19,39 @@ int mailfolder_expunge(struct mailfolder * folder) | |||
19 | 19 | ||
20 | int mailfolder_status(struct mailfolder * folder, | 20 | int mailfolder_status(struct mailfolder * folder, |
21 | uint32_t * result_messages, uint32_t * result_recent, | 21 | uint32_t * result_messages, uint32_t * result_recent, |
22 | uint32_t * result_unseen) | 22 | uint32_t * result_unseen) |
23 | { | 23 | { |
24 | return mailsession_status_folder(folder->fld_session, | 24 | return mailsession_status_folder(folder->fld_session, |
25 | folder->fld_pathname, result_messages, | 25 | folder->fld_pathname, result_messages, |
26 | result_recent, result_unseen); | 26 | result_recent, result_unseen); |
27 | } | 27 | } |
28 | 28 | ||
29 | int mailfolder_append_message(struct mailfolder * folder, | 29 | int mailfolder_append_message(struct mailfolder * folder, |
30 | char * message, size_t size) | 30 | char * message, size_t size) |
31 | { | 31 | { |
32 | return mailsession_append_message(folder->fld_session, message, size); | 32 | return mailsession_append_message(folder->fld_session, message, size); |
33 | } | 33 | } |
34 | 34 | ||
35 | int mailfolder_append_message_flags(struct mailfolder * folder, | ||
36 | char * message, size_t size, struct mail_flags * flags) | ||
37 | { | ||
38 | return mailsession_append_message_flags(folder->fld_session, message, | ||
39 | size, flags); | ||
40 | } | ||
41 | |||
35 | int mailfolder_get_messages_list(struct mailfolder * folder, | 42 | int mailfolder_get_messages_list(struct mailfolder * folder, |
36 | struct mailmessage_list ** result) | 43 | struct mailmessage_list ** result) |
37 | { | 44 | { |
38 | int r; | 45 | int r; |
39 | struct mailmessage_list * msg_list; | 46 | struct mailmessage_list * msg_list; |
40 | unsigned int i; | 47 | unsigned int i; |
41 | 48 | ||
42 | r = mailsession_get_messages_list(folder->fld_session, &msg_list); | 49 | r = mailsession_get_messages_list(folder->fld_session, &msg_list); |
43 | if (r != MAIL_NO_ERROR) | 50 | if (r != MAIL_NO_ERROR) |
44 | return r; | 51 | return r; |
45 | 52 | ||
46 | for(i = 0 ; i < carray_count(msg_list->msg_tab) ; i ++) { | 53 | for(i = 0 ; i < carray_count(msg_list->msg_tab) ; i ++) { |
47 | mailmessage * msg; | 54 | mailmessage * msg; |
48 | 55 | ||
49 | msg = carray_get(msg_list->msg_tab, i); | 56 | msg = carray_get(msg_list->msg_tab, i); |
50 | msg->msg_folder = folder; | 57 | msg->msg_folder = folder; |
diff --git a/kmicromail/libetpan/generic/mailfolder.h b/kmicromail/libetpan/generic/mailfolder.h index 3ecad23..ff53470 100644 --- a/kmicromail/libetpan/generic/mailfolder.h +++ b/kmicromail/libetpan/generic/mailfolder.h | |||
@@ -4,29 +4,32 @@ | |||
4 | 4 | ||
5 | #include "mailstorage_types.h" | 5 | #include "mailstorage_types.h" |
6 | 6 | ||
7 | int mailfolder_noop(struct mailfolder * folder); | 7 | int mailfolder_noop(struct mailfolder * folder); |
8 | 8 | ||
9 | int mailfolder_check(struct mailfolder * folder); | 9 | int mailfolder_check(struct mailfolder * folder); |
10 | 10 | ||
11 | int mailfolder_expunge(struct mailfolder * folder); | 11 | int mailfolder_expunge(struct mailfolder * folder); |
12 | 12 | ||
13 | int mailfolder_status(struct mailfolder * folder, | 13 | int mailfolder_status(struct mailfolder * folder, |
14 | uint32_t * result_messages, uint32_t * result_recent, | 14 | uint32_t * result_messages, uint32_t * result_recent, |
15 | uint32_t * result_unseen); | 15 | uint32_t * result_unseen); |
16 | 16 | ||
17 | int mailfolder_append_message(struct mailfolder * folder, | 17 | int mailfolder_append_message(struct mailfolder * folder, |
18 | char * message, size_t size); | 18 | char * message, size_t size); |
19 | 19 | ||
20 | int mailfolder_append_message_flags(struct mailfolder * folder, | ||
21 | char * message, size_t size, struct mail_flags * flags); | ||
22 | |||
20 | int mailfolder_get_messages_list(struct mailfolder * folder, | 23 | int mailfolder_get_messages_list(struct mailfolder * folder, |
21 | struct mailmessage_list ** result); | 24 | struct mailmessage_list ** result); |
22 | 25 | ||
23 | int mailfolder_get_envelopes_list(struct mailfolder * folder, | 26 | int mailfolder_get_envelopes_list(struct mailfolder * folder, |
24 | struct mailmessage_list * result); | 27 | struct mailmessage_list * result); |
25 | 28 | ||
26 | int mailfolder_get_message(struct mailfolder * folder, | 29 | int mailfolder_get_message(struct mailfolder * folder, |
27 | uint32_t num, mailmessage ** result); | 30 | uint32_t num, mailmessage ** result); |
28 | 31 | ||
29 | int mailfolder_get_message_by_uid(struct mailfolder * folder, | 32 | int mailfolder_get_message_by_uid(struct mailfolder * folder, |
30 | const char * uid, mailmessage ** result); | 33 | const char * uid, mailmessage ** result); |
31 | 34 | ||
32 | #endif | 35 | #endif |
diff --git a/kmicromail/libetpan/generic/mailstorage.c b/kmicromail/libetpan/generic/mailstorage.c index 25e561e..dc91744 100644 --- a/kmicromail/libetpan/generic/mailstorage.c +++ b/kmicromail/libetpan/generic/mailstorage.c | |||
@@ -310,25 +310,32 @@ void mailstorage_disconnect(struct mailstorage * storage) | |||
310 | while ((cur = clist_begin(storage->sto_shared_folders)) != NULL) { | 310 | while ((cur = clist_begin(storage->sto_shared_folders)) != NULL) { |
311 | struct mailfolder * folder; | 311 | struct mailfolder * folder; |
312 | 312 | ||
313 | folder = cur->data; | 313 | folder = cur->data; |
314 | mailfolder_disconnect(folder); | 314 | mailfolder_disconnect(folder); |
315 | } | 315 | } |
316 | 316 | ||
317 | if (storage->sto_session == NULL) | 317 | if (storage->sto_session == NULL) |
318 | return; | 318 | return; |
319 | 319 | ||
320 | r = mailsession_logout(storage->sto_session); | 320 | r = mailsession_logout(storage->sto_session); |
321 | 321 | ||
322 | mailsession_free(storage->sto_session); | 322 | mailsession_free(storage->sto_session); |
323 | storage->sto_session = NULL; | 323 | storage->sto_session = NULL; |
324 | } | 324 | } |
325 | 325 | ||
326 | |||
327 | int mailstorage_noop(struct mailstorage * storage) | ||
328 | { | ||
329 | return mailsession_noop(storage->sto_session); | ||
330 | } | ||
331 | |||
332 | |||
326 | static int mailstorage_get_folder(struct mailstorage * storage, | 333 | static int mailstorage_get_folder(struct mailstorage * storage, |
327 | char * pathname, mailsession ** result) | 334 | char * pathname, mailsession ** result) |
328 | { | 335 | { |
329 | if (storage->sto_driver->sto_get_folder_session == NULL) | 336 | if (storage->sto_driver->sto_get_folder_session == NULL) |
330 | return MAIL_ERROR_NOT_IMPLEMENTED; | 337 | return MAIL_ERROR_NOT_IMPLEMENTED; |
331 | 338 | ||
332 | return storage->sto_driver->sto_get_folder_session(storage, | 339 | return storage->sto_driver->sto_get_folder_session(storage, |
333 | pathname, result); | 340 | pathname, result); |
334 | } | 341 | } |
diff --git a/kmicromail/libetpan/generic/mailstorage.h b/kmicromail/libetpan/generic/mailstorage.h index d56aef1..4c57883 100644 --- a/kmicromail/libetpan/generic/mailstorage.h +++ b/kmicromail/libetpan/generic/mailstorage.h | |||
@@ -58,41 +58,42 @@ extern "C" { | |||
58 | 58 | ||
59 | @return The mail storage is returned. | 59 | @return The mail storage is returned. |
60 | */ | 60 | */ |
61 | 61 | ||
62 | struct mailstorage * mailstorage_new(char * sto_id); | 62 | struct mailstorage * mailstorage_new(char * sto_id); |
63 | 63 | ||
64 | void mailstorage_free(struct mailstorage * storage); | 64 | void mailstorage_free(struct mailstorage * storage); |
65 | 65 | ||
66 | /* | 66 | /* |
67 | session will be initialized on success. | 67 | session will be initialized on success. |
68 | */ | 68 | */ |
69 | 69 | ||
70 | int mailstorage_connect(struct mailstorage * storage); | 70 | int mailstorage_connect(struct mailstorage * storage); |
71 | 71 | ||
72 | void mailstorage_disconnect(struct mailstorage * storage); | 72 | void mailstorage_disconnect(struct mailstorage * storage); |
73 | 73 | ||
74 | int mailstorage_noop(struct mailstorage * storage); | ||
75 | |||
74 | 76 | ||
75 | /* folder */ | 77 | /* folder */ |
76 | 78 | ||
77 | struct mailfolder * mailfolder_new(struct mailstorage * fld_storage, | 79 | struct mailfolder * mailfolder_new(struct mailstorage * fld_storage, |
78 | char * fld_pathname, char * fld_virtual_name); | 80 | char * fld_pathname, char * fld_virtual_name); |
79 | 81 | ||
80 | void mailfolder_free(struct mailfolder * folder); | 82 | void mailfolder_free(struct mailfolder * folder); |
81 | 83 | ||
82 | int mailfolder_add_child(struct mailfolder * parent, | 84 | int mailfolder_add_child(struct mailfolder * parent, |
83 | struct mailfolder * child); | 85 | struct mailfolder * child); |
84 | 86 | ||
85 | int mailfolder_detach_parent(struct mailfolder * folder); | 87 | int mailfolder_detach_parent(struct mailfolder * folder); |
86 | 88 | ||
87 | int mailfolder_connect(struct mailfolder * folder); | 89 | int mailfolder_connect(struct mailfolder * folder); |
88 | 90 | ||
89 | void mailfolder_disconnect(struct mailfolder * folder); | 91 | void mailfolder_disconnect(struct mailfolder * folder); |
90 | 92 | ||
91 | |||
92 | #ifdef __cplusplus | 93 | #ifdef __cplusplus |
93 | } | 94 | } |
94 | #endif | 95 | #endif |
95 | 96 | ||
96 | #endif | 97 | #endif |
97 | 98 | ||
98 | 99 | ||
diff --git a/kmicromail/libetpan/generic/mboxdriver.c b/kmicromail/libetpan/generic/mboxdriver.c index fa3e2ea..c19a668 100644 --- a/kmicromail/libetpan/generic/mboxdriver.c +++ b/kmicromail/libetpan/generic/mboxdriver.c | |||
@@ -64,32 +64,35 @@ static int mboxdriver_parameters(mailsession * session, | |||
64 | static int mboxdriver_connect_path(mailsession * session, char * path); | 64 | static int mboxdriver_connect_path(mailsession * session, char * path); |
65 | 65 | ||
66 | static int mboxdriver_logout(mailsession * session); | 66 | static int mboxdriver_logout(mailsession * session); |
67 | 67 | ||
68 | static int mboxdriver_expunge_folder(mailsession * session); | 68 | static int mboxdriver_expunge_folder(mailsession * session); |
69 | 69 | ||
70 | static int mboxdriver_status_folder(mailsession * session, char * mb, | 70 | static int mboxdriver_status_folder(mailsession * session, char * mb, |
71 | uint32_t * result_messages, uint32_t * result_recent, | 71 | uint32_t * result_messages, uint32_t * result_recent, |
72 | uint32_t * result_unseen); | 72 | uint32_t * result_unseen); |
73 | 73 | ||
74 | static int mboxdriver_messages_number(mailsession * session, char * mb, | 74 | static int mboxdriver_messages_number(mailsession * session, char * mb, |
75 | uint32_t * result); | 75 | uint32_t * result); |
76 | 76 | ||
77 | static int mboxdriver_append_message(mailsession * session, | 77 | static int mboxdriver_append_message(mailsession * session, |
78 | char * message, size_t size); | 78 | char * message, size_t size); |
79 | 79 | ||
80 | static int mboxdriver_append_message_flags(mailsession * session, | ||
81 | char * message, size_t size, struct mail_flags * flags); | ||
82 | |||
80 | static int mboxdriver_get_messages_list(mailsession * session, | 83 | static int mboxdriver_get_messages_list(mailsession * session, |
81 | struct mailmessage_list ** result); | 84 | struct mailmessage_list ** result); |
82 | 85 | ||
83 | static int | 86 | static int |
84 | mboxdriver_get_envelopes_list(mailsession * session, | 87 | mboxdriver_get_envelopes_list(mailsession * session, |
85 | struct mailmessage_list * env_list); | 88 | struct mailmessage_list * env_list); |
86 | 89 | ||
87 | static int mboxdriver_remove_message(mailsession * session, uint32_t num); | 90 | static int mboxdriver_remove_message(mailsession * session, uint32_t num); |
88 | 91 | ||
89 | static int mboxdriver_get_message(mailsession * session, | 92 | static int mboxdriver_get_message(mailsession * session, |
90 | uint32_t num, mailmessage ** result); | 93 | uint32_t num, mailmessage ** result); |
91 | 94 | ||
92 | static int mboxdriver_get_message_by_uid(mailsession * session, | 95 | static int mboxdriver_get_message_by_uid(mailsession * session, |
93 | const char * uid, | 96 | const char * uid, |
94 | mailmessage ** result); | 97 | mailmessage ** result); |
95 | 98 | ||
@@ -113,32 +116,33 @@ static mailsession_driver local_mbox_session_driver = { | |||
113 | .sess_delete_folder = NULL, | 116 | .sess_delete_folder = NULL, |
114 | .sess_rename_folder = NULL, | 117 | .sess_rename_folder = NULL, |
115 | .sess_check_folder = NULL, | 118 | .sess_check_folder = NULL, |
116 | .sess_examine_folder = NULL, | 119 | .sess_examine_folder = NULL, |
117 | .sess_select_folder = NULL, | 120 | .sess_select_folder = NULL, |
118 | .sess_expunge_folder = mboxdriver_expunge_folder, | 121 | .sess_expunge_folder = mboxdriver_expunge_folder, |
119 | .sess_status_folder = mboxdriver_status_folder, | 122 | .sess_status_folder = mboxdriver_status_folder, |
120 | .sess_messages_number = mboxdriver_messages_number, | 123 | .sess_messages_number = mboxdriver_messages_number, |
121 | .sess_recent_number = mboxdriver_messages_number, | 124 | .sess_recent_number = mboxdriver_messages_number, |
122 | .sess_unseen_number = mboxdriver_messages_number, | 125 | .sess_unseen_number = mboxdriver_messages_number, |
123 | .sess_list_folders = NULL, | 126 | .sess_list_folders = NULL, |
124 | .sess_lsub_folders = NULL, | 127 | .sess_lsub_folders = NULL, |
125 | .sess_subscribe_folder = NULL, | 128 | .sess_subscribe_folder = NULL, |
126 | .sess_unsubscribe_folder = NULL, | 129 | .sess_unsubscribe_folder = NULL, |
127 | 130 | ||
128 | .sess_append_message = mboxdriver_append_message, | 131 | .sess_append_message = mboxdriver_append_message, |
132 | .sess_append_message_flags = mboxdriver_append_message_flags, | ||
129 | .sess_copy_message = NULL, | 133 | .sess_copy_message = NULL, |
130 | .sess_move_message = NULL, | 134 | .sess_move_message = NULL, |
131 | 135 | ||
132 | .sess_get_messages_list = mboxdriver_get_messages_list, | 136 | .sess_get_messages_list = mboxdriver_get_messages_list, |
133 | .sess_get_envelopes_list = mboxdriver_get_envelopes_list, | 137 | .sess_get_envelopes_list = mboxdriver_get_envelopes_list, |
134 | .sess_remove_message = mboxdriver_remove_message, | 138 | .sess_remove_message = mboxdriver_remove_message, |
135 | #if 0 | 139 | #if 0 |
136 | .sess_search_messages = maildriver_generic_search_messages, | 140 | .sess_search_messages = maildriver_generic_search_messages, |
137 | #endif | 141 | #endif |
138 | 142 | ||
139 | .sess_get_message = mboxdriver_get_message, | 143 | .sess_get_message = mboxdriver_get_message, |
140 | .sess_get_message_by_uid = mboxdriver_get_message_by_uid, | 144 | .sess_get_message_by_uid = mboxdriver_get_message_by_uid, |
141 | }; | 145 | }; |
142 | 146 | ||
143 | mailsession_driver * mbox_session_driver = &local_mbox_session_driver; | 147 | mailsession_driver * mbox_session_driver = &local_mbox_session_driver; |
144 | 148 | ||
@@ -331,32 +335,38 @@ static int mboxdriver_append_message(mailsession * session, | |||
331 | struct mailmbox_folder * folder; | 335 | struct mailmbox_folder * folder; |
332 | 336 | ||
333 | folder = get_mbox_session(session); | 337 | folder = get_mbox_session(session); |
334 | if (folder == NULL) | 338 | if (folder == NULL) |
335 | return MAIL_ERROR_APPEND; | 339 | return MAIL_ERROR_APPEND; |
336 | 340 | ||
337 | r = mailmbox_append_message(folder, message, size); | 341 | r = mailmbox_append_message(folder, message, size); |
338 | 342 | ||
339 | switch (r) { | 343 | switch (r) { |
340 | case MAILMBOX_ERROR_FILE: | 344 | case MAILMBOX_ERROR_FILE: |
341 | return MAIL_ERROR_DISKSPACE; | 345 | return MAIL_ERROR_DISKSPACE; |
342 | default: | 346 | default: |
343 | return mboxdriver_mbox_error_to_mail_error(r); | 347 | return mboxdriver_mbox_error_to_mail_error(r); |
344 | } | 348 | } |
345 | } | 349 | } |
346 | 350 | ||
351 | static int mboxdriver_append_message_flags(mailsession * session, | ||
352 | char * message, size_t size, struct mail_flags * flags) | ||
353 | { | ||
354 | return mboxdriver_append_message(session, message, size); | ||
355 | } | ||
356 | |||
347 | static int mboxdriver_get_messages_list(mailsession * session, | 357 | static int mboxdriver_get_messages_list(mailsession * session, |
348 | struct mailmessage_list ** result) | 358 | struct mailmessage_list ** result) |
349 | { | 359 | { |
350 | struct mailmbox_folder * folder; | 360 | struct mailmbox_folder * folder; |
351 | int res; | 361 | int res; |
352 | 362 | ||
353 | folder = get_mbox_session(session); | 363 | folder = get_mbox_session(session); |
354 | if (folder == NULL) { | 364 | if (folder == NULL) { |
355 | res = MAIL_ERROR_BAD_STATE; | 365 | res = MAIL_ERROR_BAD_STATE; |
356 | goto err; | 366 | goto err; |
357 | } | 367 | } |
358 | 368 | ||
359 | return mbox_get_messages_list(folder, session, mbox_message_driver, result); | 369 | return mbox_get_messages_list(folder, session, mbox_message_driver, result); |
360 | 370 | ||
361 | err: | 371 | err: |
362 | return res; | 372 | return res; |
diff --git a/kmicromail/libetpan/generic/mboxdriver_cached.c b/kmicromail/libetpan/generic/mboxdriver_cached.c index 07871fa..3af7fb9 100644 --- a/kmicromail/libetpan/generic/mboxdriver_cached.c +++ b/kmicromail/libetpan/generic/mboxdriver_cached.c | |||
@@ -73,32 +73,35 @@ static int mboxdriver_cached_check_folder(mailsession * session); | |||
73 | 73 | ||
74 | static int mboxdriver_cached_expunge_folder(mailsession * session); | 74 | static int mboxdriver_cached_expunge_folder(mailsession * session); |
75 | 75 | ||
76 | static int mboxdriver_cached_status_folder(mailsession * session, char * mb, | 76 | static int mboxdriver_cached_status_folder(mailsession * session, char * mb, |
77 | uint32_t * result_messages, uint32_t * result_recent, | 77 | uint32_t * result_messages, uint32_t * result_recent, |
78 | uint32_t * result_unseen); | 78 | uint32_t * result_unseen); |
79 | static int mboxdriver_cached_messages_number(mailsession * session, char * mb, | 79 | static int mboxdriver_cached_messages_number(mailsession * session, char * mb, |
80 | uint32_t * result); | 80 | uint32_t * result); |
81 | static int mboxdriver_cached_recent_number(mailsession * session, char * mb, | 81 | static int mboxdriver_cached_recent_number(mailsession * session, char * mb, |
82 | uint32_t * result); | 82 | uint32_t * result); |
83 | static int mboxdriver_cached_unseen_number(mailsession * session, char * mb, | 83 | static int mboxdriver_cached_unseen_number(mailsession * session, char * mb, |
84 | uint32_t * result); | 84 | uint32_t * result); |
85 | 85 | ||
86 | static int mboxdriver_cached_append_message(mailsession * session, | 86 | static int mboxdriver_cached_append_message(mailsession * session, |
87 | char * message, size_t size); | 87 | char * message, size_t size); |
88 | 88 | ||
89 | static int mboxdriver_cached_append_message_flags(mailsession * session, | ||
90 | char * message, size_t size, struct mail_flags * flags); | ||
91 | |||
89 | static int | 92 | static int |
90 | mboxdriver_cached_get_messages_list(mailsession * session, | 93 | mboxdriver_cached_get_messages_list(mailsession * session, |
91 | struct mailmessage_list ** result); | 94 | struct mailmessage_list ** result); |
92 | 95 | ||
93 | static int | 96 | static int |
94 | mboxdriver_cached_get_envelopes_list(mailsession * session, | 97 | mboxdriver_cached_get_envelopes_list(mailsession * session, |
95 | struct mailmessage_list * env_list); | 98 | struct mailmessage_list * env_list); |
96 | 99 | ||
97 | static int mboxdriver_cached_remove_message(mailsession * session, | 100 | static int mboxdriver_cached_remove_message(mailsession * session, |
98 | uint32_t num); | 101 | uint32_t num); |
99 | 102 | ||
100 | static int mboxdriver_cached_get_message(mailsession * session, | 103 | static int mboxdriver_cached_get_message(mailsession * session, |
101 | uint32_t num, mailmessage ** result); | 104 | uint32_t num, mailmessage ** result); |
102 | 105 | ||
103 | static int mboxdriver_cached_get_message_by_uid(mailsession * session, | 106 | static int mboxdriver_cached_get_message_by_uid(mailsession * session, |
104 | const char * uid, | 107 | const char * uid, |
@@ -124,32 +127,34 @@ static mailsession_driver local_mbox_cached_session_driver = { | |||
124 | .sess_delete_folder = NULL, | 127 | .sess_delete_folder = NULL, |
125 | .sess_rename_folder = NULL, | 128 | .sess_rename_folder = NULL, |
126 | .sess_check_folder = mboxdriver_cached_check_folder, | 129 | .sess_check_folder = mboxdriver_cached_check_folder, |
127 | .sess_examine_folder = NULL, | 130 | .sess_examine_folder = NULL, |
128 | .sess_select_folder = NULL, | 131 | .sess_select_folder = NULL, |
129 | .sess_expunge_folder = mboxdriver_cached_expunge_folder, | 132 | .sess_expunge_folder = mboxdriver_cached_expunge_folder, |
130 | .sess_status_folder = mboxdriver_cached_status_folder, | 133 | .sess_status_folder = mboxdriver_cached_status_folder, |
131 | .sess_messages_number = mboxdriver_cached_messages_number, | 134 | .sess_messages_number = mboxdriver_cached_messages_number, |
132 | .sess_recent_number = mboxdriver_cached_recent_number, | 135 | .sess_recent_number = mboxdriver_cached_recent_number, |
133 | .sess_unseen_number = mboxdriver_cached_unseen_number, | 136 | .sess_unseen_number = mboxdriver_cached_unseen_number, |
134 | .sess_list_folders = NULL, | 137 | .sess_list_folders = NULL, |
135 | .sess_lsub_folders = NULL, | 138 | .sess_lsub_folders = NULL, |
136 | .sess_subscribe_folder = NULL, | 139 | .sess_subscribe_folder = NULL, |
137 | .sess_unsubscribe_folder = NULL, | 140 | .sess_unsubscribe_folder = NULL, |
138 | 141 | ||
139 | .sess_append_message = mboxdriver_cached_append_message, | 142 | .sess_append_message = mboxdriver_cached_append_message, |
143 | .sess_append_message_flags = mboxdriver_cached_append_message_flags, | ||
144 | |||
140 | .sess_copy_message = NULL, | 145 | .sess_copy_message = NULL, |
141 | .sess_move_message = NULL, | 146 | .sess_move_message = NULL, |
142 | 147 | ||
143 | .sess_get_messages_list = mboxdriver_cached_get_messages_list, | 148 | .sess_get_messages_list = mboxdriver_cached_get_messages_list, |
144 | .sess_get_envelopes_list = mboxdriver_cached_get_envelopes_list, | 149 | .sess_get_envelopes_list = mboxdriver_cached_get_envelopes_list, |
145 | .sess_remove_message = mboxdriver_cached_remove_message, | 150 | .sess_remove_message = mboxdriver_cached_remove_message, |
146 | #if 0 | 151 | #if 0 |
147 | .sess_search_messages = maildriver_generic_search_messages, | 152 | .sess_search_messages = maildriver_generic_search_messages, |
148 | #endif | 153 | #endif |
149 | 154 | ||
150 | .sess_get_message = mboxdriver_cached_get_message, | 155 | .sess_get_message = mboxdriver_cached_get_message, |
151 | .sess_get_message_by_uid = mboxdriver_cached_get_message_by_uid, | 156 | .sess_get_message_by_uid = mboxdriver_cached_get_message_by_uid, |
152 | }; | 157 | }; |
153 | 158 | ||
154 | mailsession_driver * mbox_cached_session_driver = | 159 | mailsession_driver * mbox_cached_session_driver = |
155 | &local_mbox_cached_session_driver; | 160 | &local_mbox_cached_session_driver; |
@@ -893,33 +898,110 @@ static int mboxdriver_cached_unseen_number(mailsession * session, char * mb, | |||
893 | 898 | ||
894 | r = mboxdriver_cached_status_folder(session, mb, | 899 | r = mboxdriver_cached_status_folder(session, mb, |
895 | &messages, &recent, &unseen); | 900 | &messages, &recent, &unseen); |
896 | if (r != MAIL_NO_ERROR) | 901 | if (r != MAIL_NO_ERROR) |
897 | return r; | 902 | return r; |
898 | 903 | ||
899 | * result = unseen; | 904 | * result = unseen; |
900 | 905 | ||
901 | return MAIL_NO_ERROR; | 906 | return MAIL_NO_ERROR; |
902 | } | 907 | } |
903 | 908 | ||
904 | /* messages operations */ | 909 | /* messages operations */ |
905 | 910 | ||
906 | static int mboxdriver_cached_append_message(mailsession * session, | 911 | static int mboxdriver_cached_append_message(mailsession * session, |
907 | char * message, size_t size) | 912 | char * message, size_t size) |
908 | { | 913 | { |
909 | return mailsession_append_message(get_ancestor(session), message, size); | 914 | return mboxdriver_cached_append_message_flags(session, |
915 | message, size, NULL); | ||
916 | } | ||
917 | |||
918 | static int mboxdriver_cached_append_message_flags(mailsession * session, | ||
919 | char * message, size_t size, struct mail_flags * flags) | ||
920 | { | ||
921 | int r; | ||
922 | struct mailmbox_folder * folder; | ||
923 | struct mbox_cached_session_state_data * data; | ||
924 | unsigned int uid; | ||
925 | struct mailmbox_msg_info * msg_info; | ||
926 | chashdatum key; | ||
927 | chashdatum value; | ||
928 | struct mail_cache_db * cache_db_flags; | ||
929 | char filename_flags[PATH_MAX]; | ||
930 | MMAPString * mmapstr; | ||
931 | char keyname[PATH_MAX]; | ||
932 | |||
933 | folder = get_mbox_session(session); | ||
934 | if (folder == NULL) | ||
935 | return MAIL_ERROR_APPEND; | ||
936 | |||
937 | r = mailmbox_append_message_uid(folder, message, size, &uid); | ||
938 | |||
939 | switch (r) { | ||
940 | case MAILMBOX_ERROR_FILE: | ||
941 | return MAIL_ERROR_DISKSPACE; | ||
942 | case MAILMBOX_NO_ERROR: | ||
943 | break; | ||
944 | default: | ||
945 | return mboxdriver_mbox_error_to_mail_error(r); | ||
946 | } | ||
947 | |||
948 | /* could store in flags store instead */ | ||
949 | |||
950 | if (flags == NULL) | ||
951 | goto exit; | ||
952 | |||
953 | key.data = &uid; | ||
954 | key.len = sizeof(uid); | ||
955 | r = chash_get(folder->mb_hash, &key, &value); | ||
956 | if (r < 0) | ||
957 | goto exit; | ||
958 | |||
959 | msg_info = value.data; | ||
960 | |||
961 | data = get_cached_data(session); | ||
962 | |||
963 | snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", | ||
964 | data->mbox_flags_directory, MAIL_DIR_SEPARATOR, data->mbox_quoted_mb, | ||
965 | MAIL_DIR_SEPARATOR, FLAGS_NAME); | ||
966 | |||
967 | r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); | ||
968 | if (r < 0) | ||
969 | goto exit; | ||
970 | |||
971 | mmapstr = mmap_string_new(""); | ||
972 | if (mmapstr == NULL) | ||
973 | goto close_db_flags; | ||
974 | |||
975 | snprintf(keyname, PATH_MAX, "%u-%lu", uid, | ||
976 | (unsigned long) msg_info->msg_body_len); | ||
977 | |||
978 | r = mboxdriver_write_cached_flags(cache_db_flags, mmapstr, keyname, flags); | ||
979 | |||
980 | mmap_string_free(mmapstr); | ||
981 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
982 | |||
983 | if (r != MAIL_NO_ERROR) | ||
984 | goto exit; | ||
985 | |||
986 | return MAIL_NO_ERROR; | ||
987 | |||
988 | close_db_flags: | ||
989 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
990 | exit: | ||
991 | return MAIL_NO_ERROR; | ||
910 | } | 992 | } |
911 | 993 | ||
912 | static int | 994 | static int |
913 | mboxdriver_cached_get_messages_list(mailsession * session, | 995 | mboxdriver_cached_get_messages_list(mailsession * session, |
914 | struct mailmessage_list ** result) | 996 | struct mailmessage_list ** result) |
915 | { | 997 | { |
916 | struct mailmbox_folder * folder; | 998 | struct mailmbox_folder * folder; |
917 | int res; | 999 | int res; |
918 | 1000 | ||
919 | folder = get_mbox_session(session); | 1001 | folder = get_mbox_session(session); |
920 | if (folder == NULL) { | 1002 | if (folder == NULL) { |
921 | res = MAIL_ERROR_BAD_STATE; | 1003 | res = MAIL_ERROR_BAD_STATE; |
922 | goto err; | 1004 | goto err; |
923 | } | 1005 | } |
924 | 1006 | ||
925 | return mbox_get_uid_messages_list(folder, | 1007 | return mbox_get_uid_messages_list(folder, |
@@ -947,33 +1029,34 @@ get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | |||
947 | if (folder == NULL) { | 1029 | if (folder == NULL) { |
948 | res = MAIL_ERROR_BAD_STATE; | 1030 | res = MAIL_ERROR_BAD_STATE; |
949 | goto err; | 1031 | goto err; |
950 | } | 1032 | } |
951 | 1033 | ||
952 | key.data = # | 1034 | key.data = # |
953 | key.len = sizeof(num); | 1035 | key.len = sizeof(num); |
954 | 1036 | ||
955 | r = chash_get(folder->mb_hash, &key, &data); | 1037 | r = chash_get(folder->mb_hash, &key, &data); |
956 | if (r < 0) { | 1038 | if (r < 0) { |
957 | res = MAIL_ERROR_MSG_NOT_FOUND; | 1039 | res = MAIL_ERROR_MSG_NOT_FOUND; |
958 | goto err; | 1040 | goto err; |
959 | } | 1041 | } |
960 | 1042 | ||
961 | info = data.data; | 1043 | info = data.data; |
962 | 1044 | ||
963 | snprintf(keyname, PATH_MAX, "%u-%u-envelope", num, info->msg_body_len); | 1045 | snprintf(keyname, PATH_MAX, "%u-%lu-envelope", num, |
1046 | (unsigned long) info->msg_body_len); | ||
964 | 1047 | ||
965 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); | 1048 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); |
966 | if (r != MAIL_NO_ERROR) { | 1049 | if (r != MAIL_NO_ERROR) { |
967 | res = r; | 1050 | res = r; |
968 | goto err; | 1051 | goto err; |
969 | } | 1052 | } |
970 | 1053 | ||
971 | * result = fields; | 1054 | * result = fields; |
972 | 1055 | ||
973 | return MAIL_NO_ERROR; | 1056 | return MAIL_NO_ERROR; |
974 | 1057 | ||
975 | err: | 1058 | err: |
976 | return res; | 1059 | return res; |
977 | } | 1060 | } |
978 | 1061 | ||
979 | static int | 1062 | static int |
@@ -993,33 +1076,34 @@ write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | |||
993 | if (folder == NULL) { | 1076 | if (folder == NULL) { |
994 | res = MAIL_ERROR_BAD_STATE; | 1077 | res = MAIL_ERROR_BAD_STATE; |
995 | goto err; | 1078 | goto err; |
996 | } | 1079 | } |
997 | 1080 | ||
998 | key.data = # | 1081 | key.data = # |
999 | key.len = sizeof(num); | 1082 | key.len = sizeof(num); |
1000 | 1083 | ||
1001 | r = chash_get(folder->mb_hash, &key, &data); | 1084 | r = chash_get(folder->mb_hash, &key, &data); |
1002 | if (r < 0) { | 1085 | if (r < 0) { |
1003 | res = MAIL_ERROR_MSG_NOT_FOUND; | 1086 | res = MAIL_ERROR_MSG_NOT_FOUND; |
1004 | goto err; | 1087 | goto err; |
1005 | } | 1088 | } |
1006 | 1089 | ||
1007 | info = data.data; | 1090 | info = data.data; |
1008 | 1091 | ||
1009 | snprintf(keyname, PATH_MAX, "%u-%u-envelope", num, info->msg_body_len); | 1092 | snprintf(keyname, PATH_MAX, "%u-%lu-envelope", num, |
1093 | (unsigned long) info->msg_body_len); | ||
1010 | 1094 | ||
1011 | r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields); | 1095 | r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields); |
1012 | if (r != MAIL_NO_ERROR) { | 1096 | if (r != MAIL_NO_ERROR) { |
1013 | res = r; | 1097 | res = r; |
1014 | goto err; | 1098 | goto err; |
1015 | } | 1099 | } |
1016 | 1100 | ||
1017 | return MAIL_NO_ERROR; | 1101 | return MAIL_NO_ERROR; |
1018 | 1102 | ||
1019 | err: | 1103 | err: |
1020 | return res; | 1104 | return res; |
1021 | } | 1105 | } |
1022 | 1106 | ||
1023 | static int | 1107 | static int |
1024 | mboxdriver_cached_get_envelopes_list(mailsession * session, | 1108 | mboxdriver_cached_get_envelopes_list(mailsession * session, |
1025 | struct mailmessage_list * env_list) | 1109 | struct mailmessage_list * env_list) |
diff --git a/kmicromail/libetpan/generic/mboxdriver_cached_message.c b/kmicromail/libetpan/generic/mboxdriver_cached_message.c index 6d92b22..828396b 100644 --- a/kmicromail/libetpan/generic/mboxdriver_cached_message.c +++ b/kmicromail/libetpan/generic/mboxdriver_cached_message.c | |||
@@ -169,33 +169,34 @@ static int mbox_initialize(mailmessage * msg_info) | |||
169 | if (folder == NULL) { | 169 | if (folder == NULL) { |
170 | res = MAIL_ERROR_BAD_STATE; | 170 | res = MAIL_ERROR_BAD_STATE; |
171 | goto err; | 171 | goto err; |
172 | } | 172 | } |
173 | 173 | ||
174 | key.data = (char *) &msg_info->msg_index; | 174 | key.data = (char *) &msg_info->msg_index; |
175 | key.len = sizeof(msg_info->msg_index); | 175 | key.len = sizeof(msg_info->msg_index); |
176 | 176 | ||
177 | r = chash_get(folder->mb_hash, &key, &data); | 177 | r = chash_get(folder->mb_hash, &key, &data); |
178 | if (r < 0) { | 178 | if (r < 0) { |
179 | res = MAIL_ERROR_MSG_NOT_FOUND; | 179 | res = MAIL_ERROR_MSG_NOT_FOUND; |
180 | goto err; | 180 | goto err; |
181 | } | 181 | } |
182 | 182 | ||
183 | info = (struct mailmbox_msg_info *) data.data; | 183 | info = (struct mailmbox_msg_info *) data.data; |
184 | 184 | ||
185 | snprintf(static_uid, PATH_MAX, "%u-%u", msg_info->msg_index, info->msg_body_len); | 185 | snprintf(static_uid, PATH_MAX, "%u-%lu", |
186 | msg_info->msg_index, (unsigned long) info->msg_body_len); | ||
186 | uid = strdup(static_uid); | 187 | uid = strdup(static_uid); |
187 | if (uid == NULL) { | 188 | if (uid == NULL) { |
188 | res = MAIL_ERROR_MEMORY; | 189 | res = MAIL_ERROR_MEMORY; |
189 | goto err; | 190 | goto err; |
190 | } | 191 | } |
191 | 192 | ||
192 | r = mailmessage_generic_initialize(msg_info); | 193 | r = mailmessage_generic_initialize(msg_info); |
193 | if (r != MAIL_NO_ERROR) { | 194 | if (r != MAIL_NO_ERROR) { |
194 | free(uid); | 195 | free(uid); |
195 | res = r; | 196 | res = r; |
196 | goto err; | 197 | goto err; |
197 | } | 198 | } |
198 | 199 | ||
199 | msg = msg_info->msg_data; | 200 | msg = msg_info->msg_data; |
200 | 201 | ||
201 | msg->msg_prefetch = mbox_prefetch; | 202 | msg->msg_prefetch = mbox_prefetch; |
diff --git a/kmicromail/libetpan/generic/mboxdriver_message.c b/kmicromail/libetpan/generic/mboxdriver_message.c index da9a65d..6922625 100644 --- a/kmicromail/libetpan/generic/mboxdriver_message.c +++ b/kmicromail/libetpan/generic/mboxdriver_message.c | |||
@@ -20,33 +20,33 @@ | |||
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "mhdriver_message.h" | 36 | #include "mboxdriver_message.h" |
37 | 37 | ||
38 | #include "mailmessage_tools.h" | 38 | #include "mailmessage_tools.h" |
39 | #include "mboxdriver_tools.h" | 39 | #include "mboxdriver_tools.h" |
40 | #include "mboxdriver.h" | 40 | #include "mboxdriver.h" |
41 | #include "mailmbox.h" | 41 | #include "mailmbox.h" |
42 | 42 | ||
43 | #include <unistd.h> | 43 | #include <unistd.h> |
44 | #include <sys/mman.h> | 44 | #include <sys/mman.h> |
45 | #include <sys/types.h> | 45 | #include <sys/types.h> |
46 | #include <sys/stat.h> | 46 | #include <sys/stat.h> |
47 | #include <fcntl.h> | 47 | #include <fcntl.h> |
48 | #include <string.h> | 48 | #include <string.h> |
49 | #include <stdlib.h> | 49 | #include <stdlib.h> |
50 | 50 | ||
51 | static int mbox_prefetch(mailmessage * msg_info); | 51 | static int mbox_prefetch(mailmessage * msg_info); |
52 | 52 | ||
@@ -143,34 +143,34 @@ static int mbox_initialize(mailmessage * msg_info) | |||
143 | if (folder == NULL) { | 143 | if (folder == NULL) { |
144 | res = MAIL_ERROR_BAD_STATE; | 144 | res = MAIL_ERROR_BAD_STATE; |
145 | goto err; | 145 | goto err; |
146 | } | 146 | } |
147 | 147 | ||
148 | key.data = &msg_info->msg_index; | 148 | key.data = &msg_info->msg_index; |
149 | key.len = sizeof(msg_info->msg_index); | 149 | key.len = sizeof(msg_info->msg_index); |
150 | 150 | ||
151 | r = chash_get(folder->mb_hash, &key, &data); | 151 | r = chash_get(folder->mb_hash, &key, &data); |
152 | if (r < 0) { | 152 | if (r < 0) { |
153 | res = MAIL_ERROR_MSG_NOT_FOUND; | 153 | res = MAIL_ERROR_MSG_NOT_FOUND; |
154 | goto err; | 154 | goto err; |
155 | } | 155 | } |
156 | 156 | ||
157 | info = data.data; | 157 | info = data.data; |
158 | 158 | ||
159 | snprintf(static_uid, PATH_MAX, "%u-%u", | 159 | snprintf(static_uid, PATH_MAX, "%u-%lu", |
160 | msg_info->msg_index, info->msg_body_len); | 160 | msg_info->msg_index, (unsigned long) info->msg_body_len); |
161 | uid = strdup(static_uid); | 161 | uid = strdup(static_uid); |
162 | if (uid == NULL) { | 162 | if (uid == NULL) { |
163 | res = MAIL_ERROR_MEMORY; | 163 | res = MAIL_ERROR_MEMORY; |
164 | goto err; | 164 | goto err; |
165 | } | 165 | } |
166 | 166 | ||
167 | r = mailmessage_generic_initialize(msg_info); | 167 | r = mailmessage_generic_initialize(msg_info); |
168 | if (r != MAIL_NO_ERROR) { | 168 | if (r != MAIL_NO_ERROR) { |
169 | free(uid); | 169 | free(uid); |
170 | res = r; | 170 | res = r; |
171 | goto err; | 171 | goto err; |
172 | } | 172 | } |
173 | 173 | ||
174 | msg = msg_info->msg_data; | 174 | msg = msg_info->msg_data; |
175 | msg->msg_prefetch = mbox_prefetch; | 175 | msg->msg_prefetch = mbox_prefetch; |
176 | msg->msg_prefetch_free = mbox_prefetch_free; | 176 | msg->msg_prefetch_free = mbox_prefetch_free; |
diff --git a/kmicromail/libetpan/generic/mboxdriver_tools.c b/kmicromail/libetpan/generic/mboxdriver_tools.c index 1e27798..252a20b 100644 --- a/kmicromail/libetpan/generic/mboxdriver_tools.c +++ b/kmicromail/libetpan/generic/mboxdriver_tools.c | |||
@@ -204,33 +204,34 @@ mboxdriver_get_cached_flags(struct mail_cache_db * cache_db, | |||
204 | if (folder == NULL) { | 204 | if (folder == NULL) { |
205 | res = MAIL_ERROR_BAD_STATE; | 205 | res = MAIL_ERROR_BAD_STATE; |
206 | goto err; | 206 | goto err; |
207 | } | 207 | } |
208 | 208 | ||
209 | key.data = # | 209 | key.data = # |
210 | key.len = sizeof(num); | 210 | key.len = sizeof(num); |
211 | 211 | ||
212 | r = chash_get(folder->mb_hash, &key, &data); | 212 | r = chash_get(folder->mb_hash, &key, &data); |
213 | if (r < 0) { | 213 | if (r < 0) { |
214 | res = MAIL_ERROR_MSG_NOT_FOUND; | 214 | res = MAIL_ERROR_MSG_NOT_FOUND; |
215 | goto err; | 215 | goto err; |
216 | } | 216 | } |
217 | 217 | ||
218 | info = data.data; | 218 | info = data.data; |
219 | 219 | ||
220 | snprintf(keyname, PATH_MAX, "%u-%u-flags", num, info->msg_body_len); | 220 | snprintf(keyname, PATH_MAX, "%u-%lu-flags", num, |
221 | (unsigned long) info->msg_body_len); | ||
221 | 222 | ||
222 | r = generic_cache_flags_read(cache_db, mmapstr, keyname, &flags); | 223 | r = generic_cache_flags_read(cache_db, mmapstr, keyname, &flags); |
223 | if (r != MAIL_NO_ERROR) { | 224 | if (r != MAIL_NO_ERROR) { |
224 | res = r; | 225 | res = r; |
225 | goto err; | 226 | goto err; |
226 | } | 227 | } |
227 | 228 | ||
228 | * result = flags; | 229 | * result = flags; |
229 | 230 | ||
230 | return MAIL_NO_ERROR; | 231 | return MAIL_NO_ERROR; |
231 | 232 | ||
232 | err: | 233 | err: |
233 | return res; | 234 | return res; |
234 | } | 235 | } |
235 | 236 | ||
236 | int | 237 | int |
diff --git a/kmicromail/libetpan/generic/mboxstorage.c b/kmicromail/libetpan/generic/mboxstorage.c index 0a7dc93..4b55b2b 100644 --- a/kmicromail/libetpan/generic/mboxstorage.c +++ b/kmicromail/libetpan/generic/mboxstorage.c | |||
@@ -52,33 +52,33 @@ mbox_mailstorage_get_folder_session(struct mailstorage * storage, | |||
52 | char * pathname, mailsession ** result); | 52 | char * pathname, mailsession ** result); |
53 | static void mbox_mailstorage_uninitialize(struct mailstorage * storage); | 53 | static void mbox_mailstorage_uninitialize(struct mailstorage * storage); |
54 | 54 | ||
55 | static mailstorage_driver mbox_mailstorage_driver = { | 55 | static mailstorage_driver mbox_mailstorage_driver = { |
56 | .sto_name = "mbox", | 56 | .sto_name = "mbox", |
57 | .sto_connect = mbox_mailstorage_connect, | 57 | .sto_connect = mbox_mailstorage_connect, |
58 | .sto_get_folder_session = mbox_mailstorage_get_folder_session, | 58 | .sto_get_folder_session = mbox_mailstorage_get_folder_session, |
59 | .sto_uninitialize = mbox_mailstorage_uninitialize, | 59 | .sto_uninitialize = mbox_mailstorage_uninitialize, |
60 | }; | 60 | }; |
61 | 61 | ||
62 | int mbox_mailstorage_init(struct mailstorage * storage, | 62 | int mbox_mailstorage_init(struct mailstorage * storage, |
63 | char * mbox_pathname, int mbox_cached, | 63 | char * mbox_pathname, int mbox_cached, |
64 | char * mbox_cache_directory, char * mbox_flags_directory) | 64 | char * mbox_cache_directory, char * mbox_flags_directory) |
65 | { | 65 | { |
66 | struct mbox_mailstorage * mbox_storage; | 66 | struct mbox_mailstorage * mbox_storage; |
67 | 67 | ||
68 | mbox_storage = malloc(sizeof(struct mbox_mailstorage)); | 68 | mbox_storage = malloc(sizeof(* mbox_storage)); |
69 | if (mbox_storage == NULL) | 69 | if (mbox_storage == NULL) |
70 | goto err; | 70 | goto err; |
71 | 71 | ||
72 | mbox_storage->mbox_pathname = strdup(mbox_pathname); | 72 | mbox_storage->mbox_pathname = strdup(mbox_pathname); |
73 | if (mbox_storage->mbox_pathname == NULL) | 73 | if (mbox_storage->mbox_pathname == NULL) |
74 | goto free; | 74 | goto free; |
75 | 75 | ||
76 | mbox_storage->mbox_cached = mbox_cached; | 76 | mbox_storage->mbox_cached = mbox_cached; |
77 | 77 | ||
78 | if (mbox_cached && (mbox_cache_directory != NULL) && | 78 | if (mbox_cached && (mbox_cache_directory != NULL) && |
79 | (mbox_flags_directory != NULL)) { | 79 | (mbox_flags_directory != NULL)) { |
80 | mbox_storage->mbox_cache_directory = strdup(mbox_cache_directory); | 80 | mbox_storage->mbox_cache_directory = strdup(mbox_cache_directory); |
81 | if (mbox_storage->mbox_cache_directory == NULL) | 81 | if (mbox_storage->mbox_cache_directory == NULL) |
82 | goto free_pathname; | 82 | goto free_pathname; |
83 | 83 | ||
84 | mbox_storage->mbox_flags_directory = strdup(mbox_flags_directory); | 84 | mbox_storage->mbox_flags_directory = strdup(mbox_flags_directory); |
diff --git a/kmicromail/libetpan/generic/mhdriver.c b/kmicromail/libetpan/generic/mhdriver.c index af38d27..05a6a4f 100644 --- a/kmicromail/libetpan/generic/mhdriver.c +++ b/kmicromail/libetpan/generic/mhdriver.c | |||
@@ -76,32 +76,34 @@ static int mhdriver_status_folder(mailsession * session, char * mb, | |||
76 | 76 | ||
77 | static int mhdriver_messages_number(mailsession * session, char * mb, | 77 | static int mhdriver_messages_number(mailsession * session, char * mb, |
78 | uint32_t * result); | 78 | uint32_t * result); |
79 | 79 | ||
80 | static int mhdriver_list_folders(mailsession * session, char * mb, | 80 | static int mhdriver_list_folders(mailsession * session, char * mb, |
81 | struct mail_list ** result); | 81 | struct mail_list ** result); |
82 | 82 | ||
83 | static int mhdriver_lsub_folders(mailsession * session, char * mb, | 83 | static int mhdriver_lsub_folders(mailsession * session, char * mb, |
84 | struct mail_list ** result); | 84 | struct mail_list ** result); |
85 | 85 | ||
86 | static int mhdriver_subscribe_folder(mailsession * session, char * mb); | 86 | static int mhdriver_subscribe_folder(mailsession * session, char * mb); |
87 | 87 | ||
88 | static int mhdriver_unsubscribe_folder(mailsession * session, char * mb); | 88 | static int mhdriver_unsubscribe_folder(mailsession * session, char * mb); |
89 | 89 | ||
90 | static int mhdriver_append_message(mailsession * session, | 90 | static int mhdriver_append_message(mailsession * session, |
91 | char * message, size_t size); | 91 | char * message, size_t size); |
92 | static int mhdriver_append_message_flags(mailsession * session, | ||
93 | char * message, size_t size, struct mail_flags * flags); | ||
92 | static int mhdriver_copy_message(mailsession * session, | 94 | static int mhdriver_copy_message(mailsession * session, |
93 | uint32_t num, char * mb); | 95 | uint32_t num, char * mb); |
94 | 96 | ||
95 | static int mhdriver_remove_message(mailsession * session, uint32_t num); | 97 | static int mhdriver_remove_message(mailsession * session, uint32_t num); |
96 | 98 | ||
97 | static int mhdriver_move_message(mailsession * session, | 99 | static int mhdriver_move_message(mailsession * session, |
98 | uint32_t num, char * mb); | 100 | uint32_t num, char * mb); |
99 | 101 | ||
100 | static int mhdriver_get_messages_list(mailsession * session, | 102 | static int mhdriver_get_messages_list(mailsession * session, |
101 | struct mailmessage_list ** result); | 103 | struct mailmessage_list ** result); |
102 | 104 | ||
103 | static int mhdriver_get_message(mailsession * session, | 105 | static int mhdriver_get_message(mailsession * session, |
104 | uint32_t num, mailmessage ** result); | 106 | uint32_t num, mailmessage ** result); |
105 | 107 | ||
106 | static int mhdriver_get_message_by_uid(mailsession * session, | 108 | static int mhdriver_get_message_by_uid(mailsession * session, |
107 | const char * uid, | 109 | const char * uid, |
@@ -126,33 +128,34 @@ static mailsession_driver local_mh_session_driver = { | |||
126 | .sess_create_folder = mhdriver_create_folder, | 128 | .sess_create_folder = mhdriver_create_folder, |
127 | .sess_delete_folder = mhdriver_delete_folder, | 129 | .sess_delete_folder = mhdriver_delete_folder, |
128 | .sess_rename_folder = mhdriver_rename_folder, | 130 | .sess_rename_folder = mhdriver_rename_folder, |
129 | .sess_check_folder = NULL, | 131 | .sess_check_folder = NULL, |
130 | .sess_examine_folder = NULL, | 132 | .sess_examine_folder = NULL, |
131 | .sess_select_folder = mhdriver_select_folder, | 133 | .sess_select_folder = mhdriver_select_folder, |
132 | .sess_expunge_folder = NULL, | 134 | .sess_expunge_folder = NULL, |
133 | .sess_status_folder = mhdriver_status_folder, | 135 | .sess_status_folder = mhdriver_status_folder, |
134 | .sess_messages_number = mhdriver_messages_number, | 136 | .sess_messages_number = mhdriver_messages_number, |
135 | .sess_recent_number = mhdriver_messages_number, | 137 | .sess_recent_number = mhdriver_messages_number, |
136 | .sess_unseen_number = mhdriver_messages_number, | 138 | .sess_unseen_number = mhdriver_messages_number, |
137 | .sess_list_folders = mhdriver_list_folders, | 139 | .sess_list_folders = mhdriver_list_folders, |
138 | .sess_lsub_folders = mhdriver_lsub_folders, | 140 | .sess_lsub_folders = mhdriver_lsub_folders, |
139 | .sess_subscribe_folder = mhdriver_subscribe_folder, | 141 | .sess_subscribe_folder = mhdriver_subscribe_folder, |
140 | .sess_unsubscribe_folder = mhdriver_unsubscribe_folder, | 142 | .sess_unsubscribe_folder = mhdriver_unsubscribe_folder, |
141 | 143 | ||
142 | .sess_append_message = mhdriver_append_message, | 144 | .sess_append_message = mhdriver_append_message, |
145 | .sess_append_message_flags = mhdriver_append_message_flags, | ||
143 | .sess_copy_message = mhdriver_copy_message, | 146 | .sess_copy_message = mhdriver_copy_message, |
144 | .sess_move_message = mhdriver_move_message, | 147 | .sess_move_message = mhdriver_move_message, |
145 | 148 | ||
146 | .sess_get_messages_list = mhdriver_get_messages_list, | 149 | .sess_get_messages_list = mhdriver_get_messages_list, |
147 | .sess_get_envelopes_list = maildriver_generic_get_envelopes_list, | 150 | .sess_get_envelopes_list = maildriver_generic_get_envelopes_list, |
148 | .sess_remove_message = mhdriver_remove_message, | 151 | .sess_remove_message = mhdriver_remove_message, |
149 | #if 0 | 152 | #if 0 |
150 | .sess_search_messages = maildriver_generic_search_messages, | 153 | .sess_search_messages = maildriver_generic_search_messages, |
151 | #endif | 154 | #endif |
152 | 155 | ||
153 | .sess_get_message = mhdriver_get_message, | 156 | .sess_get_message = mhdriver_get_message, |
154 | .sess_get_message_by_uid = mhdriver_get_message_by_uid, | 157 | .sess_get_message_by_uid = mhdriver_get_message_by_uid, |
155 | }; | 158 | }; |
156 | 159 | ||
157 | mailsession_driver * mh_session_driver = &local_mh_session_driver; | 160 | mailsession_driver * mh_session_driver = &local_mh_session_driver; |
158 | 161 | ||
@@ -671,32 +674,38 @@ static int mhdriver_append_message(mailsession * session, | |||
671 | 674 | ||
672 | folder = get_mh_cur_folder(session); | 675 | folder = get_mh_cur_folder(session); |
673 | if (folder == NULL) | 676 | if (folder == NULL) |
674 | return MAIL_ERROR_BAD_STATE; | 677 | return MAIL_ERROR_BAD_STATE; |
675 | 678 | ||
676 | r = mailmh_folder_add_message(folder, message, size); | 679 | r = mailmh_folder_add_message(folder, message, size); |
677 | 680 | ||
678 | switch (r) { | 681 | switch (r) { |
679 | case MAILMH_ERROR_FILE: | 682 | case MAILMH_ERROR_FILE: |
680 | return MAIL_ERROR_DISKSPACE; | 683 | return MAIL_ERROR_DISKSPACE; |
681 | 684 | ||
682 | default: | 685 | default: |
683 | return mhdriver_mh_error_to_mail_error(r); | 686 | return mhdriver_mh_error_to_mail_error(r); |
684 | } | 687 | } |
685 | } | 688 | } |
686 | 689 | ||
690 | static int mhdriver_append_message_flags(mailsession * session, | ||
691 | char * message, size_t size, struct mail_flags * flags) | ||
692 | { | ||
693 | return mhdriver_append_message(session, message, size); | ||
694 | } | ||
695 | |||
687 | static int mhdriver_copy_message(mailsession * session, | 696 | static int mhdriver_copy_message(mailsession * session, |
688 | uint32_t num, char * mb) | 697 | uint32_t num, char * mb) |
689 | { | 698 | { |
690 | int fd; | 699 | int fd; |
691 | int r; | 700 | int r; |
692 | struct mailmh_folder * folder; | 701 | struct mailmh_folder * folder; |
693 | struct mailmh * mh; | 702 | struct mailmh * mh; |
694 | int res; | 703 | int res; |
695 | 704 | ||
696 | mh = get_mh_session(session); | 705 | mh = get_mh_session(session); |
697 | if (mh == NULL) { | 706 | if (mh == NULL) { |
698 | res = MAIL_ERROR_BAD_STATE; | 707 | res = MAIL_ERROR_BAD_STATE; |
699 | goto err; | 708 | goto err; |
700 | } | 709 | } |
701 | 710 | ||
702 | folder = get_mh_cur_folder(session); | 711 | folder = get_mh_cur_folder(session); |
diff --git a/kmicromail/libetpan/generic/mhdriver_cached.c b/kmicromail/libetpan/generic/mhdriver_cached.c index 5c35089..04aa523 100644 --- a/kmicromail/libetpan/generic/mhdriver_cached.c +++ b/kmicromail/libetpan/generic/mhdriver_cached.c | |||
@@ -95,32 +95,34 @@ static int mhdriver_cached_recent_number(mailsession * session, char * mb, | |||
95 | static int mhdriver_cached_unseen_number(mailsession * session, char * mb, | 95 | static int mhdriver_cached_unseen_number(mailsession * session, char * mb, |
96 | uint32_t * result); | 96 | uint32_t * result); |
97 | 97 | ||
98 | static int mhdriver_cached_list_folders(mailsession * session, char * mb, | 98 | static int mhdriver_cached_list_folders(mailsession * session, char * mb, |
99 | struct mail_list ** result); | 99 | struct mail_list ** result); |
100 | 100 | ||
101 | static int mhdriver_cached_lsub_folders(mailsession * session, char * mb, | 101 | static int mhdriver_cached_lsub_folders(mailsession * session, char * mb, |
102 | struct mail_list ** result); | 102 | struct mail_list ** result); |
103 | 103 | ||
104 | static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb); | 104 | static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb); |
105 | 105 | ||
106 | static int mhdriver_cached_unsubscribe_folder(mailsession * session, | 106 | static int mhdriver_cached_unsubscribe_folder(mailsession * session, |
107 | char * mb); | 107 | char * mb); |
108 | 108 | ||
109 | static int mhdriver_cached_append_message(mailsession * session, | 109 | static int mhdriver_cached_append_message(mailsession * session, |
110 | char * message, size_t size); | 110 | char * message, size_t size); |
111 | static int mhdriver_cached_append_message_flags(mailsession * session, | ||
112 | char * message, size_t size, struct mail_flags * flags); | ||
111 | static int mhdriver_cached_copy_message(mailsession * session, | 113 | static int mhdriver_cached_copy_message(mailsession * session, |
112 | uint32_t num, char * mb); | 114 | uint32_t num, char * mb); |
113 | 115 | ||
114 | static int mhdriver_cached_remove_message(mailsession * session, | 116 | static int mhdriver_cached_remove_message(mailsession * session, |
115 | uint32_t num); | 117 | uint32_t num); |
116 | 118 | ||
117 | static int mhdriver_cached_move_message(mailsession * session, | 119 | static int mhdriver_cached_move_message(mailsession * session, |
118 | uint32_t num, char * mb); | 120 | uint32_t num, char * mb); |
119 | 121 | ||
120 | static int | 122 | static int |
121 | mhdriver_cached_get_messages_list(mailsession * session, | 123 | mhdriver_cached_get_messages_list(mailsession * session, |
122 | struct mailmessage_list ** result); | 124 | struct mailmessage_list ** result); |
123 | 125 | ||
124 | static int | 126 | static int |
125 | mhdriver_cached_get_envelopes_list(mailsession * session, | 127 | mhdriver_cached_get_envelopes_list(mailsession * session, |
126 | struct mailmessage_list * env_list); | 128 | struct mailmessage_list * env_list); |
@@ -152,32 +154,33 @@ static mailsession_driver local_mh_cached_session_driver = { | |||
152 | .sess_delete_folder = mhdriver_cached_delete_folder, | 154 | .sess_delete_folder = mhdriver_cached_delete_folder, |
153 | .sess_rename_folder = mhdriver_cached_rename_folder, | 155 | .sess_rename_folder = mhdriver_cached_rename_folder, |
154 | .sess_check_folder = mhdriver_cached_check_folder, | 156 | .sess_check_folder = mhdriver_cached_check_folder, |
155 | .sess_examine_folder = NULL, | 157 | .sess_examine_folder = NULL, |
156 | .sess_select_folder = mhdriver_cached_select_folder, | 158 | .sess_select_folder = mhdriver_cached_select_folder, |
157 | .sess_expunge_folder = mhdriver_cached_expunge_folder, | 159 | .sess_expunge_folder = mhdriver_cached_expunge_folder, |
158 | .sess_status_folder = mhdriver_cached_status_folder, | 160 | .sess_status_folder = mhdriver_cached_status_folder, |
159 | .sess_messages_number = mhdriver_cached_messages_number, | 161 | .sess_messages_number = mhdriver_cached_messages_number, |
160 | .sess_recent_number = mhdriver_cached_recent_number, | 162 | .sess_recent_number = mhdriver_cached_recent_number, |
161 | .sess_unseen_number = mhdriver_cached_unseen_number, | 163 | .sess_unseen_number = mhdriver_cached_unseen_number, |
162 | .sess_list_folders = mhdriver_cached_list_folders, | 164 | .sess_list_folders = mhdriver_cached_list_folders, |
163 | .sess_lsub_folders = mhdriver_cached_lsub_folders, | 165 | .sess_lsub_folders = mhdriver_cached_lsub_folders, |
164 | .sess_subscribe_folder = mhdriver_cached_subscribe_folder, | 166 | .sess_subscribe_folder = mhdriver_cached_subscribe_folder, |
165 | .sess_unsubscribe_folder = mhdriver_cached_unsubscribe_folder, | 167 | .sess_unsubscribe_folder = mhdriver_cached_unsubscribe_folder, |
166 | 168 | ||
167 | .sess_append_message = mhdriver_cached_append_message, | 169 | .sess_append_message = mhdriver_cached_append_message, |
170 | .sess_append_message_flags = mhdriver_cached_append_message_flags, | ||
168 | .sess_copy_message = mhdriver_cached_copy_message, | 171 | .sess_copy_message = mhdriver_cached_copy_message, |
169 | .sess_move_message = mhdriver_cached_move_message, | 172 | .sess_move_message = mhdriver_cached_move_message, |
170 | 173 | ||
171 | .sess_get_messages_list = mhdriver_cached_get_messages_list, | 174 | .sess_get_messages_list = mhdriver_cached_get_messages_list, |
172 | .sess_get_envelopes_list = mhdriver_cached_get_envelopes_list, | 175 | .sess_get_envelopes_list = mhdriver_cached_get_envelopes_list, |
173 | .sess_remove_message = mhdriver_cached_remove_message, | 176 | .sess_remove_message = mhdriver_cached_remove_message, |
174 | #if 0 | 177 | #if 0 |
175 | .sess_search_messages = maildriver_generic_search_messages, | 178 | .sess_search_messages = maildriver_generic_search_messages, |
176 | #endif | 179 | #endif |
177 | 180 | ||
178 | .sess_get_message = mhdriver_cached_get_message, | 181 | .sess_get_message = mhdriver_cached_get_message, |
179 | .sess_get_message_by_uid = mhdriver_cached_get_message_by_uid, | 182 | .sess_get_message_by_uid = mhdriver_cached_get_message_by_uid, |
180 | }; | 183 | }; |
181 | 184 | ||
182 | mailsession_driver * mh_cached_session_driver = | 185 | mailsession_driver * mh_cached_session_driver = |
183 | &local_mh_cached_session_driver; | 186 | &local_mh_cached_session_driver; |
@@ -870,33 +873,111 @@ static int mhdriver_cached_lsub_folders(mailsession * session, char * mb, | |||
870 | static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb) | 873 | static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb) |
871 | { | 874 | { |
872 | return mailsession_subscribe_folder(get_ancestor(session), mb); | 875 | return mailsession_subscribe_folder(get_ancestor(session), mb); |
873 | } | 876 | } |
874 | 877 | ||
875 | static int mhdriver_cached_unsubscribe_folder(mailsession * session, | 878 | static int mhdriver_cached_unsubscribe_folder(mailsession * session, |
876 | char * mb) | 879 | char * mb) |
877 | { | 880 | { |
878 | return mailsession_unsubscribe_folder(get_ancestor(session), mb); | 881 | return mailsession_unsubscribe_folder(get_ancestor(session), mb); |
879 | } | 882 | } |
880 | 883 | ||
881 | /* messages operations */ | 884 | /* messages operations */ |
882 | 885 | ||
883 | static int mhdriver_cached_append_message(mailsession * session, | 886 | static int mhdriver_cached_append_message(mailsession * session, |
884 | char * message, size_t size) | 887 | char * message, size_t size) |
885 | { | 888 | { |
886 | return mailsession_append_message(get_ancestor(session), message, size); | 889 | return mhdriver_cached_append_message_flags(session, |
890 | message, size, NULL); | ||
891 | } | ||
892 | |||
893 | static int mhdriver_cached_append_message_flags(mailsession * session, | ||
894 | char * message, size_t size, struct mail_flags * flags) | ||
895 | { | ||
896 | int r; | ||
897 | struct mailmh_folder * folder; | ||
898 | struct mailmh_msg_info * msg_info; | ||
899 | chashdatum key; | ||
900 | chashdatum value; | ||
901 | uint32_t uid; | ||
902 | struct mh_cached_session_state_data * data; | ||
903 | char filename_flags[PATH_MAX]; | ||
904 | struct mail_cache_db * cache_db_flags; | ||
905 | MMAPString * mmapstr; | ||
906 | char keyname[PATH_MAX]; | ||
907 | |||
908 | folder = get_mh_cur_folder(session); | ||
909 | if (folder == NULL) | ||
910 | return MAIL_ERROR_BAD_STATE; | ||
911 | |||
912 | r = mailmh_folder_add_message_uid(folder, | ||
913 | message, size, &uid); | ||
914 | |||
915 | switch (r) { | ||
916 | case MAILMH_ERROR_FILE: | ||
917 | return MAIL_ERROR_DISKSPACE; | ||
918 | |||
919 | case MAILMH_NO_ERROR: | ||
920 | break; | ||
921 | |||
922 | default: | ||
923 | return mhdriver_mh_error_to_mail_error(r); | ||
924 | } | ||
925 | |||
926 | if (flags == NULL) | ||
927 | goto exit; | ||
928 | |||
929 | key.data = &uid; | ||
930 | key.len = sizeof(uid); | ||
931 | r = chash_get(folder->fl_msgs_hash, &key, &value); | ||
932 | if (r < 0) | ||
933 | return MAIL_ERROR_CACHE_MISS; | ||
934 | |||
935 | msg_info = value.data; | ||
936 | |||
937 | data = get_cached_data(session); | ||
938 | |||
939 | snprintf(filename_flags, PATH_MAX, "%s/%s/%s", | ||
940 | data->mh_flags_directory, data->mh_quoted_mb, FLAGS_NAME); | ||
941 | |||
942 | r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); | ||
943 | if (r < 0) | ||
944 | goto exit; | ||
945 | |||
946 | mmapstr = mmap_string_new(""); | ||
947 | if (mmapstr == NULL) | ||
948 | goto close_db_flags; | ||
949 | |||
950 | snprintf(keyname, PATH_MAX, "%u-%lu-%lu-flags", | ||
951 | uid, (unsigned long) msg_info->msg_mtime, | ||
952 | (unsigned long) msg_info->msg_size); | ||
953 | |||
954 | r = mhdriver_write_cached_flags(cache_db_flags, mmapstr, keyname, flags); | ||
955 | |||
956 | mmap_string_free(mmapstr); | ||
957 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
958 | |||
959 | if (r != MAIL_NO_ERROR) | ||
960 | goto exit; | ||
961 | |||
962 | return MAIL_NO_ERROR; | ||
963 | |||
964 | close_db_flags: | ||
965 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
966 | exit: | ||
967 | return MAIL_NO_ERROR; | ||
887 | } | 968 | } |
888 | 969 | ||
889 | static int mhdriver_cached_copy_message(mailsession * session, | 970 | static int mhdriver_cached_copy_message(mailsession * session, |
890 | uint32_t num, char * mb) | 971 | uint32_t num, char * mb) |
891 | { | 972 | { |
892 | return mailsession_copy_message(get_ancestor(session), num, mb); | 973 | return mailsession_copy_message(get_ancestor(session), num, mb); |
893 | } | 974 | } |
894 | 975 | ||
895 | static int mhdriver_cached_remove_message(mailsession * session, uint32_t num) | 976 | static int mhdriver_cached_remove_message(mailsession * session, uint32_t num) |
896 | { | 977 | { |
897 | return mailsession_remove_message(get_ancestor(session), num); | 978 | return mailsession_remove_message(get_ancestor(session), num); |
898 | } | 979 | } |
899 | 980 | ||
900 | static int mhdriver_cached_move_message(mailsession * session, | 981 | static int mhdriver_cached_move_message(mailsession * session, |
901 | uint32_t num, char * mb) | 982 | uint32_t num, char * mb) |
902 | { | 983 | { |
@@ -940,34 +1021,35 @@ get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | |||
940 | chashdatum data; | 1021 | chashdatum data; |
941 | 1022 | ||
942 | folder = get_mh_cur_folder(session); | 1023 | folder = get_mh_cur_folder(session); |
943 | 1024 | ||
944 | #if 0 | 1025 | #if 0 |
945 | msg_info = cinthash_find(mh_data->mh_cur_folder->fl_msgs_hash, num); | 1026 | msg_info = cinthash_find(mh_data->mh_cur_folder->fl_msgs_hash, num); |
946 | if (msg_info == NULL) | 1027 | if (msg_info == NULL) |
947 | return MAIL_ERROR_CACHE_MISS; | 1028 | return MAIL_ERROR_CACHE_MISS; |
948 | #endif | 1029 | #endif |
949 | key.data = # | 1030 | key.data = # |
950 | key.len = sizeof(num); | 1031 | key.len = sizeof(num); |
951 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 1032 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
952 | if (r < 0) | 1033 | if (r < 0) |
953 | return MAIL_ERROR_CACHE_MISS; | 1034 | return MAIL_ERROR_CACHE_MISS; |
954 | msg_info = data.data; | 1035 | msg_info = data.data; |
955 | 1036 | ||
956 | snprintf(keyname, PATH_MAX, "%u-%u-%u-envelope", | 1037 | snprintf(keyname, PATH_MAX, "%u-%lu-%lu-envelope", |
957 | num, (uint32_t) msg_info->msg_mtime, msg_info->msg_size); | 1038 | num, (unsigned long) msg_info->msg_mtime, |
1039 | (unsigned long) msg_info->msg_size); | ||
958 | 1040 | ||
959 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); | 1041 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); |
960 | if (r != MAIL_NO_ERROR) { | 1042 | if (r != MAIL_NO_ERROR) { |
961 | res = r; | 1043 | res = r; |
962 | goto err; | 1044 | goto err; |
963 | } | 1045 | } |
964 | 1046 | ||
965 | * result = fields; | 1047 | * result = fields; |
966 | 1048 | ||
967 | return MAIL_NO_ERROR; | 1049 | return MAIL_NO_ERROR; |
968 | 1050 | ||
969 | err: | 1051 | err: |
970 | return res; | 1052 | return res; |
971 | } | 1053 | } |
972 | 1054 | ||
973 | static int | 1055 | static int |
@@ -985,34 +1067,35 @@ write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | |||
985 | 1067 | ||
986 | folder = get_mh_cur_folder(session); | 1068 | folder = get_mh_cur_folder(session); |
987 | #if 0 | 1069 | #if 0 |
988 | msg_info = cinthash_find(mh_data->mh_cur_folder->fl_msgs_hash, num); | 1070 | msg_info = cinthash_find(mh_data->mh_cur_folder->fl_msgs_hash, num); |
989 | if (msg_info == NULL) { | 1071 | if (msg_info == NULL) { |
990 | res = MAIL_ERROR_CACHE_MISS; | 1072 | res = MAIL_ERROR_CACHE_MISS; |
991 | goto err; | 1073 | goto err; |
992 | } | 1074 | } |
993 | #endif | 1075 | #endif |
994 | key.data = # | 1076 | key.data = # |
995 | key.len = sizeof(num); | 1077 | key.len = sizeof(num); |
996 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 1078 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
997 | if (r < 0) | 1079 | if (r < 0) |
998 | return MAIL_ERROR_CACHE_MISS; | 1080 | return MAIL_ERROR_CACHE_MISS; |
999 | msg_info = data.data; | 1081 | msg_info = data.data; |
1000 | 1082 | ||
1001 | snprintf(keyname, PATH_MAX, "%u-%u-%u-envelope", | 1083 | snprintf(keyname, PATH_MAX, "%u-%lu-%lu-envelope", |
1002 | num, (uint32_t) msg_info->msg_mtime, msg_info->msg_size); | 1084 | num, (unsigned long) msg_info->msg_mtime, |
1085 | (unsigned long) msg_info->msg_size); | ||
1003 | 1086 | ||
1004 | r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields); | 1087 | r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields); |
1005 | if (r != MAIL_NO_ERROR) { | 1088 | if (r != MAIL_NO_ERROR) { |
1006 | res = r; | 1089 | res = r; |
1007 | goto err; | 1090 | goto err; |
1008 | } | 1091 | } |
1009 | 1092 | ||
1010 | return MAIL_NO_ERROR; | 1093 | return MAIL_NO_ERROR; |
1011 | 1094 | ||
1012 | err: | 1095 | err: |
1013 | return res; | 1096 | return res; |
1014 | } | 1097 | } |
1015 | 1098 | ||
1016 | static int | 1099 | static int |
1017 | mhdriver_cached_get_envelopes_list(mailsession * session, | 1100 | mhdriver_cached_get_envelopes_list(mailsession * session, |
1018 | struct mailmessage_list * env_list) | 1101 | struct mailmessage_list * env_list) |
diff --git a/kmicromail/libetpan/generic/mhdriver_cached_message.c b/kmicromail/libetpan/generic/mhdriver_cached_message.c index f716fb9..f69868d 100644 --- a/kmicromail/libetpan/generic/mhdriver_cached_message.c +++ b/kmicromail/libetpan/generic/mhdriver_cached_message.c | |||
@@ -166,34 +166,34 @@ static int mh_initialize(mailmessage * msg_info) | |||
166 | char static_uid[PATH_MAX]; | 166 | char static_uid[PATH_MAX]; |
167 | struct mailmh_msg_info * mh_msg_info; | 167 | struct mailmh_msg_info * mh_msg_info; |
168 | chashdatum key; | 168 | chashdatum key; |
169 | chashdatum data; | 169 | chashdatum data; |
170 | struct mailmh_folder * folder; | 170 | struct mailmh_folder * folder; |
171 | 171 | ||
172 | folder = get_mh_cur_folder(msg_info); | 172 | folder = get_mh_cur_folder(msg_info); |
173 | 173 | ||
174 | key.data = &msg_info->msg_index; | 174 | key.data = &msg_info->msg_index; |
175 | key.len = sizeof(msg_info->msg_index); | 175 | key.len = sizeof(msg_info->msg_index); |
176 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 176 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
177 | if (r < 0) | 177 | if (r < 0) |
178 | return MAIL_ERROR_INVAL; | 178 | return MAIL_ERROR_INVAL; |
179 | 179 | ||
180 | mh_msg_info = data.data; | 180 | mh_msg_info = data.data; |
181 | 181 | ||
182 | snprintf(static_uid, PATH_MAX, "%u-%lu-%u", msg_info->msg_index, | 182 | snprintf(static_uid, PATH_MAX, "%u-%lu-%lu", msg_info->msg_index, |
183 | mh_msg_info->msg_mtime, mh_msg_info->msg_size); | 183 | mh_msg_info->msg_mtime, (unsigned long) mh_msg_info->msg_size); |
184 | uid = strdup(static_uid); | 184 | uid = strdup(static_uid); |
185 | if (uid == NULL) | 185 | if (uid == NULL) |
186 | return MAIL_ERROR_MEMORY; | 186 | return MAIL_ERROR_MEMORY; |
187 | 187 | ||
188 | r = mailmessage_generic_initialize(msg_info); | 188 | r = mailmessage_generic_initialize(msg_info); |
189 | if (r != MAIL_NO_ERROR) { | 189 | if (r != MAIL_NO_ERROR) { |
190 | free(uid); | 190 | free(uid); |
191 | return r; | 191 | return r; |
192 | } | 192 | } |
193 | 193 | ||
194 | msg = msg_info->msg_data; | 194 | msg = msg_info->msg_data; |
195 | msg->msg_prefetch = mh_prefetch; | 195 | msg->msg_prefetch = mh_prefetch; |
196 | msg->msg_prefetch_free = mh_prefetch_free; | 196 | msg->msg_prefetch_free = mh_prefetch_free; |
197 | msg_info->msg_uid = uid; | 197 | msg_info->msg_uid = uid; |
198 | 198 | ||
199 | return MAIL_NO_ERROR; | 199 | return MAIL_NO_ERROR; |
diff --git a/kmicromail/libetpan/generic/mhdriver_message.c b/kmicromail/libetpan/generic/mhdriver_message.c index 2c023e7..aafd2d9 100644 --- a/kmicromail/libetpan/generic/mhdriver_message.c +++ b/kmicromail/libetpan/generic/mhdriver_message.c | |||
@@ -131,34 +131,35 @@ static int mh_initialize(mailmessage * msg_info) | |||
131 | struct generic_message_t * msg; | 131 | struct generic_message_t * msg; |
132 | int r; | 132 | int r; |
133 | char * uid; | 133 | char * uid; |
134 | char static_uid[PATH_MAX]; | 134 | char static_uid[PATH_MAX]; |
135 | struct mailmh_msg_info * mh_msg_info; | 135 | struct mailmh_msg_info * mh_msg_info; |
136 | chashdatum key; | 136 | chashdatum key; |
137 | chashdatum value; | 137 | chashdatum value; |
138 | 138 | ||
139 | key.data = &msg_info->msg_index; | 139 | key.data = &msg_info->msg_index; |
140 | key.len = sizeof(msg_info->msg_index); | 140 | key.len = sizeof(msg_info->msg_index); |
141 | r = chash_get(get_mh_cur_folder(msg_info)->fl_msgs_hash, &key, &value); | 141 | r = chash_get(get_mh_cur_folder(msg_info)->fl_msgs_hash, &key, &value); |
142 | if (r < 0) | 142 | if (r < 0) |
143 | return MAIL_ERROR_INVAL; | 143 | return MAIL_ERROR_INVAL; |
144 | 144 | ||
145 | mh_msg_info = value.data; | 145 | mh_msg_info = value.data; |
146 | 146 | ||
147 | snprintf(static_uid, PATH_MAX, "%u-%lu-%u", msg_info->msg_index, | 147 | snprintf(static_uid, PATH_MAX, "%u-%lu-%lu", msg_info->msg_index, |
148 | mh_msg_info->msg_mtime, mh_msg_info->msg_size); | 148 | (unsigned long) mh_msg_info->msg_mtime, |
149 | (unsigned long) mh_msg_info->msg_size); | ||
149 | uid = strdup(static_uid); | 150 | uid = strdup(static_uid); |
150 | if (uid == NULL) | 151 | if (uid == NULL) |
151 | return MAIL_ERROR_MEMORY; | 152 | return MAIL_ERROR_MEMORY; |
152 | 153 | ||
153 | r = mailmessage_generic_initialize(msg_info); | 154 | r = mailmessage_generic_initialize(msg_info); |
154 | if (r != MAIL_NO_ERROR) { | 155 | if (r != MAIL_NO_ERROR) { |
155 | free(uid); | 156 | free(uid); |
156 | return r; | 157 | return r; |
157 | } | 158 | } |
158 | 159 | ||
159 | msg = msg_info->msg_data; | 160 | msg = msg_info->msg_data; |
160 | msg->msg_prefetch = mh_prefetch; | 161 | msg->msg_prefetch = mh_prefetch; |
161 | msg->msg_prefetch_free = mh_prefetch_free; | 162 | msg->msg_prefetch_free = mh_prefetch_free; |
162 | msg_info->msg_uid = uid; | 163 | msg_info->msg_uid = uid; |
163 | 164 | ||
164 | return MAIL_NO_ERROR; | 165 | return MAIL_NO_ERROR; |
diff --git a/kmicromail/libetpan/generic/mhdriver_tools.c b/kmicromail/libetpan/generic/mhdriver_tools.c index cb863fa..c15bb6d 100644 --- a/kmicromail/libetpan/generic/mhdriver_tools.c +++ b/kmicromail/libetpan/generic/mhdriver_tools.c | |||
@@ -356,34 +356,35 @@ mhdriver_get_cached_flags(struct mail_cache_db * cache_db, | |||
356 | chashdatum data; | 356 | chashdatum data; |
357 | struct mailmh_folder * folder; | 357 | struct mailmh_folder * folder; |
358 | 358 | ||
359 | folder = cached_get_mh_cur_folder(session); | 359 | folder = cached_get_mh_cur_folder(session); |
360 | #if 0 | 360 | #if 0 |
361 | msg_info = cinthash_find(mh_data->cur_folder->fl_msgs_hash, num); | 361 | msg_info = cinthash_find(mh_data->cur_folder->fl_msgs_hash, num); |
362 | if (msg_info == NULL) | 362 | if (msg_info == NULL) |
363 | return MAIL_ERROR_CACHE_MISS; | 363 | return MAIL_ERROR_CACHE_MISS; |
364 | #endif | 364 | #endif |
365 | key.data = # | 365 | key.data = # |
366 | key.len = sizeof(num); | 366 | key.len = sizeof(num); |
367 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 367 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
368 | if (r < 0) | 368 | if (r < 0) |
369 | return MAIL_ERROR_CACHE_MISS; | 369 | return MAIL_ERROR_CACHE_MISS; |
370 | msg_info = data.data; | 370 | msg_info = data.data; |
371 | 371 | ||
372 | snprintf(keyname, PATH_MAX, "%u-%u-%u-flags", | 372 | snprintf(keyname, PATH_MAX, "%u-%lu-%lu-flags", |
373 | num, (uint32_t) msg_info->msg_mtime, msg_info->msg_size); | 373 | num, (unsigned long) msg_info->msg_mtime, |
374 | (unsigned long) msg_info->msg_size); | ||
374 | 375 | ||
375 | r = generic_cache_flags_read(cache_db, mmapstr, keyname, &flags); | 376 | r = generic_cache_flags_read(cache_db, mmapstr, keyname, &flags); |
376 | if (r != MAIL_NO_ERROR) { | 377 | if (r != MAIL_NO_ERROR) { |
377 | res = r; | 378 | res = r; |
378 | goto err; | 379 | goto err; |
379 | } | 380 | } |
380 | 381 | ||
381 | * result = flags; | 382 | * result = flags; |
382 | 383 | ||
383 | return MAIL_NO_ERROR; | 384 | return MAIL_NO_ERROR; |
384 | 385 | ||
385 | err: | 386 | err: |
386 | return res; | 387 | return res; |
387 | } | 388 | } |
388 | 389 | ||
389 | int | 390 | int |
diff --git a/kmicromail/libetpan/generic/mhstorage.c b/kmicromail/libetpan/generic/mhstorage.c index 32fc26b..715b961 100644 --- a/kmicromail/libetpan/generic/mhstorage.c +++ b/kmicromail/libetpan/generic/mhstorage.c | |||
@@ -49,33 +49,33 @@ static int mh_mailstorage_get_folder_session(struct mailstorage * storage, | |||
49 | char * pathname, mailsession ** result); | 49 | char * pathname, mailsession ** result); |
50 | static void mh_mailstorage_uninitialize(struct mailstorage * storage); | 50 | static void mh_mailstorage_uninitialize(struct mailstorage * storage); |
51 | 51 | ||
52 | static mailstorage_driver mh_mailstorage_driver = { | 52 | static mailstorage_driver mh_mailstorage_driver = { |
53 | .sto_name = "mh", | 53 | .sto_name = "mh", |
54 | .sto_connect = mh_mailstorage_connect, | 54 | .sto_connect = mh_mailstorage_connect, |
55 | .sto_get_folder_session = mh_mailstorage_get_folder_session, | 55 | .sto_get_folder_session = mh_mailstorage_get_folder_session, |
56 | .sto_uninitialize = mh_mailstorage_uninitialize, | 56 | .sto_uninitialize = mh_mailstorage_uninitialize, |
57 | }; | 57 | }; |
58 | 58 | ||
59 | int mh_mailstorage_init(struct mailstorage * storage, | 59 | int mh_mailstorage_init(struct mailstorage * storage, |
60 | char * mh_pathname, int mh_cached, | 60 | char * mh_pathname, int mh_cached, |
61 | char * mh_cache_directory, char * mh_flags_directory) | 61 | char * mh_cache_directory, char * mh_flags_directory) |
62 | { | 62 | { |
63 | struct mh_mailstorage * mh_storage; | 63 | struct mh_mailstorage * mh_storage; |
64 | 64 | ||
65 | mh_storage = malloc(sizeof(struct mh_mailstorage)); | 65 | mh_storage = malloc(sizeof(* mh_storage)); |
66 | if (mh_storage == NULL) | 66 | if (mh_storage == NULL) |
67 | goto err; | 67 | goto err; |
68 | 68 | ||
69 | mh_storage->mh_pathname = strdup(mh_pathname); | 69 | mh_storage->mh_pathname = strdup(mh_pathname); |
70 | if (mh_storage->mh_pathname == NULL) | 70 | if (mh_storage->mh_pathname == NULL) |
71 | goto free; | 71 | goto free; |
72 | 72 | ||
73 | mh_storage->mh_cached = mh_cached; | 73 | mh_storage->mh_cached = mh_cached; |
74 | 74 | ||
75 | if (mh_cached && (mh_cache_directory != NULL) && | 75 | if (mh_cached && (mh_cache_directory != NULL) && |
76 | (mh_flags_directory != NULL)) { | 76 | (mh_flags_directory != NULL)) { |
77 | mh_storage->mh_cache_directory = strdup(mh_cache_directory); | 77 | mh_storage->mh_cache_directory = strdup(mh_cache_directory); |
78 | if (mh_storage->mh_cache_directory == NULL) | 78 | if (mh_storage->mh_cache_directory == NULL) |
79 | goto free_pathname; | 79 | goto free_pathname; |
80 | mh_storage->mh_flags_directory = strdup(mh_flags_directory); | 80 | mh_storage->mh_flags_directory = strdup(mh_flags_directory); |
81 | if (mh_storage->mh_flags_directory == NULL) | 81 | if (mh_storage->mh_flags_directory == NULL) |
diff --git a/kmicromail/libetpan/generic/nntpdriver.c b/kmicromail/libetpan/generic/nntpdriver.c index fde5f1a..1b65838 100644 --- a/kmicromail/libetpan/generic/nntpdriver.c +++ b/kmicromail/libetpan/generic/nntpdriver.c | |||
@@ -56,32 +56,35 @@ static int nntpdriver_connect_stream(mailsession * session, mailstream * s); | |||
56 | static int nntpdriver_login(mailsession * session, | 56 | static int nntpdriver_login(mailsession * session, |
57 | char * userid, char * password); | 57 | char * userid, char * password); |
58 | 58 | ||
59 | static int nntpdriver_logout(mailsession * session); | 59 | static int nntpdriver_logout(mailsession * session); |
60 | 60 | ||
61 | static int nntpdriver_status_folder(mailsession * session, char * mb, | 61 | static int nntpdriver_status_folder(mailsession * session, char * mb, |
62 | uint32_t * result_messages, | 62 | uint32_t * result_messages, |
63 | uint32_t * result_recent, | 63 | uint32_t * result_recent, |
64 | uint32_t * result_unseen); | 64 | uint32_t * result_unseen); |
65 | 65 | ||
66 | static int nntpdriver_messages_number(mailsession * session, char * mb, | 66 | static int nntpdriver_messages_number(mailsession * session, char * mb, |
67 | uint32_t * result); | 67 | uint32_t * result); |
68 | 68 | ||
69 | static int nntpdriver_append_message(mailsession * session, | 69 | static int nntpdriver_append_message(mailsession * session, |
70 | char * message, size_t size); | 70 | char * message, size_t size); |
71 | 71 | ||
72 | static int nntpdriver_append_message_flags(mailsession * session, | ||
73 | char * message, size_t size, struct mail_flags * flags); | ||
74 | |||
72 | static int | 75 | static int |
73 | nntpdriver_get_envelopes_list(mailsession * session, | 76 | nntpdriver_get_envelopes_list(mailsession * session, |
74 | struct mailmessage_list * env_list); | 77 | struct mailmessage_list * env_list); |
75 | 78 | ||
76 | 79 | ||
77 | static int nntpdriver_get_messages_list(mailsession * session, | 80 | static int nntpdriver_get_messages_list(mailsession * session, |
78 | struct mailmessage_list ** result); | 81 | struct mailmessage_list ** result); |
79 | 82 | ||
80 | static int nntpdriver_list_folders(mailsession * session, char * mb, | 83 | static int nntpdriver_list_folders(mailsession * session, char * mb, |
81 | struct mail_list ** result); | 84 | struct mail_list ** result); |
82 | 85 | ||
83 | static int nntpdriver_lsub_folders(mailsession * session, char * mb, | 86 | static int nntpdriver_lsub_folders(mailsession * session, char * mb, |
84 | struct mail_list ** result); | 87 | struct mail_list ** result); |
85 | 88 | ||
86 | static int nntpdriver_subscribe_folder(mailsession * session, char * mb); | 89 | static int nntpdriver_subscribe_folder(mailsession * session, char * mb); |
87 | 90 | ||
@@ -116,32 +119,33 @@ static mailsession_driver local_nntp_session_driver = { | |||
116 | .sess_delete_folder = NULL, | 119 | .sess_delete_folder = NULL, |
117 | .sess_rename_folder = NULL, | 120 | .sess_rename_folder = NULL, |
118 | .sess_check_folder = NULL, | 121 | .sess_check_folder = NULL, |
119 | .sess_examine_folder = NULL, | 122 | .sess_examine_folder = NULL, |
120 | .sess_select_folder = nntpdriver_select_folder, | 123 | .sess_select_folder = nntpdriver_select_folder, |
121 | .sess_expunge_folder = NULL, | 124 | .sess_expunge_folder = NULL, |
122 | .sess_status_folder = nntpdriver_status_folder, | 125 | .sess_status_folder = nntpdriver_status_folder, |
123 | .sess_messages_number = nntpdriver_messages_number, | 126 | .sess_messages_number = nntpdriver_messages_number, |
124 | .sess_recent_number = nntpdriver_messages_number, | 127 | .sess_recent_number = nntpdriver_messages_number, |
125 | .sess_unseen_number = nntpdriver_messages_number, | 128 | .sess_unseen_number = nntpdriver_messages_number, |
126 | .sess_list_folders = nntpdriver_list_folders, | 129 | .sess_list_folders = nntpdriver_list_folders, |
127 | .sess_lsub_folders = nntpdriver_lsub_folders, | 130 | .sess_lsub_folders = nntpdriver_lsub_folders, |
128 | .sess_subscribe_folder = nntpdriver_subscribe_folder, | 131 | .sess_subscribe_folder = nntpdriver_subscribe_folder, |
129 | .sess_unsubscribe_folder = nntpdriver_unsubscribe_folder, | 132 | .sess_unsubscribe_folder = nntpdriver_unsubscribe_folder, |
130 | 133 | ||
131 | .sess_append_message = nntpdriver_append_message, | 134 | .sess_append_message = nntpdriver_append_message, |
135 | .sess_append_message_flags = nntpdriver_append_message_flags, | ||
132 | .sess_copy_message = NULL, | 136 | .sess_copy_message = NULL, |
133 | .sess_move_message = NULL, | 137 | .sess_move_message = NULL, |
134 | 138 | ||
135 | .sess_get_messages_list = nntpdriver_get_messages_list, | 139 | .sess_get_messages_list = nntpdriver_get_messages_list, |
136 | .sess_get_envelopes_list = nntpdriver_get_envelopes_list, | 140 | .sess_get_envelopes_list = nntpdriver_get_envelopes_list, |
137 | .sess_remove_message = NULL, | 141 | .sess_remove_message = NULL, |
138 | #if 0 | 142 | #if 0 |
139 | .sess_search_messages = maildriver_generic_search_messages, | 143 | .sess_search_messages = maildriver_generic_search_messages, |
140 | #endif | 144 | #endif |
141 | 145 | ||
142 | .sess_get_message = nntpdriver_get_message, | 146 | .sess_get_message = nntpdriver_get_message, |
143 | .sess_get_message_by_uid = nntpdriver_get_message_by_uid, | 147 | .sess_get_message_by_uid = nntpdriver_get_message_by_uid, |
144 | }; | 148 | }; |
145 | 149 | ||
146 | 150 | ||
147 | mailsession_driver * nntp_session_driver = &local_nntp_session_driver; | 151 | mailsession_driver * nntp_session_driver = &local_nntp_session_driver; |
@@ -617,32 +621,38 @@ static int nntpdriver_append_message(mailsession * session, | |||
617 | return r; | 621 | return r; |
618 | break; | 622 | break; |
619 | 623 | ||
620 | case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD: | 624 | case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD: |
621 | r = nntpdriver_authenticate_password(session); | 625 | r = nntpdriver_authenticate_password(session); |
622 | if (r != MAIL_NO_ERROR) | 626 | if (r != MAIL_NO_ERROR) |
623 | return r; | 627 | return r; |
624 | break; | 628 | break; |
625 | 629 | ||
626 | default: | 630 | default: |
627 | return nntpdriver_nntp_error_to_mail_error(r); | 631 | return nntpdriver_nntp_error_to_mail_error(r); |
628 | } | 632 | } |
629 | } | 633 | } |
630 | while (1); | 634 | while (1); |
631 | } | 635 | } |
632 | 636 | ||
637 | static int nntpdriver_append_message_flags(mailsession * session, | ||
638 | char * message, size_t size, struct mail_flags * flags) | ||
639 | { | ||
640 | return nntpdriver_append_message(session, message, size); | ||
641 | } | ||
642 | |||
633 | 643 | ||
634 | static int xover_resp_to_fields(struct newsnntp_xover_resp_item * item, | 644 | static int xover_resp_to_fields(struct newsnntp_xover_resp_item * item, |
635 | struct mailimf_fields ** result); | 645 | struct mailimf_fields ** result); |
636 | 646 | ||
637 | 647 | ||
638 | static int | 648 | static int |
639 | nntpdriver_get_envelopes_list(mailsession * session, | 649 | nntpdriver_get_envelopes_list(mailsession * session, |
640 | struct mailmessage_list * env_list) | 650 | struct mailmessage_list * env_list) |
641 | { | 651 | { |
642 | newsnntp * nntp; | 652 | newsnntp * nntp; |
643 | int r; | 653 | int r; |
644 | struct nntp_session_state_data * data; | 654 | struct nntp_session_state_data * data; |
645 | clist * list; | 655 | clist * list; |
646 | int done; | 656 | int done; |
647 | clistiter * cur; | 657 | clistiter * cur; |
648 | uint32_t first_seq; | 658 | uint32_t first_seq; |
diff --git a/kmicromail/libetpan/generic/nntpdriver_cached.c b/kmicromail/libetpan/generic/nntpdriver_cached.c index 1f8a8af..0343a65 100644 --- a/kmicromail/libetpan/generic/nntpdriver_cached.c +++ b/kmicromail/libetpan/generic/nntpdriver_cached.c | |||
@@ -83,32 +83,35 @@ static int nntpdriver_cached_status_folder(mailsession * session, | |||
83 | uint32_t * result_messages, | 83 | uint32_t * result_messages, |
84 | uint32_t * result_recent, | 84 | uint32_t * result_recent, |
85 | uint32_t * result_unseen); | 85 | uint32_t * result_unseen); |
86 | 86 | ||
87 | static int nntpdriver_cached_messages_number(mailsession * session, char * mb, | 87 | static int nntpdriver_cached_messages_number(mailsession * session, char * mb, |
88 | uint32_t * result); | 88 | uint32_t * result); |
89 | 89 | ||
90 | static int nntpdriver_cached_recent_number(mailsession * session, char * mb, | 90 | static int nntpdriver_cached_recent_number(mailsession * session, char * mb, |
91 | uint32_t * result); | 91 | uint32_t * result); |
92 | 92 | ||
93 | static int nntpdriver_cached_unseen_number(mailsession * session, char * mb, | 93 | static int nntpdriver_cached_unseen_number(mailsession * session, char * mb, |
94 | uint32_t * result); | 94 | uint32_t * result); |
95 | 95 | ||
96 | static int nntpdriver_cached_append_message(mailsession * session, | 96 | static int nntpdriver_cached_append_message(mailsession * session, |
97 | char * message, size_t size); | 97 | char * message, size_t size); |
98 | 98 | ||
99 | static int nntpdriver_cached_append_message_flags(mailsession * session, | ||
100 | char * message, size_t size, struct mail_flags * flags); | ||
101 | |||
99 | static int | 102 | static int |
100 | nntpdriver_cached_get_envelopes_list(mailsession * session, | 103 | nntpdriver_cached_get_envelopes_list(mailsession * session, |
101 | struct mailmessage_list * env_list); | 104 | struct mailmessage_list * env_list); |
102 | 105 | ||
103 | 106 | ||
104 | static int | 107 | static int |
105 | nntpdriver_cached_get_messages_list(mailsession * session, | 108 | nntpdriver_cached_get_messages_list(mailsession * session, |
106 | struct mailmessage_list ** result); | 109 | struct mailmessage_list ** result); |
107 | 110 | ||
108 | static int nntpdriver_cached_list_folders(mailsession * session, char * mb, | 111 | static int nntpdriver_cached_list_folders(mailsession * session, char * mb, |
109 | struct mail_list ** result); | 112 | struct mail_list ** result); |
110 | 113 | ||
111 | static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb, | 114 | static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb, |
112 | struct mail_list ** result); | 115 | struct mail_list ** result); |
113 | 116 | ||
114 | static int nntpdriver_cached_subscribe_folder(mailsession * session, | 117 | static int nntpdriver_cached_subscribe_folder(mailsession * session, |
@@ -146,32 +149,33 @@ static mailsession_driver local_nntp_cached_session_driver = { | |||
146 | .sess_delete_folder = NULL, | 149 | .sess_delete_folder = NULL, |
147 | .sess_rename_folder = NULL, | 150 | .sess_rename_folder = NULL, |
148 | .sess_check_folder = nntpdriver_cached_check_folder, | 151 | .sess_check_folder = nntpdriver_cached_check_folder, |
149 | .sess_examine_folder = NULL, | 152 | .sess_examine_folder = NULL, |
150 | .sess_select_folder = nntpdriver_cached_select_folder, | 153 | .sess_select_folder = nntpdriver_cached_select_folder, |
151 | .sess_expunge_folder = NULL, | 154 | .sess_expunge_folder = NULL, |
152 | .sess_status_folder = nntpdriver_cached_status_folder, | 155 | .sess_status_folder = nntpdriver_cached_status_folder, |
153 | .sess_messages_number = nntpdriver_cached_messages_number, | 156 | .sess_messages_number = nntpdriver_cached_messages_number, |
154 | .sess_recent_number = nntpdriver_cached_recent_number, | 157 | .sess_recent_number = nntpdriver_cached_recent_number, |
155 | .sess_unseen_number = nntpdriver_cached_unseen_number, | 158 | .sess_unseen_number = nntpdriver_cached_unseen_number, |
156 | .sess_list_folders = nntpdriver_cached_list_folders, | 159 | .sess_list_folders = nntpdriver_cached_list_folders, |
157 | .sess_lsub_folders = nntpdriver_cached_lsub_folders, | 160 | .sess_lsub_folders = nntpdriver_cached_lsub_folders, |
158 | .sess_subscribe_folder = nntpdriver_cached_subscribe_folder, | 161 | .sess_subscribe_folder = nntpdriver_cached_subscribe_folder, |
159 | .sess_unsubscribe_folder = nntpdriver_cached_unsubscribe_folder, | 162 | .sess_unsubscribe_folder = nntpdriver_cached_unsubscribe_folder, |
160 | 163 | ||
161 | .sess_append_message = nntpdriver_cached_append_message, | 164 | .sess_append_message = nntpdriver_cached_append_message, |
165 | .sess_append_message_flags = nntpdriver_cached_append_message_flags, | ||
162 | .sess_copy_message = NULL, | 166 | .sess_copy_message = NULL, |
163 | .sess_move_message = NULL, | 167 | .sess_move_message = NULL, |
164 | 168 | ||
165 | .sess_get_messages_list = nntpdriver_cached_get_messages_list, | 169 | .sess_get_messages_list = nntpdriver_cached_get_messages_list, |
166 | .sess_get_envelopes_list = nntpdriver_cached_get_envelopes_list, | 170 | .sess_get_envelopes_list = nntpdriver_cached_get_envelopes_list, |
167 | .sess_remove_message = NULL, | 171 | .sess_remove_message = NULL, |
168 | #if 0 | 172 | #if 0 |
169 | .sess_search_messages = maildriver_generic_search_messages, | 173 | .sess_search_messages = maildriver_generic_search_messages, |
170 | #endif | 174 | #endif |
171 | 175 | ||
172 | .sess_get_message = nntpdriver_cached_get_message, | 176 | .sess_get_message = nntpdriver_cached_get_message, |
173 | .sess_get_message_by_uid = nntpdriver_cached_get_message_by_uid, | 177 | .sess_get_message_by_uid = nntpdriver_cached_get_message_by_uid, |
174 | }; | 178 | }; |
175 | 179 | ||
176 | 180 | ||
177 | mailsession_driver * nntp_cached_session_driver = | 181 | mailsession_driver * nntp_cached_session_driver = |
@@ -618,32 +622,38 @@ static int nntpdriver_cached_subscribe_folder(mailsession * session, | |||
618 | static int nntpdriver_cached_unsubscribe_folder(mailsession * session, | 622 | static int nntpdriver_cached_unsubscribe_folder(mailsession * session, |
619 | char * mb) | 623 | char * mb) |
620 | { | 624 | { |
621 | return mailsession_unsubscribe_folder(get_ancestor(session), mb); | 625 | return mailsession_unsubscribe_folder(get_ancestor(session), mb); |
622 | } | 626 | } |
623 | 627 | ||
624 | 628 | ||
625 | 629 | ||
626 | /* messages operations */ | 630 | /* messages operations */ |
627 | 631 | ||
628 | static int nntpdriver_cached_append_message(mailsession * session, | 632 | static int nntpdriver_cached_append_message(mailsession * session, |
629 | char * message, size_t size) | 633 | char * message, size_t size) |
630 | { | 634 | { |
631 | return mailsession_append_message(get_ancestor(session), message, size); | 635 | return mailsession_append_message(get_ancestor(session), message, size); |
632 | } | 636 | } |
633 | 637 | ||
638 | static int nntpdriver_cached_append_message_flags(mailsession * session, | ||
639 | char * message, size_t size, struct mail_flags * flags) | ||
640 | { | ||
641 | return nntpdriver_cached_append_message(session, message, size); | ||
642 | } | ||
643 | |||
634 | 644 | ||
635 | 645 | ||
636 | static int | 646 | static int |
637 | get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | 647 | get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, |
638 | mailsession * session, uint32_t num, | 648 | mailsession * session, uint32_t num, |
639 | struct mailimf_fields ** result) | 649 | struct mailimf_fields ** result) |
640 | { | 650 | { |
641 | char keyname[PATH_MAX]; | 651 | char keyname[PATH_MAX]; |
642 | int r; | 652 | int r; |
643 | struct mailimf_fields * fields; | 653 | struct mailimf_fields * fields; |
644 | int res; | 654 | int res; |
645 | 655 | ||
646 | snprintf(keyname, PATH_MAX, "%i-envelope", num); | 656 | snprintf(keyname, PATH_MAX, "%i-envelope", num); |
647 | 657 | ||
648 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); | 658 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); |
649 | if (r != MAIL_NO_ERROR) { | 659 | if (r != MAIL_NO_ERROR) { |
diff --git a/kmicromail/libetpan/generic/nntpstorage.c b/kmicromail/libetpan/generic/nntpstorage.c index 5ba333b..89974cd 100644 --- a/kmicromail/libetpan/generic/nntpstorage.c +++ b/kmicromail/libetpan/generic/nntpstorage.c | |||
@@ -58,33 +58,33 @@ static mailstorage_driver nntp_mailstorage_driver = { | |||
58 | .sto_name = "nntp", | 58 | .sto_name = "nntp", |
59 | .sto_connect = nntp_mailstorage_connect, | 59 | .sto_connect = nntp_mailstorage_connect, |
60 | .sto_get_folder_session = nntp_mailstorage_get_folder_session, | 60 | .sto_get_folder_session = nntp_mailstorage_get_folder_session, |
61 | .sto_uninitialize = nntp_mailstorage_uninitialize, | 61 | .sto_uninitialize = nntp_mailstorage_uninitialize, |
62 | }; | 62 | }; |
63 | 63 | ||
64 | int nntp_mailstorage_init(struct mailstorage * storage, | 64 | int nntp_mailstorage_init(struct mailstorage * storage, |
65 | char * nn_servername, uint16_t nn_port, | 65 | char * nn_servername, uint16_t nn_port, |
66 | char * nn_command, | 66 | char * nn_command, |
67 | int nn_connection_type, int nn_auth_type, | 67 | int nn_connection_type, int nn_auth_type, |
68 | char * nn_login, char * nn_password, | 68 | char * nn_login, char * nn_password, |
69 | int nn_cached, char * nn_cache_directory, char * nn_flags_directory) | 69 | int nn_cached, char * nn_cache_directory, char * nn_flags_directory) |
70 | { | 70 | { |
71 | struct nntp_mailstorage * nntp_storage; | 71 | struct nntp_mailstorage * nntp_storage; |
72 | int res; | 72 | int res; |
73 | 73 | ||
74 | nntp_storage = malloc(sizeof(struct nntp_mailstorage)); | 74 | nntp_storage = malloc(sizeof(* nntp_storage)); |
75 | if (nntp_storage == NULL) { | 75 | if (nntp_storage == NULL) { |
76 | res = MAIL_ERROR_MEMORY; | 76 | res = MAIL_ERROR_MEMORY; |
77 | goto err; | 77 | goto err; |
78 | } | 78 | } |
79 | 79 | ||
80 | nntp_storage->nntp_servername = strdup(nn_servername); | 80 | nntp_storage->nntp_servername = strdup(nn_servername); |
81 | if (nntp_storage->nntp_servername == NULL) { | 81 | if (nntp_storage->nntp_servername == NULL) { |
82 | res = MAIL_ERROR_MEMORY; | 82 | res = MAIL_ERROR_MEMORY; |
83 | goto free; | 83 | goto free; |
84 | } | 84 | } |
85 | 85 | ||
86 | nntp_storage->nntp_connection_type = nn_connection_type; | 86 | nntp_storage->nntp_connection_type = nn_connection_type; |
87 | 87 | ||
88 | if (nn_port == 0) { | 88 | if (nn_port == 0) { |
89 | switch (nn_connection_type) { | 89 | switch (nn_connection_type) { |
90 | case CONNECTION_TYPE_PLAIN: | 90 | case CONNECTION_TYPE_PLAIN: |
diff --git a/kmicromail/libetpan/generic/pop3driver.c b/kmicromail/libetpan/generic/pop3driver.c index 20b0fc2..375879e 100644 --- a/kmicromail/libetpan/generic/pop3driver.c +++ b/kmicromail/libetpan/generic/pop3driver.c | |||
@@ -96,32 +96,33 @@ static mailsession_driver local_pop3_session_driver = { | |||
96 | .sess_delete_folder = NULL, | 96 | .sess_delete_folder = NULL, |
97 | .sess_rename_folder = NULL, | 97 | .sess_rename_folder = NULL, |
98 | .sess_check_folder = NULL, | 98 | .sess_check_folder = NULL, |
99 | .sess_examine_folder = NULL, | 99 | .sess_examine_folder = NULL, |
100 | .sess_select_folder = NULL, | 100 | .sess_select_folder = NULL, |
101 | .sess_expunge_folder = NULL, | 101 | .sess_expunge_folder = NULL, |
102 | .sess_status_folder = pop3driver_status_folder, | 102 | .sess_status_folder = pop3driver_status_folder, |
103 | .sess_messages_number = pop3driver_messages_number, | 103 | .sess_messages_number = pop3driver_messages_number, |
104 | .sess_recent_number = pop3driver_messages_number, | 104 | .sess_recent_number = pop3driver_messages_number, |
105 | .sess_unseen_number = pop3driver_messages_number, | 105 | .sess_unseen_number = pop3driver_messages_number, |
106 | .sess_list_folders = NULL, | 106 | .sess_list_folders = NULL, |
107 | .sess_lsub_folders = NULL, | 107 | .sess_lsub_folders = NULL, |
108 | .sess_subscribe_folder = NULL, | 108 | .sess_subscribe_folder = NULL, |
109 | .sess_unsubscribe_folder = NULL, | 109 | .sess_unsubscribe_folder = NULL, |
110 | 110 | ||
111 | .sess_append_message = NULL, | 111 | .sess_append_message = NULL, |
112 | .sess_append_message_flags = NULL, | ||
112 | .sess_copy_message = NULL, | 113 | .sess_copy_message = NULL, |
113 | .sess_move_message = NULL, | 114 | .sess_move_message = NULL, |
114 | 115 | ||
115 | .sess_get_messages_list = pop3driver_get_messages_list, | 116 | .sess_get_messages_list = pop3driver_get_messages_list, |
116 | .sess_get_envelopes_list = maildriver_generic_get_envelopes_list, | 117 | .sess_get_envelopes_list = maildriver_generic_get_envelopes_list, |
117 | .sess_remove_message = pop3driver_remove_message, | 118 | .sess_remove_message = pop3driver_remove_message, |
118 | #if 0 | 119 | #if 0 |
119 | .sess_search_messages = maildriver_generic_search_messages, | 120 | .sess_search_messages = maildriver_generic_search_messages, |
120 | #endif | 121 | #endif |
121 | 122 | ||
122 | .sess_get_message = pop3driver_get_message, | 123 | .sess_get_message = pop3driver_get_message, |
123 | .sess_get_message_by_uid = NULL, | 124 | .sess_get_message_by_uid = NULL, |
124 | }; | 125 | }; |
125 | 126 | ||
126 | mailsession_driver * pop3_session_driver = &local_pop3_session_driver; | 127 | mailsession_driver * pop3_session_driver = &local_pop3_session_driver; |
127 | 128 | ||
diff --git a/kmicromail/libetpan/generic/pop3driver_cached.c b/kmicromail/libetpan/generic/pop3driver_cached.c index 6f97303..24f624b 100644 --- a/kmicromail/libetpan/generic/pop3driver_cached.c +++ b/kmicromail/libetpan/generic/pop3driver_cached.c | |||
@@ -97,32 +97,35 @@ static int pop3driver_cached_unseen_number(mailsession * session, | |||
97 | uint32_t * result); | 97 | uint32_t * result); |
98 | 98 | ||
99 | static int pop3driver_cached_remove_message(mailsession * session, | 99 | static int pop3driver_cached_remove_message(mailsession * session, |
100 | uint32_t num); | 100 | uint32_t num); |
101 | 101 | ||
102 | static int | 102 | static int |
103 | pop3driver_cached_get_messages_list(mailsession * session, | 103 | pop3driver_cached_get_messages_list(mailsession * session, |
104 | struct mailmessage_list ** result); | 104 | struct mailmessage_list ** result); |
105 | 105 | ||
106 | static int | 106 | static int |
107 | pop3driver_cached_get_envelopes_list(mailsession * session, | 107 | pop3driver_cached_get_envelopes_list(mailsession * session, |
108 | struct mailmessage_list * env_list); | 108 | struct mailmessage_list * env_list); |
109 | 109 | ||
110 | static int pop3driver_cached_get_message(mailsession * session, | 110 | static int pop3driver_cached_get_message(mailsession * session, |
111 | uint32_t num, mailmessage ** result); | 111 | uint32_t num, mailmessage ** result); |
112 | 112 | ||
113 | static int pop3driver_cached_get_message_by_uid(mailsession * session, | ||
114 | const char * uid, mailmessage ** result); | ||
115 | |||
113 | static mailsession_driver local_pop3_cached_session_driver = { | 116 | static mailsession_driver local_pop3_cached_session_driver = { |
114 | .sess_name = "pop3-cached", | 117 | .sess_name = "pop3-cached", |
115 | 118 | ||
116 | .sess_initialize = pop3driver_cached_initialize, | 119 | .sess_initialize = pop3driver_cached_initialize, |
117 | .sess_uninitialize = pop3driver_cached_uninitialize, | 120 | .sess_uninitialize = pop3driver_cached_uninitialize, |
118 | 121 | ||
119 | .sess_parameters = pop3driver_cached_parameters, | 122 | .sess_parameters = pop3driver_cached_parameters, |
120 | 123 | ||
121 | .sess_connect_stream = pop3driver_cached_connect_stream, | 124 | .sess_connect_stream = pop3driver_cached_connect_stream, |
122 | .sess_connect_path = NULL, | 125 | .sess_connect_path = NULL, |
123 | .sess_starttls = pop3driver_cached_starttls, | 126 | .sess_starttls = pop3driver_cached_starttls, |
124 | .sess_login = pop3driver_cached_login, | 127 | .sess_login = pop3driver_cached_login, |
125 | .sess_logout = pop3driver_cached_logout, | 128 | .sess_logout = pop3driver_cached_logout, |
126 | .sess_noop = pop3driver_cached_noop, | 129 | .sess_noop = pop3driver_cached_noop, |
127 | 130 | ||
128 | .sess_build_folder_name = NULL, | 131 | .sess_build_folder_name = NULL, |
@@ -130,44 +133,45 @@ static mailsession_driver local_pop3_cached_session_driver = { | |||
130 | .sess_delete_folder = NULL, | 133 | .sess_delete_folder = NULL, |
131 | .sess_rename_folder = NULL, | 134 | .sess_rename_folder = NULL, |
132 | .sess_check_folder = pop3driver_cached_check_folder, | 135 | .sess_check_folder = pop3driver_cached_check_folder, |
133 | .sess_examine_folder = NULL, | 136 | .sess_examine_folder = NULL, |
134 | .sess_select_folder = NULL, | 137 | .sess_select_folder = NULL, |
135 | .sess_expunge_folder = pop3driver_cached_expunge_folder, | 138 | .sess_expunge_folder = pop3driver_cached_expunge_folder, |
136 | .sess_status_folder = pop3driver_cached_status_folder, | 139 | .sess_status_folder = pop3driver_cached_status_folder, |
137 | .sess_messages_number = pop3driver_cached_messages_number, | 140 | .sess_messages_number = pop3driver_cached_messages_number, |
138 | .sess_recent_number = pop3driver_cached_recent_number, | 141 | .sess_recent_number = pop3driver_cached_recent_number, |
139 | .sess_unseen_number = pop3driver_cached_unseen_number, | 142 | .sess_unseen_number = pop3driver_cached_unseen_number, |
140 | .sess_list_folders = NULL, | 143 | .sess_list_folders = NULL, |
141 | .sess_lsub_folders = NULL, | 144 | .sess_lsub_folders = NULL, |
142 | .sess_subscribe_folder = NULL, | 145 | .sess_subscribe_folder = NULL, |
143 | .sess_unsubscribe_folder = NULL, | 146 | .sess_unsubscribe_folder = NULL, |
144 | 147 | ||
145 | .sess_append_message = NULL, | 148 | .sess_append_message = NULL, |
149 | .sess_append_message_flags = NULL, | ||
146 | .sess_copy_message = NULL, | 150 | .sess_copy_message = NULL, |
147 | .sess_move_message = NULL, | 151 | .sess_move_message = NULL, |
148 | 152 | ||
149 | .sess_get_messages_list = pop3driver_cached_get_messages_list, | 153 | .sess_get_messages_list = pop3driver_cached_get_messages_list, |
150 | .sess_get_envelopes_list = pop3driver_cached_get_envelopes_list, | 154 | .sess_get_envelopes_list = pop3driver_cached_get_envelopes_list, |
151 | .sess_remove_message = pop3driver_cached_remove_message, | 155 | .sess_remove_message = pop3driver_cached_remove_message, |
152 | #if 0 | 156 | #if 0 |
153 | .sess_search_messages = maildriver_generic_search_messages, | 157 | .sess_search_messages = maildriver_generic_search_messages, |
154 | #endif | 158 | #endif |
155 | 159 | ||
156 | .sess_get_message = pop3driver_cached_get_message, | 160 | .sess_get_message = pop3driver_cached_get_message, |
157 | .sess_get_message_by_uid = NULL, | 161 | .sess_get_message_by_uid = pop3driver_cached_get_message_by_uid, |
158 | }; | 162 | }; |
159 | 163 | ||
160 | mailsession_driver * pop3_cached_session_driver = | 164 | mailsession_driver * pop3_cached_session_driver = |
161 | &local_pop3_cached_session_driver; | 165 | &local_pop3_cached_session_driver; |
162 | 166 | ||
163 | #define ENV_NAME "env.db" | 167 | #define ENV_NAME "env.db" |
164 | #define FLAGS_NAME "flags.db" | 168 | #define FLAGS_NAME "flags.db" |
165 | 169 | ||
166 | 170 | ||
167 | static inline struct pop3_cached_session_state_data * | 171 | static inline struct pop3_cached_session_state_data * |
168 | get_cached_data(mailsession * session) | 172 | get_cached_data(mailsession * session) |
169 | { | 173 | { |
170 | return session->sess_data; | 174 | return session->sess_data; |
171 | } | 175 | } |
172 | 176 | ||
173 | static inline mailsession * get_ancestor(mailsession * session) | 177 | static inline mailsession * get_ancestor(mailsession * session) |
@@ -842,16 +846,54 @@ static int pop3driver_cached_get_message(mailsession * session, | |||
842 | int r; | 846 | int r; |
843 | 847 | ||
844 | msg_info = mailmessage_new(); | 848 | msg_info = mailmessage_new(); |
845 | if (msg_info == NULL) | 849 | if (msg_info == NULL) |
846 | return MAIL_ERROR_MEMORY; | 850 | return MAIL_ERROR_MEMORY; |
847 | 851 | ||
848 | r = mailmessage_init(msg_info, session, pop3_cached_message_driver, num, 0); | 852 | r = mailmessage_init(msg_info, session, pop3_cached_message_driver, num, 0); |
849 | if (r != MAIL_NO_ERROR) { | 853 | if (r != MAIL_NO_ERROR) { |
850 | mailmessage_free(msg_info); | 854 | mailmessage_free(msg_info); |
851 | return r; | 855 | return r; |
852 | } | 856 | } |
853 | 857 | ||
854 | * result = msg_info; | 858 | * result = msg_info; |
855 | 859 | ||
856 | return MAIL_NO_ERROR; | 860 | return MAIL_NO_ERROR; |
857 | } | 861 | } |
862 | |||
863 | static int pop3driver_cached_get_message_by_uid(mailsession * session, | ||
864 | const char * uid, mailmessage ** result) | ||
865 | { | ||
866 | mailpop3 * pop3; | ||
867 | struct mailpop3_msg_info * msg_info; | ||
868 | int found; | ||
869 | unsigned int i; | ||
870 | |||
871 | if (uid == NULL) | ||
872 | return MAIL_ERROR_INVAL; | ||
873 | |||
874 | pop3 = get_pop3_session(session); | ||
875 | |||
876 | found = 0; | ||
877 | |||
878 | /* iterate all messages and look for uid */ | ||
879 | for(i = 0 ; i < carray_count(pop3->pop3_msg_tab) ; i++) { | ||
880 | msg_info = carray_get(pop3->pop3_msg_tab, i); | ||
881 | |||
882 | if (msg_info == NULL) | ||
883 | continue; | ||
884 | |||
885 | if (msg_info->msg_deleted) | ||
886 | continue; | ||
887 | |||
888 | /* uid found, stop looking */ | ||
889 | if (strcmp(msg_info->msg_uidl, uid) == 0) { | ||
890 | found = 1; | ||
891 | break; | ||
892 | } | ||
893 | } | ||
894 | |||
895 | if (!found) | ||
896 | return MAIL_ERROR_MSG_NOT_FOUND; | ||
897 | |||
898 | return pop3driver_cached_get_message(session, msg_info->msg_index, result); | ||
899 | } | ||
diff --git a/kmicromail/libetpan/generic/pop3driver_message.c b/kmicromail/libetpan/generic/pop3driver_message.c index 77bd94c..357bb2e 100644 --- a/kmicromail/libetpan/generic/pop3driver_message.c +++ b/kmicromail/libetpan/generic/pop3driver_message.c | |||
@@ -26,32 +26,34 @@ | |||
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "pop3driver_message.h" | 36 | #include "pop3driver_message.h" |
37 | 37 | ||
38 | #include "mailmessage_tools.h" | 38 | #include "mailmessage_tools.h" |
39 | #include "pop3driver_tools.h" | 39 | #include "pop3driver_tools.h" |
40 | #include "pop3driver.h" | 40 | #include "pop3driver.h" |
41 | #include "mailpop3.h" | 41 | #include "mailpop3.h" |
42 | #include <stdlib.h> | ||
43 | #include <string.h> | ||
42 | 44 | ||
43 | static int pop3_prefetch(mailmessage * msg_info); | 45 | static int pop3_prefetch(mailmessage * msg_info); |
44 | 46 | ||
45 | static void pop3_prefetch_free(struct generic_message_t * msg); | 47 | static void pop3_prefetch_free(struct generic_message_t * msg); |
46 | 48 | ||
47 | static int pop3_initialize(mailmessage * msg_info); | 49 | static int pop3_initialize(mailmessage * msg_info); |
48 | 50 | ||
49 | static int pop3_fetch_header(mailmessage * msg_info, | 51 | static int pop3_fetch_header(mailmessage * msg_info, |
50 | char ** result, | 52 | char ** result, |
51 | size_t * result_len); | 53 | size_t * result_len); |
52 | 54 | ||
53 | static int pop3_fetch_size(mailmessage * msg_info, | 55 | static int pop3_fetch_size(mailmessage * msg_info, |
54 | size_t * result); | 56 | size_t * result); |
55 | 57 | ||
56 | static mailmessage_driver local_pop3_message_driver = { | 58 | static mailmessage_driver local_pop3_message_driver = { |
57 | .msg_name = "pop3", | 59 | .msg_name = "pop3", |
@@ -67,32 +69,44 @@ static mailmessage_driver local_pop3_message_driver = { | |||
67 | .msg_fetch = mailmessage_generic_fetch, | 69 | .msg_fetch = mailmessage_generic_fetch, |
68 | .msg_fetch_header = pop3_fetch_header, | 70 | .msg_fetch_header = pop3_fetch_header, |
69 | .msg_fetch_body = mailmessage_generic_fetch_body, | 71 | .msg_fetch_body = mailmessage_generic_fetch_body, |
70 | .msg_fetch_size = pop3_fetch_size, | 72 | .msg_fetch_size = pop3_fetch_size, |
71 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, | 73 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, |
72 | .msg_fetch_section = mailmessage_generic_fetch_section, | 74 | .msg_fetch_section = mailmessage_generic_fetch_section, |
73 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, | 75 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, |
74 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, | 76 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, |
75 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, | 77 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, |
76 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, | 78 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, |
77 | 79 | ||
78 | .msg_get_flags = NULL, | 80 | .msg_get_flags = NULL, |
79 | }; | 81 | }; |
80 | 82 | ||
81 | mailmessage_driver * pop3_message_driver = &local_pop3_message_driver; | 83 | mailmessage_driver * pop3_message_driver = &local_pop3_message_driver; |
82 | 84 | ||
85 | static inline struct pop3_session_state_data * | ||
86 | get_data(mailsession * session) | ||
87 | { | ||
88 | return session->sess_data; | ||
89 | } | ||
90 | |||
91 | |||
92 | static mailpop3 * get_pop3_session(mailsession * session) | ||
93 | { | ||
94 | return get_data(session)->pop3_session; | ||
95 | } | ||
96 | |||
83 | 97 | ||
84 | static int pop3_prefetch(mailmessage * msg_info) | 98 | static int pop3_prefetch(mailmessage * msg_info) |
85 | { | 99 | { |
86 | char * msg_content; | 100 | char * msg_content; |
87 | size_t msg_length; | 101 | size_t msg_length; |
88 | struct generic_message_t * msg; | 102 | struct generic_message_t * msg; |
89 | int r; | 103 | int r; |
90 | 104 | ||
91 | r = pop3driver_retr(msg_info->msg_session, msg_info->msg_index, | 105 | r = pop3driver_retr(msg_info->msg_session, msg_info->msg_index, |
92 | &msg_content, &msg_length); | 106 | &msg_content, &msg_length); |
93 | if (r != MAIL_NO_ERROR) | 107 | if (r != MAIL_NO_ERROR) |
94 | return r; | 108 | return r; |
95 | 109 | ||
96 | msg = msg_info->msg_data; | 110 | msg = msg_info->msg_data; |
97 | 111 | ||
98 | msg->msg_message = msg_content; | 112 | msg->msg_message = msg_content; |
@@ -100,40 +114,60 @@ static int pop3_prefetch(mailmessage * msg_info) | |||
100 | 114 | ||
101 | return MAIL_NO_ERROR; | 115 | return MAIL_NO_ERROR; |
102 | } | 116 | } |
103 | 117 | ||
104 | static void pop3_prefetch_free(struct generic_message_t * msg) | 118 | static void pop3_prefetch_free(struct generic_message_t * msg) |
105 | { | 119 | { |
106 | if (msg->msg_message != NULL) { | 120 | if (msg->msg_message != NULL) { |
107 | mmap_string_unref(msg->msg_message); | 121 | mmap_string_unref(msg->msg_message); |
108 | msg->msg_message = NULL; | 122 | msg->msg_message = NULL; |
109 | } | 123 | } |
110 | } | 124 | } |
111 | 125 | ||
112 | static int pop3_initialize(mailmessage * msg_info) | 126 | static int pop3_initialize(mailmessage * msg_info) |
113 | { | 127 | { |
114 | struct generic_message_t * msg; | 128 | struct generic_message_t * msg; |
115 | int r; | 129 | int r; |
130 | char * uid; | ||
131 | struct mailpop3_msg_info * info; | ||
132 | mailpop3 * pop3; | ||
133 | |||
134 | pop3 = get_pop3_session(msg_info->msg_session); | ||
135 | |||
136 | r = mailpop3_get_msg_info(pop3, msg_info->msg_index, &info); | ||
137 | switch (r) { | ||
138 | case MAILPOP3_NO_ERROR: | ||
139 | break; | ||
140 | default: | ||
141 | return pop3driver_pop3_error_to_mail_error(r); | ||
142 | } | ||
143 | |||
144 | uid = strdup(info->msg_uidl); | ||
145 | if (uid == NULL) | ||
146 | return MAIL_ERROR_MEMORY; | ||
116 | 147 | ||
117 | r = mailmessage_generic_initialize(msg_info); | 148 | r = mailmessage_generic_initialize(msg_info); |
118 | if (r != MAIL_NO_ERROR) | 149 | if (r != MAIL_NO_ERROR) { |
150 | free(uid); | ||
119 | return r; | 151 | return r; |
152 | } | ||
120 | 153 | ||
121 | msg = msg_info->msg_data; | 154 | msg = msg_info->msg_data; |
122 | msg->msg_prefetch = pop3_prefetch; | 155 | msg->msg_prefetch = pop3_prefetch; |
123 | msg->msg_prefetch_free = pop3_prefetch_free; | 156 | msg->msg_prefetch_free = pop3_prefetch_free; |
157 | msg_info->msg_uid = uid; | ||
124 | 158 | ||
125 | return MAIL_NO_ERROR; | 159 | return MAIL_NO_ERROR; |
126 | } | 160 | } |
127 | 161 | ||
128 | 162 | ||
129 | static int pop3_fetch_header(mailmessage * msg_info, | 163 | static int pop3_fetch_header(mailmessage * msg_info, |
130 | char ** result, | 164 | char ** result, |
131 | size_t * result_len) | 165 | size_t * result_len) |
132 | { | 166 | { |
133 | struct generic_message_t * msg; | 167 | struct generic_message_t * msg; |
134 | char * headers; | 168 | char * headers; |
135 | size_t headers_length; | 169 | size_t headers_length; |
136 | int r; | 170 | int r; |
137 | 171 | ||
138 | msg = msg_info->msg_data; | 172 | msg = msg_info->msg_data; |
139 | 173 | ||
diff --git a/kmicromail/libetpan/generic/pop3storage.c b/kmicromail/libetpan/generic/pop3storage.c index 8e7a94e..375aeaf 100644 --- a/kmicromail/libetpan/generic/pop3storage.c +++ b/kmicromail/libetpan/generic/pop3storage.c | |||
@@ -55,33 +55,33 @@ static void pop3_mailstorage_uninitialize(struct mailstorage * storage); | |||
55 | static mailstorage_driver pop3_mailstorage_driver = { | 55 | static mailstorage_driver pop3_mailstorage_driver = { |
56 | .sto_name = "pop3", | 56 | .sto_name = "pop3", |
57 | .sto_connect = pop3_mailstorage_connect, | 57 | .sto_connect = pop3_mailstorage_connect, |
58 | .sto_get_folder_session = pop3_mailstorage_get_folder_session, | 58 | .sto_get_folder_session = pop3_mailstorage_get_folder_session, |
59 | .sto_uninitialize = pop3_mailstorage_uninitialize, | 59 | .sto_uninitialize = pop3_mailstorage_uninitialize, |
60 | }; | 60 | }; |
61 | 61 | ||
62 | int pop3_mailstorage_init(struct mailstorage * storage, | 62 | int pop3_mailstorage_init(struct mailstorage * storage, |
63 | char * pop3_servername, uint16_t pop3_port, | 63 | char * pop3_servername, uint16_t pop3_port, |
64 | char * pop3_command, | 64 | char * pop3_command, |
65 | int pop3_connection_type, int pop3_auth_type, | 65 | int pop3_connection_type, int pop3_auth_type, |
66 | char * pop3_login, char * pop3_password, | 66 | char * pop3_login, char * pop3_password, |
67 | int pop3_cached, char * pop3_cache_directory, char * pop3_flags_directory) | 67 | int pop3_cached, char * pop3_cache_directory, char * pop3_flags_directory) |
68 | { | 68 | { |
69 | struct pop3_mailstorage * pop3_storage; | 69 | struct pop3_mailstorage * pop3_storage; |
70 | 70 | ||
71 | pop3_storage = malloc(sizeof(struct pop3_mailstorage)); | 71 | pop3_storage = malloc(sizeof(* pop3_storage)); |
72 | if (pop3_storage == NULL) | 72 | if (pop3_storage == NULL) |
73 | goto err; | 73 | goto err; |
74 | 74 | ||
75 | pop3_storage->pop3_servername = strdup(pop3_servername); | 75 | pop3_storage->pop3_servername = strdup(pop3_servername); |
76 | if (pop3_storage->pop3_servername == NULL) | 76 | if (pop3_storage->pop3_servername == NULL) |
77 | goto free; | 77 | goto free; |
78 | 78 | ||
79 | pop3_storage->pop3_connection_type = pop3_connection_type; | 79 | pop3_storage->pop3_connection_type = pop3_connection_type; |
80 | 80 | ||
81 | if (pop3_port == 0) { | 81 | if (pop3_port == 0) { |
82 | switch (pop3_connection_type) { | 82 | switch (pop3_connection_type) { |
83 | case CONNECTION_TYPE_PLAIN: | 83 | case CONNECTION_TYPE_PLAIN: |
84 | case CONNECTION_TYPE_TRY_STARTTLS: | 84 | case CONNECTION_TYPE_TRY_STARTTLS: |
85 | case CONNECTION_TYPE_STARTTLS: | 85 | case CONNECTION_TYPE_STARTTLS: |
86 | case CONNECTION_TYPE_COMMAND: | 86 | case CONNECTION_TYPE_COMMAND: |
87 | case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: | 87 | case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: |