summaryrefslogtreecommitdiffabout
path: root/kmicromail
Unidiff
Diffstat (limited to 'kmicromail') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/generic/imapdriver.c28
-rw-r--r--kmicromail/libetpan/generic/imapdriver_cached.c16
-rw-r--r--kmicromail/libetpan/generic/imapdriver_cached_message.c2
-rw-r--r--kmicromail/libetpan/generic/imapdriver_tools.c38
-rw-r--r--kmicromail/libetpan/generic/imapdriver_tools.h3
-rw-r--r--kmicromail/libetpan/generic/imapstorage.c2
-rw-r--r--kmicromail/libetpan/generic/maildirdriver.c51
-rw-r--r--kmicromail/libetpan/generic/maildirdriver_cached.c78
-rw-r--r--kmicromail/libetpan/generic/maildirdriver_cached_message.c88
-rw-r--r--kmicromail/libetpan/generic/maildirdriver_message.c58
-rw-r--r--kmicromail/libetpan/generic/maildirstorage.c3
-rw-r--r--kmicromail/libetpan/generic/maildirstorage.h2
-rw-r--r--kmicromail/libetpan/generic/maildriver.c10
-rw-r--r--kmicromail/libetpan/generic/maildriver.h3
-rw-r--r--kmicromail/libetpan/generic/maildriver_types.h2
-rw-r--r--kmicromail/libetpan/generic/mailfolder.c7
-rw-r--r--kmicromail/libetpan/generic/mailfolder.h3
-rw-r--r--kmicromail/libetpan/generic/mailstorage.c7
-rw-r--r--kmicromail/libetpan/generic/mailstorage.h3
-rw-r--r--kmicromail/libetpan/generic/mboxdriver.c10
-rw-r--r--kmicromail/libetpan/generic/mboxdriver_cached.c90
-rw-r--r--kmicromail/libetpan/generic/mboxdriver_cached_message.c3
-rw-r--r--kmicromail/libetpan/generic/mboxdriver_message.c6
-rw-r--r--kmicromail/libetpan/generic/mboxdriver_tools.c3
-rw-r--r--kmicromail/libetpan/generic/mboxstorage.c2
-rw-r--r--kmicromail/libetpan/generic/mhdriver.c11
-rw-r--r--kmicromail/libetpan/generic/mhdriver_cached.c93
-rw-r--r--kmicromail/libetpan/generic/mhdriver_cached_message.c4
-rw-r--r--kmicromail/libetpan/generic/mhdriver_message.c5
-rw-r--r--kmicromail/libetpan/generic/mhdriver_tools.c5
-rw-r--r--kmicromail/libetpan/generic/mhstorage.c2
-rw-r--r--kmicromail/libetpan/generic/nntpdriver.c10
-rw-r--r--kmicromail/libetpan/generic/nntpdriver_cached.c10
-rw-r--r--kmicromail/libetpan/generic/nntpstorage.c2
-rw-r--r--kmicromail/libetpan/generic/pop3driver.c1
-rw-r--r--kmicromail/libetpan/generic/pop3driver_cached.c44
-rw-r--r--kmicromail/libetpan/generic/pop3driver_message.c36
-rw-r--r--kmicromail/libetpan/generic/pop3storage.c2
-rw-r--r--kmicromail/libetpan/imap/mailimap.c2
-rw-r--r--kmicromail/libetpan/imap/mailimap_keywords.c2
-rw-r--r--kmicromail/libetpan/imf/mailimf.c2
-rw-r--r--kmicromail/libetpan/include/libetpan/libetpan.h12
-rw-r--r--kmicromail/libetpan/include/libetpan/maildir.h7
-rw-r--r--kmicromail/libetpan/include/libetpan/maildirstorage.h2
-rw-r--r--kmicromail/libetpan/include/libetpan/maildriver.h3
-rw-r--r--kmicromail/libetpan/include/libetpan/maildriver_types.h2
-rw-r--r--kmicromail/libetpan/include/libetpan/mailfolder.h3
-rw-r--r--kmicromail/libetpan/include/libetpan/mailmbox.h4
-rw-r--r--kmicromail/libetpan/include/libetpan/mailmbox_types.h1
-rw-r--r--kmicromail/libetpan/include/libetpan/mailmh.h7
-rw-r--r--kmicromail/libetpan/include/libetpan/mailstorage.h3
-rw-r--r--kmicromail/libetpan/maildir/maildir.c33
-rw-r--r--kmicromail/libetpan/maildir/maildir.h7
-rw-r--r--kmicromail/libetpan/mbox/mailmbox.c21
-rw-r--r--kmicromail/libetpan/mbox/mailmbox.h4
-rw-r--r--kmicromail/libetpan/mbox/mailmbox_types.c3
-rw-r--r--kmicromail/libetpan/mbox/mailmbox_types.h1
-rw-r--r--kmicromail/libetpan/mh/mailmh.c28
-rw-r--r--kmicromail/libetpan/mh/mailmh.h7
-rw-r--r--kmicromail/libetpan/mime/mailmime_decode.c24
-rw-r--r--kmicromail/libetpan/mime/mailmime_write.c2
-rw-r--r--kmicromail/libetpan/smtp/mailsmtp.c2
-rw-r--r--kmicromail/libetpan/smtp/mailsmtp_helper.c12
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp58
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp46
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp47
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.h2
-rw-r--r--kmicromail/opiemail.cpp47
68 files changed, 1025 insertions, 112 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
@@ -1,287 +1,290 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "imapdriver.h" 36#include "imapdriver.h"
37 37
38#include "mail.h" 38#include "mail.h"
39#include "imapdriver_tools.h" 39#include "imapdriver_tools.h"
40#include "mailmessage.h" 40#include "mailmessage.h"
41#include "imapdriver_message.h" 41#include "imapdriver_message.h"
42#include "imapdriver_types.h" 42#include "imapdriver_types.h"
43#include "maildriver.h" 43#include "maildriver.h"
44#include "maildriver_tools.h" 44#include "maildriver_tools.h"
45#include "generic_cache.h" 45#include "generic_cache.h"
46 46
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50static int imapdriver_initialize(mailsession * session); 50static int imapdriver_initialize(mailsession * session);
51 51
52static void imapdriver_uninitialize(mailsession * session); 52static void imapdriver_uninitialize(mailsession * session);
53 53
54static int imapdriver_connect_stream(mailsession * session, mailstream * s); 54static int imapdriver_connect_stream(mailsession * session, mailstream * s);
55 55
56static int imapdriver_starttls(mailsession * session); 56static int imapdriver_starttls(mailsession * session);
57 57
58static int imapdriver_login(mailsession * session, 58static int imapdriver_login(mailsession * session,
59 char * userid, char * password); 59 char * userid, char * password);
60 60
61static int imapdriver_logout(mailsession * session); 61static int imapdriver_logout(mailsession * session);
62 62
63static int imapdriver_noop(mailsession * session); 63static int imapdriver_noop(mailsession * session);
64 64
65static int imapdriver_build_folder_name(mailsession * session, char * mb, 65static int imapdriver_build_folder_name(mailsession * session, char * mb,
66 char * name, char ** result); 66 char * name, char ** result);
67 67
68static int imapdriver_create_folder(mailsession * session, char * mb); 68static int imapdriver_create_folder(mailsession * session, char * mb);
69 69
70static int imapdriver_delete_folder(mailsession * session, char * mb); 70static int imapdriver_delete_folder(mailsession * session, char * mb);
71 71
72static int imapdriver_rename_folder(mailsession * session, char * mb, 72static int imapdriver_rename_folder(mailsession * session, char * mb,
73 char * new_name); 73 char * new_name);
74 74
75static int imapdriver_check_folder(mailsession * session); 75static int imapdriver_check_folder(mailsession * session);
76 76
77static int imapdriver_examine_folder(mailsession * session, char * mb); 77static int imapdriver_examine_folder(mailsession * session, char * mb);
78 78
79static int imapdriver_select_folder(mailsession * session, char * mb); 79static int imapdriver_select_folder(mailsession * session, char * mb);
80static int imapdriver_expunge_folder(mailsession * session); 80static int imapdriver_expunge_folder(mailsession * session);
81 81
82static int imapdriver_status_folder(mailsession * session, char * mb, 82static int imapdriver_status_folder(mailsession * session, char * mb,
83 uint32_t * result_messages, uint32_t * result_recent, 83 uint32_t * result_messages, uint32_t * result_recent,
84 uint32_t * result_unseen); 84 uint32_t * result_unseen);
85 85
86static int imapdriver_messages_number(mailsession * session, char * mb, 86static int imapdriver_messages_number(mailsession * session, char * mb,
87 uint32_t * result); 87 uint32_t * result);
88 88
89static int imapdriver_recent_number(mailsession * session, char * mb, 89static int imapdriver_recent_number(mailsession * session, char * mb,
90 uint32_t * result); 90 uint32_t * result);
91 91
92static int imapdriver_unseen_number(mailsession * session, char * mb, 92static int imapdriver_unseen_number(mailsession * session, char * mb,
93 uint32_t * result); 93 uint32_t * result);
94 94
95static int imapdriver_list_folders(mailsession * session, char * mb, 95static int imapdriver_list_folders(mailsession * session, char * mb,
96 struct mail_list ** result); 96 struct mail_list ** result);
97static int imapdriver_lsub_folders(mailsession * session, char * mb, 97static int imapdriver_lsub_folders(mailsession * session, char * mb,
98 struct mail_list ** result); 98 struct mail_list ** result);
99static int imapdriver_subscribe_folder(mailsession * session, char * mb); 99static int imapdriver_subscribe_folder(mailsession * session, char * mb);
100static int imapdriver_unsubscribe_folder(mailsession * session, char * mb); 100static int imapdriver_unsubscribe_folder(mailsession * session, char * mb);
101static int imapdriver_append_message(mailsession * session, 101static int imapdriver_append_message(mailsession * session,
102 char * message, size_t size); 102 char * message, size_t size);
103static int imapdriver_append_message_flags(mailsession * session,
104 char * message, size_t size, struct mail_flags * flags);
103static int imapdriver_copy_message(mailsession * session, 105static int imapdriver_copy_message(mailsession * session,
104 uint32_t num, char * mb); 106 uint32_t num, char * mb);
105 107
106static int imapdriver_get_messages_list(mailsession * session, 108static int imapdriver_get_messages_list(mailsession * session,
107 struct mailmessage_list ** result); 109 struct mailmessage_list ** result);
108 110
109static int 111static int
110imapdriver_get_envelopes_list(mailsession * session, 112imapdriver_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
115static int imapdriver_search_messages(mailsession * session, char * charset, 117static 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
119 121
120static int imapdriver_get_message(mailsession * session, 122static int imapdriver_get_message(mailsession * session,
121 uint32_t num, mailmessage ** result); 123 uint32_t num, mailmessage ** result);
122 124
123static int imapdriver_get_message_by_uid(mailsession * session, 125static int imapdriver_get_message_by_uid(mailsession * session,
124 const char * uid, 126 const char * uid,
125 mailmessage ** result); 127 mailmessage ** result);
126 128
127static mailsession_driver local_imap_session_driver = { 129static mailsession_driver local_imap_session_driver = {
128 .sess_name = "imap", 130 .sess_name = "imap",
129 131
130 .sess_initialize = imapdriver_initialize, 132 .sess_initialize = imapdriver_initialize,
131 .sess_uninitialize = imapdriver_uninitialize, 133 .sess_uninitialize = imapdriver_uninitialize,
132 134
133 .sess_parameters = NULL, 135 .sess_parameters = NULL,
134 136
135 .sess_connect_stream = imapdriver_connect_stream, 137 .sess_connect_stream = imapdriver_connect_stream,
136 .sess_connect_path = NULL, 138 .sess_connect_path = NULL,
137 .sess_starttls = imapdriver_starttls, 139 .sess_starttls = imapdriver_starttls,
138 .sess_login = imapdriver_login, 140 .sess_login = imapdriver_login,
139 .sess_logout = imapdriver_logout, 141 .sess_logout = imapdriver_logout,
140 .sess_noop = imapdriver_noop, 142 .sess_noop = imapdriver_noop,
141 143
142 .sess_build_folder_name = imapdriver_build_folder_name, 144 .sess_build_folder_name = imapdriver_build_folder_name,
143 .sess_create_folder = imapdriver_create_folder, 145 .sess_create_folder = imapdriver_create_folder,
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
174mailsession_driver * imap_session_driver = &local_imap_session_driver; 177mailsession_driver * imap_session_driver = &local_imap_session_driver;
175 178
176static inline struct imap_session_state_data * get_data(mailsession * session) 179static inline struct imap_session_state_data * get_data(mailsession * session)
177{ 180{
178 return session->sess_data; 181 return session->sess_data;
179} 182}
180 183
181static mailimap * get_imap_session(mailsession * session) 184static mailimap * get_imap_session(mailsession * session)
182{ 185{
183 return get_data(session)->imap_session; 186 return get_data(session)->imap_session;
184} 187}
185 188
186static int imapdriver_initialize(mailsession * session) 189static int imapdriver_initialize(mailsession * session)
187{ 190{
188 struct imap_session_state_data * data; 191 struct imap_session_state_data * data;
189 mailimap * imap; 192 mailimap * imap;
190 struct mail_flags_store * flags_store; 193 struct mail_flags_store * flags_store;
191 194
192 imap = mailimap_new(0, NULL); 195 imap = mailimap_new(0, NULL);
193 if (imap == NULL) 196 if (imap == NULL)
194 goto err; 197 goto err;
195 198
196 flags_store = mail_flags_store_new(); 199 flags_store = mail_flags_store_new();
197 if (flags_store == NULL) 200 if (flags_store == NULL)
198 goto free_session; 201 goto free_session;
199 202
200 data = malloc(sizeof(* data)); 203 data = malloc(sizeof(* data));
201 if (data == NULL) 204 if (data == NULL)
202 goto free_flags_store; 205 goto free_flags_store;
203 206
204 data->imap_mailbox = NULL; 207 data->imap_mailbox = NULL;
205 data->imap_session = imap; 208 data->imap_session = imap;
206 data->imap_flags_store = flags_store; 209 data->imap_flags_store = flags_store;
207 210
208 session->sess_data = data; 211 session->sess_data = data;
209 212
210 return MAIL_NO_ERROR; 213 return MAIL_NO_ERROR;
211 214
212 free_flags_store: 215 free_flags_store:
213 mail_flags_store_free(flags_store); 216 mail_flags_store_free(flags_store);
214 free_session: 217 free_session:
215 mailimap_free(imap); 218 mailimap_free(imap);
216 err: 219 err:
217 return MAIL_ERROR_MEMORY; 220 return MAIL_ERROR_MEMORY;
218} 221}
219 222
220static void imap_flags_store_process(mailimap * imap, 223static void imap_flags_store_process(mailimap * imap,
221 struct mail_flags_store * flags_store) 224 struct mail_flags_store * flags_store)
222{ 225{
223 unsigned int i; 226 unsigned int i;
224 int r; 227 int r;
225 mailmessage * first; 228 mailmessage * first;
226 mailmessage * last; 229 mailmessage * last;
227 230
228 mail_flags_store_sort(flags_store); 231 mail_flags_store_sort(flags_store);
229 232
230 if (carray_count(flags_store->fls_tab) == 0) 233 if (carray_count(flags_store->fls_tab) == 0)
231 return; 234 return;
232 235
233 first = carray_get(flags_store->fls_tab, 0); 236 first = carray_get(flags_store->fls_tab, 0);
234 last = first; 237 last = first;
235 238
236 for(i = 1 ; i < carray_count(flags_store->fls_tab) ; i ++) { 239 for(i = 1 ; i < carray_count(flags_store->fls_tab) ; i ++) {
237 mailmessage * msg; 240 mailmessage * msg;
238 241
239 msg = carray_get(flags_store->fls_tab, i); 242 msg = carray_get(flags_store->fls_tab, i);
240 243
241 if (last->msg_index + 1 == msg->msg_index) { 244 if (last->msg_index + 1 == msg->msg_index) {
242 r = mail_flags_compare(first->msg_flags, msg->msg_flags); 245 r = mail_flags_compare(first->msg_flags, msg->msg_flags);
243 if (r == 0) { 246 if (r == 0) {
244 last = msg; 247 last = msg;
245 continue; 248 continue;
246 } 249 }
247 } 250 }
248 251
249 r = imap_store_flags(imap, first->msg_index, 252 r = imap_store_flags(imap, first->msg_index,
250 last->msg_index, first->msg_flags); 253 last->msg_index, first->msg_flags);
251 254
252 first = msg; 255 first = msg;
253 last = msg; 256 last = msg;
254 } 257 }
255 258
256 r = imap_store_flags(imap, first->msg_index, last->msg_index, 259 r = imap_store_flags(imap, first->msg_index, last->msg_index,
257 first->msg_flags); 260 first->msg_flags);
258 261
259 mail_flags_store_clear(flags_store); 262 mail_flags_store_clear(flags_store);
260} 263}
261 264
262static void imapdriver_uninitialize(mailsession * session) 265static void imapdriver_uninitialize(mailsession * session)
263{ 266{
264 struct imap_session_state_data * data; 267 struct imap_session_state_data * data;
265 268
266 data = get_data(session); 269 data = get_data(session);
267 270
268 imap_flags_store_process(data->imap_session, 271 imap_flags_store_process(data->imap_session,
269 data->imap_flags_store); 272 data->imap_flags_store);
270 mail_flags_store_free(data->imap_flags_store); 273 mail_flags_store_free(data->imap_flags_store);
271 274
272 mailimap_free(data->imap_session); 275 mailimap_free(data->imap_session);
273 if (data->imap_mailbox != NULL) 276 if (data->imap_mailbox != NULL)
274 free(data->imap_mailbox); 277 free(data->imap_mailbox);
275 free(data); 278 free(data);
276 279
277 session->sess_data = NULL; 280 session->sess_data = NULL;
278} 281}
279 282
280static int imapdriver_connect_stream(mailsession * session, mailstream * s) 283static int imapdriver_connect_stream(mailsession * session, mailstream * s)
281{ 284{
282 int r; 285 int r;
283 286
284 r = mailimap_connect(get_imap_session(session), s); 287 r = mailimap_connect(get_imap_session(session), s);
285 288
286 return imap_error_to_mail_error(r); 289 return imap_error_to_mail_error(r);
287} 290}
@@ -646,256 +649,281 @@ static int imapdriver_recent_number(mailsession * session, char * mb,
646 uint32_t recent; 649 uint32_t recent;
647 uint32_t unseen; 650 uint32_t unseen;
648 int r; 651 int r;
649 652
650 r = imapdriver_status_folder(session, mb, &messages, &recent, &unseen); 653 r = imapdriver_status_folder(session, mb, &messages, &recent, &unseen);
651 if (r != MAIL_NO_ERROR) 654 if (r != MAIL_NO_ERROR)
652 return r; 655 return r;
653 656
654 * result = recent; 657 * result = recent;
655 658
656 return MAIL_NO_ERROR; 659 return MAIL_NO_ERROR;
657} 660}
658 661
659static int imapdriver_unseen_number(mailsession * session, char * mb, 662static int imapdriver_unseen_number(mailsession * session, char * mb,
660 uint32_t * result) 663 uint32_t * result)
661{ 664{
662 uint32_t messages; 665 uint32_t messages;
663 uint32_t recent; 666 uint32_t recent;
664 uint32_t unseen; 667 uint32_t unseen;
665 int r; 668 int r;
666 669
667 r = imapdriver_status_folder(session, mb, &messages, &recent, &unseen); 670 r = imapdriver_status_folder(session, mb, &messages, &recent, &unseen);
668 if (r != MAIL_NO_ERROR) 671 if (r != MAIL_NO_ERROR)
669 return r; 672 return r;
670 673
671 * result = unseen; 674 * result = unseen;
672 675
673 return MAIL_NO_ERROR; 676 return MAIL_NO_ERROR;
674} 677}
675 678
676enum { 679enum {
677 IMAP_LIST, IMAP_LSUB 680 IMAP_LIST, IMAP_LSUB
678}; 681};
679 682
680static int imapdriver_list_lsub_folders(mailsession * session, int type, 683static int imapdriver_list_lsub_folders(mailsession * session, int type,
681 char * mb, 684 char * mb,
682 struct mail_list ** result) 685 struct mail_list ** result)
683{ 686{
684 clist * imap_list; 687 clist * imap_list;
685 struct mail_list * resp; 688 struct mail_list * resp;
686 int r; 689 int r;
687 int res; 690 int res;
688 691
689 switch (type) { 692 switch (type) {
690 case IMAP_LIST: 693 case IMAP_LIST:
691 r = mailimap_list(get_imap_session(session), mb, 694 r = mailimap_list(get_imap_session(session), mb,
692 "*", &imap_list); 695 "*", &imap_list);
693 break; 696 break;
694 case IMAP_LSUB: 697 case IMAP_LSUB:
695 r = mailimap_lsub(get_imap_session(session), mb, 698 r = mailimap_lsub(get_imap_session(session), mb,
696 "*", &imap_list); 699 "*", &imap_list);
697 break; 700 break;
698 default: 701 default:
699 res = MAIL_ERROR_LIST; 702 res = MAIL_ERROR_LIST;
700 goto err; 703 goto err;
701 } 704 }
702 705
703 switch (r) { 706 switch (r) {
704 case MAILIMAP_NO_ERROR: 707 case MAILIMAP_NO_ERROR:
705 break; 708 break;
706 default: 709 default:
707 res = imap_error_to_mail_error(r); 710 res = imap_error_to_mail_error(r);
708 goto err; 711 goto err;
709 } 712 }
710 713
711 r = imap_list_to_list(imap_list, &resp); 714 r = imap_list_to_list(imap_list, &resp);
712 if (r != MAIL_NO_ERROR) { 715 if (r != MAIL_NO_ERROR) {
713 mailimap_list_result_free(imap_list); 716 mailimap_list_result_free(imap_list);
714 res = r; 717 res = r;
715 goto err; 718 goto err;
716 } 719 }
717 720
718 mailimap_list_result_free(imap_list); 721 mailimap_list_result_free(imap_list);
719 722
720 * result = resp; 723 * result = resp;
721 724
722 return MAIL_NO_ERROR; 725 return MAIL_NO_ERROR;
723 726
724 err: 727 err:
725 return res; 728 return res;
726} 729}
727 730
728static int imapdriver_list_folders(mailsession * session, char * mb, 731static int imapdriver_list_folders(mailsession * session, char * mb,
729 struct mail_list ** result) 732 struct mail_list ** result)
730{ 733{
731 return imapdriver_list_lsub_folders(session, IMAP_LIST, mb, 734 return imapdriver_list_lsub_folders(session, IMAP_LIST, mb,
732 result); 735 result);
733} 736}
734 737
735static int imapdriver_lsub_folders(mailsession * session, char * mb, 738static int imapdriver_lsub_folders(mailsession * session, char * mb,
736 struct mail_list ** result) 739 struct mail_list ** result)
737{ 740{
738 return imapdriver_list_lsub_folders(session, IMAP_LSUB, mb, 741 return imapdriver_list_lsub_folders(session, IMAP_LSUB, mb,
739 result); 742 result);
740} 743}
741 744
742static int imapdriver_subscribe_folder(mailsession * session, char * mb) 745static int imapdriver_subscribe_folder(mailsession * session, char * mb)
743{ 746{
744 int r; 747 int r;
745 748
746 r = mailimap_subscribe(get_imap_session(session), mb); 749 r = mailimap_subscribe(get_imap_session(session), mb);
747 750
748 return imap_error_to_mail_error(r); 751 return imap_error_to_mail_error(r);
749} 752}
750 753
751static int imapdriver_unsubscribe_folder(mailsession * session, char * mb) 754static int imapdriver_unsubscribe_folder(mailsession * session, char * mb)
752{ 755{
753 int r; 756 int r;
754 757
755 r = mailimap_unsubscribe(get_imap_session(session), mb); 758 r = mailimap_unsubscribe(get_imap_session(session), mb);
756 759
757 return imap_error_to_mail_error(r); 760 return imap_error_to_mail_error(r);
758} 761}
759 762
760/* messages operations */ 763/* messages operations */
761 764
762static int imapdriver_append_message(mailsession * session, 765static 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
777static 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
774static int imapdriver_copy_message(mailsession * session, 802static 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);
790 818
791 return imap_error_to_mail_error(r); 819 return imap_error_to_mail_error(r);
792 820
793 err: 821 err:
794 return res; 822 return res;
795} 823}
796 824
797static int imapdriver_get_messages_list(mailsession * session, 825static int imapdriver_get_messages_list(mailsession * session,
798 struct mailmessage_list ** result) 826 struct mailmessage_list ** result)
799{ 827{
800 return imap_get_messages_list(get_imap_session(session), 828 return imap_get_messages_list(get_imap_session(session),
801 session, imap_message_driver, 1, 829 session, imap_message_driver, 1,
802 result); 830 result);
803} 831}
804 832
805 833
806 834
807static int 835static int
808imapdriver_get_envelopes_list(mailsession * session, 836imapdriver_get_envelopes_list(mailsession * session,
809 struct mailmessage_list * env_list) 837 struct mailmessage_list * env_list)
810{ 838{
811 struct mailimap_set * set; 839 struct mailimap_set * set;
812 struct mailimap_fetch_att * fetch_att; 840 struct mailimap_fetch_att * fetch_att;
813 struct mailimap_fetch_type * fetch_type; 841 struct mailimap_fetch_type * fetch_type;
814 int res; 842 int res;
815 clist * fetch_result; 843 clist * fetch_result;
816 int r; 844 int r;
817 uint32_t exists; 845 uint32_t exists;
818 clist * msg_list; 846 clist * msg_list;
819 847
820 if (get_imap_session(session)->imap_selection_info == NULL) { 848 if (get_imap_session(session)->imap_selection_info == NULL) {
821 res = MAIL_ERROR_BAD_STATE; 849 res = MAIL_ERROR_BAD_STATE;
822 goto err; 850 goto err;
823 } 851 }
824 852
825 imap_flags_store_process(get_imap_session(session), 853 imap_flags_store_process(get_imap_session(session),
826 get_data(session)->imap_flags_store); 854 get_data(session)->imap_flags_store);
827 855
828 exists = get_imap_session(session)->imap_selection_info->sel_exists; 856 exists = get_imap_session(session)->imap_selection_info->sel_exists;
829 857
830 if (exists == 0) 858 if (exists == 0)
831 return MAIL_NO_ERROR; 859 return MAIL_NO_ERROR;
832 860
833 fetch_type = mailimap_fetch_type_new_fetch_att_list_empty(); 861 fetch_type = mailimap_fetch_type_new_fetch_att_list_empty();
834 if (fetch_type == NULL) { 862 if (fetch_type == NULL) {
835 res = MAIL_ERROR_MEMORY; 863 res = MAIL_ERROR_MEMORY;
836 goto err; 864 goto err;
837 } 865 }
838 866
839 fetch_att = mailimap_fetch_att_new_uid(); 867 fetch_att = mailimap_fetch_att_new_uid();
840 if (fetch_att == NULL) { 868 if (fetch_att == NULL) {
841 res = MAIL_ERROR_MEMORY; 869 res = MAIL_ERROR_MEMORY;
842 goto free_fetch_type; 870 goto free_fetch_type;
843 } 871 }
844 872
845 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); 873 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
846 if (r != MAILIMAP_NO_ERROR) { 874 if (r != MAILIMAP_NO_ERROR) {
847 mailimap_fetch_att_free(fetch_att); 875 mailimap_fetch_att_free(fetch_att);
848 res = MAIL_ERROR_MEMORY; 876 res = MAIL_ERROR_MEMORY;
849 goto free_fetch_type; 877 goto free_fetch_type;
850 } 878 }
851 879
852 fetch_att = mailimap_fetch_att_new_flags(); 880 fetch_att = mailimap_fetch_att_new_flags();
853 if (fetch_att == NULL) { 881 if (fetch_att == NULL) {
854 res = MAIL_ERROR_MEMORY; 882 res = MAIL_ERROR_MEMORY;
855 goto free_fetch_type; 883 goto free_fetch_type;
856 } 884 }
857 885
858 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); 886 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
859 if (r != MAILIMAP_NO_ERROR) { 887 if (r != MAILIMAP_NO_ERROR) {
860 mailimap_fetch_att_free(fetch_att); 888 mailimap_fetch_att_free(fetch_att);
861 res = MAIL_ERROR_MEMORY; 889 res = MAIL_ERROR_MEMORY;
862 goto free_fetch_type; 890 goto free_fetch_type;
863 } 891 }
864 892
865 r = imap_add_envelope_fetch_att(fetch_type); 893 r = imap_add_envelope_fetch_att(fetch_type);
866 if (r != MAIL_NO_ERROR) { 894 if (r != MAIL_NO_ERROR) {
867 res = r; 895 res = r;
868 goto free_fetch_type; 896 goto free_fetch_type;
869 } 897 }
870 898
871 r = maildriver_env_list_to_msg_list(env_list, &msg_list); 899 r = maildriver_env_list_to_msg_list(env_list, &msg_list);
872 if (r != MAIL_NO_ERROR) { 900 if (r != MAIL_NO_ERROR) {
873 res = MAIL_ERROR_MEMORY; 901 res = MAIL_ERROR_MEMORY;
874 goto free_fetch_type; 902 goto free_fetch_type;
875 } 903 }
876 904
877 if (clist_begin(msg_list) == NULL) { 905 if (clist_begin(msg_list) == NULL) {
878 /* no need to fetch envelopes */ 906 /* no need to fetch envelopes */
879 907
880 mailimap_fetch_type_free(fetch_type); 908 mailimap_fetch_type_free(fetch_type);
881 clist_free(msg_list); 909 clist_free(msg_list);
882 return MAIL_NO_ERROR; 910 return MAIL_NO_ERROR;
883 } 911 }
884 912
885 r = msg_list_to_imap_set(msg_list, &set); 913 r = msg_list_to_imap_set(msg_list, &set);
886 if (r != MAIL_NO_ERROR) { 914 if (r != MAIL_NO_ERROR) {
887 clist_foreach(msg_list, (clist_func) free, NULL); 915 clist_foreach(msg_list, (clist_func) free, NULL);
888 clist_free(msg_list); 916 clist_free(msg_list);
889 res = MAIL_ERROR_MEMORY; 917 res = MAIL_ERROR_MEMORY;
890 goto free_fetch_type; 918 goto free_fetch_type;
891 } 919 }
892 clist_foreach(msg_list, (clist_func) free, NULL); 920 clist_foreach(msg_list, (clist_func) free, NULL);
893 clist_free(msg_list); 921 clist_free(msg_list);
894 922
895 r = mailimap_uid_fetch(get_imap_session(session), set, 923 r = mailimap_uid_fetch(get_imap_session(session), set,
896 fetch_type, &fetch_result); 924 fetch_type, &fetch_result);
897 925
898 mailimap_fetch_type_free(fetch_type); 926 mailimap_fetch_type_free(fetch_type);
899 mailimap_set_free(set); 927 mailimap_set_free(set);
900 928
901 switch (r) { 929 switch (r) {
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
@@ -1,295 +1,298 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "imapdriver_cached.h" 36#include "imapdriver_cached.h"
37 37
38#include "libetpan-config.h" 38#include "libetpan-config.h"
39 39
40#include <stdio.h> 40#include <stdio.h>
41#include <sys/types.h> 41#include <sys/types.h>
42#include <sys/stat.h> 42#include <sys/stat.h>
43#include <fcntl.h> 43#include <fcntl.h>
44#include <string.h> 44#include <string.h>
45#include <unistd.h> 45#include <unistd.h>
46#include <stdlib.h> 46#include <stdlib.h>
47 47
48#include "mail.h" 48#include "mail.h"
49#include "imapdriver_tools.h" 49#include "imapdriver_tools.h"
50#include "mail_cache_db.h" 50#include "mail_cache_db.h"
51#include "mailmessage.h" 51#include "mailmessage.h"
52#include "imapdriver_cached_message.h" 52#include "imapdriver_cached_message.h"
53#include "maildriver.h" 53#include "maildriver.h"
54#include "imapdriver_types.h" 54#include "imapdriver_types.h"
55#include "generic_cache.h" 55#include "generic_cache.h"
56#include "imfcache.h" 56#include "imfcache.h"
57#include "maildriver_tools.h" 57#include "maildriver_tools.h"
58#include "imapdriver.h" 58#include "imapdriver.h"
59 59
60static int imapdriver_cached_initialize(mailsession * session); 60static int imapdriver_cached_initialize(mailsession * session);
61static void imapdriver_cached_uninitialize(mailsession * session); 61static void imapdriver_cached_uninitialize(mailsession * session);
62 62
63static int imapdriver_cached_parameters(mailsession * session, 63static int imapdriver_cached_parameters(mailsession * session,
64 int id, void * value); 64 int id, void * value);
65 65
66static int imapdriver_cached_connect_stream(mailsession * session, 66static int imapdriver_cached_connect_stream(mailsession * session,
67 mailstream * s); 67 mailstream * s);
68 68
69static int imapdriver_cached_starttls(mailsession * session); 69static int imapdriver_cached_starttls(mailsession * session);
70 70
71static int imapdriver_cached_login(mailsession * session, 71static int imapdriver_cached_login(mailsession * session,
72 char * userid, char * password); 72 char * userid, char * password);
73static int imapdriver_cached_logout(mailsession * session); 73static int imapdriver_cached_logout(mailsession * session);
74static int imapdriver_cached_noop(mailsession * session); 74static int imapdriver_cached_noop(mailsession * session);
75static int imapdriver_cached_build_folder_name(mailsession * session, 75static int imapdriver_cached_build_folder_name(mailsession * session,
76 char * mb, 76 char * mb,
77 char * name, char ** result); 77 char * name, char ** result);
78static int imapdriver_cached_create_folder(mailsession * session, char * mb); 78static int imapdriver_cached_create_folder(mailsession * session, char * mb);
79static int imapdriver_cached_delete_folder(mailsession * session, char * mb); 79static int imapdriver_cached_delete_folder(mailsession * session, char * mb);
80static int imapdriver_cached_rename_folder(mailsession * session, char * mb, 80static int imapdriver_cached_rename_folder(mailsession * session, char * mb,
81 char * new_name); 81 char * new_name);
82static int imapdriver_cached_check_folder(mailsession * session); 82static int imapdriver_cached_check_folder(mailsession * session);
83static int imapdriver_cached_examine_folder(mailsession * session, 83static int imapdriver_cached_examine_folder(mailsession * session,
84 char * mb); 84 char * mb);
85static int imapdriver_cached_select_folder(mailsession * session, char * mb); 85static int imapdriver_cached_select_folder(mailsession * session, char * mb);
86static int imapdriver_cached_expunge_folder(mailsession * session); 86static int imapdriver_cached_expunge_folder(mailsession * session);
87static int imapdriver_cached_status_folder(mailsession * session, char * mb, 87static int imapdriver_cached_status_folder(mailsession * session, char * mb,
88 uint32_t * result_messages, 88 uint32_t * result_messages,
89 uint32_t * result_recent, 89 uint32_t * result_recent,
90 uint32_t * result_unseen); 90 uint32_t * result_unseen);
91static int imapdriver_cached_messages_number(mailsession * session, 91static int imapdriver_cached_messages_number(mailsession * session,
92 char * mb, 92 char * mb,
93 uint32_t * result); 93 uint32_t * result);
94static int imapdriver_cached_recent_number(mailsession * session, char * mb, 94static int imapdriver_cached_recent_number(mailsession * session, char * mb,
95 uint32_t * result); 95 uint32_t * result);
96static int imapdriver_cached_unseen_number(mailsession * session, char * mb, 96static int imapdriver_cached_unseen_number(mailsession * session, char * mb,
97 uint32_t * result); 97 uint32_t * result);
98static int imapdriver_cached_list_folders(mailsession * session, char * mb, 98static int imapdriver_cached_list_folders(mailsession * session, char * mb,
99 struct mail_list ** result); 99 struct mail_list ** result);
100static int imapdriver_cached_lsub_folders(mailsession * session, char * mb, 100static int imapdriver_cached_lsub_folders(mailsession * session, char * mb,
101 struct mail_list ** result); 101 struct mail_list ** result);
102static int imapdriver_cached_subscribe_folder(mailsession * session, 102static int imapdriver_cached_subscribe_folder(mailsession * session,
103 char * mb); 103 char * mb);
104static int imapdriver_cached_unsubscribe_folder(mailsession * session, 104static int imapdriver_cached_unsubscribe_folder(mailsession * session,
105 char * mb); 105 char * mb);
106static int imapdriver_cached_append_message(mailsession * session, 106static int imapdriver_cached_append_message(mailsession * session,
107 char * message, size_t size); 107 char * message, size_t size);
108static int imapdriver_cached_append_message_flags(mailsession * session,
109 char * message, size_t size, struct mail_flags * flags);
108static int imapdriver_cached_copy_message(mailsession * session, 110static int imapdriver_cached_copy_message(mailsession * session,
109 uint32_t num, char * mb); 111 uint32_t num, char * mb);
110 112
111static int imapdriver_cached_get_messages_list(mailsession * session, 113static int imapdriver_cached_get_messages_list(mailsession * session,
112 struct mailmessage_list ** 114 struct mailmessage_list **
113 result); 115 result);
114static int 116static int
115imapdriver_cached_get_envelopes_list(mailsession * session, 117imapdriver_cached_get_envelopes_list(mailsession * session,
116 struct mailmessage_list * env_list); 118 struct mailmessage_list * env_list);
117static int imapdriver_cached_remove_message(mailsession * session, 119static int imapdriver_cached_remove_message(mailsession * session,
118 uint32_t num); 120 uint32_t num);
119 121
120#if 0 122#if 0
121static int imapdriver_cached_search_messages(mailsession * session, 123static 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,
124 struct mail_search_result ** 126 struct mail_search_result **
125 result); 127 result);
126#endif 128#endif
127 129
128static int imapdriver_cached_get_message(mailsession * session, 130static int imapdriver_cached_get_message(mailsession * session,
129 uint32_t num, mailmessage ** result); 131 uint32_t num, mailmessage ** result);
130 132
131static int imapdriver_cached_get_message_by_uid(mailsession * session, 133static int imapdriver_cached_get_message_by_uid(mailsession * session,
132 const char * uid, 134 const char * uid,
133 mailmessage ** result); 135 mailmessage ** result);
134 136
135static mailsession_driver local_imap_cached_session_driver = { 137static mailsession_driver local_imap_cached_session_driver = {
136 .sess_name = "imap-cached", 138 .sess_name = "imap-cached",
137 139
138 .sess_initialize = imapdriver_cached_initialize, 140 .sess_initialize = imapdriver_cached_initialize,
139 .sess_uninitialize = imapdriver_cached_uninitialize, 141 .sess_uninitialize = imapdriver_cached_uninitialize,
140 142
141 .sess_parameters = imapdriver_cached_parameters, 143 .sess_parameters = imapdriver_cached_parameters,
142 144
143 .sess_connect_stream = imapdriver_cached_connect_stream, 145 .sess_connect_stream = imapdriver_cached_connect_stream,
144 .sess_connect_path = NULL, 146 .sess_connect_path = NULL,
145 .sess_starttls = imapdriver_cached_starttls, 147 .sess_starttls = imapdriver_cached_starttls,
146 .sess_login = imapdriver_cached_login, 148 .sess_login = imapdriver_cached_login,
147 .sess_logout = imapdriver_cached_logout, 149 .sess_logout = imapdriver_cached_logout,
148 .sess_noop = imapdriver_cached_noop, 150 .sess_noop = imapdriver_cached_noop,
149 151
150 .sess_build_folder_name = imapdriver_cached_build_folder_name, 152 .sess_build_folder_name = imapdriver_cached_build_folder_name,
151 .sess_create_folder = imapdriver_cached_create_folder, 153 .sess_create_folder = imapdriver_cached_create_folder,
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
182mailsession_driver * imap_cached_session_driver = 185mailsession_driver * imap_cached_session_driver =
183&local_imap_cached_session_driver; 186&local_imap_cached_session_driver;
184 187
185#define CACHE_MESSAGE_LIST 188#define CACHE_MESSAGE_LIST
186 189
187static inline struct imap_cached_session_state_data * 190static inline struct imap_cached_session_state_data *
188get_cached_data(mailsession * session) 191get_cached_data(mailsession * session)
189{ 192{
190 return session->sess_data; 193 return session->sess_data;
191} 194}
192 195
193static inline mailsession * get_ancestor(mailsession * s) 196static inline mailsession * get_ancestor(mailsession * s)
194{ 197{
195 return get_cached_data(s)->imap_ancestor; 198 return get_cached_data(s)->imap_ancestor;
196} 199}
197 200
198static inline 201static inline
199struct imap_session_state_data * get_ancestor_data(mailsession * s) 202struct imap_session_state_data * get_ancestor_data(mailsession * s)
200{ 203{
201 return get_ancestor(s)->sess_data; 204 return get_ancestor(s)->sess_data;
202} 205}
203 206
204static inline mailimap * get_imap_session(mailsession * session) 207static inline mailimap * get_imap_session(mailsession * session)
205{ 208{
206 return get_ancestor_data(session)->imap_session; 209 return get_ancestor_data(session)->imap_session;
207} 210}
208 211
209static int imapdriver_cached_initialize(mailsession * session) 212static int imapdriver_cached_initialize(mailsession * session)
210{ 213{
211 struct imap_cached_session_state_data * data; 214 struct imap_cached_session_state_data * data;
212 215
213 data = malloc(sizeof(* data)); 216 data = malloc(sizeof(* data));
214 if (data == NULL) 217 if (data == NULL)
215 goto err; 218 goto err;
216 219
217 data->imap_ancestor = mailsession_new(imap_session_driver); 220 data->imap_ancestor = mailsession_new(imap_session_driver);
218 if (data->imap_ancestor == NULL) 221 if (data->imap_ancestor == NULL)
219 goto free_data; 222 goto free_data;
220 data->imap_quoted_mb = NULL; 223 data->imap_quoted_mb = NULL;
221 data->imap_cache_directory[0] = '\0'; 224 data->imap_cache_directory[0] = '\0';
222 data->imap_uid_list = carray_new(128); 225 data->imap_uid_list = carray_new(128);
223 if (data->imap_uid_list == NULL) 226 if (data->imap_uid_list == NULL)
224 goto free_session; 227 goto free_session;
225 228
226 session->sess_data = data; 229 session->sess_data = data;
227 230
228 return MAIL_NO_ERROR; 231 return MAIL_NO_ERROR;
229 232
230 free_session: 233 free_session:
231 mailsession_free(data->imap_ancestor); 234 mailsession_free(data->imap_ancestor);
232 free_data: 235 free_data:
233 free(data); 236 free(data);
234 err: 237 err:
235 return MAIL_ERROR_MEMORY; 238 return MAIL_ERROR_MEMORY;
236} 239}
237 240
238static void 241static void
239free_quoted_mb(struct imap_cached_session_state_data * imap_cached_data) 242free_quoted_mb(struct imap_cached_session_state_data * imap_cached_data)
240{ 243{
241 if (imap_cached_data->imap_quoted_mb != NULL) { 244 if (imap_cached_data->imap_quoted_mb != NULL) {
242 free(imap_cached_data->imap_quoted_mb); 245 free(imap_cached_data->imap_quoted_mb);
243 imap_cached_data->imap_quoted_mb = NULL; 246 imap_cached_data->imap_quoted_mb = NULL;
244 } 247 }
245} 248}
246 249
247struct uid_cache_item { 250struct uid_cache_item {
248 uint32_t uid; 251 uint32_t uid;
249 uint32_t size; 252 uint32_t size;
250}; 253};
251 254
252static int update_uid_cache(mailsession * session, 255static int update_uid_cache(mailsession * session,
253 struct mailmessage_list * env_list) 256 struct mailmessage_list * env_list)
254{ 257{
255 unsigned int i; 258 unsigned int i;
256 int r; 259 int r;
257 struct imap_cached_session_state_data * data; 260 struct imap_cached_session_state_data * data;
258 int res; 261 int res;
259 262
260 data = get_cached_data(session); 263 data = get_cached_data(session);
261 264
262 /* free all UID cache */ 265 /* free all UID cache */
263 for(i = 0 ; i < carray_count(data->imap_uid_list) ; i ++) { 266 for(i = 0 ; i < carray_count(data->imap_uid_list) ; i ++) {
264 struct uid_cache_item * cache_item; 267 struct uid_cache_item * cache_item;
265 268
266 cache_item = carray_get(data->imap_uid_list, i); 269 cache_item = carray_get(data->imap_uid_list, i);
267 free(cache_item); 270 free(cache_item);
268 } 271 }
269 272
270 /* build UID cache */ 273 /* build UID cache */
271 r = carray_set_size(data->imap_uid_list, 274 r = carray_set_size(data->imap_uid_list,
272 carray_count(env_list->msg_tab)); 275 carray_count(env_list->msg_tab));
273 if (r < 0) { 276 if (r < 0) {
274 res = MAIL_ERROR_MEMORY; 277 res = MAIL_ERROR_MEMORY;
275 goto err; 278 goto err;
276 } 279 }
277 280
278 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 281 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
279 struct uid_cache_item * cache_item; 282 struct uid_cache_item * cache_item;
280 mailmessage * msg; 283 mailmessage * msg;
281 284
282 cache_item = malloc(sizeof(* cache_item)); 285 cache_item = malloc(sizeof(* cache_item));
283 if (cache_item == NULL) { 286 if (cache_item == NULL) {
284 res = MAIL_ERROR_MEMORY; 287 res = MAIL_ERROR_MEMORY;
285 goto err; 288 goto err;
286 } 289 }
287 msg = carray_get(env_list->msg_tab, i); 290 msg = carray_get(env_list->msg_tab, i);
288 cache_item->uid = msg->msg_index; 291 cache_item->uid = msg->msg_index;
289 cache_item->size = msg->msg_size; 292 cache_item->size = msg->msg_size;
290 293
291 carray_set(data->imap_uid_list, i, cache_item); 294 carray_set(data->imap_uid_list, i, cache_item);
292 } 295 }
293 296
294 return MAIL_NO_ERROR; 297 return MAIL_NO_ERROR;
295 298
@@ -651,256 +654,269 @@ static int imapdriver_cached_select_folder(mailsession * session, char * mb)
651 /* clear UID cache */ 654 /* clear UID cache */
652 carray_set_size(data->imap_uid_list, 0); 655 carray_set_size(data->imap_uid_list, 0);
653 656
654 return MAIL_NO_ERROR; 657 return MAIL_NO_ERROR;
655} 658}
656 659
657static int imapdriver_cached_expunge_folder(mailsession * session) 660static int imapdriver_cached_expunge_folder(mailsession * session)
658{ 661{
659 int r; 662 int r;
660 663
661 r = mailsession_expunge_folder(get_ancestor(session)); 664 r = mailsession_expunge_folder(get_ancestor(session));
662 665
663 check_for_uid_cache(session); 666 check_for_uid_cache(session);
664 667
665 return r; 668 return r;
666} 669}
667 670
668static int imapdriver_cached_status_folder(mailsession * session, char * mb, 671static int imapdriver_cached_status_folder(mailsession * session, char * mb,
669 uint32_t * result_messages, uint32_t * result_recent, 672 uint32_t * result_messages, uint32_t * result_recent,
670 uint32_t * result_unseen) 673 uint32_t * result_unseen)
671{ 674{
672 int r; 675 int r;
673 676
674 r = mailsession_status_folder(get_ancestor(session), mb, result_messages, 677 r = mailsession_status_folder(get_ancestor(session), mb, result_messages,
675 result_recent, result_unseen); 678 result_recent, result_unseen);
676 679
677 check_for_uid_cache(session); 680 check_for_uid_cache(session);
678 681
679 return r; 682 return r;
680} 683}
681 684
682static int imapdriver_cached_messages_number(mailsession * session, 685static int imapdriver_cached_messages_number(mailsession * session,
683 char * mb, 686 char * mb,
684 uint32_t * result) 687 uint32_t * result)
685{ 688{
686 int r; 689 int r;
687 690
688 r = mailsession_messages_number(get_ancestor(session), mb, result); 691 r = mailsession_messages_number(get_ancestor(session), mb, result);
689 692
690 check_for_uid_cache(session); 693 check_for_uid_cache(session);
691 694
692 return r; 695 return r;
693} 696}
694 697
695static int imapdriver_cached_recent_number(mailsession * session, char * mb, 698static int imapdriver_cached_recent_number(mailsession * session, char * mb,
696 uint32_t * result) 699 uint32_t * result)
697{ 700{
698 int r; 701 int r;
699 702
700 r = mailsession_recent_number(get_ancestor(session), mb, result); 703 r = mailsession_recent_number(get_ancestor(session), mb, result);
701 704
702 check_for_uid_cache(session); 705 check_for_uid_cache(session);
703 706
704 return r; 707 return r;
705} 708}
706 709
707static int imapdriver_cached_unseen_number(mailsession * session, char * mb, 710static int imapdriver_cached_unseen_number(mailsession * session, char * mb,
708 uint32_t * result) 711 uint32_t * result)
709{ 712{
710 int r; 713 int r;
711 714
712 r = mailsession_unseen_number(get_ancestor(session), mb, result); 715 r = mailsession_unseen_number(get_ancestor(session), mb, result);
713 716
714 check_for_uid_cache(session); 717 check_for_uid_cache(session);
715 718
716 return r; 719 return r;
717} 720}
718 721
719static int imapdriver_cached_list_folders(mailsession * session, char * mb, 722static int imapdriver_cached_list_folders(mailsession * session, char * mb,
720 struct mail_list ** result) 723 struct mail_list ** result)
721{ 724{
722 int r; 725 int r;
723 726
724 r = mailsession_list_folders(get_ancestor(session), mb, result); 727 r = mailsession_list_folders(get_ancestor(session), mb, result);
725 728
726 check_for_uid_cache(session); 729 check_for_uid_cache(session);
727 730
728 return r; 731 return r;
729} 732}
730 733
731static int imapdriver_cached_lsub_folders(mailsession * session, char * mb, 734static int imapdriver_cached_lsub_folders(mailsession * session, char * mb,
732 struct mail_list ** result) 735 struct mail_list ** result)
733{ 736{
734 int r; 737 int r;
735 738
736 r = mailsession_lsub_folders(get_ancestor(session), mb, result); 739 r = mailsession_lsub_folders(get_ancestor(session), mb, result);
737 740
738 check_for_uid_cache(session); 741 check_for_uid_cache(session);
739 742
740 return r; 743 return r;
741} 744}
742 745
743static int imapdriver_cached_subscribe_folder(mailsession * session, 746static int imapdriver_cached_subscribe_folder(mailsession * session,
744 char * mb) 747 char * mb)
745{ 748{
746 int r; 749 int r;
747 750
748 r = mailsession_subscribe_folder(get_ancestor(session), mb); 751 r = mailsession_subscribe_folder(get_ancestor(session), mb);
749 752
750 check_for_uid_cache(session); 753 check_for_uid_cache(session);
751 754
752 return r; 755 return r;
753} 756}
754 757
755static int imapdriver_cached_unsubscribe_folder(mailsession * session, 758static int imapdriver_cached_unsubscribe_folder(mailsession * session,
756 char * mb) 759 char * mb)
757{ 760{
758 int r; 761 int r;
759 762
760 r = mailsession_unsubscribe_folder(get_ancestor(session), mb); 763 r = mailsession_unsubscribe_folder(get_ancestor(session), mb);
761 764
762 check_for_uid_cache(session); 765 check_for_uid_cache(session);
763 766
764 return r; 767 return r;
765} 768}
766 769
767static int imapdriver_cached_append_message(mailsession * session, 770static 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
782static 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
779static int imapdriver_cached_copy_message(mailsession * session, 795static 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
791static int cmp_uid(uint32_t ** pa, uint32_t ** pb) 807static 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;
795 811
796 a = * pa; 812 a = * pa;
797 b = * pb; 813 b = * pb;
798 814
799 return * a - * b; 815 return * a - * b;
800} 816}
801 817
802 818
803static int imapdriver_cached_get_messages_list(mailsession * session, 819static int imapdriver_cached_get_messages_list(mailsession * session,
804 struct mailmessage_list ** 820 struct mailmessage_list **
805 result) 821 result)
806{ 822{
807#if 0 823#if 0
808 mailsession * imap_session; 824 mailsession * imap_session;
809#endif 825#endif
810 mailimap * imap; 826 mailimap * imap;
811 uint32_t uid_max; 827 uint32_t uid_max;
812 struct imap_cached_session_state_data * data; 828 struct imap_cached_session_state_data * data;
813 struct mailmessage_list * env_list; 829 struct mailmessage_list * env_list;
814 unsigned i; 830 unsigned i;
815 int r; 831 int r;
816 int res; 832 int res;
817 carray * tab; 833 carray * tab;
818 834
819#if 0 835#if 0
820 data = session->data; 836 data = session->data;
821 imap_session = get_ancestor(session); 837 imap_session = get_ancestor(session);
822 imap = ((struct imap_session_state_data *) (imap_session->data))->session; 838 imap = ((struct imap_session_state_data *) (imap_session->data))->session;
823#endif 839#endif
824 data = get_cached_data(session); 840 data = get_cached_data(session);
825 imap = get_imap_session(session); 841 imap = get_imap_session(session);
826 842
827 uid_max = 0; 843 uid_max = 0;
828 844
829#ifdef CACHE_MESSAGE_LIST 845#ifdef CACHE_MESSAGE_LIST
830 /* get UID max */ 846 /* get UID max */
831 uid_max = 0; 847 uid_max = 0;
832 for(i = 0 ; i < carray_count(data->imap_uid_list) ; i ++) { 848 for(i = 0 ; i < carray_count(data->imap_uid_list) ; i ++) {
833 struct uid_cache_item * cache_item; 849 struct uid_cache_item * cache_item;
834 850
835 cache_item = carray_get(data->imap_uid_list, i); 851 cache_item = carray_get(data->imap_uid_list, i);
836 if (cache_item->uid > uid_max) 852 if (cache_item->uid > uid_max)
837 uid_max = cache_item->uid; 853 uid_max = cache_item->uid;
838 } 854 }
839#endif 855#endif
840 856
841 r = imap_get_messages_list(imap, session, imap_cached_message_driver, 857 r = imap_get_messages_list(imap, session, imap_cached_message_driver,
842 uid_max + 1, &env_list); 858 uid_max + 1, &env_list);
843 859
844 check_for_uid_cache(session); 860 check_for_uid_cache(session);
845 861
846 if (r != MAIL_NO_ERROR) { 862 if (r != MAIL_NO_ERROR) {
847 res = r; 863 res = r;
848 goto err; 864 goto err;
849 } 865 }
850 866
851#ifdef CACHE_MESSAGE_LIST 867#ifdef CACHE_MESSAGE_LIST
852 /* remove unsollicited message */ 868 /* remove unsollicited message */
853 i = 0; 869 i = 0;
854 while (i < carray_count(env_list->msg_tab)) { 870 while (i < carray_count(env_list->msg_tab)) {
855 mailmessage * msg; 871 mailmessage * msg;
856 872
857 msg = carray_get(env_list->msg_tab, i); 873 msg = carray_get(env_list->msg_tab, i);
858 if (msg->msg_index < uid_max + 1) 874 if (msg->msg_index < uid_max + 1)
859 carray_delete(env_list->msg_tab, i); 875 carray_delete(env_list->msg_tab, i);
860 else 876 else
861 i ++; 877 i ++;
862 } 878 }
863 879
864 tab = carray_new(carray_count(env_list->msg_tab) + 880 tab = carray_new(carray_count(env_list->msg_tab) +
865 carray_count(data->imap_uid_list)); 881 carray_count(data->imap_uid_list));
866 if (tab == NULL) { 882 if (tab == NULL) {
867 res = MAIL_ERROR_MEMORY; 883 res = MAIL_ERROR_MEMORY;
868 goto free; 884 goto free;
869 } 885 }
870 carray_set_size(tab, 886 carray_set_size(tab,
871 carray_count(env_list->msg_tab) + carray_count(data->imap_uid_list)); 887 carray_count(env_list->msg_tab) + carray_count(data->imap_uid_list));
872 888
873 /* sort cached data before adding them to the list */ 889 /* sort cached data before adding them to the list */
874 qsort(carray_data(data->imap_uid_list), carray_count(data->imap_uid_list), 890 qsort(carray_data(data->imap_uid_list), carray_count(data->imap_uid_list),
875 sizeof(* carray_data(data->imap_uid_list)), 891 sizeof(* carray_data(data->imap_uid_list)),
876 (int (*)(const void *, const void *)) cmp_uid); 892 (int (*)(const void *, const void *)) cmp_uid);
877 893
878 /* adds cached UID */ 894 /* adds cached UID */
879 for(i = 0 ; i < carray_count(data->imap_uid_list) ; i ++) { 895 for(i = 0 ; i < carray_count(data->imap_uid_list) ; i ++) {
880 struct uid_cache_item * cache_item; 896 struct uid_cache_item * cache_item;
881 mailmessage * msg; 897 mailmessage * msg;
882 898
883 cache_item = carray_get(data->imap_uid_list, i); 899 cache_item = carray_get(data->imap_uid_list, i);
884 900
885 msg = mailmessage_new(); 901 msg = mailmessage_new();
886 if (msg == NULL) { 902 if (msg == NULL) {
887 res = MAIL_ERROR_MEMORY; 903 res = MAIL_ERROR_MEMORY;
888 goto free; 904 goto free;
889 } 905 }
890 906
891 r = mailmessage_init(msg, session, imap_cached_message_driver, 907 r = mailmessage_init(msg, session, imap_cached_message_driver,
892 cache_item->uid, cache_item->size); 908 cache_item->uid, cache_item->size);
893 if (r != MAIL_NO_ERROR) { 909 if (r != MAIL_NO_ERROR) {
894 mailmessage_free(msg); 910 mailmessage_free(msg);
895 res = r; 911 res = r;
896 goto free; 912 goto free;
897 } 913 }
898 914
899 carray_set(tab, i, msg); 915 carray_set(tab, i, msg);
900 } 916 }
901 917
902 /* adds new elements */ 918 /* adds new elements */
903 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 919 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
904 mailmessage * msg; 920 mailmessage * msg;
905 921
906 msg = carray_get(env_list->msg_tab, i); 922 msg = carray_get(env_list->msg_tab, i);
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
@@ -87,257 +87,257 @@ static int imap_fetch_section_header(mailmessage * msg_info,
87static int imap_fetch_section_mime(mailmessage * msg_info, 87static int imap_fetch_section_mime(mailmessage * msg_info,
88 struct mailmime * mime, 88 struct mailmime * mime,
89 char ** result, 89 char ** result,
90 size_t * result_len); 90 size_t * result_len);
91 91
92static int imap_fetch_section_body(mailmessage * msg_info, 92static int imap_fetch_section_body(mailmessage * msg_info,
93 struct mailmime * mime, 93 struct mailmime * mime,
94 char ** result, 94 char ** result,
95 size_t * result_len); 95 size_t * result_len);
96 96
97 97
98static int imap_fetch_envelope(mailmessage * msg_info, 98static int imap_fetch_envelope(mailmessage * msg_info,
99 struct mailimf_fields ** result); 99 struct mailimf_fields ** result);
100 100
101static int imap_get_flags(mailmessage * msg_info, 101static int imap_get_flags(mailmessage * msg_info,
102 struct mail_flags ** result); 102 struct mail_flags ** result);
103 103
104static mailmessage_driver local_imap_cached_message_driver = { 104static mailmessage_driver local_imap_cached_message_driver = {
105 .msg_name = "imap-cached", 105 .msg_name = "imap-cached",
106 106
107 .msg_initialize = imap_initialize, 107 .msg_initialize = imap_initialize,
108 .msg_uninitialize = imap_uninitialize, 108 .msg_uninitialize = imap_uninitialize,
109 109
110 .msg_flush = imap_flush, 110 .msg_flush = imap_flush,
111 .msg_check = imap_check, 111 .msg_check = imap_check,
112 112
113 .msg_fetch_result_free = imap_fetch_result_free, 113 .msg_fetch_result_free = imap_fetch_result_free,
114 114
115 .msg_fetch = imap_fetch, 115 .msg_fetch = imap_fetch,
116 .msg_fetch_header = imap_fetch_header, 116 .msg_fetch_header = imap_fetch_header,
117 .msg_fetch_body = imap_fetch_body, 117 .msg_fetch_body = imap_fetch_body,
118 .msg_fetch_size = imap_fetch_size, 118 .msg_fetch_size = imap_fetch_size,
119 .msg_get_bodystructure = imap_get_bodystructure, 119 .msg_get_bodystructure = imap_get_bodystructure,
120 .msg_fetch_section = imap_fetch_section, 120 .msg_fetch_section = imap_fetch_section,
121 .msg_fetch_section_header = imap_fetch_section_header, 121 .msg_fetch_section_header = imap_fetch_section_header,
122 .msg_fetch_section_mime = imap_fetch_section_mime, 122 .msg_fetch_section_mime = imap_fetch_section_mime,
123 .msg_fetch_section_body = imap_fetch_section_body, 123 .msg_fetch_section_body = imap_fetch_section_body,
124 .msg_fetch_envelope = imap_fetch_envelope, 124 .msg_fetch_envelope = imap_fetch_envelope,
125 125
126 .msg_get_flags = imap_get_flags, 126 .msg_get_flags = imap_get_flags,
127}; 127};
128 128
129mailmessage_driver * imap_cached_message_driver = 129mailmessage_driver * imap_cached_message_driver =
130&local_imap_cached_message_driver; 130&local_imap_cached_message_driver;
131 131
132static inline struct imap_cached_session_state_data * 132static inline struct imap_cached_session_state_data *
133get_cached_session_data(mailmessage * msg) 133get_cached_session_data(mailmessage * msg)
134{ 134{
135 return msg->msg_session->sess_data; 135 return msg->msg_session->sess_data;
136} 136}
137 137
138static inline mailmessage * get_ancestor(mailmessage * msg_info) 138static inline mailmessage * get_ancestor(mailmessage * msg_info)
139{ 139{
140 return msg_info->msg_data; 140 return msg_info->msg_data;
141} 141}
142 142
143static inline struct imap_cached_session_state_data * 143static inline struct imap_cached_session_state_data *
144cached_session_get_data(mailsession * s) 144cached_session_get_data(mailsession * s)
145{ 145{
146 return s->sess_data; 146 return s->sess_data;
147} 147}
148 148
149static inline mailsession * cached_session_get_ancestor(mailsession * s) 149static inline mailsession * cached_session_get_ancestor(mailsession * s)
150{ 150{
151 return cached_session_get_data(s)->imap_ancestor; 151 return cached_session_get_data(s)->imap_ancestor;
152} 152}
153 153
154static inline struct imap_session_state_data * 154static inline struct imap_session_state_data *
155cached_session_get_ancestor_data(mailsession * s) 155cached_session_get_ancestor_data(mailsession * s)
156{ 156{
157 return cached_session_get_ancestor(s)->sess_data; 157 return cached_session_get_ancestor(s)->sess_data;
158} 158}
159 159
160static inline mailimap * 160static inline mailimap *
161cached_session_get_imap_session(mailsession * session) 161cached_session_get_imap_session(mailsession * session)
162{ 162{
163 return cached_session_get_ancestor_data(session)->imap_session; 163 return cached_session_get_ancestor_data(session)->imap_session;
164} 164}
165 165
166static inline mailimap * get_imap_session(mailmessage * msg) 166static inline mailimap * get_imap_session(mailmessage * msg)
167{ 167{
168 return cached_session_get_imap_session(msg->msg_session); 168 return cached_session_get_imap_session(msg->msg_session);
169} 169}
170 170
171static inline mailsession * get_ancestor_session(mailmessage * msg_info) 171static inline mailsession * get_ancestor_session(mailmessage * msg_info)
172{ 172{
173 return cached_session_get_ancestor(msg_info->msg_session); 173 return cached_session_get_ancestor(msg_info->msg_session);
174} 174}
175 175
176 176
177static void generate_key_from_mime_section(char * key, size_t size, 177static void generate_key_from_mime_section(char * key, size_t size,
178 struct mailmime * mime) 178 struct mailmime * mime)
179{ 179{
180 clistiter * cur; 180 clistiter * cur;
181 MMAPString * gstr; 181 MMAPString * gstr;
182 struct mailmime_section * part; 182 struct mailmime_section * part;
183 int r; 183 int r;
184 184
185 snprintf(key, size, "unvalid"); 185 snprintf(key, size, "unvalid");
186 186
187 r = mailmime_get_section_id(mime, &part); 187 r = mailmime_get_section_id(mime, &part);
188 if (r != MAILIMF_NO_ERROR) 188 if (r != MAILIMF_NO_ERROR)
189 goto err; 189 goto err;
190 190
191 gstr = mmap_string_new("part"); 191 gstr = mmap_string_new("part");
192 if (gstr == NULL) 192 if (gstr == NULL)
193 goto free_section; 193 goto free_section;
194 194
195 for(cur = clist_begin(part->sec_list) ; 195 for(cur = clist_begin(part->sec_list) ;
196 cur != NULL ; cur = clist_next(cur)) { 196 cur != NULL ; cur = clist_next(cur)) {
197 char s[20]; 197 char s[20];
198 198
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
218static void generate_key_from_section(char * key, size_t size, 218static 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);
232 break; 232 break;
233 case IMAP_SECTION_MIME: 233 case IMAP_SECTION_MIME:
234 snprintf(key, size, "%s-%s-mime", msg_info->msg_uid, section_str); 234 snprintf(key, size, "%s-%s-mime", msg_info->msg_uid, section_str);
235 break; 235 break;
236 case IMAP_SECTION_BODY: 236 case IMAP_SECTION_BODY:
237 snprintf(key, size, "%s-%s-text", msg_info->msg_uid, section_str); 237 snprintf(key, size, "%s-%s-text", msg_info->msg_uid, section_str);
238 break; 238 break;
239 } 239 }
240} 240}
241 241
242static void generate_key_from_message(char * key, size_t size, 242static void generate_key_from_message(char * key, size_t size,
243 mailmessage * msg_info, 243 mailmessage * msg_info,
244 int type) 244 int type)
245{ 245{
246 switch (type) { 246 switch (type) {
247 case MAILIMAP_MSG_ATT_RFC822: 247 case MAILIMAP_MSG_ATT_RFC822:
248 snprintf(key, size, "%s-rfc822", msg_info->msg_uid); 248 snprintf(key, size, "%s-rfc822", msg_info->msg_uid);
249 break; 249 break;
250 case MAILIMAP_MSG_ATT_RFC822_HEADER: 250 case MAILIMAP_MSG_ATT_RFC822_HEADER:
251 snprintf(key, size, "%s-rfc822-header", msg_info->msg_uid); 251 snprintf(key, size, "%s-rfc822-header", msg_info->msg_uid);
252 break; 252 break;
253 case MAILIMAP_MSG_ATT_RFC822_TEXT: 253 case MAILIMAP_MSG_ATT_RFC822_TEXT:
254 snprintf(key, size, "%s-rfc822-text", msg_info->msg_uid); 254 snprintf(key, size, "%s-rfc822-text", msg_info->msg_uid);
255 break; 255 break;
256 case MAILIMAP_MSG_ATT_ENVELOPE: 256 case MAILIMAP_MSG_ATT_ENVELOPE:
257 snprintf(key, size, "%s-envelope", msg_info->msg_uid); 257 snprintf(key, size, "%s-envelope", msg_info->msg_uid);
258 break; 258 break;
259 } 259 }
260} 260}
261 261
262static void build_cache_name(char * filename, size_t size, 262static void build_cache_name(char * filename, size_t size,
263 mailmessage * msg, char * key) 263 mailmessage * msg, char * key)
264{ 264{
265 char * quoted_mb; 265 char * quoted_mb;
266 266
267 quoted_mb = get_cached_session_data(msg)->imap_quoted_mb; 267 quoted_mb = get_cached_session_data(msg)->imap_quoted_mb;
268 268
269 snprintf(filename, size, "%s/%s", quoted_mb, key); 269 snprintf(filename, size, "%s/%s", quoted_mb, key);
270} 270}
271 271
272static int imap_initialize(mailmessage * msg_info) 272static int imap_initialize(mailmessage * msg_info)
273{ 273{
274 mailmessage * ancestor; 274 mailmessage * ancestor;
275 int r; 275 int r;
276 char key[PATH_MAX]; 276 char key[PATH_MAX];
277 char * uid; 277 char * uid;
278 mailimap * imap; 278 mailimap * imap;
279 279
280 ancestor = mailmessage_new(); 280 ancestor = mailmessage_new();
281 if (ancestor == NULL) 281 if (ancestor == NULL)
282 return MAIL_ERROR_MEMORY; 282 return MAIL_ERROR_MEMORY;
283 283
284 r = mailmessage_init(ancestor, get_ancestor_session(msg_info), 284 r = mailmessage_init(ancestor, get_ancestor_session(msg_info),
285 imap_message_driver, 285 imap_message_driver,
286 msg_info->msg_index, 0); 286 msg_info->msg_index, 0);
287 if (r != MAIL_NO_ERROR) { 287 if (r != MAIL_NO_ERROR) {
288 mailmessage_free(ancestor); 288 mailmessage_free(ancestor);
289 return r; 289 return r;
290 } 290 }
291 291
292 imap = get_imap_session(msg_info); 292 imap = get_imap_session(msg_info);
293 293
294 snprintf(key, PATH_MAX, "%u-%u", 294 snprintf(key, PATH_MAX, "%u-%u",
295 imap->imap_selection_info->sel_uidvalidity, msg_info->msg_index); 295 imap->imap_selection_info->sel_uidvalidity, msg_info->msg_index);
296 uid = strdup(key); 296 uid = strdup(key);
297 if (uid == NULL) { 297 if (uid == NULL) {
298 mailmessage_free(ancestor); 298 mailmessage_free(ancestor);
299 return MAIL_ERROR_MEMORY; 299 return MAIL_ERROR_MEMORY;
300 } 300 }
301 301
302 msg_info->msg_data = ancestor; 302 msg_info->msg_data = ancestor;
303 msg_info->msg_uid = uid; 303 msg_info->msg_uid = uid;
304 304
305 return MAIL_NO_ERROR; 305 return MAIL_NO_ERROR;
306} 306}
307 307
308static void imap_uninitialize(mailmessage * msg_info) 308static void imap_uninitialize(mailmessage * msg_info)
309{ 309{
310 mailmessage_free(get_ancestor(msg_info)); 310 mailmessage_free(get_ancestor(msg_info));
311 msg_info->msg_data = NULL; 311 msg_info->msg_data = NULL;
312} 312}
313 313
314static void imap_flush(mailmessage * msg_info) 314static void imap_flush(mailmessage * msg_info)
315{ 315{
316 if (msg_info->msg_mime != NULL) { 316 if (msg_info->msg_mime != NULL) {
317 mailmime_free(msg_info->msg_mime); 317 mailmime_free(msg_info->msg_mime);
318 msg_info->msg_mime = NULL; 318 msg_info->msg_mime = NULL;
319 } 319 }
320} 320}
321 321
322static void imap_check(mailmessage * msg_info) 322static void imap_check(mailmessage * msg_info)
323{ 323{
324 get_ancestor(msg_info)->msg_flags = msg_info->msg_flags; 324 get_ancestor(msg_info)->msg_flags = msg_info->msg_flags;
325 mailmessage_check(get_ancestor(msg_info)); 325 mailmessage_check(get_ancestor(msg_info));
326 get_ancestor(msg_info)->msg_flags = NULL; 326 get_ancestor(msg_info)->msg_flags = NULL;
327} 327}
328 328
329static void imap_fetch_result_free(mailmessage * msg_info, 329static void imap_fetch_result_free(mailmessage * msg_info,
330 char * msg) 330 char * msg)
331{ 331{
332 mailmessage_fetch_result_free(get_ancestor(msg_info), msg); 332 mailmessage_fetch_result_free(get_ancestor(msg_info), msg);
333} 333}
334 334
335static int imap_fetch(mailmessage * msg_info, 335static int imap_fetch(mailmessage * msg_info,
336 char ** result, 336 char ** result,
337 size_t * result_len) 337 size_t * result_len)
338{ 338{
339 char key[PATH_MAX]; 339 char key[PATH_MAX];
340 char filename[PATH_MAX]; 340 char filename[PATH_MAX];
341 int r; 341 int r;
342 char * str; 342 char * str;
343 size_t len; 343 size_t len;
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
@@ -2982,399 +2982,423 @@ uid_list_to_env_list(clist * fetch_result,
2982 if (r < 0) { 2982 if (r < 0) {
2983 res = MAIL_ERROR_MEMORY; 2983 res = MAIL_ERROR_MEMORY;
2984 goto free_msg; 2984 goto free_msg;
2985 } 2985 }
2986 } 2986 }
2987 2987
2988 env_list = mailmessage_list_new(tab); 2988 env_list = mailmessage_list_new(tab);
2989 if (env_list == NULL) { 2989 if (env_list == NULL) {
2990 res = MAIL_ERROR_MEMORY; 2990 res = MAIL_ERROR_MEMORY;
2991 goto free_list; 2991 goto free_list;
2992 } 2992 }
2993 2993
2994 * result = env_list; 2994 * result = env_list;
2995 2995
2996 return MAIL_NO_ERROR; 2996 return MAIL_NO_ERROR;
2997 2997
2998 free_msg: 2998 free_msg:
2999 mailmessage_free(msg); 2999 mailmessage_free(msg);
3000 free_list: 3000 free_list:
3001 for(i = 0 ; i < carray_count(tab) ; i++) 3001 for(i = 0 ; i < carray_count(tab) ; i++)
3002 mailmessage_free(carray_get(tab, i)); 3002 mailmessage_free(carray_get(tab, i));
3003 err: 3003 err:
3004 return res; 3004 return res;
3005} 3005}
3006 3006
3007 3007
3008/* 3008/*
3009 MAILIMAP_FLAG_FETCH_RECENT, 3009 MAILIMAP_FLAG_FETCH_RECENT,
3010 MAILIMAP_FLAG_FETCH_OTHER 3010 MAILIMAP_FLAG_FETCH_OTHER
3011 3011
3012 MAILIMAP_FLAG_ANSWERED, 3012 MAILIMAP_FLAG_ANSWERED,
3013 MAILIMAP_FLAG_FLAGGED, 3013 MAILIMAP_FLAG_FLAGGED,
3014 MAILIMAP_FLAG_DELETED, 3014 MAILIMAP_FLAG_DELETED,
3015 MAILIMAP_FLAG_SEEN, 3015 MAILIMAP_FLAG_SEEN,
3016 MAILIMAP_FLAG_DRAFT, 3016 MAILIMAP_FLAG_DRAFT,
3017 MAILIMAP_FLAG_KEYWORD, 3017 MAILIMAP_FLAG_KEYWORD,
3018 MAILIMAP_FLAG_EXTENSION 3018 MAILIMAP_FLAG_EXTENSION
3019*/ 3019*/
3020 3020
3021static int imap_flags_to_flags(struct mailimap_msg_att_dynamic * att_dyn, 3021static int imap_flags_to_flags(struct mailimap_msg_att_dynamic * att_dyn,
3022 struct mail_flags ** result) 3022 struct mail_flags ** result)
3023{ 3023{
3024 struct mail_flags * flags; 3024 struct mail_flags * flags;
3025 clist * flag_list; 3025 clist * flag_list;
3026 clistiter * cur; 3026 clistiter * cur;
3027 3027
3028 flags = mail_flags_new_empty(); 3028 flags = mail_flags_new_empty();
3029 if (flags == NULL) 3029 if (flags == NULL)
3030 goto err; 3030 goto err;
3031 flags->fl_flags = 0; 3031 flags->fl_flags = 0;
3032 3032
3033 flag_list = att_dyn->att_list; 3033 flag_list = att_dyn->att_list;
3034 if (flag_list != NULL) { 3034 if (flag_list != NULL) {
3035 for(cur = clist_begin(flag_list) ; cur != NULL ; 3035 for(cur = clist_begin(flag_list) ; cur != NULL ;
3036 cur = clist_next(cur)) { 3036 cur = clist_next(cur)) {
3037 struct mailimap_flag_fetch * flag_fetch; 3037 struct mailimap_flag_fetch * flag_fetch;
3038 3038
3039 flag_fetch = clist_content(cur); 3039 flag_fetch = clist_content(cur);
3040 if (flag_fetch->fl_type == MAILIMAP_FLAG_FETCH_RECENT) 3040 if (flag_fetch->fl_type == MAILIMAP_FLAG_FETCH_RECENT)
3041 flags->fl_flags |= MAIL_FLAG_NEW; 3041 flags->fl_flags |= MAIL_FLAG_NEW;
3042 else { 3042 else {
3043 char * keyword; 3043 char * keyword;
3044 int r; 3044 int r;
3045 3045
3046 switch (flag_fetch->fl_flag->fl_type) { 3046 switch (flag_fetch->fl_flag->fl_type) {
3047 case MAILIMAP_FLAG_ANSWERED: 3047 case MAILIMAP_FLAG_ANSWERED:
3048 flags->fl_flags |= MAIL_FLAG_ANSWERED; 3048 flags->fl_flags |= MAIL_FLAG_ANSWERED;
3049 break; 3049 break;
3050 case MAILIMAP_FLAG_FLAGGED: 3050 case MAILIMAP_FLAG_FLAGGED:
3051 flags->fl_flags |= MAIL_FLAG_FLAGGED; 3051 flags->fl_flags |= MAIL_FLAG_FLAGGED;
3052 break; 3052 break;
3053 case MAILIMAP_FLAG_DELETED: 3053 case MAILIMAP_FLAG_DELETED:
3054 flags->fl_flags |= MAIL_FLAG_DELETED; 3054 flags->fl_flags |= MAIL_FLAG_DELETED;
3055 break; 3055 break;
3056 case MAILIMAP_FLAG_SEEN: 3056 case MAILIMAP_FLAG_SEEN:
3057 flags->fl_flags |= MAIL_FLAG_SEEN; 3057 flags->fl_flags |= MAIL_FLAG_SEEN;
3058 break; 3058 break;
3059 case MAILIMAP_FLAG_DRAFT: 3059 case MAILIMAP_FLAG_DRAFT:
3060 keyword = strdup("Draft"); 3060 keyword = strdup("Draft");
3061 if (keyword == NULL) 3061 if (keyword == NULL)
3062 goto free; 3062 goto free;
3063 r = clist_append(flags->fl_extension, keyword); 3063 r = clist_append(flags->fl_extension, keyword);
3064 if (r < 0) { 3064 if (r < 0) {
3065 free(keyword); 3065 free(keyword);
3066 goto free; 3066 goto free;
3067 } 3067 }
3068 break; 3068 break;
3069 case MAILIMAP_FLAG_KEYWORD: 3069 case MAILIMAP_FLAG_KEYWORD:
3070 if (strcasecmp(flag_fetch->fl_flag->fl_data.fl_keyword, 3070 if (strcasecmp(flag_fetch->fl_flag->fl_data.fl_keyword,
3071 "$Forwarded") == 0) { 3071 "$Forwarded") == 0) {
3072 flags->fl_flags |= MAIL_FLAG_FORWARDED; 3072 flags->fl_flags |= MAIL_FLAG_FORWARDED;
3073 } 3073 }
3074 else { 3074 else {
3075 keyword = strdup(flag_fetch->fl_flag->fl_data.fl_keyword); 3075 keyword = strdup(flag_fetch->fl_flag->fl_data.fl_keyword);
3076 if (keyword == NULL) 3076 if (keyword == NULL)
3077 goto free; 3077 goto free;
3078 r = clist_append(flags->fl_extension, keyword); 3078 r = clist_append(flags->fl_extension, keyword);
3079 if (r < 0) { 3079 if (r < 0) {
3080 free(keyword); 3080 free(keyword);
3081 goto free; 3081 goto free;
3082 } 3082 }
3083 } 3083 }
3084 break; 3084 break;
3085 case MAILIMAP_FLAG_EXTENSION: 3085 case MAILIMAP_FLAG_EXTENSION:
3086 /* do nothing */ 3086 /* do nothing */
3087 break; 3087 break;
3088 } 3088 }
3089 } 3089 }
3090 } 3090 }
3091 /* 3091 /*
3092 MAIL_FLAG_NEW was set for \Recent messages. 3092 MAIL_FLAG_NEW was set for \Recent messages.
3093 Correct this flag for \Seen messages by unsetting it. 3093 Correct this flag for \Seen messages by unsetting it.
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
3110static int flags_to_imap_flags(struct mail_flags * flags, 3110int 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;
3136 goto free_flag_list; 3135 goto free_flag_list;
3137 } 3136 }
3138 } 3137 }
3139 3138
3140 if ((flags->fl_flags & MAIL_FLAG_FLAGGED) != 0) { 3139 if ((flags->fl_flags & MAIL_FLAG_FLAGGED) != 0) {
3141 flag = mailimap_flag_new_flagged(); 3140 flag = mailimap_flag_new_flagged();
3142 if (flag == NULL) { 3141 if (flag == NULL) {
3143 res = MAIL_ERROR_MEMORY; 3142 res = MAIL_ERROR_MEMORY;
3144 goto free_flag_list; 3143 goto free_flag_list;
3145 } 3144 }
3146 r = mailimap_flag_list_add(flag_list, flag); 3145 r = mailimap_flag_list_add(flag_list, flag);
3147 if (r != MAILIMAP_NO_ERROR) { 3146 if (r != MAILIMAP_NO_ERROR) {
3148 mailimap_flag_free(flag); 3147 mailimap_flag_free(flag);
3149 res = MAIL_ERROR_MEMORY; 3148 res = MAIL_ERROR_MEMORY;
3150 goto free_flag_list; 3149 goto free_flag_list;
3151 } 3150 }
3152 } 3151 }
3153 3152
3154 if ((flags->fl_flags & MAIL_FLAG_SEEN) != 0) { 3153 if ((flags->fl_flags & MAIL_FLAG_SEEN) != 0) {
3155 flag = mailimap_flag_new_seen(); 3154 flag = mailimap_flag_new_seen();
3156 if (flag == NULL) { 3155 if (flag == NULL) {
3157 res = MAIL_ERROR_MEMORY; 3156 res = MAIL_ERROR_MEMORY;
3158 goto free_flag_list; 3157 goto free_flag_list;
3159 } 3158 }
3160 r = mailimap_flag_list_add(flag_list, flag); 3159 r = mailimap_flag_list_add(flag_list, flag);
3161 if (r != MAILIMAP_NO_ERROR) { 3160 if (r != MAILIMAP_NO_ERROR) {
3162 res = MAIL_ERROR_MEMORY; 3161 res = MAIL_ERROR_MEMORY;
3163 goto free_flag_list; 3162 goto free_flag_list;
3164 } 3163 }
3165 } 3164 }
3166 3165
3167 if ((flags->fl_flags & MAIL_FLAG_ANSWERED) != 0) { 3166 if ((flags->fl_flags & MAIL_FLAG_ANSWERED) != 0) {
3168 flag = mailimap_flag_new_answered(); 3167 flag = mailimap_flag_new_answered();
3169 if (flag == NULL) { 3168 if (flag == NULL) {
3170 res = MAIL_ERROR_MEMORY; 3169 res = MAIL_ERROR_MEMORY;
3171 goto free_flag_list; 3170 goto free_flag_list;
3172 } 3171 }
3173 r = mailimap_flag_list_add(flag_list, flag); 3172 r = mailimap_flag_list_add(flag_list, flag);
3174 if (r != MAILIMAP_NO_ERROR) { 3173 if (r != MAILIMAP_NO_ERROR) {
3175 mailimap_flag_free(flag); 3174 mailimap_flag_free(flag);
3176 res = MAIL_ERROR_MEMORY; 3175 res = MAIL_ERROR_MEMORY;
3177 goto free_flag_list; 3176 goto free_flag_list;
3178 } 3177 }
3179 } 3178 }
3180 3179
3181 if ((flags->fl_flags & MAIL_FLAG_FORWARDED) != 0) { 3180 if ((flags->fl_flags & MAIL_FLAG_FORWARDED) != 0) {
3182 char * flag_str; 3181 char * flag_str;
3183 3182
3184 flag_str = strdup("$Forwarded"); 3183 flag_str = strdup("$Forwarded");
3185 if (flag_str == NULL) { 3184 if (flag_str == NULL) {
3186 res = MAIL_ERROR_MEMORY; 3185 res = MAIL_ERROR_MEMORY;
3187 goto free_flag_list; 3186 goto free_flag_list;
3188 } 3187 }
3189 flag = mailimap_flag_new_flag_keyword(flag_str); 3188 flag = mailimap_flag_new_flag_keyword(flag_str);
3190 if (flag == NULL) { 3189 if (flag == NULL) {
3191 free(flag_str); 3190 free(flag_str);
3192 res = MAIL_ERROR_MEMORY; 3191 res = MAIL_ERROR_MEMORY;
3193 goto free_flag_list; 3192 goto free_flag_list;
3194 } 3193 }
3195 r = mailimap_flag_list_add(flag_list, flag); 3194 r = mailimap_flag_list_add(flag_list, flag);
3196 if (r != MAILIMAP_NO_ERROR) { 3195 if (r != MAILIMAP_NO_ERROR) {
3197 mailimap_flag_free(flag); 3196 mailimap_flag_free(flag);
3198 res = MAIL_ERROR_MEMORY; 3197 res = MAIL_ERROR_MEMORY;
3199 goto free_flag_list; 3198 goto free_flag_list;
3200 } 3199 }
3201 } 3200 }
3202 3201
3203 for(cur = clist_begin(flags->fl_extension) ; cur != NULL ; 3202 for(cur = clist_begin(flags->fl_extension) ; cur != NULL ;
3204 cur = clist_next(cur)) { 3203 cur = clist_next(cur)) {
3205 char * flag_str; 3204 char * flag_str;
3206 3205
3207 flag_str = clist_content(cur); 3206 flag_str = clist_content(cur);
3208 3207
3209 if (strcasecmp(flag_str, "Draft") == 0) { 3208 if (strcasecmp(flag_str, "Draft") == 0) {
3210 flag = mailimap_flag_new_draft(); 3209 flag = mailimap_flag_new_draft();
3211 if (flag == NULL) { 3210 if (flag == NULL) {
3212 res = MAIL_ERROR_MEMORY; 3211 res = MAIL_ERROR_MEMORY;
3213 goto free_flag_list; 3212 goto free_flag_list;
3214 } 3213 }
3215 r = mailimap_flag_list_add(flag_list, flag); 3214 r = mailimap_flag_list_add(flag_list, flag);
3216 if (r != MAILIMAP_NO_ERROR) { 3215 if (r != MAILIMAP_NO_ERROR) {
3217 mailimap_flag_free(flag); 3216 mailimap_flag_free(flag);
3218 res = MAIL_ERROR_MEMORY; 3217 res = MAIL_ERROR_MEMORY;
3219 goto free_flag_list; 3218 goto free_flag_list;
3220 } 3219 }
3221 } 3220 }
3222 else { 3221 else {
3223 flag_str = strdup(flag_str); 3222 flag_str = strdup(flag_str);
3224 if (flag_str == NULL) { 3223 if (flag_str == NULL) {
3225 res = MAIL_ERROR_MEMORY; 3224 res = MAIL_ERROR_MEMORY;
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
3252static 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
3260static int 3284static int
3261imap_fetch_result_to_flags(clist * fetch_result, uint32_t index, 3285imap_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)) {
3269 struct mailimap_msg_att * msg_att; 3293 struct mailimap_msg_att * msg_att;
3270 clistiter * item_cur; 3294 clistiter * item_cur;
3271 uint32_t uid; 3295 uint32_t uid;
3272 struct mailimap_msg_att_dynamic * att_dyn; 3296 struct mailimap_msg_att_dynamic * att_dyn;
3273 3297
3274 msg_att = clist_content(cur); 3298 msg_att = clist_content(cur);
3275 3299
3276 uid = 0; 3300 uid = 0;
3277 att_dyn = NULL; 3301 att_dyn = NULL;
3278 3302
3279 for(item_cur = clist_begin(msg_att->att_list) ; item_cur != NULL ; 3303 for(item_cur = clist_begin(msg_att->att_list) ; item_cur != NULL ;
3280 item_cur = clist_next(item_cur)) { 3304 item_cur = clist_next(item_cur)) {
3281 struct mailimap_msg_att_item * item; 3305 struct mailimap_msg_att_item * item;
3282 3306
3283 item = clist_content(item_cur); 3307 item = clist_content(item_cur);
3284 3308
3285 if (item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 3309 if (item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
3286 switch (item->att_data.att_static->att_type) { 3310 switch (item->att_data.att_static->att_type) {
3287 case MAILIMAP_MSG_ATT_UID: 3311 case MAILIMAP_MSG_ATT_UID:
3288 uid = item->att_data.att_static->att_data.att_uid; 3312 uid = item->att_data.att_static->att_data.att_uid;
3289 break; 3313 break;
3290 } 3314 }
3291 } 3315 }
3292 else if (item->att_type == MAILIMAP_MSG_ATT_ITEM_DYNAMIC) { 3316 else if (item->att_type == MAILIMAP_MSG_ATT_ITEM_DYNAMIC) {
3293 if (att_dyn == NULL) { 3317 if (att_dyn == NULL) {
3294 att_dyn = item->att_data.att_dyn; 3318 att_dyn = item->att_data.att_dyn;
3295 } 3319 }
3296 } 3320 }
3297 } 3321 }
3298 3322
3299 if (uid != 0) { 3323 if (uid != 0) {
3300 if (uid == index) { 3324 if (uid == index) {
3301 struct mail_flags * flags; 3325 struct mail_flags * flags;
3302 3326
3303 if (att_dyn != NULL) { 3327 if (att_dyn != NULL) {
3304 r = imap_flags_to_flags(att_dyn, &flags); 3328 r = imap_flags_to_flags(att_dyn, &flags);
3305 3329
3306 if (r == MAIL_NO_ERROR) { 3330 if (r == MAIL_NO_ERROR) {
3307 * result = flags; 3331 * result = flags;
3308 return MAIL_NO_ERROR; 3332 return MAIL_NO_ERROR;
3309 } 3333 }
3310 } 3334 }
3311 } 3335 }
3312 } 3336 }
3313 } 3337 }
3314 3338
3315 return MAIL_ERROR_MSG_NOT_FOUND; 3339 return MAIL_ERROR_MSG_NOT_FOUND;
3316} 3340}
3317 3341
3318 3342
3319int imap_fetch_flags(mailimap * imap, 3343int imap_fetch_flags(mailimap * imap,
3320 uint32_t index, struct mail_flags ** result) 3344 uint32_t index, struct mail_flags ** result)
3321{ 3345{
3322 struct mailimap_fetch_att * fetch_att; 3346 struct mailimap_fetch_att * fetch_att;
3323 struct mailimap_fetch_type * fetch_type; 3347 struct mailimap_fetch_type * fetch_type;
3324 struct mailimap_set * set; 3348 struct mailimap_set * set;
3325 int r; 3349 int r;
3326 int res; 3350 int res;
3327 clist * fetch_result; 3351 clist * fetch_result;
3328 struct mail_flags * flags; 3352 struct mail_flags * flags;
3329 3353
3330 fetch_type = mailimap_fetch_type_new_fetch_att_list_empty(); 3354 fetch_type = mailimap_fetch_type_new_fetch_att_list_empty();
3331 if (fetch_type == NULL) { 3355 if (fetch_type == NULL) {
3332 res = MAIL_ERROR_MEMORY; 3356 res = MAIL_ERROR_MEMORY;
3333 goto err; 3357 goto err;
3334 } 3358 }
3335 3359
3336 fetch_att = mailimap_fetch_att_new_uid(); 3360 fetch_att = mailimap_fetch_att_new_uid();
3337 if (fetch_att == NULL) { 3361 if (fetch_att == NULL) {
3338 res = MAIL_ERROR_MEMORY; 3362 res = MAIL_ERROR_MEMORY;
3339 goto free_fetch_type; 3363 goto free_fetch_type;
3340 } 3364 }
3341 3365
3342 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); 3366 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
3343 if (r != MAILIMAP_NO_ERROR) { 3367 if (r != MAILIMAP_NO_ERROR) {
3344 mailimap_fetch_att_free(fetch_att); 3368 mailimap_fetch_att_free(fetch_att);
3345 res = MAIL_ERROR_MEMORY; 3369 res = MAIL_ERROR_MEMORY;
3346 goto free_fetch_type; 3370 goto free_fetch_type;
3347 } 3371 }
3348 3372
3349 fetch_att = mailimap_fetch_att_new_flags(); 3373 fetch_att = mailimap_fetch_att_new_flags();
3350 if (fetch_att == NULL) { 3374 if (fetch_att == NULL) {
3351 res = MAIL_ERROR_MEMORY; 3375 res = MAIL_ERROR_MEMORY;
3352 goto free_fetch_type; 3376 goto free_fetch_type;
3353 } 3377 }
3354 3378
3355 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); 3379 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
3356 if (r != MAILIMAP_NO_ERROR) { 3380 if (r != MAILIMAP_NO_ERROR) {
3357 mailimap_fetch_att_free(fetch_att); 3381 mailimap_fetch_att_free(fetch_att);
3358 res = MAIL_ERROR_MEMORY; 3382 res = MAIL_ERROR_MEMORY;
3359 goto free_fetch_type; 3383 goto free_fetch_type;
3360 } 3384 }
3361 3385
3362 set = mailimap_set_new_single(index); 3386 set = mailimap_set_new_single(index);
3363 if (set == NULL) { 3387 if (set == NULL) {
3364 res = MAIL_ERROR_MEMORY; 3388 res = MAIL_ERROR_MEMORY;
3365 goto free_fetch_type; 3389 goto free_fetch_type;
3366 } 3390 }
3367 3391
3368 r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result); 3392 r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result);
3369 3393
3370 mailimap_fetch_type_free(fetch_type); 3394 mailimap_fetch_type_free(fetch_type);
3371 mailimap_set_free(set); 3395 mailimap_set_free(set);
3372 3396
3373 switch (r) { 3397 switch (r) {
3374 case MAILIMAP_NO_ERROR: 3398 case MAILIMAP_NO_ERROR:
3375 break; 3399 break;
3376 default: 3400 default:
3377 return imap_error_to_mail_error(r); 3401 return imap_error_to_mail_error(r);
3378 } 3402 }
3379 3403
3380 r = imap_fetch_result_to_flags(fetch_result, index, &flags); 3404 r = imap_fetch_result_to_flags(fetch_result, index, &flags);
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
@@ -1,113 +1,116 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef IMAPDRIVER_TOOLS_H 36#ifndef IMAPDRIVER_TOOLS_H
37 37
38#define IMAPDRIVER_TOOLS_H 38#define IMAPDRIVER_TOOLS_H
39 39
40#include "mailimap.h" 40#include "mailimap.h"
41#include "mailmime.h" 41#include "mailmime.h"
42#include "imapdriver_types.h" 42#include "imapdriver_types.h"
43#include "mail_cache_db.h" 43#include "mail_cache_db.h"
44 44
45#ifdef __cplusplus 45#ifdef __cplusplus
46extern "C" { 46extern "C" {
47#endif 47#endif
48 48
49int imap_list_to_list(clist * imap_list, struct mail_list ** result); 49int imap_list_to_list(clist * imap_list, struct mail_list ** result);
50 50
51int 51int
52section_to_imap_section(struct mailmime_section * section, int type, 52section_to_imap_section(struct mailmime_section * section, int type,
53 struct mailimap_section ** result); 53 struct mailimap_section ** result);
54 54
55int imap_get_msg_att_info(struct mailimap_msg_att * msg_att, 55int imap_get_msg_att_info(struct mailimap_msg_att * msg_att,
56 uint32_t * puid, 56 uint32_t * puid,
57 struct mailimap_envelope ** pimap_envelope, 57 struct mailimap_envelope ** pimap_envelope,
58 char ** preferences, 58 char ** preferences,
59 size_t * pref_size, 59 size_t * pref_size,
60 struct mailimap_msg_att_dynamic ** patt_dyn, 60 struct mailimap_msg_att_dynamic ** patt_dyn,
61 struct mailimap_body ** pimap_body); 61 struct mailimap_body ** pimap_body);
62 62
63int imap_add_envelope_fetch_att(struct mailimap_fetch_type * fetch_type); 63int imap_add_envelope_fetch_att(struct mailimap_fetch_type * fetch_type);
64 64
65int imap_env_to_fields(struct mailimap_envelope * env, 65int imap_env_to_fields(struct mailimap_envelope * env,
66 char * ref_str, size_t ref_size, 66 char * ref_str, size_t ref_size,
67 struct mailimf_fields ** result); 67 struct mailimf_fields ** result);
68 68
69int 69int
70imap_fetch_result_to_envelop_list(clist * fetch_result, 70imap_fetch_result_to_envelop_list(clist * fetch_result,
71 struct mailmessage_list * env_list); 71 struct mailmessage_list * env_list);
72 72
73int imap_body_to_body(struct mailimap_body * imap_body, 73int imap_body_to_body(struct mailimap_body * imap_body,
74 struct mailmime ** result); 74 struct mailmime ** result);
75 75
76#if 0 76#if 0
77int mail_search_to_imap_search(struct mail_search_key * key, 77int mail_search_to_imap_search(struct mail_search_key * key,
78 struct mailimap_search_key ** result); 78 struct mailimap_search_key ** result);
79#endif 79#endif
80 80
81int msg_list_to_imap_set(clist * msg_list, 81int msg_list_to_imap_set(clist * msg_list,
82 struct mailimap_set ** result); 82 struct mailimap_set ** result);
83 83
84int imap_error_to_mail_error(int error); 84int imap_error_to_mail_error(int error);
85 85
86int imap_store_flags(mailimap * imap, uint32_t first, uint32_t last, 86int imap_store_flags(mailimap * imap, uint32_t first, uint32_t last,
87 struct mail_flags * flags); 87 struct mail_flags * flags);
88 88
89int imap_fetch_flags(mailimap * imap, 89int imap_fetch_flags(mailimap * imap,
90 uint32_t index, struct mail_flags ** result); 90 uint32_t index, struct mail_flags ** result);
91 91
92int imap_get_messages_list(mailimap * imap, 92int 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
97int 97int
98imapdriver_get_cached_envelope(struct mail_cache_db * cache_db, 98imapdriver_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
103int 103int
104imapdriver_write_cached_envelope(struct mail_cache_db * cache_db, 104imapdriver_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
109int 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
@@ -1,202 +1,202 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "imapstorage.h" 36#include "imapstorage.h"
37 37
38#include <stdlib.h> 38#include <stdlib.h>
39#include <string.h> 39#include <string.h>
40 40
41#include "mail.h" 41#include "mail.h"
42#include "imapdriver.h" 42#include "imapdriver.h"
43#include "imapdriver_cached.h" 43#include "imapdriver_cached.h"
44#include "mailstorage_tools.h" 44#include "mailstorage_tools.h"
45#include "maildriver.h" 45#include "maildriver.h"
46 46
47/* imap storage */ 47/* imap storage */
48 48
49#define IMAP_DEFAULT_PORT 143 49#define IMAP_DEFAULT_PORT 143
50#define IMAPS_DEFAULT_PORT 993 50#define IMAPS_DEFAULT_PORT 993
51 51
52static int imap_mailstorage_connect(struct mailstorage * storage); 52static int imap_mailstorage_connect(struct mailstorage * storage);
53static int 53static int
54imap_mailstorage_get_folder_session(struct mailstorage * storage, 54imap_mailstorage_get_folder_session(struct mailstorage * storage,
55 char * pathname, mailsession ** result); 55 char * pathname, mailsession ** result);
56static void imap_mailstorage_uninitialize(struct mailstorage * storage); 56static void imap_mailstorage_uninitialize(struct mailstorage * storage);
57 57
58static mailstorage_driver imap_mailstorage_driver = { 58static 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
65int imap_mailstorage_init(struct mailstorage * storage, 65int 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:
91 case CONNECTION_TYPE_COMMAND_STARTTLS: 91 case CONNECTION_TYPE_COMMAND_STARTTLS:
92 imap_port = IMAP_DEFAULT_PORT; 92 imap_port = IMAP_DEFAULT_PORT;
93 break; 93 break;
94 94
95 case CONNECTION_TYPE_TLS: 95 case CONNECTION_TYPE_TLS:
96 case CONNECTION_TYPE_COMMAND_TLS: 96 case CONNECTION_TYPE_COMMAND_TLS:
97 imap_port = IMAPS_DEFAULT_PORT; 97 imap_port = IMAPS_DEFAULT_PORT;
98 break; 98 break;
99 } 99 }
100 } 100 }
101 101
102 imap_storage->imap_port = imap_port; 102 imap_storage->imap_port = imap_port;
103 103
104 if (imap_command != NULL) { 104 if (imap_command != NULL) {
105 imap_storage->imap_command = strdup(imap_command); 105 imap_storage->imap_command = strdup(imap_command);
106 if (imap_storage->imap_command == NULL) 106 if (imap_storage->imap_command == NULL)
107 goto free_servername; 107 goto free_servername;
108 } 108 }
109 else 109 else
110 imap_storage->imap_command = NULL; 110 imap_storage->imap_command = NULL;
111 111
112 imap_storage->imap_auth_type = imap_auth_type; 112 imap_storage->imap_auth_type = imap_auth_type;
113 113
114 if (imap_login != NULL) { 114 if (imap_login != NULL) {
115 imap_storage->imap_login = strdup(imap_login); 115 imap_storage->imap_login = strdup(imap_login);
116 if (imap_storage->imap_login == NULL) 116 if (imap_storage->imap_login == NULL)
117 goto free_command; 117 goto free_command;
118 } 118 }
119 else 119 else
120 imap_storage->imap_login = NULL; 120 imap_storage->imap_login = NULL;
121 121
122 if (imap_password != NULL) { 122 if (imap_password != NULL) {
123 imap_storage->imap_password = strdup(imap_password); 123 imap_storage->imap_password = strdup(imap_password);
124 if (imap_storage->imap_password == NULL) 124 if (imap_storage->imap_password == NULL)
125 goto free_login; 125 goto free_login;
126 } 126 }
127 else 127 else
128 imap_storage->imap_password = NULL; 128 imap_storage->imap_password = NULL;
129 129
130 imap_storage->imap_cached = imap_cached; 130 imap_storage->imap_cached = imap_cached;
131 131
132 if (imap_cached && (imap_cache_directory != NULL)) { 132 if (imap_cached && (imap_cache_directory != NULL)) {
133 imap_storage->imap_cache_directory = strdup(imap_cache_directory); 133 imap_storage->imap_cache_directory = strdup(imap_cache_directory);
134 if (imap_storage->imap_cache_directory == NULL) 134 if (imap_storage->imap_cache_directory == NULL)
135 goto free_password; 135 goto free_password;
136 } 136 }
137 else { 137 else {
138 imap_storage->imap_cached = FALSE; 138 imap_storage->imap_cached = FALSE;
139 imap_storage->imap_cache_directory = NULL; 139 imap_storage->imap_cache_directory = NULL;
140 } 140 }
141 141
142 storage->sto_data = imap_storage; 142 storage->sto_data = imap_storage;
143 storage->sto_driver = &imap_mailstorage_driver; 143 storage->sto_driver = &imap_mailstorage_driver;
144 144
145 return MAIL_NO_ERROR; 145 return MAIL_NO_ERROR;
146 146
147 free_password: 147 free_password:
148 free(imap_storage->imap_password); 148 free(imap_storage->imap_password);
149 free_login: 149 free_login:
150 free(imap_storage->imap_login); 150 free(imap_storage->imap_login);
151 free_command: 151 free_command:
152 free(imap_storage->imap_command); 152 free(imap_storage->imap_command);
153 free_servername: 153 free_servername:
154 free(imap_storage->imap_servername); 154 free(imap_storage->imap_servername);
155 free: 155 free:
156 free(imap_storage); 156 free(imap_storage);
157 err: 157 err:
158 return MAIL_ERROR_MEMORY; 158 return MAIL_ERROR_MEMORY;
159} 159}
160 160
161static void imap_mailstorage_uninitialize(struct mailstorage * storage) 161static void imap_mailstorage_uninitialize(struct mailstorage * storage)
162{ 162{
163 struct imap_mailstorage * imap_storage; 163 struct imap_mailstorage * imap_storage;
164 164
165 imap_storage = storage->sto_data; 165 imap_storage = storage->sto_data;
166 166
167 if (imap_storage->imap_cache_directory != NULL) 167 if (imap_storage->imap_cache_directory != NULL)
168 free(imap_storage->imap_cache_directory); 168 free(imap_storage->imap_cache_directory);
169 if (imap_storage->imap_password != NULL) 169 if (imap_storage->imap_password != NULL)
170 free(imap_storage->imap_password); 170 free(imap_storage->imap_password);
171 if (imap_storage->imap_login != NULL) 171 if (imap_storage->imap_login != NULL)
172 free(imap_storage->imap_login); 172 free(imap_storage->imap_login);
173 if (imap_storage->imap_command != NULL) 173 if (imap_storage->imap_command != NULL)
174 free(imap_storage->imap_command); 174 free(imap_storage->imap_command);
175 free(imap_storage->imap_servername); 175 free(imap_storage->imap_servername);
176 free(imap_storage); 176 free(imap_storage);
177 177
178 storage->sto_data = NULL; 178 storage->sto_data = NULL;
179} 179}
180 180
181static int imap_connect(struct mailstorage * storage, 181static int imap_connect(struct mailstorage * storage,
182 mailsession ** result) 182 mailsession ** result)
183{ 183{
184 struct imap_mailstorage * imap_storage; 184 struct imap_mailstorage * imap_storage;
185 mailsession_driver * driver; 185 mailsession_driver * driver;
186 int r; 186 int r;
187 int res; 187 int res;
188 mailsession * session; 188 mailsession * session;
189 189
190 imap_storage = storage->sto_data; 190 imap_storage = storage->sto_data;
191 191
192 if (imap_storage->imap_cached) 192 if (imap_storage->imap_cached)
193 driver = imap_cached_session_driver; 193 driver = imap_cached_session_driver;
194 else 194 else
195 driver = imap_session_driver; 195 driver = imap_session_driver;
196 196
197 r = mailstorage_generic_connect(driver, 197 r = mailstorage_generic_connect(driver,
198 imap_storage->imap_servername, 198 imap_storage->imap_servername,
199 imap_storage->imap_port, 199 imap_storage->imap_port,
200 imap_storage->imap_command, 200 imap_storage->imap_command,
201 imap_storage->imap_connection_type, 201 imap_storage->imap_connection_type,
202 IMAPDRIVER_CACHED_SET_CACHE_DIRECTORY, 202 IMAPDRIVER_CACHED_SET_CACHE_DIRECTORY,
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
@@ -1,497 +1,548 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 36
37/* 37/*
38 flags directory MUST be kept so that we can have other flags 38 flags directory MUST be kept so that we can have other flags
39 than standards 39 than standards
40*/ 40*/
41 41
42#include "maildirdriver.h" 42#include "maildirdriver.h"
43 43
44#include <stdio.h> 44#include <stdio.h>
45#include <sys/types.h> 45#include <sys/types.h>
46#include <dirent.h> 46#include <dirent.h>
47#include <unistd.h> 47#include <unistd.h>
48#include <sys/stat.h> 48#include <sys/stat.h>
49#include <ctype.h> 49#include <ctype.h>
50#include <fcntl.h> 50#include <fcntl.h>
51#include <sys/mman.h> 51#include <sys/mman.h>
52#include <stdlib.h> 52#include <stdlib.h>
53#include <string.h> 53#include <string.h>
54 54
55#include "maildir.h" 55#include "maildir.h"
56#include "maildriver_tools.h" 56#include "maildriver_tools.h"
57#include "maildirdriver_message.h" 57#include "maildirdriver_message.h"
58#include "maildirdriver_tools.h" 58#include "maildirdriver_tools.h"
59#include "mailmessage.h" 59#include "mailmessage.h"
60#include "generic_cache.h" 60#include "generic_cache.h"
61 61
62static int initialize(mailsession * session); 62static int initialize(mailsession * session);
63 63
64static void uninitialize(mailsession * session); 64static void uninitialize(mailsession * session);
65 65
66static int connect_path(mailsession * session, char * path); 66static int connect_path(mailsession * session, char * path);
67 67
68static int logout(mailsession * session); 68static int logout(mailsession * session);
69 69
70static int expunge_folder(mailsession * session); 70static int expunge_folder(mailsession * session);
71 71
72static int status_folder(mailsession * session, char * mb, 72static 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
76static int recent_number(mailsession * session, char * mb, 76static int recent_number(mailsession * session, char * mb,
77 uint32_t * result); 77 uint32_t * result);
78 78
79static int unseen_number(mailsession * session, char * mb, 79static int unseen_number(mailsession * session, char * mb,
80 uint32_t * result); 80 uint32_t * result);
81 81
82static int messages_number(mailsession * session, char * mb, 82static int messages_number(mailsession * session, char * mb,
83 uint32_t * result); 83 uint32_t * result);
84 84
85static int append_message(mailsession * session, 85static int append_message(mailsession * session,
86 char * message, size_t size); 86 char * message, size_t size);
87 87
88static int append_message_flags(mailsession * session,
89 char * message, size_t size, struct mail_flags * flags);
90
88static int get_messages_list(mailsession * session, 91static int get_messages_list(mailsession * session,
89 struct mailmessage_list ** result); 92 struct mailmessage_list ** result);
90 93
91static int get_envelopes_list(mailsession * session, 94static int get_envelopes_list(mailsession * session,
92 struct mailmessage_list * env_list); 95 struct mailmessage_list * env_list);
93 96
94static int check_folder(mailsession * session); 97static int check_folder(mailsession * session);
95 98
96static int get_message_by_uid(mailsession * session, 99static int get_message_by_uid(mailsession * session,
97 const char * uid, mailmessage ** result); 100 const char * uid, mailmessage ** result);
98 101
99static mailsession_driver local_maildir_session_driver = { 102static 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,
104 107
105 .sess_parameters = NULL, 108 .sess_parameters = NULL,
106 109
107 .sess_connect_stream = NULL, 110 .sess_connect_stream = NULL,
108 .sess_connect_path = connect_path, 111 .sess_connect_path = connect_path,
109 .sess_starttls = NULL, 112 .sess_starttls = NULL,
110 .sess_login = NULL, 113 .sess_login = NULL,
111 .sess_logout = logout, 114 .sess_logout = logout,
112 .sess_noop = NULL, 115 .sess_noop = NULL,
113 116
114 .sess_build_folder_name = NULL, 117 .sess_build_folder_name = NULL,
115 .sess_create_folder = NULL, 118 .sess_create_folder = NULL,
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
146mailsession_driver * maildir_session_driver = &local_maildir_session_driver; 150mailsession_driver * maildir_session_driver = &local_maildir_session_driver;
147 151
148 152
149static int flags_store_process(struct maildir * md, 153static int flags_store_process(struct maildir * md,
150 struct mail_flags_store * flags_store); 154 struct mail_flags_store * flags_store);
151 155
152 156
153static inline struct maildir_session_state_data * get_data(mailsession * session) 157static inline struct maildir_session_state_data * get_data(mailsession * session)
154{ 158{
155 return session->sess_data; 159 return session->sess_data;
156} 160}
157 161
158static struct maildir * get_maildir_session(mailsession * session) 162static struct maildir * get_maildir_session(mailsession * session)
159{ 163{
160 return get_data(session)->md_session; 164 return get_data(session)->md_session;
161} 165}
162 166
163static int initialize(mailsession * session) 167static int initialize(mailsession * session)
164{ 168{
165 struct maildir_session_state_data * data; 169 struct maildir_session_state_data * data;
166 170
167 data = malloc(sizeof(* data)); 171 data = malloc(sizeof(* data));
168 if (data == NULL) 172 if (data == NULL)
169 goto err; 173 goto err;
170 174
171 data->md_session = NULL; 175 data->md_session = NULL;
172 176
173 data->md_flags_store = mail_flags_store_new(); 177 data->md_flags_store = mail_flags_store_new();
174 if (data->md_flags_store == NULL) 178 if (data->md_flags_store == NULL)
175 goto free; 179 goto free;
176 180
177 session->sess_data = data; 181 session->sess_data = data;
178 182
179 return MAIL_NO_ERROR; 183 return MAIL_NO_ERROR;
180 184
181 free: 185 free:
182 free(data); 186 free(data);
183 err: 187 err:
184 return MAIL_ERROR_MEMORY; 188 return MAIL_ERROR_MEMORY;
185} 189}
186 190
187static void uninitialize(mailsession * session) 191static void uninitialize(mailsession * session)
188{ 192{
189 struct maildir_session_state_data * data; 193 struct maildir_session_state_data * data;
190 194
191 data = get_data(session); 195 data = get_data(session);
192 196
193 if (data->md_session != NULL) 197 if (data->md_session != NULL)
194 flags_store_process(data->md_session, data->md_flags_store); 198 flags_store_process(data->md_session, data->md_flags_store);
195 199
196 mail_flags_store_free(data->md_flags_store); 200 mail_flags_store_free(data->md_flags_store);
197 if (data->md_session != NULL) 201 if (data->md_session != NULL)
198 maildir_free(data->md_session); 202 maildir_free(data->md_session);
199 203
200 free(data); 204 free(data);
201 205
202 session->sess_data = NULL; 206 session->sess_data = NULL;
203} 207}
204 208
205 209
206static int connect_path(mailsession * session, char * path) 210static int connect_path(mailsession * session, char * path)
207{ 211{
208 struct maildir * md; 212 struct maildir * md;
209 int res; 213 int res;
210 int r; 214 int r;
211 215
212 if (get_maildir_session(session) != NULL) { 216 if (get_maildir_session(session) != NULL) {
213 res = MAIL_ERROR_BAD_STATE; 217 res = MAIL_ERROR_BAD_STATE;
214 goto err; 218 goto err;
215 } 219 }
216 220
217 md = maildir_new(path); 221 md = maildir_new(path);
218 if (md == NULL) { 222 if (md == NULL) {
219 res = MAIL_ERROR_MEMORY; 223 res = MAIL_ERROR_MEMORY;
220 goto err; 224 goto err;
221 } 225 }
222 226
223 r = maildir_update(md); 227 r = maildir_update(md);
224 if (r != MAILDIR_NO_ERROR) { 228 if (r != MAILDIR_NO_ERROR) {
225 res = maildirdriver_maildir_error_to_mail_error(r); 229 res = maildirdriver_maildir_error_to_mail_error(r);
226 goto free; 230 goto free;
227 } 231 }
228 232
229 get_data(session)->md_session = md; 233 get_data(session)->md_session = md;
230 234
231 return MAIL_NO_ERROR; 235 return MAIL_NO_ERROR;
232 236
233 free: 237 free:
234 maildir_free(md); 238 maildir_free(md);
235 err: 239 err:
236 return res; 240 return res;
237} 241}
238 242
239static int logout(mailsession * session) 243static int logout(mailsession * session)
240{ 244{
241 struct maildir * md; 245 struct maildir * md;
242 246
243 check_folder(session); 247 check_folder(session);
244 248
245 md = get_maildir_session(session); 249 md = get_maildir_session(session);
246 if (md == NULL) 250 if (md == NULL)
247 return MAIL_ERROR_BAD_STATE; 251 return MAIL_ERROR_BAD_STATE;
248 252
249 maildir_free(md); 253 maildir_free(md);
250 get_data(session)->md_session = NULL; 254 get_data(session)->md_session = NULL;
251 255
252 return MAIL_NO_ERROR; 256 return MAIL_NO_ERROR;
253} 257}
254 258
255/* folders operations */ 259/* folders operations */
256 260
257static int status_folder(mailsession * session, char * mb, 261static int status_folder(mailsession * session, char * mb,
258 uint32_t * result_messages, uint32_t * result_recent, 262 uint32_t * result_messages, uint32_t * result_recent,
259 uint32_t * result_unseen) 263 uint32_t * result_unseen)
260{ 264{
261 int r; 265 int r;
262 struct maildir * md; 266 struct maildir * md;
263 unsigned int i; 267 unsigned int i;
264 uint32_t messages; 268 uint32_t messages;
265 uint32_t recent; 269 uint32_t recent;
266 uint32_t unseen; 270 uint32_t unseen;
267 271
268 check_folder(session); 272 check_folder(session);
269 273
270 md = get_maildir_session(session); 274 md = get_maildir_session(session);
271 if (md == NULL) 275 if (md == NULL)
272 return MAIL_ERROR_BAD_STATE; 276 return MAIL_ERROR_BAD_STATE;
273 277
274 r = maildir_update(md); 278 r = maildir_update(md);
275 if (r != MAILDIR_NO_ERROR) 279 if (r != MAILDIR_NO_ERROR)
276 return maildirdriver_maildir_error_to_mail_error(r); 280 return maildirdriver_maildir_error_to_mail_error(r);
277 281
278 messages = 0; 282 messages = 0;
279 recent = 0; 283 recent = 0;
280 unseen = 0; 284 unseen = 0;
281 for(i = 0 ; i < carray_count(md->mdir_msg_list) ; i ++) { 285 for(i = 0 ; i < carray_count(md->mdir_msg_list) ; i ++) {
282 struct maildir_msg * msg; 286 struct maildir_msg * msg;
283 287
284 msg = carray_get(md->mdir_msg_list, i); 288 msg = carray_get(md->mdir_msg_list, i);
285 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) 289 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0)
286 recent ++; 290 recent ++;
287 if ((msg->msg_flags & MAILDIR_FLAG_SEEN) == 0) 291 if ((msg->msg_flags & MAILDIR_FLAG_SEEN) == 0)
288 unseen ++; 292 unseen ++;
289 messages ++; 293 messages ++;
290 } 294 }
291 295
292 * result_messages = messages; 296 * result_messages = messages;
293 * result_recent = recent; 297 * result_recent = recent;
294 * result_unseen = unseen; 298 * result_unseen = unseen;
295 299
296 return MAIL_NO_ERROR; 300 return MAIL_NO_ERROR;
297} 301}
298 302
299static int messages_number(mailsession * session, char * mb, 303static int messages_number(mailsession * session, char * mb,
300 uint32_t * result) 304 uint32_t * result)
301{ 305{
302 struct maildir * md; 306 struct maildir * md;
303 int r; 307 int r;
304 308
305 md = get_maildir_session(session); 309 md = get_maildir_session(session);
306 if (md == NULL) 310 if (md == NULL)
307 return MAIL_ERROR_BAD_STATE; 311 return MAIL_ERROR_BAD_STATE;
308 312
309 r = maildir_update(md); 313 r = maildir_update(md);
310 if (r != MAILDIR_NO_ERROR) 314 if (r != MAILDIR_NO_ERROR)
311 return maildirdriver_maildir_error_to_mail_error(r); 315 return maildirdriver_maildir_error_to_mail_error(r);
312 316
313 * result = carray_count(md->mdir_msg_list); 317 * result = carray_count(md->mdir_msg_list);
314 318
315 return MAIL_NO_ERROR; 319 return MAIL_NO_ERROR;
316} 320}
317 321
318static int unseen_number(mailsession * session, char * mb, 322static int unseen_number(mailsession * session, char * mb,
319 uint32_t * result) 323 uint32_t * result)
320{ 324{
321 uint32_t messages; 325 uint32_t messages;
322 uint32_t recent; 326 uint32_t recent;
323 uint32_t unseen; 327 uint32_t unseen;
324 int r; 328 int r;
325 329
326 r = status_folder(session, mb, &messages, &recent, &unseen); 330 r = status_folder(session, mb, &messages, &recent, &unseen);
327 if (r != MAIL_NO_ERROR) 331 if (r != MAIL_NO_ERROR)
328 return r; 332 return r;
329 333
330 * result = unseen; 334 * result = unseen;
331 335
332 return MAIL_NO_ERROR; 336 return MAIL_NO_ERROR;
333} 337}
334 338
335static int recent_number(mailsession * session, char * mb, 339static int recent_number(mailsession * session, char * mb,
336 uint32_t * result) 340 uint32_t * result)
337{ 341{
338 uint32_t messages; 342 uint32_t messages;
339 uint32_t recent; 343 uint32_t recent;
340 uint32_t unseen; 344 uint32_t unseen;
341 int r; 345 int r;
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
355static int append_message(mailsession * session, 359static 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
380static 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
372static int get_messages_list(mailsession * session, 423static 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) {
386 res = maildirdriver_maildir_error_to_mail_error(r); 437 res = maildirdriver_maildir_error_to_mail_error(r);
387 goto err; 438 goto err;
388 } 439 }
389 440
390 r = maildir_get_messages_list(session, md, 441 r = maildir_get_messages_list(session, md,
391 maildir_message_driver, &env_list); 442 maildir_message_driver, &env_list);
392 if (r != MAILDIR_NO_ERROR) { 443 if (r != MAILDIR_NO_ERROR) {
393 res = r; 444 res = r;
394 goto free_list; 445 goto free_list;
395 } 446 }
396 447
397 * result = env_list; 448 * result = env_list;
398 449
399 return MAIL_NO_ERROR; 450 return MAIL_NO_ERROR;
400 451
401 free_list: 452 free_list:
402 mailmessage_list_free(env_list); 453 mailmessage_list_free(env_list);
403 err: 454 err:
404 return res; 455 return res;
405} 456}
406 457
407static int get_envelopes_list(mailsession * session, 458static int get_envelopes_list(mailsession * session,
408 struct mailmessage_list * env_list) 459 struct mailmessage_list * env_list)
409{ 460{
410 int r; 461 int r;
411 struct maildir * md; 462 struct maildir * md;
412 unsigned int i; 463 unsigned int i;
413 int res; 464 int res;
414 465
415 check_folder(session); 466 check_folder(session);
416 467
417 md = get_maildir_session(session); 468 md = get_maildir_session(session);
418 if (md == NULL) { 469 if (md == NULL) {
419 res = MAIL_ERROR_BAD_STATE; 470 res = MAIL_ERROR_BAD_STATE;
420 goto err; 471 goto err;
421 } 472 }
422 473
423 r = maildir_update(md); 474 r = maildir_update(md);
424 if (r != MAILDIR_NO_ERROR) { 475 if (r != MAILDIR_NO_ERROR) {
425 res = maildirdriver_maildir_error_to_mail_error(r); 476 res = maildirdriver_maildir_error_to_mail_error(r);
426 goto err; 477 goto err;
427 } 478 }
428 479
429 r = maildriver_generic_get_envelopes_list(session, env_list); 480 r = maildriver_generic_get_envelopes_list(session, env_list);
430 if (r != MAIL_NO_ERROR) { 481 if (r != MAIL_NO_ERROR) {
431 res = r; 482 res = r;
432 goto err; 483 goto err;
433 } 484 }
434 485
435 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i++) { 486 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i++) {
436 struct maildir_msg * md_msg; 487 struct maildir_msg * md_msg;
437 mailmessage * msg; 488 mailmessage * msg;
438 uint32_t driver_flags; 489 uint32_t driver_flags;
439 clist * ext; 490 clist * ext;
440 chashdatum key; 491 chashdatum key;
441 chashdatum value; 492 chashdatum value;
442 493
443 msg = carray_get(env_list->msg_tab, i); 494 msg = carray_get(env_list->msg_tab, i);
444 495
445 key.data = msg->msg_uid; 496 key.data = msg->msg_uid;
446 key.len = strlen(msg->msg_uid); 497 key.len = strlen(msg->msg_uid);
447 r = chash_get(md->mdir_msg_hash, &key, &value); 498 r = chash_get(md->mdir_msg_hash, &key, &value);
448 if (r < 0) 499 if (r < 0)
449 continue; 500 continue;
450 501
451 md_msg = value.data; 502 md_msg = value.data;
452 503
453 driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags); 504 driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags);
454 505
455 if (msg->msg_flags == NULL) { 506 if (msg->msg_flags == NULL) {
456 ext = clist_new(); 507 ext = clist_new();
457 if (ext == NULL) { 508 if (ext == NULL) {
458 res = MAIL_ERROR_MEMORY; 509 res = MAIL_ERROR_MEMORY;
459 continue; 510 continue;
460 } 511 }
461 512
462 msg->msg_flags = mail_flags_new(driver_flags, ext); 513 msg->msg_flags = mail_flags_new(driver_flags, ext);
463 if (msg->msg_flags == NULL) { 514 if (msg->msg_flags == NULL) {
464 clist_free(ext); 515 clist_free(ext);
465 res = MAIL_ERROR_MEMORY; 516 res = MAIL_ERROR_MEMORY;
466 continue; 517 continue;
467 } 518 }
468 519
469 if ((md_msg->msg_flags & MAILDIR_FLAG_NEW) != 0) { 520 if ((md_msg->msg_flags & MAILDIR_FLAG_NEW) != 0) {
470 mail_flags_store_set(get_data(session)->md_flags_store, msg); 521 mail_flags_store_set(get_data(session)->md_flags_store, msg);
471 } 522 }
472 } 523 }
473 else { 524 else {
474 msg->msg_flags->fl_flags &= MAIL_FLAG_FORWARDED; 525 msg->msg_flags->fl_flags &= MAIL_FLAG_FORWARDED;
475 msg->msg_flags->fl_flags |= driver_flags; 526 msg->msg_flags->fl_flags |= driver_flags;
476 } 527 }
477 } 528 }
478 529
479 return MAIL_NO_ERROR; 530 return MAIL_NO_ERROR;
480 531
481 err: 532 err:
482 return res; 533 return res;
483} 534}
484 535
485 536
486static int expunge_folder(mailsession * session) 537static int expunge_folder(mailsession * session)
487{ 538{
488 unsigned int i; 539 unsigned int i;
489 int r; 540 int r;
490 int res; 541 int res;
491 struct maildir * md; 542 struct maildir * md;
492 543
493 check_folder(session); 544 check_folder(session);
494 545
495 md = get_maildir_session(session); 546 md = get_maildir_session(session);
496 if (md == NULL) 547 if (md == NULL)
497 return MAIL_ERROR_BAD_STATE; 548 return MAIL_ERROR_BAD_STATE;
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
@@ -1,263 +1,267 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "maildirdriver.h" 36#include "maildirdriver.h"
37 37
38#include <stdio.h> 38#include <stdio.h>
39#include <sys/types.h> 39#include <sys/types.h>
40#include <dirent.h> 40#include <dirent.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <sys/stat.h> 42#include <sys/stat.h>
43#include <ctype.h> 43#include <ctype.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <sys/mman.h> 45#include <sys/mman.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48 48
49#include "mail.h" 49#include "mail.h"
50#include "maildir.h" 50#include "maildir.h"
51#include "maildriver_tools.h" 51#include "maildriver_tools.h"
52#include "maildirdriver_tools.h" 52#include "maildirdriver_tools.h"
53#include "maildirdriver_cached_message.h" 53#include "maildirdriver_cached_message.h"
54#include "mailmessage.h" 54#include "mailmessage.h"
55#include "generic_cache.h" 55#include "generic_cache.h"
56#include "imfcache.h" 56#include "imfcache.h"
57#include "mail_cache_db.h" 57#include "mail_cache_db.h"
58#include "libetpan-config.h" 58#include "libetpan-config.h"
59 59
60static int initialize(mailsession * session); 60static int initialize(mailsession * session);
61 61
62static void uninitialize(mailsession * session); 62static void uninitialize(mailsession * session);
63 63
64static int parameters(mailsession * session, 64static int parameters(mailsession * session,
65 int id, void * value); 65 int id, void * value);
66 66
67static int connect_path(mailsession * session, char * path); 67static int connect_path(mailsession * session, char * path);
68 68
69static int logout(mailsession * session); 69static int logout(mailsession * session);
70 70
71static int expunge_folder(mailsession * session); 71static int expunge_folder(mailsession * session);
72 72
73static int status_folder(mailsession * session, char * mb, 73static 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
77static int recent_number(mailsession * session, char * mb, 77static int recent_number(mailsession * session, char * mb,
78 uint32_t * result); 78 uint32_t * result);
79 79
80static int unseen_number(mailsession * session, char * mb, 80static int unseen_number(mailsession * session, char * mb,
81 uint32_t * result); 81 uint32_t * result);
82 82
83static int messages_number(mailsession * session, char * mb, 83static int messages_number(mailsession * session, char * mb,
84 uint32_t * result); 84 uint32_t * result);
85 85
86static int append_message(mailsession * session, 86static int append_message(mailsession * session,
87 char * message, size_t size); 87 char * message, size_t size);
88 88
89static int append_message_flags(mailsession * session,
90 char * message, size_t size, struct mail_flags * flags);
91
89static int get_messages_list(mailsession * session, 92static int get_messages_list(mailsession * session,
90 struct mailmessage_list ** result); 93 struct mailmessage_list ** result);
91 94
92static int get_envelopes_list(mailsession * session, 95static int get_envelopes_list(mailsession * session,
93 struct mailmessage_list * env_list); 96 struct mailmessage_list * env_list);
94 97
95static int check_folder(mailsession * session); 98static int check_folder(mailsession * session);
96 99
97static int get_message(mailsession * session, 100static int get_message(mailsession * session,
98 uint32_t num, mailmessage ** result); 101 uint32_t num, mailmessage ** result);
99 102
100static int get_message_by_uid(mailsession * session, 103static int get_message_by_uid(mailsession * session,
101 const char * uid, mailmessage ** result); 104 const char * uid, mailmessage ** result);
102 105
103static mailsession_driver local_maildir_cached_session_driver = { 106static mailsession_driver local_maildir_cached_session_driver = {
104 .sess_name = "maildir-cached", 107 .sess_name = "maildir-cached",
105 108
106 .sess_initialize = initialize, 109 .sess_initialize = initialize,
107 .sess_uninitialize = uninitialize, 110 .sess_uninitialize = uninitialize,
108 111
109 .sess_parameters = parameters, 112 .sess_parameters = parameters,
110 113
111 .sess_connect_stream = NULL, 114 .sess_connect_stream = NULL,
112 .sess_connect_path = connect_path, 115 .sess_connect_path = connect_path,
113 .sess_starttls = NULL, 116 .sess_starttls = NULL,
114 .sess_login = NULL, 117 .sess_login = NULL,
115 .sess_logout = logout, 118 .sess_logout = logout,
116 .sess_noop = NULL, 119 .sess_noop = NULL,
117 120
118 .sess_build_folder_name = NULL, 121 .sess_build_folder_name = NULL,
119 .sess_create_folder = NULL, 122 .sess_create_folder = NULL,
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
150mailsession_driver * maildir_cached_session_driver = 154mailsession_driver * maildir_cached_session_driver =
151&local_maildir_cached_session_driver; 155&local_maildir_cached_session_driver;
152 156
153 157
154static inline struct maildir_cached_session_state_data * 158static inline struct maildir_cached_session_state_data *
155get_cached_data(mailsession * session) 159get_cached_data(mailsession * session)
156{ 160{
157 return session->sess_data; 161 return session->sess_data;
158} 162}
159 163
160static inline mailsession * get_ancestor(mailsession * session) 164static inline mailsession * get_ancestor(mailsession * session)
161{ 165{
162 return get_cached_data(session)->md_ancestor; 166 return get_cached_data(session)->md_ancestor;
163} 167}
164 168
165static inline struct maildir_session_state_data * 169static inline struct maildir_session_state_data *
166get_ancestor_data(mailsession * session) 170get_ancestor_data(mailsession * session)
167{ 171{
168 return get_ancestor(session)->sess_data; 172 return get_ancestor(session)->sess_data;
169} 173}
170 174
171 175
172static struct maildir * get_maildir_session(mailsession * session) 176static struct maildir * get_maildir_session(mailsession * session)
173{ 177{
174 return get_ancestor_data(session)->md_session; 178 return get_ancestor_data(session)->md_session;
175} 179}
176 180
177static int initialize(mailsession * session) 181static int initialize(mailsession * session)
178{ 182{
179 struct maildir_cached_session_state_data * data; 183 struct maildir_cached_session_state_data * data;
180 184
181 data = malloc(sizeof(* data)); 185 data = malloc(sizeof(* data));
182 if (data == NULL) 186 if (data == NULL)
183 goto err; 187 goto err;
184 188
185 data->md_ancestor = mailsession_new(maildir_session_driver); 189 data->md_ancestor = mailsession_new(maildir_session_driver);
186 if (data->md_ancestor == NULL) 190 if (data->md_ancestor == NULL)
187 goto free; 191 goto free;
188 192
189 data->md_flags_store = mail_flags_store_new(); 193 data->md_flags_store = mail_flags_store_new();
190 if (data->md_flags_store == NULL) 194 if (data->md_flags_store == NULL)
191 goto free_session; 195 goto free_session;
192 196
193 data->md_quoted_mb = NULL; 197 data->md_quoted_mb = NULL;
194 data->md_cache_directory[0] = '\0'; 198 data->md_cache_directory[0] = '\0';
195 data->md_flags_directory[0] = '\0'; 199 data->md_flags_directory[0] = '\0';
196 200
197 session->sess_data = data; 201 session->sess_data = data;
198 202
199 return MAIL_NO_ERROR; 203 return MAIL_NO_ERROR;
200 204
201 free_session: 205 free_session:
202 mailsession_free(data->md_ancestor); 206 mailsession_free(data->md_ancestor);
203 free: 207 free:
204 free(data); 208 free(data);
205 err: 209 err:
206 return MAIL_ERROR_MEMORY; 210 return MAIL_ERROR_MEMORY;
207} 211}
208 212
209static void 213static void
210free_quoted_mb(struct maildir_cached_session_state_data * maildir_cached_data) 214free_quoted_mb(struct maildir_cached_session_state_data * maildir_cached_data)
211{ 215{
212 if (maildir_cached_data->md_quoted_mb != NULL) { 216 if (maildir_cached_data->md_quoted_mb != NULL) {
213 free(maildir_cached_data->md_quoted_mb); 217 free(maildir_cached_data->md_quoted_mb);
214 maildir_cached_data->md_quoted_mb = NULL; 218 maildir_cached_data->md_quoted_mb = NULL;
215 } 219 }
216} 220}
217 221
218static int 222static int
219write_cached_flags(struct mail_cache_db * cache_db, 223write_cached_flags(struct mail_cache_db * cache_db,
220 MMAPString * mmapstr, 224 MMAPString * mmapstr,
221 char * uid, struct mail_flags * flags); 225 char * uid, struct mail_flags * flags);
222 226
223#define ENV_NAME "env.db" 227#define ENV_NAME "env.db"
224#define FLAGS_NAME "flags.db" 228#define FLAGS_NAME "flags.db"
225 229
226static int flags_store_process(char * flags_directory, char * quoted_mb, 230static int flags_store_process(char * flags_directory, char * quoted_mb,
227 struct mail_flags_store * flags_store) 231 struct mail_flags_store * flags_store)
228{ 232{
229 char filename_flags[PATH_MAX]; 233 char filename_flags[PATH_MAX];
230 struct mail_cache_db * cache_db_flags; 234 struct mail_cache_db * cache_db_flags;
231 MMAPString * mmapstr; 235 MMAPString * mmapstr;
232 unsigned int i; 236 unsigned int i;
233 int r; 237 int r;
234 int res; 238 int res;
235 239
236 if (carray_count(flags_store->fls_tab) == 0) 240 if (carray_count(flags_store->fls_tab) == 0)
237 return MAIL_NO_ERROR; 241 return MAIL_NO_ERROR;
238 242
239 if (quoted_mb == NULL) 243 if (quoted_mb == NULL)
240 return MAIL_NO_ERROR; 244 return MAIL_NO_ERROR;
241 245
242 snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", 246 snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s",
243 flags_directory, MAIL_DIR_SEPARATOR, quoted_mb, 247 flags_directory, MAIL_DIR_SEPARATOR, quoted_mb,
244 MAIL_DIR_SEPARATOR, FLAGS_NAME); 248 MAIL_DIR_SEPARATOR, FLAGS_NAME);
245 249
246 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 250 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
247 if (r < 0) { 251 if (r < 0) {
248 res = MAIL_ERROR_FILE; 252 res = MAIL_ERROR_FILE;
249 goto err; 253 goto err;
250 } 254 }
251 255
252 mmapstr = mmap_string_new(""); 256 mmapstr = mmap_string_new("");
253 if (mmapstr == NULL) { 257 if (mmapstr == NULL) {
254 res = MAIL_ERROR_MEMORY; 258 res = MAIL_ERROR_MEMORY;
255 goto close_db_flags; 259 goto close_db_flags;
256 } 260 }
257 261
258 for(i = 0 ; i < carray_count(flags_store->fls_tab) ; i ++) { 262 for(i = 0 ; i < carray_count(flags_store->fls_tab) ; i ++) {
259 mailmessage * msg; 263 mailmessage * msg;
260 264
261 msg = carray_get(flags_store->fls_tab, i); 265 msg = carray_get(flags_store->fls_tab, i);
262 266
263 r = write_cached_flags(cache_db_flags, mmapstr, 267 r = write_cached_flags(cache_db_flags, mmapstr,
@@ -329,259 +333,333 @@ static int parameters(mailsession * session,
329 return MAIL_NO_ERROR; 333 return MAIL_NO_ERROR;
330 334
331 default: 335 default:
332 return mailsession_parameters(data->md_ancestor, id, value); 336 return mailsession_parameters(data->md_ancestor, id, value);
333 } 337 }
334} 338}
335 339
336 340
337static int get_cache_folder(mailsession * session, char ** result) 341static int get_cache_folder(mailsession * session, char ** result)
338{ 342{
339 struct maildir * md; 343 struct maildir * md;
340 char * quoted_mb; 344 char * quoted_mb;
341 int res; 345 int res;
342 int r; 346 int r;
343 char key[PATH_MAX]; 347 char key[PATH_MAX];
344 struct maildir_cached_session_state_data * data; 348 struct maildir_cached_session_state_data * data;
345 349
346 md = get_maildir_session(session); 350 md = get_maildir_session(session);
347 data = get_cached_data(session); 351 data = get_cached_data(session);
348 352
349 quoted_mb = maildriver_quote_mailbox(md->mdir_path); 353 quoted_mb = maildriver_quote_mailbox(md->mdir_path);
350 if (quoted_mb == NULL) { 354 if (quoted_mb == NULL) {
351 res = MAIL_ERROR_MEMORY; 355 res = MAIL_ERROR_MEMORY;
352 goto err; 356 goto err;
353 } 357 }
354 358
355 snprintf(key, PATH_MAX, "%s/%s", data->md_cache_directory, quoted_mb); 359 snprintf(key, PATH_MAX, "%s/%s", data->md_cache_directory, quoted_mb);
356 r = generic_cache_create_dir(key); 360 r = generic_cache_create_dir(key);
357 if (r != MAIL_NO_ERROR) { 361 if (r != MAIL_NO_ERROR) {
358 res = r; 362 res = r;
359 goto free_quoted_mb; 363 goto free_quoted_mb;
360 } 364 }
361 365
362 snprintf(key, PATH_MAX, "%s/%s", data->md_flags_directory, quoted_mb); 366 snprintf(key, PATH_MAX, "%s/%s", data->md_flags_directory, quoted_mb);
363 r = generic_cache_create_dir(key); 367 r = generic_cache_create_dir(key);
364 if (r != MAIL_NO_ERROR) { 368 if (r != MAIL_NO_ERROR) {
365 res = r; 369 res = r;
366 goto free_quoted_mb; 370 goto free_quoted_mb;
367 } 371 }
368 372
369 * result = quoted_mb; 373 * result = quoted_mb;
370 374
371 return MAIL_NO_ERROR; 375 return MAIL_NO_ERROR;
372 376
373 free_quoted_mb: 377 free_quoted_mb:
374 free(quoted_mb); 378 free(quoted_mb);
375 err: 379 err:
376 return res; 380 return res;
377} 381}
378 382
379 383
380static int connect_path(mailsession * session, char * path) 384static int connect_path(mailsession * session, char * path)
381{ 385{
382 int r; 386 int r;
383 int res; 387 int res;
384 char * quoted_mb; 388 char * quoted_mb;
385 389
386 r = mailsession_connect_path(get_ancestor(session), path); 390 r = mailsession_connect_path(get_ancestor(session), path);
387 if (r != MAIL_NO_ERROR) { 391 if (r != MAIL_NO_ERROR) {
388 res = r; 392 res = r;
389 goto err; 393 goto err;
390 } 394 }
391 395
392 r = get_cache_folder(session, &quoted_mb); 396 r = get_cache_folder(session, &quoted_mb);
393 if (r != MAIL_NO_ERROR) { 397 if (r != MAIL_NO_ERROR) {
394 res = r; 398 res = r;
395 goto logout; 399 goto logout;
396 } 400 }
397 401
398 get_cached_data(session)->md_quoted_mb = quoted_mb; 402 get_cached_data(session)->md_quoted_mb = quoted_mb;
399 403
400 return MAILDIR_NO_ERROR; 404 return MAILDIR_NO_ERROR;
401 405
402 logout: 406 logout:
403 mailsession_logout(get_ancestor(session)); 407 mailsession_logout(get_ancestor(session));
404 err: 408 err:
405 return res; 409 return res;
406} 410}
407 411
408static int logout(mailsession * session) 412static int logout(mailsession * session)
409{ 413{
410 struct maildir_cached_session_state_data * data; 414 struct maildir_cached_session_state_data * data;
411 int r; 415 int r;
412 416
413 data = get_cached_data(session); 417 data = get_cached_data(session);
414 418
415 flags_store_process(data->md_flags_directory, 419 flags_store_process(data->md_flags_directory,
416 data->md_quoted_mb, data->md_flags_store); 420 data->md_quoted_mb, data->md_flags_store);
417 421
418 r = mailsession_logout(get_ancestor(session)); 422 r = mailsession_logout(get_ancestor(session));
419 if (r != MAIL_NO_ERROR) 423 if (r != MAIL_NO_ERROR)
420 return r; 424 return r;
421 425
422 free_quoted_mb(get_cached_data(session)); 426 free_quoted_mb(get_cached_data(session));
423 427
424 return MAIL_NO_ERROR; 428 return MAIL_NO_ERROR;
425} 429}
426 430
427static int status_folder(mailsession * session, char * mb, 431static int status_folder(mailsession * session, char * mb,
428 uint32_t * result_messages, uint32_t * result_recent, 432 uint32_t * result_messages, uint32_t * result_recent,
429 uint32_t * result_unseen) 433 uint32_t * result_unseen)
430{ 434{
431 return mailsession_status_folder(get_ancestor(session), mb, 435 return mailsession_status_folder(get_ancestor(session), mb,
432 result_messages, result_recent, result_unseen); 436 result_messages, result_recent, result_unseen);
433} 437}
434 438
435static int messages_number(mailsession * session, char * mb, 439static int messages_number(mailsession * session, char * mb,
436 uint32_t * result) 440 uint32_t * result)
437{ 441{
438 return mailsession_messages_number(get_ancestor(session), mb, result); 442 return mailsession_messages_number(get_ancestor(session), mb, result);
439} 443}
440 444
441static int unseen_number(mailsession * session, char * mb, 445static 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
447static int recent_number(mailsession * session, char * mb, 451static 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
454static int append_message(mailsession * session, 458static 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
467static 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
463static int uid_clean_up(struct mail_cache_db * uid_db, 541static 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
476 hash_exist = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYALL); 554 hash_exist = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYALL);
477 if (hash_exist == NULL) { 555 if (hash_exist == NULL) {
478 res = MAIL_ERROR_MEMORY; 556 res = MAIL_ERROR_MEMORY;
479 goto err; 557 goto err;
480 } 558 }
481 559
482 value.data = NULL; 560 value.data = NULL;
483 value.len = 0; 561 value.len = 0;
484 562
485 key.data = "max-uid"; 563 key.data = "max-uid";
486 key.len = strlen("max-uid"); 564 key.len = strlen("max-uid");
487 r = chash_set(hash_exist, &key, &value, NULL); 565 r = chash_set(hash_exist, &key, &value, NULL);
488 566
489 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 567 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
490 mailmessage * msg; 568 mailmessage * msg;
491 569
492 msg = carray_get(env_list->msg_tab, i); 570 msg = carray_get(env_list->msg_tab, i);
493 571
494 value.data = NULL; 572 value.data = NULL;
495 value.len = 0; 573 value.len = 0;
496 574
497 key.data = msg->msg_uid; 575 key.data = msg->msg_uid;
498 key.len = strlen(msg->msg_uid); 576 key.len = strlen(msg->msg_uid);
499 r = chash_set(hash_exist, &key, &value, NULL); 577 r = chash_set(hash_exist, &key, &value, NULL);
500 if (r < 0) { 578 if (r < 0) {
501 res = MAIL_ERROR_MEMORY; 579 res = MAIL_ERROR_MEMORY;
502 goto free; 580 goto free;
503 } 581 }
504 582
505 snprintf(key_str, sizeof(key_str), "uid-%lu", 583 snprintf(key_str, sizeof(key_str), "uid-%lu",
506 (unsigned long) msg->msg_index); 584 (unsigned long) msg->msg_index);
507 key.data = key_str; 585 key.data = key_str;
508 key.len = strlen(key_str); 586 key.len = strlen(key_str);
509 r = chash_set(hash_exist, &key, &value, NULL); 587 r = chash_set(hash_exist, &key, &value, NULL);
510 if (r < 0) { 588 if (r < 0) {
511 res = MAIL_ERROR_MEMORY; 589 res = MAIL_ERROR_MEMORY;
512 goto free; 590 goto free;
513 } 591 }
514 } 592 }
515 593
516 mail_cache_db_clean_up(uid_db, hash_exist); 594 mail_cache_db_clean_up(uid_db, hash_exist);
517 595
518 chash_free(hash_exist); 596 chash_free(hash_exist);
519 597
520 return MAIL_NO_ERROR; 598 return MAIL_NO_ERROR;
521 599
522 free: 600 free:
523 chash_free(hash_exist); 601 chash_free(hash_exist);
524 err: 602 err:
525 return res; 603 return res;
526} 604}
527 605
528static int get_messages_list(mailsession * session, 606static int get_messages_list(mailsession * session,
529 struct mailmessage_list ** result) 607 struct mailmessage_list ** result)
530{ 608{
531 struct maildir * md; 609 struct maildir * md;
532 int r; 610 int r;
533 struct mailmessage_list * env_list; 611 struct mailmessage_list * env_list;
534 int res; 612 int res;
535 uint32_t max_uid; 613 uint32_t max_uid;
536 char filename[PATH_MAX]; 614 char filename[PATH_MAX];
537 struct mail_cache_db * uid_db; 615 struct mail_cache_db * uid_db;
538 void * value; 616 void * value;
539 size_t value_len; 617 size_t value_len;
540 unsigned long i; 618 unsigned long i;
541 struct maildir_cached_session_state_data * data; 619 struct maildir_cached_session_state_data * data;
542 char key[PATH_MAX]; 620 char key[PATH_MAX];
543 621
544 data = get_cached_data(session); 622 data = get_cached_data(session);
545 623
546 md = get_maildir_session(session); 624 md = get_maildir_session(session);
547 if (md == NULL) { 625 if (md == NULL) {
548 res = MAIL_ERROR_BAD_STATE; 626 res = MAIL_ERROR_BAD_STATE;
549 goto err; 627 goto err;
550 } 628 }
551 629
552 check_folder(session); 630 check_folder(session);
553 631
554 r = maildir_update(md); 632 r = maildir_update(md);
555 if (r != MAILDIR_NO_ERROR) { 633 if (r != MAILDIR_NO_ERROR) {
556 res = maildirdriver_maildir_error_to_mail_error(r); 634 res = maildirdriver_maildir_error_to_mail_error(r);
557 goto err; 635 goto err;
558 } 636 }
559 637
560 r = maildir_get_messages_list(session, md, 638 r = maildir_get_messages_list(session, md,
561 maildir_cached_message_driver, &env_list); 639 maildir_cached_message_driver, &env_list);
562 if (r != MAILDIR_NO_ERROR) { 640 if (r != MAILDIR_NO_ERROR) {
563 res = r; 641 res = r;
564 goto err; 642 goto err;
565 } 643 }
566 644
567 /* read/write DB */ 645 /* read/write DB */
568 646
569 snprintf(filename, sizeof(filename), "%s%c%s%c%s", 647 snprintf(filename, sizeof(filename), "%s%c%s%c%s",
570 data->md_flags_directory, MAIL_DIR_SEPARATOR, data->md_quoted_mb, 648 data->md_flags_directory, MAIL_DIR_SEPARATOR, data->md_quoted_mb,
571 MAIL_DIR_SEPARATOR, UID_NAME); 649 MAIL_DIR_SEPARATOR, UID_NAME);
572 650
573 r = mail_cache_db_open_lock(filename, &uid_db); 651 r = mail_cache_db_open_lock(filename, &uid_db);
574 if (r < 0) { 652 if (r < 0) {
575 res = MAIL_ERROR_MEMORY; 653 res = MAIL_ERROR_MEMORY;
576 goto free_list; 654 goto free_list;
577 } 655 }
578 656
579 max_uid = 0; 657 max_uid = 0;
580 r = mail_cache_db_get(uid_db, "max-uid", sizeof("max-uid") - 1, 658 r = mail_cache_db_get(uid_db, "max-uid", sizeof("max-uid") - 1,
581 &value, &value_len); 659 &value, &value_len);
582 if (r == 0) { 660 if (r == 0) {
583 memcpy(&max_uid, value, sizeof(max_uid)); 661 memcpy(&max_uid, value, sizeof(max_uid));
584 } 662 }
585 663
586 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 664 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
587 mailmessage * msg; 665 mailmessage * msg;
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
@@ -1,248 +1,334 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "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
53static int get_flags(mailmessage * msg_info,
54 struct mail_flags ** result);
55
51static int prefetch(mailmessage * msg_info); 56static int prefetch(mailmessage * msg_info);
52 57
53static void prefetch_free(struct generic_message_t * msg); 58static void prefetch_free(struct generic_message_t * msg);
54 59
55static int initialize(mailmessage * msg_info); 60static int initialize(mailmessage * msg_info);
56 61
57static void check(mailmessage * msg_info); 62static void check(mailmessage * msg_info);
58 63
59static mailmessage_driver local_maildir_cached_message_driver = { 64static 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
84mailmessage_driver * maildir_cached_message_driver = 89mailmessage_driver * maildir_cached_message_driver =
85&local_maildir_cached_message_driver; 90&local_maildir_cached_message_driver;
86 91
87struct maildir_msg_data { 92struct maildir_msg_data {
88 int fd; 93 int fd;
89}; 94};
90 95
91#if 0 96#if 0
92static inline struct maildir_cached_session_state_data * 97static inline struct maildir_cached_session_state_data *
93get_cached_session_data(mailmessage * msg) 98get_cached_session_data(mailmessage * msg)
94{ 99{
95 return msg->session->data; 100 return msg->session->data;
96} 101}
97 102
98static inline mailsession * cached_session_get_ancestor(mailsession * session) 103static inline mailsession * cached_session_get_ancestor(mailsession * session)
99{ 104{
100 return get_data(session)->session; 105 return get_data(session)->session;
101} 106}
102 107
103static inline struct maildir_session_state_data * 108static inline struct maildir_session_state_data *
104cached_session_get_ancestor_data(mailsession * session) 109cached_session_get_ancestor_data(mailsession * session)
105{ 110{
106 return get_ancestor(session)->data; 111 return get_ancestor(session)->data;
107} 112}
108 113
109static struct maildir * get_maildir_session(mailmessage * msg) 114static struct maildir * get_maildir_session(mailmessage * msg)
110{ 115{
111 return cached_session_get_ancestor_data(msg->session)->session; 116 return cached_session_get_ancestor_data(msg->session)->session;
112} 117}
113#endif 118#endif
114static inline struct maildir_cached_session_state_data * 119static inline struct maildir_cached_session_state_data *
115get_cached_session_data(mailmessage * msg) 120get_cached_session_data(mailmessage * msg)
116{ 121{
117 return msg->msg_session->sess_data; 122 return msg->msg_session->sess_data;
118} 123}
119 124
120static inline struct maildir_cached_session_state_data * 125static inline struct maildir_cached_session_state_data *
121cached_session_get_data(mailsession * s) 126cached_session_get_data(mailsession * s)
122{ 127{
123 return s->sess_data; 128 return s->sess_data;
124} 129}
125 130
126static inline mailsession * cached_session_get_ancestor(mailsession * s) 131static inline mailsession * cached_session_get_ancestor(mailsession * s)
127{ 132{
128 return cached_session_get_data(s)->md_ancestor; 133 return cached_session_get_data(s)->md_ancestor;
129} 134}
130 135
131static inline struct maildir_session_state_data * 136static inline struct maildir_session_state_data *
132cached_session_get_ancestor_data(mailsession * s) 137cached_session_get_ancestor_data(mailsession * s)
133{ 138{
134 return cached_session_get_ancestor(s)->sess_data; 139 return cached_session_get_ancestor(s)->sess_data;
135} 140}
136 141
137static inline struct maildir_session_state_data * 142static inline struct maildir_session_state_data *
138get_session_ancestor_data(mailmessage * msg) 143get_session_ancestor_data(mailmessage * msg)
139{ 144{
140 return cached_session_get_ancestor_data(msg->msg_session); 145 return cached_session_get_ancestor_data(msg->msg_session);
141} 146}
142 147
143static inline struct maildir * 148static inline struct maildir *
144cached_session_get_maildir_session(mailsession * session) 149cached_session_get_maildir_session(mailsession * session)
145{ 150{
146 return cached_session_get_ancestor_data(session)->md_session; 151 return cached_session_get_ancestor_data(session)->md_session;
147} 152}
148 153
149static inline struct maildir * get_maildir_session(mailmessage * msg) 154static inline struct maildir * get_maildir_session(mailmessage * msg)
150{ 155{
151 return cached_session_get_maildir_session(msg->msg_session); 156 return cached_session_get_maildir_session(msg->msg_session);
152} 157}
153 158
154static int prefetch(mailmessage * msg_info) 159static int prefetch(mailmessage * msg_info)
155{ 160{
156 struct generic_message_t * msg; 161 struct generic_message_t * msg;
157 int res; 162 int res;
158 struct maildir_msg_data * data; 163 struct maildir_msg_data * data;
159 char * filename; 164 char * filename;
160 int fd; 165 int fd;
161 char * mapping; 166 char * mapping;
162 struct maildir * md; 167 struct maildir * md;
163 168
164 md = get_maildir_session(msg_info); 169 md = get_maildir_session(msg_info);
165 170
166 filename = maildir_message_get(md, msg_info->msg_uid); 171 filename = maildir_message_get(md, msg_info->msg_uid);
167 if (filename == NULL) { 172 if (filename == NULL) {
168 res = MAIL_ERROR_MEMORY; 173 res = MAIL_ERROR_MEMORY;
169 goto err; 174 goto err;
170 } 175 }
171 176
172 fd = open(filename, O_RDONLY); 177 fd = open(filename, O_RDONLY);
173 free(filename); 178 free(filename);
174 if (fd == -1) { 179 if (fd == -1) {
175 res = MAIL_ERROR_FILE; 180 res = MAIL_ERROR_FILE;
176 goto err; 181 goto err;
177 } 182 }
178 183
179 mapping = mmap(NULL, msg_info->msg_size, PROT_READ, MAP_PRIVATE, fd, 0); 184 mapping = mmap(NULL, msg_info->msg_size, PROT_READ, MAP_PRIVATE, fd, 0);
180 if (mapping == MAP_FAILED) { 185 if (mapping == MAP_FAILED) {
181 res = MAIL_ERROR_FILE; 186 res = MAIL_ERROR_FILE;
182 goto close; 187 goto close;
183 } 188 }
184 189
185 data = malloc(sizeof(* data)); 190 data = malloc(sizeof(* data));
186 if (data == NULL) { 191 if (data == NULL) {
187 res = MAIL_ERROR_MEMORY; 192 res = MAIL_ERROR_MEMORY;
188 goto unmap; 193 goto unmap;
189 } 194 }
190 195
191 data->fd = fd; 196 data->fd = fd;
192 197
193 msg = msg_info->msg_data; 198 msg = msg_info->msg_data;
194 199
195 msg->msg_data = data; 200 msg->msg_data = data;
196 msg->msg_message = mapping; 201 msg->msg_message = mapping;
197 msg->msg_length = msg_info->msg_size; 202 msg->msg_length = msg_info->msg_size;
198 203
199 return MAIL_NO_ERROR; 204 return MAIL_NO_ERROR;
200 205
201 unmap: 206 unmap:
202 munmap(mapping, msg_info->msg_size); 207 munmap(mapping, msg_info->msg_size);
203 close: 208 close:
204 close(fd); 209 close(fd);
205 err: 210 err:
206 return res; 211 return res;
207} 212}
208 213
209static void prefetch_free(struct generic_message_t * msg) 214static void prefetch_free(struct generic_message_t * msg)
210{ 215{
211 if (msg->msg_message != NULL) { 216 if (msg->msg_message != NULL) {
212 struct maildir_msg_data * data; 217 struct maildir_msg_data * data;
213 218
214 munmap(msg->msg_message, msg->msg_length); 219 munmap(msg->msg_message, msg->msg_length);
215 msg->msg_message = NULL; 220 msg->msg_message = NULL;
216 data = msg->msg_data; 221 data = msg->msg_data;
217 close(data->fd); 222 close(data->fd);
218 free(data); 223 free(data);
219 } 224 }
220} 225}
221 226
222static int initialize(mailmessage * msg_info) 227static int initialize(mailmessage * msg_info)
223{ 228{
224 struct generic_message_t * msg; 229 struct generic_message_t * msg;
225 int r; 230 int r;
226 231
227 r = mailmessage_generic_initialize(msg_info); 232 r = mailmessage_generic_initialize(msg_info);
228 if (r != MAIL_NO_ERROR) 233 if (r != MAIL_NO_ERROR)
229 return r; 234 return r;
230 235
231 msg = msg_info->msg_data; 236 msg = msg_info->msg_data;
232 msg->msg_prefetch = prefetch; 237 msg->msg_prefetch = prefetch;
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
238static void check(mailmessage * msg_info) 243static 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
257static 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
@@ -1,199 +1,255 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "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
52static int get_flags(mailmessage * msg_info,
53 struct mail_flags ** result);
54
51static int prefetch(mailmessage * msg_info); 55static int prefetch(mailmessage * msg_info);
52 56
53static void prefetch_free(struct generic_message_t * msg); 57static void prefetch_free(struct generic_message_t * msg);
54 58
55static int initialize(mailmessage * msg_info); 59static int initialize(mailmessage * msg_info);
56 60
57static void check(mailmessage * msg_info); 61static void check(mailmessage * msg_info);
58 62
59static mailmessage_driver local_maildir_message_driver = { 63static 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
84mailmessage_driver * maildir_message_driver = &local_maildir_message_driver; 88mailmessage_driver * maildir_message_driver = &local_maildir_message_driver;
85 89
86struct maildir_msg_data { 90struct maildir_msg_data {
87 int fd; 91 int fd;
88}; 92};
89 93
90static inline struct maildir_session_state_data * 94static inline struct maildir_session_state_data *
91get_session_data(mailmessage * msg) 95get_session_data(mailmessage * msg)
92{ 96{
93 return msg->msg_session->sess_data; 97 return msg->msg_session->sess_data;
94} 98}
95 99
96static struct maildir * get_maildir_session(mailmessage * msg) 100static struct maildir * get_maildir_session(mailmessage * msg)
97{ 101{
98 return get_session_data(msg)->md_session; 102 return get_session_data(msg)->md_session;
99} 103}
100 104
101static int prefetch(mailmessage * msg_info) 105static int prefetch(mailmessage * msg_info)
102{ 106{
103 struct generic_message_t * msg; 107 struct generic_message_t * msg;
104 int res; 108 int res;
105 struct maildir_msg_data * data; 109 struct maildir_msg_data * data;
106 char * filename; 110 char * filename;
107 int fd; 111 int fd;
108 char * mapping; 112 char * mapping;
109 struct maildir * md; 113 struct maildir * md;
110 114
111 md = get_maildir_session(msg_info); 115 md = get_maildir_session(msg_info);
112 116
113 if (msg_info->msg_uid == NULL) { 117 if (msg_info->msg_uid == NULL) {
114 res = MAIL_ERROR_INVAL; 118 res = MAIL_ERROR_INVAL;
115 goto err; 119 goto err;
116 } 120 }
117 121
118 filename = maildir_message_get(md, msg_info->msg_uid); 122 filename = maildir_message_get(md, msg_info->msg_uid);
119 if (filename == NULL) { 123 if (filename == NULL) {
120 res = MAIL_ERROR_MEMORY; 124 res = MAIL_ERROR_MEMORY;
121 goto err; 125 goto err;
122 } 126 }
123 127
124 fd = open(filename, O_RDONLY); 128 fd = open(filename, O_RDONLY);
125 free(filename); 129 free(filename);
126 if (fd == -1) { 130 if (fd == -1) {
127 res = MAIL_ERROR_FILE; 131 res = MAIL_ERROR_FILE;
128 goto err; 132 goto err;
129 } 133 }
130 134
131 mapping = mmap(NULL, msg_info->msg_size, PROT_READ, MAP_PRIVATE, fd, 0); 135 mapping = mmap(NULL, msg_info->msg_size, PROT_READ, MAP_PRIVATE, fd, 0);
132 if (mapping == MAP_FAILED) { 136 if (mapping == MAP_FAILED) {
133 res = MAIL_ERROR_FILE; 137 res = MAIL_ERROR_FILE;
134 goto close; 138 goto close;
135 } 139 }
136 140
137 data = malloc(sizeof(* data)); 141 data = malloc(sizeof(* data));
138 if (data == NULL) { 142 if (data == NULL) {
139 res = MAIL_ERROR_MEMORY; 143 res = MAIL_ERROR_MEMORY;
140 goto unmap; 144 goto unmap;
141 } 145 }
142 146
143 data->fd = fd; 147 data->fd = fd;
144 148
145 msg = msg_info->msg_data; 149 msg = msg_info->msg_data;
146 150
147 msg->msg_data = data; 151 msg->msg_data = data;
148 msg->msg_message = mapping; 152 msg->msg_message = mapping;
149 msg->msg_length = msg_info->msg_size; 153 msg->msg_length = msg_info->msg_size;
150 154
151 return MAIL_NO_ERROR; 155 return MAIL_NO_ERROR;
152 156
153 unmap: 157 unmap:
154 munmap(mapping, msg_info->msg_size); 158 munmap(mapping, msg_info->msg_size);
155 close: 159 close:
156 close(fd); 160 close(fd);
157 err: 161 err:
158 return res; 162 return res;
159} 163}
160 164
161static void prefetch_free(struct generic_message_t * msg) 165static void prefetch_free(struct generic_message_t * msg)
162{ 166{
163 if (msg->msg_message != NULL) { 167 if (msg->msg_message != NULL) {
164 struct maildir_msg_data * data; 168 struct maildir_msg_data * data;
165 169
166 munmap(msg->msg_message, msg->msg_length); 170 munmap(msg->msg_message, msg->msg_length);
167 msg->msg_message = NULL; 171 msg->msg_message = NULL;
168 data = msg->msg_data; 172 data = msg->msg_data;
169 close(data->fd); 173 close(data->fd);
170 free(data); 174 free(data);
171 } 175 }
172} 176}
173 177
174static int initialize(mailmessage * msg_info) 178static int initialize(mailmessage * msg_info)
175{ 179{
176 struct generic_message_t * msg; 180 struct generic_message_t * msg;
177 int r; 181 int r;
178 182
179 r = mailmessage_generic_initialize(msg_info); 183 r = mailmessage_generic_initialize(msg_info);
180 if (r != MAIL_NO_ERROR) 184 if (r != MAIL_NO_ERROR)
181 return r; 185 return r;
182 186
183 msg = msg_info->msg_data; 187 msg = msg_info->msg_data;
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
190static void check(mailmessage * msg_info) 194static 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
205static 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
@@ -1,192 +1,193 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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
49static int maildir_mailstorage_connect(struct mailstorage * storage); 50static int maildir_mailstorage_connect(struct mailstorage * storage);
50static int 51static int
51maildir_mailstorage_get_folder_session(struct mailstorage * storage, 52maildir_mailstorage_get_folder_session(struct mailstorage * storage,
52 char * pathname, mailsession ** result); 53 char * pathname, mailsession ** result);
53static void maildir_mailstorage_uninitialize(struct mailstorage * storage); 54static void maildir_mailstorage_uninitialize(struct mailstorage * storage);
54 55
55static mailstorage_driver maildir_mailstorage_driver = { 56static 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
62int maildir_mailstorage_init(struct mailstorage * storage, 63int 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);
85 if (maildir_storage->md_flags_directory == NULL) 86 if (maildir_storage->md_flags_directory == NULL)
86 goto free_cache_directory; 87 goto free_cache_directory;
87 } 88 }
88 else { 89 else {
89 maildir_storage->md_cached = FALSE; 90 maildir_storage->md_cached = FALSE;
90 maildir_storage->md_cache_directory = NULL; 91 maildir_storage->md_cache_directory = NULL;
91 maildir_storage->md_flags_directory = NULL; 92 maildir_storage->md_flags_directory = NULL;
92 } 93 }
93 94
94 storage->sto_data = maildir_storage; 95 storage->sto_data = maildir_storage;
95 storage->sto_driver = &maildir_mailstorage_driver; 96 storage->sto_driver = &maildir_mailstorage_driver;
96 97
97 return MAIL_NO_ERROR; 98 return MAIL_NO_ERROR;
98 99
99 free_cache_directory: 100 free_cache_directory:
100 free(maildir_storage->md_cache_directory); 101 free(maildir_storage->md_cache_directory);
101 free_pathname: 102 free_pathname:
102 free(maildir_storage->md_pathname); 103 free(maildir_storage->md_pathname);
103 free: 104 free:
104 free(maildir_storage); 105 free(maildir_storage);
105 err: 106 err:
106 return MAIL_ERROR_MEMORY; 107 return MAIL_ERROR_MEMORY;
107} 108}
108 109
109static void maildir_mailstorage_uninitialize(struct mailstorage * storage) 110static void maildir_mailstorage_uninitialize(struct mailstorage * storage)
110{ 111{
111 struct maildir_mailstorage * maildir_storage; 112 struct maildir_mailstorage * maildir_storage;
112 113
113 maildir_storage = storage->sto_data; 114 maildir_storage = storage->sto_data;
114 if (maildir_storage->md_flags_directory != NULL) 115 if (maildir_storage->md_flags_directory != NULL)
115 free(maildir_storage->md_flags_directory); 116 free(maildir_storage->md_flags_directory);
116 if (maildir_storage->md_cache_directory != NULL) 117 if (maildir_storage->md_cache_directory != NULL)
117 free(maildir_storage->md_cache_directory); 118 free(maildir_storage->md_cache_directory);
118 free(maildir_storage->md_pathname); 119 free(maildir_storage->md_pathname);
119 free(maildir_storage); 120 free(maildir_storage);
120 121
121 storage->sto_data = NULL; 122 storage->sto_data = NULL;
122} 123}
123 124
124static int maildir_mailstorage_connect(struct mailstorage * storage) 125static int maildir_mailstorage_connect(struct mailstorage * storage)
125{ 126{
126 struct maildir_mailstorage * maildir_storage; 127 struct maildir_mailstorage * maildir_storage;
127 mailsession_driver * driver; 128 mailsession_driver * driver;
128 int r; 129 int r;
129 int res; 130 int res;
130 mailsession * session; 131 mailsession * session;
131 132
132 maildir_storage = storage->sto_data; 133 maildir_storage = storage->sto_data;
133 134
134 if (maildir_storage->md_cached) 135 if (maildir_storage->md_cached)
135 driver = maildir_cached_session_driver; 136 driver = maildir_cached_session_driver;
136 else 137 else
137 driver = maildir_session_driver; 138 driver = maildir_session_driver;
138 139
139 session = mailsession_new(driver); 140 session = mailsession_new(driver);
140 if (session == NULL) { 141 if (session == NULL) {
141 res = MAIL_ERROR_MEMORY; 142 res = MAIL_ERROR_MEMORY;
142 goto err; 143 goto err;
143 } 144 }
144 145
145 if (maildir_storage->md_cached) { 146 if (maildir_storage->md_cached) {
146 r = mailsession_parameters(session, 147 r = mailsession_parameters(session,
147 MAILDIRDRIVER_CACHED_SET_CACHE_DIRECTORY, 148 MAILDIRDRIVER_CACHED_SET_CACHE_DIRECTORY,
148 maildir_storage->md_cache_directory); 149 maildir_storage->md_cache_directory);
149 if (r != MAIL_NO_ERROR) { 150 if (r != MAIL_NO_ERROR) {
150 res = r; 151 res = r;
151 goto free; 152 goto free;
152 } 153 }
153 154
154 r = mailsession_parameters(session, 155 r = mailsession_parameters(session,
155 MAILDIRDRIVER_CACHED_SET_FLAGS_DIRECTORY, 156 MAILDIRDRIVER_CACHED_SET_FLAGS_DIRECTORY,
156 maildir_storage->md_flags_directory); 157 maildir_storage->md_flags_directory);
157 if (r != MAIL_NO_ERROR) { 158 if (r != MAIL_NO_ERROR) {
158 res = r; 159 res = r;
159 goto free; 160 goto free;
160 } 161 }
161 } 162 }
162 163
163 r = mailsession_connect_path(session, maildir_storage->md_pathname); 164 r = mailsession_connect_path(session, maildir_storage->md_pathname);
164 switch (r) { 165 switch (r) {
165 case MAIL_NO_ERROR_NON_AUTHENTICATED: 166 case MAIL_NO_ERROR_NON_AUTHENTICATED:
166 case MAIL_NO_ERROR_AUTHENTICATED: 167 case MAIL_NO_ERROR_AUTHENTICATED:
167 case MAIL_NO_ERROR: 168 case MAIL_NO_ERROR:
168 break; 169 break;
169 default: 170 default:
170 res = r; 171 res = r;
171 goto free; 172 goto free;
172 } 173 }
173 174
174 storage->sto_session = session; 175 storage->sto_session = session;
175 176
176 return MAIL_NO_ERROR; 177 return MAIL_NO_ERROR;
177 178
178 free: 179 free:
179 mailsession_free(session); 180 mailsession_free(session);
180 err: 181 err:
181 return res; 182 return res;
182} 183}
183 184
184static int 185static int
185maildir_mailstorage_get_folder_session(struct mailstorage * storage, 186maildir_mailstorage_get_folder_session(struct mailstorage * storage,
186 char * pathname, mailsession ** result) 187 char * pathname, mailsession ** result)
187{ 188{
188 * result = storage->sto_session; 189 * result = storage->sto_session;
189 190
190 return MAIL_NO_ERROR; 191 return MAIL_NO_ERROR;
191} 192}
192 193
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
@@ -1,69 +1,69 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#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
43extern "C" { 43extern "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
61int maildir_mailstorage_init(struct mailstorage * storage, 61int 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);
64 64
65#ifdef __cplusplus 65#ifdef __cplusplus
66} 66}
67#endif 67#endif
68 68
69#endif 69#endif
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
@@ -157,217 +157,227 @@ int mailsession_delete_folder(mailsession * session, char * mb)
157 157
158 return session->sess_driver->sess_delete_folder(session, mb); 158 return session->sess_driver->sess_delete_folder(session, mb);
159} 159}
160 160
161int mailsession_rename_folder(mailsession * session, 161int mailsession_rename_folder(mailsession * session,
162 char * mb, char * new_name) 162 char * mb, char * new_name)
163{ 163{
164 if (session->sess_driver->sess_rename_folder == NULL) 164 if (session->sess_driver->sess_rename_folder == NULL)
165 return MAIL_ERROR_NOT_IMPLEMENTED; 165 return MAIL_ERROR_NOT_IMPLEMENTED;
166 166
167 return session->sess_driver->sess_rename_folder(session, mb, new_name); 167 return session->sess_driver->sess_rename_folder(session, mb, new_name);
168} 168}
169 169
170int mailsession_check_folder(mailsession * session) 170int mailsession_check_folder(mailsession * session)
171{ 171{
172 if (session->sess_driver->sess_check_folder == NULL) 172 if (session->sess_driver->sess_check_folder == NULL)
173 return MAIL_ERROR_NOT_IMPLEMENTED; 173 return MAIL_ERROR_NOT_IMPLEMENTED;
174 174
175 return session->sess_driver->sess_check_folder(session); 175 return session->sess_driver->sess_check_folder(session);
176} 176}
177 177
178int mailsession_examine_folder(mailsession * session, char * mb) 178int mailsession_examine_folder(mailsession * session, char * mb)
179{ 179{
180 if (session->sess_driver->sess_examine_folder == NULL) 180 if (session->sess_driver->sess_examine_folder == NULL)
181 return MAIL_ERROR_NOT_IMPLEMENTED; 181 return MAIL_ERROR_NOT_IMPLEMENTED;
182 182
183 return session->sess_driver->sess_examine_folder(session, mb); 183 return session->sess_driver->sess_examine_folder(session, mb);
184} 184}
185 185
186int mailsession_select_folder(mailsession * session, char * mb) 186int mailsession_select_folder(mailsession * session, char * mb)
187{ 187{
188 if (session->sess_driver->sess_select_folder == NULL) 188 if (session->sess_driver->sess_select_folder == NULL)
189 return MAIL_ERROR_NOT_IMPLEMENTED; 189 return MAIL_ERROR_NOT_IMPLEMENTED;
190 190
191 return session->sess_driver->sess_select_folder(session, mb); 191 return session->sess_driver->sess_select_folder(session, mb);
192} 192}
193 193
194int mailsession_expunge_folder(mailsession * session) 194int mailsession_expunge_folder(mailsession * session)
195{ 195{
196 if (session->sess_driver->sess_expunge_folder == NULL) 196 if (session->sess_driver->sess_expunge_folder == NULL)
197 return MAIL_ERROR_NOT_IMPLEMENTED; 197 return MAIL_ERROR_NOT_IMPLEMENTED;
198 198
199 return session->sess_driver->sess_expunge_folder(session); 199 return session->sess_driver->sess_expunge_folder(session);
200} 200}
201 201
202int mailsession_status_folder(mailsession * session, char * mb, 202int mailsession_status_folder(mailsession * session, char * mb,
203 uint32_t * result_messages, uint32_t * result_recent, 203 uint32_t * result_messages, uint32_t * result_recent,
204 uint32_t * result_unseen) 204 uint32_t * result_unseen)
205{ 205{
206 if (session->sess_driver->sess_status_folder == NULL) 206 if (session->sess_driver->sess_status_folder == NULL)
207 return MAIL_ERROR_NOT_IMPLEMENTED; 207 return MAIL_ERROR_NOT_IMPLEMENTED;
208 208
209 return session->sess_driver->sess_status_folder(session, mb, 209 return session->sess_driver->sess_status_folder(session, mb,
210 result_messages, result_recent, result_unseen); 210 result_messages, result_recent, result_unseen);
211} 211}
212 212
213int mailsession_messages_number(mailsession * session, char * mb, 213int mailsession_messages_number(mailsession * session, char * mb,
214 uint32_t * result) 214 uint32_t * result)
215{ 215{
216 if (session->sess_driver->sess_messages_number == NULL) 216 if (session->sess_driver->sess_messages_number == NULL)
217 return MAIL_ERROR_NOT_IMPLEMENTED; 217 return MAIL_ERROR_NOT_IMPLEMENTED;
218 218
219 return session->sess_driver->sess_messages_number(session, mb, result); 219 return session->sess_driver->sess_messages_number(session, mb, result);
220} 220}
221 221
222int mailsession_recent_number(mailsession * session, char * mb, 222int mailsession_recent_number(mailsession * session, char * mb,
223 uint32_t * result) 223 uint32_t * result)
224{ 224{
225 if (session->sess_driver->sess_recent_number == NULL) 225 if (session->sess_driver->sess_recent_number == NULL)
226 return MAIL_ERROR_NOT_IMPLEMENTED; 226 return MAIL_ERROR_NOT_IMPLEMENTED;
227 227
228 return session->sess_driver->sess_recent_number(session, mb, result); 228 return session->sess_driver->sess_recent_number(session, mb, result);
229} 229}
230 230
231int mailsession_unseen_number(mailsession * session, char * mb, 231int mailsession_unseen_number(mailsession * session, char * mb,
232 uint32_t * result) 232 uint32_t * result)
233{ 233{
234 if (session->sess_driver->sess_unseen_number == NULL) 234 if (session->sess_driver->sess_unseen_number == NULL)
235 return MAIL_ERROR_NOT_IMPLEMENTED; 235 return MAIL_ERROR_NOT_IMPLEMENTED;
236 236
237 return session->sess_driver->sess_recent_number(session, mb, result); 237 return session->sess_driver->sess_recent_number(session, mb, result);
238} 238}
239 239
240int mailsession_list_folders(mailsession * session, char * mb, 240int mailsession_list_folders(mailsession * session, char * mb,
241 struct mail_list ** result) 241 struct mail_list ** result)
242{ 242{
243 if (session->sess_driver->sess_list_folders == NULL) 243 if (session->sess_driver->sess_list_folders == NULL)
244 return MAIL_ERROR_NOT_IMPLEMENTED; 244 return MAIL_ERROR_NOT_IMPLEMENTED;
245 245
246 return session->sess_driver->sess_list_folders(session, mb, result); 246 return session->sess_driver->sess_list_folders(session, mb, result);
247} 247}
248 248
249int mailsession_lsub_folders(mailsession * session, char * mb, 249int mailsession_lsub_folders(mailsession * session, char * mb,
250 struct mail_list ** result) 250 struct mail_list ** result)
251{ 251{
252 if (session->sess_driver->sess_lsub_folders == NULL) 252 if (session->sess_driver->sess_lsub_folders == NULL)
253 return MAIL_ERROR_NOT_IMPLEMENTED; 253 return MAIL_ERROR_NOT_IMPLEMENTED;
254 254
255 return session->sess_driver->sess_lsub_folders(session, mb, result); 255 return session->sess_driver->sess_lsub_folders(session, mb, result);
256} 256}
257 257
258int mailsession_subscribe_folder(mailsession * session, char * mb) 258int mailsession_subscribe_folder(mailsession * session, char * mb)
259{ 259{
260 if (session->sess_driver->sess_subscribe_folder == NULL) 260 if (session->sess_driver->sess_subscribe_folder == NULL)
261 return MAIL_ERROR_NOT_IMPLEMENTED; 261 return MAIL_ERROR_NOT_IMPLEMENTED;
262 262
263 return session->sess_driver->sess_subscribe_folder(session, mb); 263 return session->sess_driver->sess_subscribe_folder(session, mb);
264} 264}
265 265
266int mailsession_unsubscribe_folder(mailsession * session, char * mb) 266int mailsession_unsubscribe_folder(mailsession * session, char * mb)
267{ 267{
268 if (session->sess_driver->sess_unsubscribe_folder == NULL) 268 if (session->sess_driver->sess_unsubscribe_folder == NULL)
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
276int mailsession_append_message(mailsession * session, 276int 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
285int 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
285int mailsession_copy_message(mailsession * session, 295int 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
294int mailsession_move_message(mailsession * session, 304int 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) &&
301 (session->sess_driver->sess_remove_message == NULL)) 311 (session->sess_driver->sess_remove_message == NULL))
302 return MAIL_ERROR_NOT_IMPLEMENTED; 312 return MAIL_ERROR_NOT_IMPLEMENTED;
303 313
304 r = mailsession_copy_message(session, num, mb); 314 r = mailsession_copy_message(session, num, mb);
305 if (r != MAIL_NO_ERROR) 315 if (r != MAIL_NO_ERROR)
306 return r; 316 return r;
307 317
308 r = mailsession_remove_message(session, num); 318 r = mailsession_remove_message(session, num);
309 if (r != MAIL_NO_ERROR) 319 if (r != MAIL_NO_ERROR)
310 return r; 320 return r;
311 321
312 return MAIL_NO_ERROR; 322 return MAIL_NO_ERROR;
313 } 323 }
314 324
315 return session->sess_driver->sess_move_message(session, num, mb); 325 return session->sess_driver->sess_move_message(session, num, mb);
316} 326}
317 327
318int mailsession_get_envelopes_list(mailsession * session, 328int mailsession_get_envelopes_list(mailsession * session,
319 struct mailmessage_list * env_list) 329 struct mailmessage_list * env_list)
320{ 330{
321 if (session->sess_driver->sess_get_envelopes_list == NULL) 331 if (session->sess_driver->sess_get_envelopes_list == NULL)
322 return MAIL_ERROR_NOT_IMPLEMENTED; 332 return MAIL_ERROR_NOT_IMPLEMENTED;
323 333
324 return session->sess_driver->sess_get_envelopes_list(session, env_list); 334 return session->sess_driver->sess_get_envelopes_list(session, env_list);
325} 335}
326 336
327int mailsession_get_messages_list(mailsession * session, 337int mailsession_get_messages_list(mailsession * session,
328 struct mailmessage_list ** result) 338 struct mailmessage_list ** result)
329{ 339{
330 if (session->sess_driver->sess_get_messages_list == NULL) 340 if (session->sess_driver->sess_get_messages_list == NULL)
331 return MAIL_ERROR_NOT_IMPLEMENTED; 341 return MAIL_ERROR_NOT_IMPLEMENTED;
332 342
333 return session->sess_driver->sess_get_messages_list(session, result); 343 return session->sess_driver->sess_get_messages_list(session, result);
334} 344}
335 345
336int mailsession_remove_message(mailsession * session, uint32_t num) 346int mailsession_remove_message(mailsession * session, uint32_t num)
337{ 347{
338 if (session->sess_driver->sess_remove_message == NULL) 348 if (session->sess_driver->sess_remove_message == NULL)
339 return MAIL_ERROR_NOT_IMPLEMENTED; 349 return MAIL_ERROR_NOT_IMPLEMENTED;
340 350
341 return session->sess_driver->sess_remove_message(session, num); 351 return session->sess_driver->sess_remove_message(session, num);
342} 352}
343 353
344#if 0 354#if 0
345int mailsession_search_messages(mailsession * session, char * charset, 355int mailsession_search_messages(mailsession * session, char * charset,
346 struct mail_search_key * key, 356 struct mail_search_key * key,
347 struct mail_search_result ** result) 357 struct mail_search_result ** result)
348{ 358{
349 if (session->sess_driver->sess_search_messages == NULL) 359 if (session->sess_driver->sess_search_messages == NULL)
350 return MAIL_ERROR_NOT_IMPLEMENTED; 360 return MAIL_ERROR_NOT_IMPLEMENTED;
351 361
352 return session->sess_driver->sess_search_messages(session, 362 return session->sess_driver->sess_search_messages(session,
353 charset, key, result); 363 charset, key, result);
354} 364}
355#endif 365#endif
356 366
357int mailsession_get_message(mailsession * session, 367int mailsession_get_message(mailsession * session,
358 uint32_t num, mailmessage ** result) 368 uint32_t num, mailmessage ** result)
359{ 369{
360 if (session->sess_driver->sess_get_message == NULL) 370 if (session->sess_driver->sess_get_message == NULL)
361 return MAIL_ERROR_NOT_IMPLEMENTED; 371 return MAIL_ERROR_NOT_IMPLEMENTED;
362 372
363 return session->sess_driver->sess_get_message(session, num, result); 373 return session->sess_driver->sess_get_message(session, num, result);
364} 374}
365 375
366int mailsession_get_message_by_uid(mailsession * session, 376int mailsession_get_message_by_uid(mailsession * session,
367 const char * uid, mailmessage ** result) 377 const char * uid, mailmessage ** result)
368{ 378{
369 if (session->sess_driver->sess_get_message_by_uid == NULL) 379 if (session->sess_driver->sess_get_message_by_uid == NULL)
370 return MAIL_ERROR_NOT_IMPLEMENTED; 380 return MAIL_ERROR_NOT_IMPLEMENTED;
371 381
372 return session->sess_driver->sess_get_message_by_uid(session, uid, result); 382 return session->sess_driver->sess_get_message_by_uid(session, uid, result);
373} 383}
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
@@ -275,256 +275,259 @@ int mailsession_expunge_folder(mailsession * session);
275*/ 275*/
276 276
277int mailsession_status_folder(mailsession * session, char * mb, 277int mailsession_status_folder(mailsession * session, char * mb,
278 uint32_t * result_messages, uint32_t * result_recent, 278 uint32_t * result_messages, uint32_t * result_recent,
279 uint32_t * result_unseen); 279 uint32_t * result_unseen);
280 280
281 281
282/* 282/*
283 mailsession_messages_number queries the number of messages in the folder 283 mailsession_messages_number queries the number of messages in the folder
284 284
285 @param session the session 285 @param session the session
286 @param mb mailbox to query 286 @param mb mailbox to query
287 @param result the number of messages is stored in (* result) 287 @param result the number of messages is stored in (* result)
288 288
289 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 289 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
290 on error 290 on error
291*/ 291*/
292 292
293int mailsession_messages_number(mailsession * session, char * mb, 293int mailsession_messages_number(mailsession * session, char * mb,
294 uint32_t * result); 294 uint32_t * result);
295 295
296/* 296/*
297 mailsession_recent_number queries the number of recent messages in the folder 297 mailsession_recent_number queries the number of recent messages in the folder
298 298
299 @param session the session 299 @param session the session
300 @param mb mailbox to query 300 @param mb mailbox to query
301 @param result the number of recent messages is stored in (* result) 301 @param result the number of recent messages is stored in (* result)
302 302
303 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 303 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
304 on error 304 on error
305*/ 305*/
306 306
307int mailsession_recent_number(mailsession * session, 307int mailsession_recent_number(mailsession * session,
308 char * mb, uint32_t * result); 308 char * mb, uint32_t * result);
309 309
310/* 310/*
311 mailsession_unseen_number queries the number of unseen messages in the folder 311 mailsession_unseen_number queries the number of unseen messages in the folder
312 312
313 @param session the session 313 @param session the session
314 @param mb mailbox to query 314 @param mb mailbox to query
315 @param result the number of unseen messages is stored in (* result) 315 @param result the number of unseen messages is stored in (* result)
316 316
317 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 317 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
318 on error 318 on error
319*/ 319*/
320 320
321int mailsession_unseen_number(mailsession * session, char * mb, 321int mailsession_unseen_number(mailsession * session, char * mb,
322 uint32_t * result); 322 uint32_t * result);
323 323
324/* 324/*
325 NOTE: driver's specific should be used 325 NOTE: driver's specific should be used
326 326
327 mailsession_list_folders returns the list of all sub-mailboxes 327 mailsession_list_folders returns the list of all sub-mailboxes
328 of the given mailbox 328 of the given mailbox
329 329
330 @param session the session 330 @param session the session
331 @param mb the mailbox 331 @param mb the mailbox
332 @param result list of mailboxes if stored in (* result), 332 @param result list of mailboxes if stored in (* result),
333 this structure have to be freed with mail_list_free() 333 this structure have to be freed with mail_list_free()
334 334
335 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 335 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
336 on error 336 on error
337*/ 337*/
338 338
339int mailsession_list_folders(mailsession * session, char * mb, 339int mailsession_list_folders(mailsession * session, char * mb,
340 struct mail_list ** result); 340 struct mail_list ** result);
341 341
342/* 342/*
343 NOTE: driver's specific should be used 343 NOTE: driver's specific should be used
344 344
345 mailsession_lsub_folders returns the list of subscribed 345 mailsession_lsub_folders returns the list of subscribed
346 sub-mailboxes of the given mailbox 346 sub-mailboxes of the given mailbox
347 347
348 @param session the session 348 @param session the session
349 @param mb the mailbox 349 @param mb the mailbox
350 @param result list of mailboxes if stored in (* result), 350 @param result list of mailboxes if stored in (* result),
351 this structure have to be freed with mail_list_free() 351 this structure have to be freed with mail_list_free()
352 352
353 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 353 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
354 on error 354 on error
355*/ 355*/
356 356
357int mailsession_lsub_folders(mailsession * session, char * mb, 357int mailsession_lsub_folders(mailsession * session, char * mb,
358 struct mail_list ** result); 358 struct mail_list ** result);
359 359
360/* 360/*
361 NOTE: driver's specific should be used 361 NOTE: driver's specific should be used
362 362
363 mailsession_subscribe_folder subscribes to the given mailbox 363 mailsession_subscribe_folder subscribes to the given mailbox
364 364
365 @param session the session 365 @param session the session
366 @param mb the mailbox 366 @param mb the mailbox
367 367
368 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 368 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
369 on error 369 on error
370*/ 370*/
371 371
372int mailsession_subscribe_folder(mailsession * session, char * mb); 372int mailsession_subscribe_folder(mailsession * session, char * mb);
373 373
374/* 374/*
375 NOTE: driver's specific should be used 375 NOTE: driver's specific should be used
376 376
377 mailsession_unsubscribe_folder unsubscribes to the given mailbox 377 mailsession_unsubscribe_folder unsubscribes to the given mailbox
378 378
379 @param session the session 379 @param session the session
380 @param mb the mailbox 380 @param mb the mailbox
381 381
382 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 382 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
383 on error 383 on error
384*/ 384*/
385 385
386int mailsession_unsubscribe_folder(mailsession * session, char * mb); 386int 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
400int mailsession_append_message(mailsession * session, 400int mailsession_append_message(mailsession * session,
401 char * message, size_t size); 401 char * message, size_t size);
402 402
403int 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
417int mailsession_copy_message(mailsession * session, 420int mailsession_copy_message(mailsession * session,
418 uint32_t num, char * mb); 421 uint32_t num, char * mb);
419 422
420/* 423/*
421 NOTE: some drivers does not implement this 424 NOTE: some drivers does not implement this
422 425
423 mailsession_move_message copies a message whose number is given to 426 mailsession_move_message copies a message whose number is given to
424 a given mailbox. The mailbox must be accessible from the same session. 427 a given mailbox. The mailbox must be accessible from the same session.
425 428
426 @param session the session 429 @param session the session
427 @param num the message number 430 @param num the message number
428 @param mb the destination mailbox 431 @param mb the destination mailbox
429 432
430 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 433 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
431 on error 434 on error
432*/ 435*/
433 436
434int mailsession_move_message(mailsession * session, 437int mailsession_move_message(mailsession * session,
435 uint32_t num, char * mb); 438 uint32_t num, char * mb);
436 439
437/* 440/*
438 mailsession_get_messages_list returns the list of message numbers 441 mailsession_get_messages_list returns the list of message numbers
439 of the current mailbox. 442 of the current mailbox.
440 443
441 @param session the session 444 @param session the session
442 @param result the list of message numbers will be stored in (* result), 445 @param result the list of message numbers will be stored in (* result),
443 this structure have to be freed with mailmessage_list_free() 446 this structure have to be freed with mailmessage_list_free()
444 447
445 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 448 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
446 on error 449 on error
447*/ 450*/
448 451
449int mailsession_get_messages_list(mailsession * session, 452int mailsession_get_messages_list(mailsession * session,
450 struct mailmessage_list ** result); 453 struct mailmessage_list ** result);
451 454
452/* 455/*
453 mailsession_get_envelopes_list fills the parsed fields in the 456 mailsession_get_envelopes_list fills the parsed fields in the
454 mailmessage structures of the mailmessage_list. 457 mailmessage structures of the mailmessage_list.
455 458
456 @param session the session 459 @param session the session
457 @param result this is the list of mailmessage structures 460 @param result this is the list of mailmessage structures
458 461
459 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 462 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
460 on error 463 on error
461*/ 464*/
462 465
463int mailsession_get_envelopes_list(mailsession * session, 466int mailsession_get_envelopes_list(mailsession * session,
464 struct mailmessage_list * result); 467 struct mailmessage_list * result);
465 468
466/* 469/*
467 NOTE: some drivers does not implement this 470 NOTE: some drivers does not implement this
468 471
469 mailsession_remove_message removes the given message from the mailbox. 472 mailsession_remove_message removes the given message from the mailbox.
470 The message is permanently deleted. 473 The message is permanently deleted.
471 474
472 @param session the session 475 @param session the session
473 @param num is the message number 476 @param num is the message number
474 477
475 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 478 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
476 on error 479 on error
477*/ 480*/
478 481
479int mailsession_remove_message(mailsession * session, uint32_t num); 482int mailsession_remove_message(mailsession * session, uint32_t num);
480 483
481 484
482/* 485/*
483 NOTE: this function is not implemented in most drivers 486 NOTE: this function is not implemented in most drivers
484 487
485 mailsession_search_message returns a list of message numbers that 488 mailsession_search_message returns a list of message numbers that
486 corresponds to the given criteria. 489 corresponds to the given criteria.
487 490
488 @param session the session 491 @param session the session
489 @param charset is the charset to use (it can be NULL) 492 @param charset is the charset to use (it can be NULL)
490 @param key is the list of criteria 493 @param key is the list of criteria
491 @param result the search result is stored in (* result), 494 @param result the search result is stored in (* result),
492 this structure have to be freed with mail_search_result_free() 495 this structure have to be freed with mail_search_result_free()
493 496
494 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 497 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
495 on error 498 on error
496*/ 499*/
497 500
498#if 0 501#if 0
499int mailsession_search_messages(mailsession * session, char * charset, 502int mailsession_search_messages(mailsession * session, char * charset,
500 struct mail_search_key * key, 503 struct mail_search_key * key,
501 struct mail_search_result ** result); 504 struct mail_search_result ** result);
502#endif 505#endif
503 506
504/* 507/*
505 mailsession_get_message returns a mailmessage structure that corresponds 508 mailsession_get_message returns a mailmessage structure that corresponds
506 to the given message number. 509 to the given message number.
507 * WARNING * mailsession_get_message_by_uid() should be used instead. 510 * WARNING * mailsession_get_message_by_uid() should be used instead.
508 511
509 @param session the session 512 @param session the session
510 @param num the message number 513 @param num the message number
511 @param result the allocated mailmessage structure will be stored 514 @param result the allocated mailmessage structure will be stored
512 in (* result), this structure have to be freed with mailmessage_free() 515 in (* result), this structure have to be freed with mailmessage_free()
513 516
514 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 517 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
515 on error 518 on error
516*/ 519*/
517 520
518int mailsession_get_message(mailsession * session, 521int mailsession_get_message(mailsession * session,
519 uint32_t num, mailmessage ** result); 522 uint32_t num, mailmessage ** result);
520 523
521/* 524/*
522 mailsession_get_message_by_uid returns a mailmessage structure 525 mailsession_get_message_by_uid returns a mailmessage structure
523 that corresponds to the given message unique identifier. 526 that corresponds to the given message unique identifier.
524 This is currently implemented only for cached drivers. 527 This is currently implemented only for cached drivers.
525 * WARNING * That will deprecates the use of mailsession_get_message() 528 * WARNING * That will deprecates the use of mailsession_get_message()
526 529
527 @param session the session 530 @param session the session
528 @param uid the message unique identifier 531 @param uid the message unique identifier
529 @param result the allocated mailmessage structure will be stored 532 @param result the allocated mailmessage structure will be stored
530 in (* result), this structure have to be freed with mailmessage_free() 533 in (* result), this structure have to be freed with mailmessage_free()
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
@@ -382,256 +382,258 @@ void mail_search_result_free(struct mail_search_result * search_result);
382 382
383 - messages_number() queries the number of messages in the folder 383 - messages_number() queries the number of messages in the folder
384 384
385 - recent_number() queries the number of recent messages in the folder 385 - recent_number() queries the number of recent messages in the folder
386 386
387 - unseen_number() queries the number of unseen messages in the folder 387 - unseen_number() queries the number of unseen messages in the folder
388 388
389 - list_folders() returns the list of all sub-mailboxes 389 - list_folders() returns the list of all sub-mailboxes
390 of the given mailbox 390 of the given mailbox
391 391
392 - lsub_folders() returns the list of subscribed 392 - lsub_folders() returns the list of subscribed
393 sub-mailboxes of the given mailbox 393 sub-mailboxes of the given mailbox
394 394
395 - subscribe_folder() subscribes to the given mailbox 395 - subscribe_folder() subscribes to the given mailbox
396 396
397 - unsubscribe_folder() unsubscribes to the given mailbox 397 - unsubscribe_folder() unsubscribes to the given mailbox
398 398
399 - append_message() adds a RFC 2822 message to the current 399 - append_message() adds a RFC 2822 message to the current
400 given mailbox 400 given mailbox
401 401
402 - copy_message() copies a message whose number is given to 402 - copy_message() copies a message whose number is given to
403 a given mailbox. The mailbox must be accessible from 403 a given mailbox. The mailbox must be accessible from
404 the same session. 404 the same session.
405 405
406 - move_message() copies a message whose number is given to 406 - move_message() copies a message whose number is given to
407 a given mailbox. The mailbox must be accessible from the 407 a given mailbox. The mailbox must be accessible from the
408 same session. 408 same session.
409 409
410 - get_messages_list() returns the list of message numbers 410 - get_messages_list() returns the list of message numbers
411 of the current mailbox. 411 of the current mailbox.
412 412
413 - get_envelopes_list() fills the parsed fields in the 413 - get_envelopes_list() fills the parsed fields in the
414 mailmessage structures of the mailmessage_list. 414 mailmessage structures of the mailmessage_list.
415 415
416 - remove_message() removes the given message from the mailbox. 416 - remove_message() removes the given message from the mailbox.
417 The message is permanently deleted. 417 The message is permanently deleted.
418 418
419 - search_message() returns a list of message numbers that 419 - search_message() returns a list of message numbers that
420 corresponds to the given criteria. 420 corresponds to the given criteria.
421 421
422 - get_message returns a mailmessage structure that corresponds 422 - get_message returns a mailmessage structure that corresponds
423 to the given message number. 423 to the given message number.
424 424
425 - get_message_by_uid returns a mailmessage structure that corresponds 425 - get_message_by_uid returns a mailmessage structure that corresponds
426 to the given message unique identifier. 426 to the given message unique identifier.
427 427
428 * mandatory functions are the following : 428 * mandatory functions are the following :
429 429
430 - connect_stream() of connect_path() 430 - connect_stream() of connect_path()
431 - logout() 431 - logout()
432 - get_messages_list() 432 - get_messages_list()
433 - get_envelopes_list() 433 - get_envelopes_list()
434 434
435 * we advise you to implement these functions : 435 * we advise you to implement these functions :
436 436
437 - select_folder() (in case a session can access several folders) 437 - select_folder() (in case a session can access several folders)
438 - noop() (to check if the server is responding) 438 - noop() (to check if the server is responding)
439 - check_folder() (to make a checkpoint of the session) 439 - check_folder() (to make a checkpoint of the session)
440 - status_folder(), messages_number(), recent_number(), unseen_number() 440 - status_folder(), messages_number(), recent_number(), unseen_number()
441 (to get stat of the folder) 441 (to get stat of the folder)
442 - append_message() (but can't be done in the case of POP3 at least) 442 - append_message() (but can't be done in the case of POP3 at least)
443 - login() in a case of an authenticated driver. 443 - login() in a case of an authenticated driver.
444 - starttls() in a case of a stream driver, if the procotol supports 444 - starttls() in a case of a stream driver, if the procotol supports
445 STARTTLS. 445 STARTTLS.
446 - get_message_by_uid() so that the application can remember the message 446 - get_message_by_uid() so that the application can remember the message
447 by UID and build its own list of messages. 447 by UID and build its own list of messages.
448 448
449 * drivers' specific : 449 * drivers' specific :
450 450
451 Everything that is specific to the driver will be implemented in this 451 Everything that is specific to the driver will be implemented in this
452 function : 452 function :
453 453
454 - parameters() 454 - parameters()
455*/ 455*/
456 456
457struct mailsession_driver { 457struct mailsession_driver {
458 char * sess_name; 458 char * sess_name;
459 459
460 int (* sess_initialize)(mailsession * session); 460 int (* sess_initialize)(mailsession * session);
461 void (* sess_uninitialize)(mailsession * session); 461 void (* sess_uninitialize)(mailsession * session);
462 462
463 int (* sess_parameters)(mailsession * session, 463 int (* sess_parameters)(mailsession * session,
464 int id, void * value); 464 int id, void * value);
465 465
466 int (* sess_connect_stream)(mailsession * session, mailstream * s); 466 int (* sess_connect_stream)(mailsession * session, mailstream * s);
467 int (* sess_connect_path)(mailsession * session, char * path); 467 int (* sess_connect_path)(mailsession * session, char * path);
468 468
469 int (* sess_starttls)(mailsession * session); 469 int (* sess_starttls)(mailsession * session);
470 470
471 int (* sess_login)(mailsession * session, char * userid, char * password); 471 int (* sess_login)(mailsession * session, char * userid, char * password);
472 int (* sess_logout)(mailsession * session); 472 int (* sess_logout)(mailsession * session);
473 int (* sess_noop)(mailsession * session); 473 int (* sess_noop)(mailsession * session);
474 474
475 /* folders operations */ 475 /* folders operations */
476 476
477 int (* sess_build_folder_name)(mailsession * session, char * mb, 477 int (* sess_build_folder_name)(mailsession * session, char * mb,
478 char * name, char ** result); 478 char * name, char ** result);
479 479
480 int (* sess_create_folder)(mailsession * session, char * mb); 480 int (* sess_create_folder)(mailsession * session, char * mb);
481 int (* sess_delete_folder)(mailsession * session, char * mb); 481 int (* sess_delete_folder)(mailsession * session, char * mb);
482 int (* sess_rename_folder)(mailsession * session, char * mb, 482 int (* sess_rename_folder)(mailsession * session, char * mb,
483 char * new_name); 483 char * new_name);
484 int (* sess_check_folder)(mailsession * session); 484 int (* sess_check_folder)(mailsession * session);
485 int (* sess_examine_folder)(mailsession * session, char * mb); 485 int (* sess_examine_folder)(mailsession * session, char * mb);
486 int (* sess_select_folder)(mailsession * session, char * mb); 486 int (* sess_select_folder)(mailsession * session, char * mb);
487 int (* sess_expunge_folder)(mailsession * session); 487 int (* sess_expunge_folder)(mailsession * session);
488 int (* sess_status_folder)(mailsession * session, char * mb, 488 int (* sess_status_folder)(mailsession * session, char * mb,
489 uint32_t * result_num, uint32_t * result_recent, 489 uint32_t * result_num, uint32_t * result_recent,
490 uint32_t * result_unseen); 490 uint32_t * result_unseen);
491 int (* sess_messages_number)(mailsession * session, char * mb, 491 int (* sess_messages_number)(mailsession * session, char * mb,
492 uint32_t * result); 492 uint32_t * result);
493 int (* sess_recent_number)(mailsession * session, char * mb, 493 int (* sess_recent_number)(mailsession * session, char * mb,
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);
526#if 0 528#if 0
527 int (* sess_search_messages)(mailsession * session, char * charset, 529 int (* sess_search_messages)(mailsession * session, char * charset,
528 struct mail_search_key * key, 530 struct mail_search_key * key,
529 struct mail_search_result ** result); 531 struct mail_search_result ** result);
530#endif 532#endif
531}; 533};
532 534
533 535
534/* 536/*
535 session is the data structure for a mail session. 537 session is the data structure for a mail session.
536 538
537 - data is the internal data structure used by the driver 539 - data is the internal data structure used by the driver
538 It is called when initializing the mailsession structure. 540 It is called when initializing the mailsession structure.
539 541
540 - driver is the driver used for the session 542 - driver is the driver used for the session
541*/ 543*/
542 544
543struct mailsession { 545struct mailsession {
544 void * sess_data; 546 void * sess_data;
545 mailsession_driver * sess_driver; 547 mailsession_driver * sess_driver;
546}; 548};
547 549
548 550
549 551
550 552
551/* 553/*
552 mailmessage_driver is the driver structure to get information from messages. 554 mailmessage_driver is the driver structure to get information from messages.
553 555
554 - name is the name of the driver 556 - name is the name of the driver
555 557
556 - initialize() is the function that will initializes a data structure 558 - initialize() is the function that will initializes a data structure
557 specific to the driver, it returns a value that will be stored 559 specific to the driver, it returns a value that will be stored
558 in the field data of the mailsession. 560 in the field data of the mailsession.
559 The field data of the session is the state of the session, 561 The field data of the session is the state of the session,
560 the internal data structure used by the driver. 562 the internal data structure used by the driver.
561 It is called when initializing the mailmessage structure with 563 It is called when initializing the mailmessage structure with
562 mailmessage_init(). 564 mailmessage_init().
563 565
564 - uninitialize() frees the structure created with initialize(). 566 - uninitialize() frees the structure created with initialize().
565 It will be called by mailmessage_free(). 567 It will be called by mailmessage_free().
566 568
567 - flush() will free from memory all temporary structures of the message 569 - flush() will free from memory all temporary structures of the message
568 (for example, the MIME structure of the message). 570 (for example, the MIME structure of the message).
569 571
570 - fetch_result_free() will free all strings resulted by fetch() or 572 - fetch_result_free() will free all strings resulted by fetch() or
571 any fetch_xxx() functions that returns a string. 573 any fetch_xxx() functions that returns a string.
572 574
573 - fetch() returns the content of the message (headers and text). 575 - fetch() returns the content of the message (headers and text).
574 576
575 - fetch_header() returns the content of the headers. 577 - fetch_header() returns the content of the headers.
576 578
577 - fetch_body() returns the message text (message content without headers) 579 - fetch_body() returns the message text (message content without headers)
578 580
579 - fetch_size() returns the size of the message content. 581 - fetch_size() returns the size of the message content.
580 582
581 - get_bodystructure() returns the MIME structure of the message. 583 - get_bodystructure() returns the MIME structure of the message.
582 584
583 - fetch_section() returns the content of a given MIME part 585 - fetch_section() returns the content of a given MIME part
584 586
585 - fetch_section_header() returns the header of the message 587 - fetch_section_header() returns the header of the message
586 contained by the given MIME part. 588 contained by the given MIME part.
587 589
588 - fetch_section_mime() returns the MIME headers of the 590 - fetch_section_mime() returns the MIME headers of the
589 given MIME part. 591 given MIME part.
590 592
591 - fetch_section_body() returns the text (if this is a message, this is the 593 - fetch_section_body() returns the text (if this is a message, this is the
592 message content without headers) of the given MIME part. 594 message content without headers) of the given MIME part.
593 595
594 - fetch_envelope() returns a mailimf_fields structure, with a list of 596 - fetch_envelope() returns a mailimf_fields structure, with a list of
595 fields chosen by the driver. 597 fields chosen by the driver.
596 598
597 - get_flags() returns a the flags related to the message. 599 - get_flags() returns a the flags related to the message.
598 When you want to get flags of a message, you have to make sure to 600 When you want to get flags of a message, you have to make sure to
599 call get_flags() at least once before using directly message->flags. 601 call get_flags() at least once before using directly message->flags.
600*/ 602*/
601 603
602#define LIBETPAN_MAIL_MESSAGE_CHECK 604#define LIBETPAN_MAIL_MESSAGE_CHECK
603 605
604struct mailmessage_driver { 606struct mailmessage_driver {
605 char * msg_name; 607 char * msg_name;
606 608
607 int (* msg_initialize)(mailmessage * msg_info); 609 int (* msg_initialize)(mailmessage * msg_info);
608 610
609 void (* msg_uninitialize)(mailmessage * msg_info); 611 void (* msg_uninitialize)(mailmessage * msg_info);
610 612
611 void (* msg_flush)(mailmessage * msg_info); 613 void (* msg_flush)(mailmessage * msg_info);
612 614
613 void (* msg_check)(mailmessage * msg_info); 615 void (* msg_check)(mailmessage * msg_info);
614 616
615 void (* msg_fetch_result_free)(mailmessage * msg_info, 617 void (* msg_fetch_result_free)(mailmessage * msg_info,
616 char * msg); 618 char * msg);
617 619
618 int (* msg_fetch)(mailmessage * msg_info, 620 int (* msg_fetch)(mailmessage * msg_info,
619 char ** result, 621 char ** result,
620 size_t * result_len); 622 size_t * result_len);
621 623
622 int (* msg_fetch_header)(mailmessage * msg_info, 624 int (* msg_fetch_header)(mailmessage * msg_info,
623 char ** result, 625 char ** result,
624 size_t * result_len); 626 size_t * result_len);
625 627
626 int (* msg_fetch_body)(mailmessage * msg_info, 628 int (* msg_fetch_body)(mailmessage * msg_info,
627 char ** result, size_t * result_len); 629 char ** result, size_t * result_len);
628 630
629 int (* msg_fetch_size)(mailmessage * msg_info, 631 int (* msg_fetch_size)(mailmessage * msg_info,
630 size_t * result); 632 size_t * result);
631 633
632 int (* msg_get_bodystructure)(mailmessage * msg_info, 634 int (* msg_get_bodystructure)(mailmessage * msg_info,
633 struct mailmime ** result); 635 struct mailmime ** result);
634 636
635 int (* msg_fetch_section)(mailmessage * msg_info, 637 int (* msg_fetch_section)(mailmessage * msg_info,
636 struct mailmime * mime, 638 struct mailmime * mime,
637 char ** result, size_t * result_len); 639 char ** result, size_t * result_len);
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
@@ -1,96 +1,103 @@
1#include "mailfolder.h" 1#include "mailfolder.h"
2 2
3#include "maildriver.h" 3#include "maildriver.h"
4 4
5int mailfolder_noop(struct mailfolder * folder) 5int mailfolder_noop(struct mailfolder * folder)
6{ 6{
7 return mailsession_noop(folder->fld_session); 7 return mailsession_noop(folder->fld_session);
8} 8}
9 9
10int mailfolder_check(struct mailfolder * folder) 10int mailfolder_check(struct mailfolder * folder)
11{ 11{
12 return mailsession_check_folder(folder->fld_session); 12 return mailsession_check_folder(folder->fld_session);
13} 13}
14 14
15int mailfolder_expunge(struct mailfolder * folder) 15int mailfolder_expunge(struct mailfolder * folder)
16{ 16{
17 return mailsession_expunge_folder(folder->fld_session); 17 return mailsession_expunge_folder(folder->fld_session);
18} 18}
19 19
20int mailfolder_status(struct mailfolder * folder, 20int 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
29int mailfolder_append_message(struct mailfolder * folder, 29int 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
35int 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
35int mailfolder_get_messages_list(struct mailfolder * folder, 42int 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;
51 } 58 }
52 59
53 * result = msg_list; 60 * result = msg_list;
54 61
55 return MAIL_NO_ERROR; 62 return MAIL_NO_ERROR;
56} 63}
57 64
58int mailfolder_get_envelopes_list(struct mailfolder * folder, 65int mailfolder_get_envelopes_list(struct mailfolder * folder,
59 struct mailmessage_list * result) 66 struct mailmessage_list * result)
60{ 67{
61 return mailsession_get_envelopes_list(folder->fld_session, result); 68 return mailsession_get_envelopes_list(folder->fld_session, result);
62} 69}
63 70
64int mailfolder_get_message(struct mailfolder * folder, 71int mailfolder_get_message(struct mailfolder * folder,
65 uint32_t num, mailmessage ** result) 72 uint32_t num, mailmessage ** result)
66{ 73{
67 mailmessage * msg; 74 mailmessage * msg;
68 int r; 75 int r;
69 76
70 r = mailsession_get_message(folder->fld_session, num, &msg); 77 r = mailsession_get_message(folder->fld_session, num, &msg);
71 if (r != MAIL_NO_ERROR) 78 if (r != MAIL_NO_ERROR)
72 return r; 79 return r;
73 80
74 msg->msg_folder = folder; 81 msg->msg_folder = folder;
75 82
76 * result = msg; 83 * result = msg;
77 84
78 return MAIL_NO_ERROR; 85 return MAIL_NO_ERROR;
79} 86}
80 87
81int mailfolder_get_message_by_uid(struct mailfolder * folder, 88int mailfolder_get_message_by_uid(struct mailfolder * folder,
82 const char * uid, mailmessage ** result) 89 const char * uid, mailmessage ** result)
83{ 90{
84 mailmessage * msg; 91 mailmessage * msg;
85 int r; 92 int r;
86 93
87 r = mailsession_get_message_by_uid(folder->fld_session, uid, &msg); 94 r = mailsession_get_message_by_uid(folder->fld_session, uid, &msg);
88 if (r != MAIL_NO_ERROR) 95 if (r != MAIL_NO_ERROR)
89 return r; 96 return r;
90 97
91 msg->msg_folder = folder; 98 msg->msg_folder = folder;
92 99
93 * result = msg; 100 * result = msg;
94 101
95 return MAIL_NO_ERROR; 102 return MAIL_NO_ERROR;
96} 103}
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
@@ -1,32 +1,35 @@
1#ifndef MAILFOLDER_H 1#ifndef MAILFOLDER_H
2 2
3#define MAILFOLDER_H 3#define MAILFOLDER_H
4 4
5#include "mailstorage_types.h" 5#include "mailstorage_types.h"
6 6
7int mailfolder_noop(struct mailfolder * folder); 7int mailfolder_noop(struct mailfolder * folder);
8 8
9int mailfolder_check(struct mailfolder * folder); 9int mailfolder_check(struct mailfolder * folder);
10 10
11int mailfolder_expunge(struct mailfolder * folder); 11int mailfolder_expunge(struct mailfolder * folder);
12 12
13int mailfolder_status(struct mailfolder * folder, 13int 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
17int mailfolder_append_message(struct mailfolder * folder, 17int mailfolder_append_message(struct mailfolder * folder,
18 char * message, size_t size); 18 char * message, size_t size);
19 19
20int mailfolder_append_message_flags(struct mailfolder * folder,
21 char * message, size_t size, struct mail_flags * flags);
22
20int mailfolder_get_messages_list(struct mailfolder * folder, 23int mailfolder_get_messages_list(struct mailfolder * folder,
21 struct mailmessage_list ** result); 24 struct mailmessage_list ** result);
22 25
23int mailfolder_get_envelopes_list(struct mailfolder * folder, 26int mailfolder_get_envelopes_list(struct mailfolder * folder,
24 struct mailmessage_list * result); 27 struct mailmessage_list * result);
25 28
26int mailfolder_get_message(struct mailfolder * folder, 29int mailfolder_get_message(struct mailfolder * folder,
27 uint32_t num, mailmessage ** result); 30 uint32_t num, mailmessage ** result);
28 31
29int mailfolder_get_message_by_uid(struct mailfolder * folder, 32int 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
@@ -198,137 +198,144 @@ int mailfolder_add_child(struct mailfolder * parent,
198{ 198{
199 unsigned int index; 199 unsigned int index;
200 int r; 200 int r;
201 201
202 r = carray_add(parent->fld_children, child, &index); 202 r = carray_add(parent->fld_children, child, &index);
203 if (r < 0) 203 if (r < 0)
204 return MAIL_ERROR_MEMORY; 204 return MAIL_ERROR_MEMORY;
205 205
206 child->fld_sibling_index = index; 206 child->fld_sibling_index = index;
207 child->fld_parent = parent; 207 child->fld_parent = parent;
208 208
209 return MAIL_NO_ERROR; 209 return MAIL_NO_ERROR;
210} 210}
211 211
212int mailfolder_detach_parent(struct mailfolder * folder) 212int mailfolder_detach_parent(struct mailfolder * folder)
213{ 213{
214 unsigned int i; 214 unsigned int i;
215 int r; 215 int r;
216 216
217 if (folder->fld_parent == NULL) 217 if (folder->fld_parent == NULL)
218 return MAIL_ERROR_INVAL; 218 return MAIL_ERROR_INVAL;
219 219
220 r = carray_delete_slow(folder->fld_parent->fld_children, 220 r = carray_delete_slow(folder->fld_parent->fld_children,
221 folder->fld_sibling_index); 221 folder->fld_sibling_index);
222 if (r < 0) 222 if (r < 0)
223 return MAIL_ERROR_INVAL; 223 return MAIL_ERROR_INVAL;
224 224
225 for(i = 0 ; i < carray_count(folder->fld_parent->fld_children) ; i ++) { 225 for(i = 0 ; i < carray_count(folder->fld_parent->fld_children) ; i ++) {
226 struct mailfolder * child; 226 struct mailfolder * child;
227 227
228 child = carray_get(folder->fld_parent->fld_children, i); 228 child = carray_get(folder->fld_parent->fld_children, i);
229 child->fld_sibling_index = i; 229 child->fld_sibling_index = i;
230 } 230 }
231 231
232 folder->fld_parent = NULL; 232 folder->fld_parent = NULL;
233 folder->fld_sibling_index = 0; 233 folder->fld_sibling_index = 0;
234 234
235 return MAIL_NO_ERROR; 235 return MAIL_NO_ERROR;
236} 236}
237 237
238struct mailstorage * mailstorage_new(char * sto_id) 238struct mailstorage * mailstorage_new(char * sto_id)
239{ 239{
240 struct mailstorage * storage; 240 struct mailstorage * storage;
241 241
242 storage = malloc(sizeof(struct mailstorage)); 242 storage = malloc(sizeof(struct mailstorage));
243 if (storage == NULL) 243 if (storage == NULL)
244 goto err; 244 goto err;
245 245
246 if (sto_id != NULL) { 246 if (sto_id != NULL) {
247 storage->sto_id = strdup(sto_id); 247 storage->sto_id = strdup(sto_id);
248 if (storage->sto_id == NULL) 248 if (storage->sto_id == NULL)
249 goto free; 249 goto free;
250 } 250 }
251 else 251 else
252 storage->sto_id = NULL; 252 storage->sto_id = NULL;
253 253
254 storage->sto_data = NULL; 254 storage->sto_data = NULL;
255 storage->sto_session = NULL; 255 storage->sto_session = NULL;
256 storage->sto_driver = NULL; 256 storage->sto_driver = NULL;
257 storage->sto_shared_folders = clist_new(); 257 storage->sto_shared_folders = clist_new();
258 if (storage->sto_shared_folders == NULL) 258 if (storage->sto_shared_folders == NULL)
259 goto free_id; 259 goto free_id;
260 260
261 return storage; 261 return storage;
262 262
263 free_id: 263 free_id:
264 if (storage->sto_id != NULL) 264 if (storage->sto_id != NULL)
265 free(storage->sto_id); 265 free(storage->sto_id);
266 free: 266 free:
267 free(storage); 267 free(storage);
268 err: 268 err:
269 return NULL; 269 return NULL;
270} 270}
271 271
272void mailstorage_free(struct mailstorage * storage) 272void mailstorage_free(struct mailstorage * storage)
273{ 273{
274 if (storage->sto_session != NULL) 274 if (storage->sto_session != NULL)
275 mailstorage_disconnect(storage); 275 mailstorage_disconnect(storage);
276 276
277 if (storage->sto_driver != NULL) { 277 if (storage->sto_driver != NULL) {
278 if (storage->sto_driver->sto_uninitialize != NULL) 278 if (storage->sto_driver->sto_uninitialize != NULL)
279 storage->sto_driver->sto_uninitialize(storage); 279 storage->sto_driver->sto_uninitialize(storage);
280 } 280 }
281 281
282 clist_free(storage->sto_shared_folders); 282 clist_free(storage->sto_shared_folders);
283 283
284 if (storage->sto_id != NULL) 284 if (storage->sto_id != NULL)
285 free(storage->sto_id); 285 free(storage->sto_id);
286 286
287 free(storage); 287 free(storage);
288} 288}
289 289
290int mailstorage_connect(struct mailstorage * storage) 290int mailstorage_connect(struct mailstorage * storage)
291{ 291{
292 if (storage->sto_session != NULL) 292 if (storage->sto_session != NULL)
293 return MAIL_NO_ERROR; 293 return MAIL_NO_ERROR;
294 294
295 if (!clist_isempty(storage->sto_shared_folders)) 295 if (!clist_isempty(storage->sto_shared_folders))
296 return MAIL_ERROR_BAD_STATE; 296 return MAIL_ERROR_BAD_STATE;
297 297
298 if (storage->sto_driver->sto_connect == NULL) 298 if (storage->sto_driver->sto_connect == NULL)
299 return MAIL_ERROR_NOT_IMPLEMENTED; 299 return MAIL_ERROR_NOT_IMPLEMENTED;
300 300
301 return storage->sto_driver->sto_connect(storage); 301 return storage->sto_driver->sto_connect(storage);
302} 302}
303 303
304 304
305void mailstorage_disconnect(struct mailstorage * storage) 305void mailstorage_disconnect(struct mailstorage * storage)
306{ 306{
307 int r; 307 int r;
308 clistiter * cur; 308 clistiter * cur;
309 309
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
327int mailstorage_noop(struct mailstorage * storage)
328{
329 return mailsession_noop(storage->sto_session);
330}
331
332
326static int mailstorage_get_folder(struct mailstorage * storage, 333static 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
@@ -1,98 +1,99 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAIL_STORAGE_H 36#ifndef MAIL_STORAGE_H
37 37
38#define MAIL_STORAGE_H 38#define MAIL_STORAGE_H
39 39
40#include <libetpan/maildriver_types.h> 40#include <libetpan/maildriver_types.h>
41#include <libetpan/mailstorage_types.h> 41#include <libetpan/mailstorage_types.h>
42 42
43#ifdef __cplusplus 43#ifdef __cplusplus
44extern "C" { 44extern "C" {
45#endif 45#endif
46 46
47/* storage */ 47/* storage */
48 48
49/* 49/*
50 mailstorage_new 50 mailstorage_new
51 51
52 This function creates an empty storage. This storage have to be initialized. 52 This function creates an empty storage. This storage have to be initialized.
53 The "driver" and "data" fields should be initialized. 53 The "driver" and "data" fields should be initialized.
54 54
55 @param id is the name of the storage. It can be NULL. 55 @param id is the name of the storage. It can be NULL.
56 The given parameter is no more needed when the creation is finished. 56 The given parameter is no more needed when the creation is finished.
57 The given string is duplicated. 57 The given string is duplicated.
58 58
59 @return The mail storage is returned. 59 @return The mail storage is returned.
60*/ 60*/
61 61
62struct mailstorage * mailstorage_new(char * sto_id); 62struct mailstorage * mailstorage_new(char * sto_id);
63 63
64void mailstorage_free(struct mailstorage * storage); 64void 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
70int mailstorage_connect(struct mailstorage * storage); 70int mailstorage_connect(struct mailstorage * storage);
71 71
72void mailstorage_disconnect(struct mailstorage * storage); 72void mailstorage_disconnect(struct mailstorage * storage);
73 73
74int mailstorage_noop(struct mailstorage * storage);
75
74 76
75/* folder */ 77/* folder */
76 78
77struct mailfolder * mailfolder_new(struct mailstorage * fld_storage, 79struct 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
80void mailfolder_free(struct mailfolder * folder); 82void mailfolder_free(struct mailfolder * folder);
81 83
82int mailfolder_add_child(struct mailfolder * parent, 84int mailfolder_add_child(struct mailfolder * parent,
83 struct mailfolder * child); 85 struct mailfolder * child);
84 86
85int mailfolder_detach_parent(struct mailfolder * folder); 87int mailfolder_detach_parent(struct mailfolder * folder);
86 88
87int mailfolder_connect(struct mailfolder * folder); 89int mailfolder_connect(struct mailfolder * folder);
88 90
89void mailfolder_disconnect(struct mailfolder * folder); 91void 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
@@ -1,474 +1,484 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "mboxdriver.h" 36#include "mboxdriver.h"
37 37
38#include <stdio.h> 38#include <stdio.h>
39#include <string.h> 39#include <string.h>
40#include <sys/types.h> 40#include <sys/types.h>
41#include <dirent.h> 41#include <dirent.h>
42#include <unistd.h> 42#include <unistd.h>
43#include <sys/stat.h> 43#include <sys/stat.h>
44#include <ctype.h> 44#include <ctype.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#include <sys/times.h> 46#include <sys/times.h>
47 47
48#include "mail.h" 48#include "mail.h"
49#include "maildriver_tools.h" 49#include "maildriver_tools.h"
50#include "mailmbox.h" 50#include "mailmbox.h"
51#include "mboxdriver_tools.h" 51#include "mboxdriver_tools.h"
52#include "maildriver.h" 52#include "maildriver.h"
53#include "carray.h" 53#include "carray.h"
54#include "mboxdriver_message.h" 54#include "mboxdriver_message.h"
55#include "mailmessage.h" 55#include "mailmessage.h"
56 56
57static int mboxdriver_initialize(mailsession * session); 57static int mboxdriver_initialize(mailsession * session);
58 58
59static void mboxdriver_uninitialize(mailsession * session); 59static void mboxdriver_uninitialize(mailsession * session);
60 60
61static int mboxdriver_parameters(mailsession * session, 61static int mboxdriver_parameters(mailsession * session,
62 int id, void * value); 62 int id, void * value);
63 63
64static int mboxdriver_connect_path(mailsession * session, char * path); 64static int mboxdriver_connect_path(mailsession * session, char * path);
65 65
66static int mboxdriver_logout(mailsession * session); 66static int mboxdriver_logout(mailsession * session);
67 67
68static int mboxdriver_expunge_folder(mailsession * session); 68static int mboxdriver_expunge_folder(mailsession * session);
69 69
70static int mboxdriver_status_folder(mailsession * session, char * mb, 70static 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
74static int mboxdriver_messages_number(mailsession * session, char * mb, 74static int mboxdriver_messages_number(mailsession * session, char * mb,
75 uint32_t * result); 75 uint32_t * result);
76 76
77static int mboxdriver_append_message(mailsession * session, 77static int mboxdriver_append_message(mailsession * session,
78 char * message, size_t size); 78 char * message, size_t size);
79 79
80static int mboxdriver_append_message_flags(mailsession * session,
81 char * message, size_t size, struct mail_flags * flags);
82
80static int mboxdriver_get_messages_list(mailsession * session, 83static int mboxdriver_get_messages_list(mailsession * session,
81 struct mailmessage_list ** result); 84 struct mailmessage_list ** result);
82 85
83static int 86static int
84mboxdriver_get_envelopes_list(mailsession * session, 87mboxdriver_get_envelopes_list(mailsession * session,
85 struct mailmessage_list * env_list); 88 struct mailmessage_list * env_list);
86 89
87static int mboxdriver_remove_message(mailsession * session, uint32_t num); 90static int mboxdriver_remove_message(mailsession * session, uint32_t num);
88 91
89static int mboxdriver_get_message(mailsession * session, 92static int mboxdriver_get_message(mailsession * session,
90 uint32_t num, mailmessage ** result); 93 uint32_t num, mailmessage ** result);
91 94
92static int mboxdriver_get_message_by_uid(mailsession * session, 95static int mboxdriver_get_message_by_uid(mailsession * session,
93 const char * uid, 96 const char * uid,
94 mailmessage ** result); 97 mailmessage ** result);
95 98
96static mailsession_driver local_mbox_session_driver = { 99static mailsession_driver local_mbox_session_driver = {
97 .sess_name = "mbox", 100 .sess_name = "mbox",
98 101
99 .sess_initialize = mboxdriver_initialize, 102 .sess_initialize = mboxdriver_initialize,
100 .sess_uninitialize = mboxdriver_uninitialize, 103 .sess_uninitialize = mboxdriver_uninitialize,
101 104
102 .sess_parameters = mboxdriver_parameters, 105 .sess_parameters = mboxdriver_parameters,
103 106
104 .sess_connect_path = mboxdriver_connect_path, 107 .sess_connect_path = mboxdriver_connect_path,
105 .sess_connect_stream = NULL, 108 .sess_connect_stream = NULL,
106 .sess_starttls = NULL, 109 .sess_starttls = NULL,
107 .sess_login = NULL, 110 .sess_login = NULL,
108 .sess_logout = mboxdriver_logout, 111 .sess_logout = mboxdriver_logout,
109 .sess_noop = NULL, 112 .sess_noop = NULL,
110 113
111 .sess_build_folder_name = NULL, 114 .sess_build_folder_name = NULL,
112 .sess_create_folder = NULL, 115 .sess_create_folder = NULL,
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
143mailsession_driver * mbox_session_driver = &local_mbox_session_driver; 147mailsession_driver * mbox_session_driver = &local_mbox_session_driver;
144 148
145static inline struct mbox_session_state_data * get_data(mailsession * session) 149static inline struct mbox_session_state_data * get_data(mailsession * session)
146{ 150{
147 return session->sess_data; 151 return session->sess_data;
148} 152}
149 153
150static inline struct mailmbox_folder * get_mbox_session(mailsession * session) 154static inline struct mailmbox_folder * get_mbox_session(mailsession * session)
151{ 155{
152 return get_data(session)->mbox_folder; 156 return get_data(session)->mbox_folder;
153} 157}
154 158
155static int mboxdriver_initialize(mailsession * session) 159static int mboxdriver_initialize(mailsession * session)
156{ 160{
157 struct mbox_session_state_data * data; 161 struct mbox_session_state_data * data;
158 162
159 data = malloc(sizeof(* data)); 163 data = malloc(sizeof(* data));
160 if (data == NULL) 164 if (data == NULL)
161 goto err; 165 goto err;
162 166
163 data->mbox_folder = NULL; 167 data->mbox_folder = NULL;
164 168
165 data->mbox_force_read_only = FALSE; 169 data->mbox_force_read_only = FALSE;
166 data->mbox_force_no_uid = TRUE; 170 data->mbox_force_no_uid = TRUE;
167 171
168 session->sess_data = data; 172 session->sess_data = data;
169 173
170 return MAIL_NO_ERROR; 174 return MAIL_NO_ERROR;
171 175
172 err: 176 err:
173 return MAIL_ERROR_MEMORY; 177 return MAIL_ERROR_MEMORY;
174} 178}
175 179
176static void free_state(struct mbox_session_state_data * mbox_data) 180static void free_state(struct mbox_session_state_data * mbox_data)
177{ 181{
178 if (mbox_data->mbox_folder != NULL) { 182 if (mbox_data->mbox_folder != NULL) {
179 mailmbox_done(mbox_data->mbox_folder); 183 mailmbox_done(mbox_data->mbox_folder);
180 mbox_data->mbox_folder = NULL; 184 mbox_data->mbox_folder = NULL;
181 } 185 }
182} 186}
183 187
184static void mboxdriver_uninitialize(mailsession * session) 188static void mboxdriver_uninitialize(mailsession * session)
185{ 189{
186 struct mbox_session_state_data * data; 190 struct mbox_session_state_data * data;
187 191
188 data = get_data(session); 192 data = get_data(session);
189 193
190 free_state(data); 194 free_state(data);
191 195
192 free(data); 196 free(data);
193} 197}
194 198
195static int mboxdriver_parameters(mailsession * session, 199static int mboxdriver_parameters(mailsession * session,
196 int id, void * value) 200 int id, void * value)
197{ 201{
198 struct mbox_session_state_data * data; 202 struct mbox_session_state_data * data;
199 203
200 data = get_data(session); 204 data = get_data(session);
201 205
202 switch (id) { 206 switch (id) {
203 case MBOXDRIVER_SET_READ_ONLY: 207 case MBOXDRIVER_SET_READ_ONLY:
204 { 208 {
205 int * param; 209 int * param;
206 210
207 param = value; 211 param = value;
208 212
209 data->mbox_force_read_only = * param; 213 data->mbox_force_read_only = * param;
210 return MAIL_NO_ERROR; 214 return MAIL_NO_ERROR;
211 } 215 }
212 216
213 case MBOXDRIVER_SET_NO_UID: 217 case MBOXDRIVER_SET_NO_UID:
214 { 218 {
215 int * param; 219 int * param;
216 220
217 param = value; 221 param = value;
218 222
219 data->mbox_force_no_uid = * param; 223 data->mbox_force_no_uid = * param;
220 return MAIL_NO_ERROR; 224 return MAIL_NO_ERROR;
221 } 225 }
222 } 226 }
223 227
224 return MAIL_ERROR_INVAL; 228 return MAIL_ERROR_INVAL;
225} 229}
226 230
227 231
228static int mboxdriver_connect_path(mailsession * session, char * path) 232static int mboxdriver_connect_path(mailsession * session, char * path)
229{ 233{
230 struct mbox_session_state_data * mbox_data; 234 struct mbox_session_state_data * mbox_data;
231 struct mailmbox_folder * folder; 235 struct mailmbox_folder * folder;
232 int r; 236 int r;
233 237
234 mbox_data = get_data(session); 238 mbox_data = get_data(session);
235 239
236 if (mbox_data->mbox_folder != NULL) 240 if (mbox_data->mbox_folder != NULL)
237 return MAIL_ERROR_BAD_STATE; 241 return MAIL_ERROR_BAD_STATE;
238 242
239 r = mailmbox_init(path, 243 r = mailmbox_init(path,
240 mbox_data->mbox_force_read_only, 244 mbox_data->mbox_force_read_only,
241 mbox_data->mbox_force_no_uid, 245 mbox_data->mbox_force_no_uid,
242 0, 246 0,
243 &folder); 247 &folder);
244 248
245 if (r != MAILMBOX_NO_ERROR) 249 if (r != MAILMBOX_NO_ERROR)
246 return mboxdriver_mbox_error_to_mail_error(r); 250 return mboxdriver_mbox_error_to_mail_error(r);
247 251
248 mbox_data->mbox_folder = folder; 252 mbox_data->mbox_folder = folder;
249 253
250 return MAIL_NO_ERROR; 254 return MAIL_NO_ERROR;
251} 255}
252 256
253static int mboxdriver_logout(mailsession * session) 257static int mboxdriver_logout(mailsession * session)
254{ 258{
255 struct mbox_session_state_data * mbox_data; 259 struct mbox_session_state_data * mbox_data;
256 260
257 mbox_data = get_data(session); 261 mbox_data = get_data(session);
258 262
259 if (mbox_data->mbox_folder == NULL) 263 if (mbox_data->mbox_folder == NULL)
260 return MAIL_ERROR_BAD_STATE; 264 return MAIL_ERROR_BAD_STATE;
261 265
262 free_state(mbox_data); 266 free_state(mbox_data);
263 267
264 mbox_data->mbox_folder = NULL; 268 mbox_data->mbox_folder = NULL;
265 269
266 return MAIL_NO_ERROR; 270 return MAIL_NO_ERROR;
267} 271}
268 272
269static int mboxdriver_expunge_folder(mailsession * session) 273static int mboxdriver_expunge_folder(mailsession * session)
270{ 274{
271 int r; 275 int r;
272 struct mbox_session_state_data * mbox_data; 276 struct mbox_session_state_data * mbox_data;
273 277
274 mbox_data = get_data(session); 278 mbox_data = get_data(session);
275 279
276 if (mbox_data->mbox_folder == NULL) 280 if (mbox_data->mbox_folder == NULL)
277 return MAIL_ERROR_BAD_STATE; 281 return MAIL_ERROR_BAD_STATE;
278 282
279 r = mailmbox_expunge(mbox_data->mbox_folder); 283 r = mailmbox_expunge(mbox_data->mbox_folder);
280 if (r != MAILMBOX_NO_ERROR) 284 if (r != MAILMBOX_NO_ERROR)
281 return mboxdriver_mbox_error_to_mail_error(r); 285 return mboxdriver_mbox_error_to_mail_error(r);
282 286
283 return MAIL_NO_ERROR; 287 return MAIL_NO_ERROR;
284} 288}
285 289
286static int mboxdriver_status_folder(mailsession * session, char * mb, 290static int mboxdriver_status_folder(mailsession * session, char * mb,
287 uint32_t * result_messages, uint32_t * result_recent, 291 uint32_t * result_messages, uint32_t * result_recent,
288 uint32_t * result_unseen) 292 uint32_t * result_unseen)
289{ 293{
290 uint32_t count; 294 uint32_t count;
291 int r; 295 int r;
292 296
293 r = mboxdriver_messages_number(session, mb, &count); 297 r = mboxdriver_messages_number(session, mb, &count);
294 if (r != MAIL_NO_ERROR) 298 if (r != MAIL_NO_ERROR)
295 return r; 299 return r;
296 300
297 * result_messages = count; 301 * result_messages = count;
298 * result_recent = count; 302 * result_recent = count;
299 * result_unseen = count; 303 * result_unseen = count;
300 304
301 return MAIL_NO_ERROR; 305 return MAIL_NO_ERROR;
302} 306}
303 307
304static int mboxdriver_messages_number(mailsession * session, char * mb, 308static int mboxdriver_messages_number(mailsession * session, char * mb,
305 uint32_t * result) 309 uint32_t * result)
306{ 310{
307 struct mailmbox_folder * folder; 311 struct mailmbox_folder * folder;
308 int r; 312 int r;
309 313
310 folder = get_mbox_session(session); 314 folder = get_mbox_session(session);
311 if (folder == NULL) 315 if (folder == NULL)
312 return MAIL_ERROR_STATUS; 316 return MAIL_ERROR_STATUS;
313 317
314 r = mailmbox_validate_read_lock(folder); 318 r = mailmbox_validate_read_lock(folder);
315 if (r != MAIL_NO_ERROR) 319 if (r != MAIL_NO_ERROR)
316 return r; 320 return r;
317 321
318 mailmbox_read_unlock(folder); 322 mailmbox_read_unlock(folder);
319 323
320 * result = carray_count(folder->mb_tab) - folder->mb_deleted_count; 324 * result = carray_count(folder->mb_tab) - folder->mb_deleted_count;
321 325
322 return MAILMBOX_NO_ERROR; 326 return MAILMBOX_NO_ERROR;
323} 327}
324 328
325/* messages operations */ 329/* messages operations */
326 330
327static int mboxdriver_append_message(mailsession * session, 331static int mboxdriver_append_message(mailsession * session,
328 char * message, size_t size) 332 char * message, size_t size)
329{ 333{
330 int r; 334 int r;
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
351static 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
347static int mboxdriver_get_messages_list(mailsession * session, 357static 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;
363} 373}
364 374
365static int 375static int
366mboxdriver_get_envelopes_list(mailsession * session, 376mboxdriver_get_envelopes_list(mailsession * session,
367 struct mailmessage_list * env_list) 377 struct mailmessage_list * env_list)
368{ 378{
369 struct mailmbox_folder * folder; 379 struct mailmbox_folder * folder;
370 unsigned int i; 380 unsigned int i;
371 int r; 381 int r;
372 int res; 382 int res;
373 383
374 folder = get_mbox_session(session); 384 folder = get_mbox_session(session);
375 if (folder == NULL) { 385 if (folder == NULL) {
376 res = MAIL_ERROR_BAD_STATE; 386 res = MAIL_ERROR_BAD_STATE;
377 goto err; 387 goto err;
378 } 388 }
379 389
380 r = mailmbox_validate_read_lock(folder); 390 r = mailmbox_validate_read_lock(folder);
381 if (r != MAILMBOX_NO_ERROR) { 391 if (r != MAILMBOX_NO_ERROR) {
382 res = mboxdriver_mbox_error_to_mail_error(r); 392 res = mboxdriver_mbox_error_to_mail_error(r);
383 goto err; 393 goto err;
384 } 394 }
385 395
386 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 396 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
387 mailmessage * msg; 397 mailmessage * msg;
388 struct mailimf_fields * fields; 398 struct mailimf_fields * fields;
389 char * headers; 399 char * headers;
390 size_t headers_len; 400 size_t headers_len;
391 size_t cur_token; 401 size_t cur_token;
392 402
393 msg = carray_get(env_list->msg_tab, i); 403 msg = carray_get(env_list->msg_tab, i);
394 if (msg == NULL) 404 if (msg == NULL)
395 continue; 405 continue;
396 406
397 if (msg->msg_fields != NULL) 407 if (msg->msg_fields != NULL)
398 continue; 408 continue;
399 409
400 r = mailmbox_fetch_msg_headers_no_lock(folder, 410 r = mailmbox_fetch_msg_headers_no_lock(folder,
401 msg->msg_index, &headers, &headers_len); 411 msg->msg_index, &headers, &headers_len);
402 if (r != MAILMBOX_NO_ERROR) { 412 if (r != MAILMBOX_NO_ERROR) {
403 res = mboxdriver_mbox_error_to_mail_error(r); 413 res = mboxdriver_mbox_error_to_mail_error(r);
404 goto unlock; 414 goto unlock;
405 } 415 }
406 416
407 cur_token = 0; 417 cur_token = 0;
408 r = mailimf_envelope_fields_parse(headers, headers_len, 418 r = mailimf_envelope_fields_parse(headers, headers_len,
409 &cur_token, &fields); 419 &cur_token, &fields);
410 420
411 if (r != MAILIMF_NO_ERROR) 421 if (r != MAILIMF_NO_ERROR)
412 continue; 422 continue;
413 423
414 msg->msg_fields = fields; 424 msg->msg_fields = fields;
415 } 425 }
416 426
417 mailmbox_read_unlock(folder); 427 mailmbox_read_unlock(folder);
418 428
419 return MAIL_NO_ERROR; 429 return MAIL_NO_ERROR;
420 430
421 unlock: 431 unlock:
422 mailmbox_read_unlock(folder); 432 mailmbox_read_unlock(folder);
423 err: 433 err:
424 return res; 434 return res;
425} 435}
426 436
427 437
428static int mboxdriver_remove_message(mailsession * session, uint32_t num) 438static int mboxdriver_remove_message(mailsession * session, uint32_t num)
429{ 439{
430 int r; 440 int r;
431 struct mailmbox_folder * folder; 441 struct mailmbox_folder * folder;
432 442
433 folder = get_mbox_session(session); 443 folder = get_mbox_session(session);
434 if (folder == NULL) 444 if (folder == NULL)
435 return MAIL_ERROR_DELETE; 445 return MAIL_ERROR_DELETE;
436 446
437 r = mailmbox_delete_msg(folder, num); 447 r = mailmbox_delete_msg(folder, num);
438 448
439 return mboxdriver_mbox_error_to_mail_error(r); 449 return mboxdriver_mbox_error_to_mail_error(r);
440} 450}
441 451
442static int mboxdriver_get_message(mailsession * session, 452static int mboxdriver_get_message(mailsession * session,
443 uint32_t num, mailmessage ** result) 453 uint32_t num, mailmessage ** result)
444{ 454{
445 mailmessage * msg_info; 455 mailmessage * msg_info;
446 int r; 456 int r;
447 457
448 msg_info = mailmessage_new(); 458 msg_info = mailmessage_new();
449 if (msg_info == NULL) 459 if (msg_info == NULL)
450 return MAIL_ERROR_MEMORY; 460 return MAIL_ERROR_MEMORY;
451 461
452 r = mailmessage_init(msg_info, session, mbox_message_driver, num, 0); 462 r = mailmessage_init(msg_info, session, mbox_message_driver, num, 0);
453 if (r != MAIL_NO_ERROR) { 463 if (r != MAIL_NO_ERROR) {
454 mailmessage_free(msg_info); 464 mailmessage_free(msg_info);
455 return r; 465 return r;
456 } 466 }
457 467
458 * result = msg_info; 468 * result = msg_info;
459 469
460 return MAIL_NO_ERROR; 470 return MAIL_NO_ERROR;
461} 471}
462 472
463static int mboxdriver_get_message_by_uid(mailsession * session, 473static int mboxdriver_get_message_by_uid(mailsession * session,
464 const char * uid, 474 const char * uid,
465 mailmessage ** result) 475 mailmessage ** result)
466{ 476{
467 uint32_t num; 477 uint32_t num;
468 char * p; 478 char * p;
469 chashdatum key; 479 chashdatum key;
470 chashdatum data; 480 chashdatum data;
471 struct mailmbox_msg_info * info; 481 struct mailmbox_msg_info * info;
472 struct mailmbox_folder * folder; 482 struct mailmbox_folder * folder;
473 int r; 483 int r;
474 484
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
@@ -1,267 +1,272 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "mboxdriver_cached.h" 36#include "mboxdriver_cached.h"
37 37
38#include <stdio.h> 38#include <stdio.h>
39#include <string.h> 39#include <string.h>
40#include <dirent.h> 40#include <dirent.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <ctype.h> 42#include <ctype.h>
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/stat.h> 44#include <sys/stat.h>
45#include <fcntl.h> 45#include <fcntl.h>
46#include <stdlib.h> 46#include <stdlib.h>
47 47
48#include "mail.h" 48#include "mail.h"
49#include "mail_cache_db.h" 49#include "mail_cache_db.h"
50#include "mboxdriver.h" 50#include "mboxdriver.h"
51#include "mboxdriver_tools.h" 51#include "mboxdriver_tools.h"
52#include "maildriver_tools.h" 52#include "maildriver_tools.h"
53#include "mailmbox.h" 53#include "mailmbox.h"
54#include "maildriver.h" 54#include "maildriver.h"
55#include "carray.h" 55#include "carray.h"
56#include "generic_cache.h" 56#include "generic_cache.h"
57#include "imfcache.h" 57#include "imfcache.h"
58#include "mboxdriver_cached_message.h" 58#include "mboxdriver_cached_message.h"
59#include "libetpan-config.h" 59#include "libetpan-config.h"
60 60
61static int mboxdriver_cached_initialize(mailsession * session); 61static int mboxdriver_cached_initialize(mailsession * session);
62 62
63static void mboxdriver_cached_uninitialize(mailsession * session); 63static void mboxdriver_cached_uninitialize(mailsession * session);
64 64
65static int mboxdriver_cached_parameters(mailsession * session, 65static int mboxdriver_cached_parameters(mailsession * session,
66 int id, void * value); 66 int id, void * value);
67 67
68static int mboxdriver_cached_connect_path(mailsession * session, char * path); 68static int mboxdriver_cached_connect_path(mailsession * session, char * path);
69 69
70static int mboxdriver_cached_logout(mailsession * session); 70static int mboxdriver_cached_logout(mailsession * session);
71 71
72static int mboxdriver_cached_check_folder(mailsession * session); 72static int mboxdriver_cached_check_folder(mailsession * session);
73 73
74static int mboxdriver_cached_expunge_folder(mailsession * session); 74static int mboxdriver_cached_expunge_folder(mailsession * session);
75 75
76static int mboxdriver_cached_status_folder(mailsession * session, char * mb, 76static 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);
79static int mboxdriver_cached_messages_number(mailsession * session, char * mb, 79static int mboxdriver_cached_messages_number(mailsession * session, char * mb,
80 uint32_t * result); 80 uint32_t * result);
81static int mboxdriver_cached_recent_number(mailsession * session, char * mb, 81static int mboxdriver_cached_recent_number(mailsession * session, char * mb,
82 uint32_t * result); 82 uint32_t * result);
83static int mboxdriver_cached_unseen_number(mailsession * session, char * mb, 83static int mboxdriver_cached_unseen_number(mailsession * session, char * mb,
84 uint32_t * result); 84 uint32_t * result);
85 85
86static int mboxdriver_cached_append_message(mailsession * session, 86static int mboxdriver_cached_append_message(mailsession * session,
87 char * message, size_t size); 87 char * message, size_t size);
88 88
89static int mboxdriver_cached_append_message_flags(mailsession * session,
90 char * message, size_t size, struct mail_flags * flags);
91
89static int 92static int
90mboxdriver_cached_get_messages_list(mailsession * session, 93mboxdriver_cached_get_messages_list(mailsession * session,
91 struct mailmessage_list ** result); 94 struct mailmessage_list ** result);
92 95
93static int 96static int
94mboxdriver_cached_get_envelopes_list(mailsession * session, 97mboxdriver_cached_get_envelopes_list(mailsession * session,
95 struct mailmessage_list * env_list); 98 struct mailmessage_list * env_list);
96 99
97static int mboxdriver_cached_remove_message(mailsession * session, 100static int mboxdriver_cached_remove_message(mailsession * session,
98 uint32_t num); 101 uint32_t num);
99 102
100static int mboxdriver_cached_get_message(mailsession * session, 103static int mboxdriver_cached_get_message(mailsession * session,
101 uint32_t num, mailmessage ** result); 104 uint32_t num, mailmessage ** result);
102 105
103static int mboxdriver_cached_get_message_by_uid(mailsession * session, 106static int mboxdriver_cached_get_message_by_uid(mailsession * session,
104 const char * uid, 107 const char * uid,
105 mailmessage ** result); 108 mailmessage ** result);
106 109
107static mailsession_driver local_mbox_cached_session_driver = { 110static mailsession_driver local_mbox_cached_session_driver = {
108 .sess_name = "mbox-cached", 111 .sess_name = "mbox-cached",
109 112
110 .sess_initialize = mboxdriver_cached_initialize, 113 .sess_initialize = mboxdriver_cached_initialize,
111 .sess_uninitialize = mboxdriver_cached_uninitialize, 114 .sess_uninitialize = mboxdriver_cached_uninitialize,
112 115
113 .sess_parameters = mboxdriver_cached_parameters, 116 .sess_parameters = mboxdriver_cached_parameters,
114 117
115 .sess_connect_path = mboxdriver_cached_connect_path, 118 .sess_connect_path = mboxdriver_cached_connect_path,
116 .sess_connect_stream = NULL, 119 .sess_connect_stream = NULL,
117 .sess_starttls = NULL, 120 .sess_starttls = NULL,
118 .sess_login = NULL, 121 .sess_login = NULL,
119 .sess_logout = mboxdriver_cached_logout, 122 .sess_logout = mboxdriver_cached_logout,
120 .sess_noop = NULL, 123 .sess_noop = NULL,
121 124
122 .sess_build_folder_name = NULL, 125 .sess_build_folder_name = NULL,
123 .sess_create_folder = NULL, 126 .sess_create_folder = NULL,
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
154mailsession_driver * mbox_cached_session_driver = 159mailsession_driver * mbox_cached_session_driver =
155&local_mbox_cached_session_driver; 160&local_mbox_cached_session_driver;
156 161
157 162
158#define ENV_NAME "env.db" 163#define ENV_NAME "env.db"
159#define FLAGS_NAME "flags.db" 164#define FLAGS_NAME "flags.db"
160 165
161 166
162 167
163static int mbox_error_to_mail_error(int error) 168static int mbox_error_to_mail_error(int error)
164{ 169{
165 switch (error) { 170 switch (error) {
166 case MAILMBOX_NO_ERROR: 171 case MAILMBOX_NO_ERROR:
167 return MAIL_NO_ERROR; 172 return MAIL_NO_ERROR;
168 173
169 case MAILMBOX_ERROR_PARSE: 174 case MAILMBOX_ERROR_PARSE:
170 return MAIL_ERROR_PARSE; 175 return MAIL_ERROR_PARSE;
171 176
172 case MAILMBOX_ERROR_INVAL: 177 case MAILMBOX_ERROR_INVAL:
173 return MAIL_ERROR_INVAL; 178 return MAIL_ERROR_INVAL;
174 179
175 case MAILMBOX_ERROR_FILE_NOT_FOUND: 180 case MAILMBOX_ERROR_FILE_NOT_FOUND:
176 return MAIL_ERROR_PARSE; 181 return MAIL_ERROR_PARSE;
177 182
178 case MAILMBOX_ERROR_MEMORY: 183 case MAILMBOX_ERROR_MEMORY:
179 return MAIL_ERROR_MEMORY; 184 return MAIL_ERROR_MEMORY;
180 185
181 case MAILMBOX_ERROR_TEMPORARY_FILE: 186 case MAILMBOX_ERROR_TEMPORARY_FILE:
182 return MAIL_ERROR_PARSE; 187 return MAIL_ERROR_PARSE;
183 188
184 case MAILMBOX_ERROR_FILE: 189 case MAILMBOX_ERROR_FILE:
185 return MAIL_ERROR_FILE; 190 return MAIL_ERROR_FILE;
186 191
187 case MAILMBOX_ERROR_MSG_NOT_FOUND: 192 case MAILMBOX_ERROR_MSG_NOT_FOUND:
188 return MAIL_ERROR_MSG_NOT_FOUND; 193 return MAIL_ERROR_MSG_NOT_FOUND;
189 194
190 case MAILMBOX_ERROR_READONLY: 195 case MAILMBOX_ERROR_READONLY:
191 return MAIL_ERROR_READONLY; 196 return MAIL_ERROR_READONLY;
192 197
193 default: 198 default:
194 return MAIL_ERROR_INVAL; 199 return MAIL_ERROR_INVAL;
195 } 200 }
196} 201}
197 202
198 203
199 204
200 205
201static inline struct mbox_cached_session_state_data * 206static inline struct mbox_cached_session_state_data *
202get_cached_data(mailsession * session) 207get_cached_data(mailsession * session)
203{ 208{
204 return session->sess_data; 209 return session->sess_data;
205} 210}
206 211
207static inline mailsession * get_ancestor(mailsession * session) 212static inline mailsession * get_ancestor(mailsession * session)
208{ 213{
209 return get_cached_data(session)->mbox_ancestor; 214 return get_cached_data(session)->mbox_ancestor;
210} 215}
211 216
212static inline struct mbox_session_state_data * 217static inline struct mbox_session_state_data *
213get_ancestor_data(mailsession * session) 218get_ancestor_data(mailsession * session)
214{ 219{
215 return get_ancestor(session)->sess_data; 220 return get_ancestor(session)->sess_data;
216} 221}
217 222
218static inline struct mailmbox_folder * 223static inline struct mailmbox_folder *
219get_mbox_session(mailsession * session) 224get_mbox_session(mailsession * session)
220{ 225{
221 return get_ancestor_data(session)->mbox_folder; 226 return get_ancestor_data(session)->mbox_folder;
222} 227}
223 228
224static int mboxdriver_cached_initialize(mailsession * session) 229static int mboxdriver_cached_initialize(mailsession * session)
225{ 230{
226 struct mbox_cached_session_state_data * cached_data; 231 struct mbox_cached_session_state_data * cached_data;
227 struct mbox_session_state_data * mbox_data; 232 struct mbox_session_state_data * mbox_data;
228 233
229 cached_data = malloc(sizeof(* cached_data)); 234 cached_data = malloc(sizeof(* cached_data));
230 if (cached_data == NULL) 235 if (cached_data == NULL)
231 goto err; 236 goto err;
232 237
233 cached_data->mbox_flags_store = mail_flags_store_new(); 238 cached_data->mbox_flags_store = mail_flags_store_new();
234 if (cached_data->mbox_flags_store == NULL) 239 if (cached_data->mbox_flags_store == NULL)
235 goto free; 240 goto free;
236 241
237 cached_data->mbox_ancestor = mailsession_new(mbox_session_driver); 242 cached_data->mbox_ancestor = mailsession_new(mbox_session_driver);
238 if (cached_data->mbox_ancestor == NULL) 243 if (cached_data->mbox_ancestor == NULL)
239 goto free_store; 244 goto free_store;
240 245
241 cached_data->mbox_quoted_mb = NULL; 246 cached_data->mbox_quoted_mb = NULL;
242 /* 247 /*
243 UID must be enabled to take advantage of the cache 248 UID must be enabled to take advantage of the cache
244 */ 249 */
245 mbox_data = cached_data->mbox_ancestor->sess_data; 250 mbox_data = cached_data->mbox_ancestor->sess_data;
246 mbox_data->mbox_force_no_uid = FALSE; 251 mbox_data->mbox_force_no_uid = FALSE;
247 252
248 session->sess_data = cached_data; 253 session->sess_data = cached_data;
249 254
250 return MAIL_NO_ERROR; 255 return MAIL_NO_ERROR;
251 256
252 free_store: 257 free_store:
253 mail_flags_store_free(cached_data->mbox_flags_store); 258 mail_flags_store_free(cached_data->mbox_flags_store);
254 free: 259 free:
255 free(cached_data); 260 free(cached_data);
256 err: 261 err:
257 return MAIL_ERROR_MEMORY; 262 return MAIL_ERROR_MEMORY;
258} 263}
259 264
260static void free_state(struct mbox_cached_session_state_data * mbox_data) 265static void free_state(struct mbox_cached_session_state_data * mbox_data)
261{ 266{
262 if (mbox_data->mbox_quoted_mb) { 267 if (mbox_data->mbox_quoted_mb) {
263 free(mbox_data->mbox_quoted_mb); 268 free(mbox_data->mbox_quoted_mb);
264 mbox_data->mbox_quoted_mb = NULL; 269 mbox_data->mbox_quoted_mb = NULL;
265 } 270 }
266} 271}
267 272
@@ -781,357 +786,436 @@ static int mboxdriver_cached_status_folder(mailsession * session, char * mb,
781 786
782 data = get_cached_data(session); 787 data = get_cached_data(session);
783 if (data->mbox_quoted_mb == NULL) { 788 if (data->mbox_quoted_mb == NULL) {
784 res = MAIL_ERROR_BAD_STATE; 789 res = MAIL_ERROR_BAD_STATE;
785 goto err; 790 goto err;
786 } 791 }
787 792
788 r = mailmbox_validate_read_lock(folder); 793 r = mailmbox_validate_read_lock(folder);
789 if (r != MAIL_NO_ERROR) { 794 if (r != MAIL_NO_ERROR) {
790 res = MAIL_ERROR_BAD_STATE; 795 res = MAIL_ERROR_BAD_STATE;
791 goto err; 796 goto err;
792 } 797 }
793 798
794 mailmbox_read_unlock(folder); 799 mailmbox_read_unlock(folder);
795 800
796 mbox_flags_store_process(data->mbox_flags_directory, data->mbox_quoted_mb, 801 mbox_flags_store_process(data->mbox_flags_directory, data->mbox_quoted_mb,
797 data->mbox_flags_store); 802 data->mbox_flags_store);
798 803
799 snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", 804 snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s",
800 data->mbox_flags_directory, MAIL_DIR_SEPARATOR, data->mbox_quoted_mb, 805 data->mbox_flags_directory, MAIL_DIR_SEPARATOR, data->mbox_quoted_mb,
801 MAIL_DIR_SEPARATOR, FLAGS_NAME); 806 MAIL_DIR_SEPARATOR, FLAGS_NAME);
802 807
803 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 808 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
804 if (r < 0) { 809 if (r < 0) {
805 res = MAIL_ERROR_FILE; 810 res = MAIL_ERROR_FILE;
806 goto err; 811 goto err;
807 } 812 }
808 813
809 mmapstr = mmap_string_new(""); 814 mmapstr = mmap_string_new("");
810 if (mmapstr == NULL) { 815 if (mmapstr == NULL) {
811 res = MAIL_ERROR_MEMORY; 816 res = MAIL_ERROR_MEMORY;
812 goto close_db_flags; 817 goto close_db_flags;
813 } 818 }
814 819
815 for(i = 0 ; i < carray_count(folder->mb_tab) ; i ++) { 820 for(i = 0 ; i < carray_count(folder->mb_tab) ; i ++) {
816 struct mailmbox_msg_info * msg_info; 821 struct mailmbox_msg_info * msg_info;
817 struct mail_flags * flags; 822 struct mail_flags * flags;
818 823
819 msg_info = carray_get(folder->mb_tab, i); 824 msg_info = carray_get(folder->mb_tab, i);
820 if (msg_info == NULL) 825 if (msg_info == NULL)
821 continue; 826 continue;
822 827
823 if (msg_info->msg_deleted) 828 if (msg_info->msg_deleted)
824 continue; 829 continue;
825 830
826 r = mboxdriver_get_cached_flags(cache_db_flags, mmapstr, 831 r = mboxdriver_get_cached_flags(cache_db_flags, mmapstr,
827 session, msg_info->msg_uid, &flags); 832 session, msg_info->msg_uid, &flags);
828 if (r != MAIL_NO_ERROR) { 833 if (r != MAIL_NO_ERROR) {
829 recent ++; 834 recent ++;
830 unseen ++; 835 unseen ++;
831 num ++; 836 num ++;
832 continue; 837 continue;
833 } 838 }
834 839
835 if ((flags->fl_flags & MAIL_FLAG_NEW) != 0) { 840 if ((flags->fl_flags & MAIL_FLAG_NEW) != 0) {
836 recent ++; 841 recent ++;
837 } 842 }
838 if ((flags->fl_flags & MAIL_FLAG_SEEN) == 0) { 843 if ((flags->fl_flags & MAIL_FLAG_SEEN) == 0) {
839 unseen ++; 844 unseen ++;
840 } 845 }
841 846
842 num ++; 847 num ++;
843 848
844 mail_flags_free(flags); 849 mail_flags_free(flags);
845 } 850 }
846 851
847 mmap_string_free(mmapstr); 852 mmap_string_free(mmapstr);
848 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 853 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
849 854
850 * result_messages = num; 855 * result_messages = num;
851 * result_recent = recent; 856 * result_recent = recent;
852 * result_unseen = unseen; 857 * result_unseen = unseen;
853 858
854 return MAIL_NO_ERROR; 859 return MAIL_NO_ERROR;
855 860
856 close_db_flags: 861 close_db_flags:
857 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 862 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
858 err: 863 err:
859 return res; 864 return res;
860} 865}
861 866
862static int mboxdriver_cached_messages_number(mailsession * session, char * mb, 867static int mboxdriver_cached_messages_number(mailsession * session, char * mb,
863 uint32_t * result) 868 uint32_t * result)
864{ 869{
865 return mailsession_messages_number(get_ancestor(session), mb, result); 870 return mailsession_messages_number(get_ancestor(session), mb, result);
866} 871}
867 872
868 873
869static int mboxdriver_cached_recent_number(mailsession * session, char * mb, 874static int mboxdriver_cached_recent_number(mailsession * session, char * mb,
870 uint32_t * result) 875 uint32_t * result)
871{ 876{
872 uint32_t messages; 877 uint32_t messages;
873 uint32_t recent; 878 uint32_t recent;
874 uint32_t unseen; 879 uint32_t unseen;
875 int r; 880 int r;
876 881
877 r = mboxdriver_cached_status_folder(session, mb, &messages, &recent, &unseen); 882 r = mboxdriver_cached_status_folder(session, mb, &messages, &recent, &unseen);
878 if (r != MAIL_NO_ERROR) 883 if (r != MAIL_NO_ERROR)
879 return r; 884 return r;
880 885
881 * result = recent; 886 * result = recent;
882 887
883 return MAIL_NO_ERROR; 888 return MAIL_NO_ERROR;
884} 889}
885 890
886static int mboxdriver_cached_unseen_number(mailsession * session, char * mb, 891static int mboxdriver_cached_unseen_number(mailsession * session, char * mb,
887 uint32_t * result) 892 uint32_t * result)
888{ 893{
889 uint32_t messages; 894 uint32_t messages;
890 uint32_t recent; 895 uint32_t recent;
891 uint32_t unseen; 896 uint32_t unseen;
892 int r; 897 int r;
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
906static int mboxdriver_cached_append_message(mailsession * session, 911static 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
918static 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
912static int 994static int
913mboxdriver_cached_get_messages_list(mailsession * session, 995mboxdriver_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,
926 session, mbox_cached_message_driver, result); 1008 session, mbox_cached_message_driver, result);
927 1009
928 err: 1010 err:
929 return res; 1011 return res;
930} 1012}
931 1013
932static int 1014static int
933get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, 1015get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr,
934 mailsession * session, uint32_t num, 1016 mailsession * session, uint32_t num,
935 struct mailimf_fields ** result) 1017 struct mailimf_fields ** result)
936{ 1018{
937 int r; 1019 int r;
938 char keyname[PATH_MAX]; 1020 char keyname[PATH_MAX];
939 struct mailimf_fields * fields; 1021 struct mailimf_fields * fields;
940 int res; 1022 int res;
941 struct mailmbox_msg_info * info; 1023 struct mailmbox_msg_info * info;
942 struct mailmbox_folder * folder; 1024 struct mailmbox_folder * folder;
943 chashdatum key; 1025 chashdatum key;
944 chashdatum data; 1026 chashdatum data;
945 1027
946 folder = get_mbox_session(session); 1028 folder = get_mbox_session(session);
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 = &num; 1034 key.data = &num;
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
979static int 1062static int
980write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, 1063write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr,
981 mailsession * session, uint32_t num, 1064 mailsession * session, uint32_t num,
982 struct mailimf_fields * fields) 1065 struct mailimf_fields * fields)
983{ 1066{
984 int r; 1067 int r;
985 char keyname[PATH_MAX]; 1068 char keyname[PATH_MAX];
986 int res; 1069 int res;
987 struct mailmbox_msg_info * info; 1070 struct mailmbox_msg_info * info;
988 struct mailmbox_folder * folder; 1071 struct mailmbox_folder * folder;
989 chashdatum key; 1072 chashdatum key;
990 chashdatum data; 1073 chashdatum data;
991 1074
992 folder = get_mbox_session(session); 1075 folder = get_mbox_session(session);
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 = &num; 1081 key.data = &num;
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
1023static int 1107static int
1024mboxdriver_cached_get_envelopes_list(mailsession * session, 1108mboxdriver_cached_get_envelopes_list(mailsession * session,
1025 struct mailmessage_list * env_list) 1109 struct mailmessage_list * env_list)
1026{ 1110{
1027 int r; 1111 int r;
1028 unsigned int i; 1112 unsigned int i;
1029 struct mbox_cached_session_state_data * cached_data; 1113 struct mbox_cached_session_state_data * cached_data;
1030 char filename_env[PATH_MAX]; 1114 char filename_env[PATH_MAX];
1031 char filename_flags[PATH_MAX]; 1115 char filename_flags[PATH_MAX];
1032 struct mail_cache_db * cache_db_env; 1116 struct mail_cache_db * cache_db_env;
1033 struct mail_cache_db * cache_db_flags; 1117 struct mail_cache_db * cache_db_flags;
1034 MMAPString * mmapstr; 1118 MMAPString * mmapstr;
1035 int res; 1119 int res;
1036 struct mailmbox_folder * folder; 1120 struct mailmbox_folder * folder;
1037 1121
1038 folder = get_mbox_session(session); 1122 folder = get_mbox_session(session);
1039 if (folder == NULL) { 1123 if (folder == NULL) {
1040 res = MAIL_ERROR_BAD_STATE; 1124 res = MAIL_ERROR_BAD_STATE;
1041 goto err; 1125 goto err;
1042 } 1126 }
1043 1127
1044 cached_data = get_cached_data(session); 1128 cached_data = get_cached_data(session);
1045 if (cached_data->mbox_quoted_mb == NULL) { 1129 if (cached_data->mbox_quoted_mb == NULL) {
1046 res = MAIL_ERROR_BAD_STATE; 1130 res = MAIL_ERROR_BAD_STATE;
1047 goto err; 1131 goto err;
1048 } 1132 }
1049 1133
1050 mbox_flags_store_process(cached_data->mbox_flags_directory, 1134 mbox_flags_store_process(cached_data->mbox_flags_directory,
1051 cached_data->mbox_quoted_mb, 1135 cached_data->mbox_quoted_mb,
1052 cached_data->mbox_flags_store); 1136 cached_data->mbox_flags_store);
1053 1137
1054 mmapstr = mmap_string_new(""); 1138 mmapstr = mmap_string_new("");
1055 if (mmapstr == NULL) { 1139 if (mmapstr == NULL) {
1056 res = MAIL_ERROR_MEMORY; 1140 res = MAIL_ERROR_MEMORY;
1057 goto err; 1141 goto err;
1058 } 1142 }
1059 1143
1060 snprintf(filename_env, PATH_MAX, "%s%c%s%c%s", 1144 snprintf(filename_env, PATH_MAX, "%s%c%s%c%s",
1061 cached_data->mbox_cache_directory, MAIL_DIR_SEPARATOR, 1145 cached_data->mbox_cache_directory, MAIL_DIR_SEPARATOR,
1062 cached_data->mbox_quoted_mb, 1146 cached_data->mbox_quoted_mb,
1063 MAIL_DIR_SEPARATOR, ENV_NAME); 1147 MAIL_DIR_SEPARATOR, ENV_NAME);
1064 1148
1065 r = mail_cache_db_open_lock(filename_env, &cache_db_env); 1149 r = mail_cache_db_open_lock(filename_env, &cache_db_env);
1066 if (r < 0) { 1150 if (r < 0) {
1067 res = MAIL_ERROR_MEMORY; 1151 res = MAIL_ERROR_MEMORY;
1068 goto free_mmapstr; 1152 goto free_mmapstr;
1069 } 1153 }
1070 1154
1071 snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", 1155 snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s",
1072 cached_data->mbox_flags_directory, MAIL_DIR_SEPARATOR, 1156 cached_data->mbox_flags_directory, MAIL_DIR_SEPARATOR,
1073 cached_data->mbox_quoted_mb, 1157 cached_data->mbox_quoted_mb,
1074 MAIL_DIR_SEPARATOR, FLAGS_NAME); 1158 MAIL_DIR_SEPARATOR, FLAGS_NAME);
1075 1159
1076 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 1160 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
1077 if (r < 0) { 1161 if (r < 0) {
1078 res = MAIL_ERROR_FILE; 1162 res = MAIL_ERROR_FILE;
1079 goto close_db_env; 1163 goto close_db_env;
1080 } 1164 }
1081 1165
1082 /* fill with cached */ 1166 /* fill with cached */
1083 1167
1084 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 1168 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
1085 mailmessage * msg; 1169 mailmessage * msg;
1086 struct mailimf_fields * fields; 1170 struct mailimf_fields * fields;
1087 struct mail_flags * flags; 1171 struct mail_flags * flags;
1088 1172
1089 msg = carray_get(env_list->msg_tab, i); 1173 msg = carray_get(env_list->msg_tab, i);
1090 1174
1091 if (msg->msg_fields == NULL) { 1175 if (msg->msg_fields == NULL) {
1092 r = get_cached_envelope(cache_db_env, mmapstr, session, 1176 r = get_cached_envelope(cache_db_env, mmapstr, session,
1093 msg->msg_index, &fields); 1177 msg->msg_index, &fields);
1094 if (r == MAIL_NO_ERROR) { 1178 if (r == MAIL_NO_ERROR) {
1095 msg->msg_cached = TRUE; 1179 msg->msg_cached = TRUE;
1096 msg->msg_fields = fields; 1180 msg->msg_fields = fields;
1097 } 1181 }
1098 } 1182 }
1099 1183
1100 if (msg->msg_flags == NULL) { 1184 if (msg->msg_flags == NULL) {
1101 r = mboxdriver_get_cached_flags(cache_db_flags, mmapstr, 1185 r = mboxdriver_get_cached_flags(cache_db_flags, mmapstr,
1102 session, msg->msg_index, 1186 session, msg->msg_index,
1103 &flags); 1187 &flags);
1104 if (r == MAIL_NO_ERROR) { 1188 if (r == MAIL_NO_ERROR) {
1105 msg->msg_flags = flags; 1189 msg->msg_flags = flags;
1106 } 1190 }
1107 } 1191 }
1108 } 1192 }
1109 1193
1110 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 1194 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
1111 mail_cache_db_close_unlock(filename_env, cache_db_env); 1195 mail_cache_db_close_unlock(filename_env, cache_db_env);
1112 1196
1113 r = mailsession_get_envelopes_list(get_ancestor(session), env_list); 1197 r = mailsession_get_envelopes_list(get_ancestor(session), env_list);
1114 1198
1115 if (r != MAIL_NO_ERROR) { 1199 if (r != MAIL_NO_ERROR) {
1116 res = r; 1200 res = r;
1117 goto free_mmapstr; 1201 goto free_mmapstr;
1118 } 1202 }
1119 1203
1120 /* add flags */ 1204 /* add flags */
1121 1205
1122 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 1206 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
1123 mailmessage * msg; 1207 mailmessage * msg;
1124 1208
1125 msg = carray_get(env_list->msg_tab, i); 1209 msg = carray_get(env_list->msg_tab, i);
1126 1210
1127 if (msg->msg_flags == NULL) 1211 if (msg->msg_flags == NULL)
1128 msg->msg_flags = mail_flags_new_empty(); 1212 msg->msg_flags = mail_flags_new_empty();
1129 } 1213 }
1130 1214
1131 r = mail_cache_db_open_lock(filename_env, &cache_db_env); 1215 r = mail_cache_db_open_lock(filename_env, &cache_db_env);
1132 if (r < 0) { 1216 if (r < 0) {
1133 res = MAIL_ERROR_MEMORY; 1217 res = MAIL_ERROR_MEMORY;
1134 goto free_mmapstr; 1218 goto free_mmapstr;
1135 } 1219 }
1136 1220
1137 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 1221 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
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
@@ -57,257 +57,258 @@ static void mbox_prefetch_free(struct generic_message_t * msg);
57 57
58static int mbox_initialize(mailmessage * msg_info); 58static int mbox_initialize(mailmessage * msg_info);
59 59
60static void mbox_uninitialize(mailmessage * msg_info); 60static void mbox_uninitialize(mailmessage * msg_info);
61 61
62static void mbox_flush(mailmessage * msg_info); 62static void mbox_flush(mailmessage * msg_info);
63 63
64static void mbox_check(mailmessage * msg_info); 64static void mbox_check(mailmessage * msg_info);
65 65
66static int mbox_fetch_size(mailmessage * msg_info, 66static int mbox_fetch_size(mailmessage * msg_info,
67 size_t * result); 67 size_t * result);
68 68
69static int mbox_get_flags(mailmessage * msg_info, 69static int mbox_get_flags(mailmessage * msg_info,
70 struct mail_flags ** result); 70 struct mail_flags ** result);
71 71
72static int mbox_fetch_header(mailmessage * msg_info, 72static int mbox_fetch_header(mailmessage * msg_info,
73 char ** result, 73 char ** result,
74 size_t * result_len); 74 size_t * result_len);
75 75
76static mailmessage_driver local_mbox_cached_message_driver = { 76static mailmessage_driver local_mbox_cached_message_driver = {
77 .msg_name = "mbox-cached", 77 .msg_name = "mbox-cached",
78 78
79 .msg_initialize = mbox_initialize, 79 .msg_initialize = mbox_initialize,
80 .msg_uninitialize = mbox_uninitialize, 80 .msg_uninitialize = mbox_uninitialize,
81 81
82 .msg_flush = mbox_flush, 82 .msg_flush = mbox_flush,
83 .msg_check = mbox_check, 83 .msg_check = mbox_check,
84 84
85 .msg_fetch_result_free = mailmessage_generic_fetch_result_free, 85 .msg_fetch_result_free = mailmessage_generic_fetch_result_free,
86 86
87 .msg_fetch = mailmessage_generic_fetch, 87 .msg_fetch = mailmessage_generic_fetch,
88 .msg_fetch_header = mbox_fetch_header, 88 .msg_fetch_header = mbox_fetch_header,
89 .msg_fetch_body = mailmessage_generic_fetch_body, 89 .msg_fetch_body = mailmessage_generic_fetch_body,
90 .msg_fetch_size = mbox_fetch_size, 90 .msg_fetch_size = mbox_fetch_size,
91 .msg_get_bodystructure = mailmessage_generic_get_bodystructure, 91 .msg_get_bodystructure = mailmessage_generic_get_bodystructure,
92 .msg_fetch_section = mailmessage_generic_fetch_section, 92 .msg_fetch_section = mailmessage_generic_fetch_section,
93 .msg_fetch_section_header = mailmessage_generic_fetch_section_header, 93 .msg_fetch_section_header = mailmessage_generic_fetch_section_header,
94 .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, 94 .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime,
95 .msg_fetch_section_body = mailmessage_generic_fetch_section_body, 95 .msg_fetch_section_body = mailmessage_generic_fetch_section_body,
96 .msg_fetch_envelope = mailmessage_generic_fetch_envelope, 96 .msg_fetch_envelope = mailmessage_generic_fetch_envelope,
97 97
98 .msg_get_flags = mbox_get_flags, 98 .msg_get_flags = mbox_get_flags,
99}; 99};
100 100
101mailmessage_driver * mbox_cached_message_driver = 101mailmessage_driver * mbox_cached_message_driver =
102&local_mbox_cached_message_driver; 102&local_mbox_cached_message_driver;
103 103
104static inline struct mbox_cached_session_state_data * 104static inline struct mbox_cached_session_state_data *
105get_cached_session_data(mailmessage * msg) 105get_cached_session_data(mailmessage * msg)
106{ 106{
107 return msg->msg_session->sess_data; 107 return msg->msg_session->sess_data;
108} 108}
109 109
110static inline mailsession * get_ancestor_session(mailmessage * msg) 110static inline mailsession * get_ancestor_session(mailmessage * msg)
111{ 111{
112 return get_cached_session_data(msg)->mbox_ancestor; 112 return get_cached_session_data(msg)->mbox_ancestor;
113} 113}
114 114
115static inline struct mbox_session_state_data * 115static inline struct mbox_session_state_data *
116get_ancestor_session_data(mailmessage * msg) 116get_ancestor_session_data(mailmessage * msg)
117{ 117{
118 return get_ancestor_session(msg)->sess_data; 118 return get_ancestor_session(msg)->sess_data;
119} 119}
120 120
121static inline struct mailmbox_folder * 121static inline struct mailmbox_folder *
122get_mbox_session(mailmessage * msg) 122get_mbox_session(mailmessage * msg)
123{ 123{
124 return get_ancestor_session_data(msg)->mbox_folder; 124 return get_ancestor_session_data(msg)->mbox_folder;
125} 125}
126 126
127static int mbox_prefetch(mailmessage * msg_info) 127static int mbox_prefetch(mailmessage * msg_info)
128{ 128{
129 struct generic_message_t * msg; 129 struct generic_message_t * msg;
130 int r; 130 int r;
131 char * msg_content; 131 char * msg_content;
132 size_t msg_length; 132 size_t msg_length;
133 133
134 r = mboxdriver_fetch_msg(get_ancestor_session(msg_info), 134 r = mboxdriver_fetch_msg(get_ancestor_session(msg_info),
135 msg_info->msg_index, 135 msg_info->msg_index,
136 &msg_content, &msg_length); 136 &msg_content, &msg_length);
137 if (r != MAIL_NO_ERROR) 137 if (r != MAIL_NO_ERROR)
138 return r; 138 return r;
139 139
140 msg = msg_info->msg_data; 140 msg = msg_info->msg_data;
141 141
142 msg->msg_message = msg_content; 142 msg->msg_message = msg_content;
143 msg->msg_length = msg_length; 143 msg->msg_length = msg_length;
144 144
145 return MAIL_NO_ERROR; 145 return MAIL_NO_ERROR;
146} 146}
147 147
148static void mbox_prefetch_free(struct generic_message_t * msg) 148static void mbox_prefetch_free(struct generic_message_t * msg)
149{ 149{
150 if (msg->msg_message != NULL) { 150 if (msg->msg_message != NULL) {
151 mmap_string_unref(msg->msg_message); 151 mmap_string_unref(msg->msg_message);
152 msg->msg_message = NULL; 152 msg->msg_message = NULL;
153 } 153 }
154} 154}
155 155
156static int mbox_initialize(mailmessage * msg_info) 156static int mbox_initialize(mailmessage * msg_info)
157{ 157{
158 struct generic_message_t * msg; 158 struct generic_message_t * msg;
159 int r; 159 int r;
160 char * uid; 160 char * uid;
161 char static_uid[PATH_MAX]; 161 char static_uid[PATH_MAX];
162 struct mailmbox_msg_info * info; 162 struct mailmbox_msg_info * info;
163 struct mailmbox_folder * folder; 163 struct mailmbox_folder * folder;
164 int res; 164 int res;
165 chashdatum key; 165 chashdatum key;
166 chashdatum data; 166 chashdatum data;
167 167
168 folder = get_mbox_session(msg_info); 168 folder = get_mbox_session(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;
202 msg->msg_prefetch_free = mbox_prefetch_free; 203 msg->msg_prefetch_free = mbox_prefetch_free;
203 msg_info->msg_uid = uid; 204 msg_info->msg_uid = uid;
204 205
205 return MAIL_NO_ERROR; 206 return MAIL_NO_ERROR;
206 207
207 err: 208 err:
208 return res; 209 return res;
209} 210}
210 211
211static void mbox_uninitialize(mailmessage * msg_info) 212static void mbox_uninitialize(mailmessage * msg_info)
212{ 213{
213 mailmessage_generic_uninitialize(msg_info); 214 mailmessage_generic_uninitialize(msg_info);
214} 215}
215 216
216#define FLAGS_NAME "flags.db" 217#define FLAGS_NAME "flags.db"
217 218
218static void mbox_flush(mailmessage * msg_info) 219static void mbox_flush(mailmessage * msg_info)
219{ 220{
220 mailmessage_generic_flush(msg_info); 221 mailmessage_generic_flush(msg_info);
221} 222}
222 223
223static void mbox_check(mailmessage * msg_info) 224static void mbox_check(mailmessage * msg_info)
224{ 225{
225 int r; 226 int r;
226 227
227 if (msg_info->msg_flags != NULL) { 228 if (msg_info->msg_flags != NULL) {
228 r = mail_flags_store_set(get_cached_session_data(msg_info)->mbox_flags_store, 229 r = mail_flags_store_set(get_cached_session_data(msg_info)->mbox_flags_store,
229 msg_info); 230 msg_info);
230 /* ignore errors */ 231 /* ignore errors */
231 } 232 }
232} 233}
233 234
234 235
235static int mbox_fetch_size(mailmessage * msg_info, 236static int mbox_fetch_size(mailmessage * msg_info,
236 size_t * result) 237 size_t * result)
237{ 238{
238 int r; 239 int r;
239 size_t size; 240 size_t size;
240 241
241 r = mboxdriver_fetch_size(get_ancestor_session(msg_info), 242 r = mboxdriver_fetch_size(get_ancestor_session(msg_info),
242 msg_info->msg_index, &size); 243 msg_info->msg_index, &size);
243 if (r != MAIL_NO_ERROR) 244 if (r != MAIL_NO_ERROR)
244 return r; 245 return r;
245 246
246 * result = size; 247 * result = size;
247 248
248 return MAIL_NO_ERROR; 249 return MAIL_NO_ERROR;
249} 250}
250 251
251static int mbox_get_flags(mailmessage * msg_info, 252static int mbox_get_flags(mailmessage * msg_info,
252 struct mail_flags ** result) 253 struct mail_flags ** result)
253{ 254{
254 int r; 255 int r;
255 struct mail_flags * flags; 256 struct mail_flags * flags;
256 struct mail_cache_db * cache_db_flags; 257 struct mail_cache_db * cache_db_flags;
257 char filename_flags[PATH_MAX]; 258 char filename_flags[PATH_MAX];
258 int res; 259 int res;
259 struct mbox_cached_session_state_data * cached_data; 260 struct mbox_cached_session_state_data * cached_data;
260 MMAPString * mmapstr; 261 MMAPString * mmapstr;
261 struct mailmbox_folder * folder; 262 struct mailmbox_folder * folder;
262 263
263 if (msg_info->msg_flags != NULL) { 264 if (msg_info->msg_flags != NULL) {
264 * result = msg_info->msg_flags; 265 * result = msg_info->msg_flags;
265 266
266 return MAIL_NO_ERROR; 267 return MAIL_NO_ERROR;
267 } 268 }
268 269
269 flags = mail_flags_store_get(get_cached_session_data(msg_info)->mbox_flags_store, 270 flags = mail_flags_store_get(get_cached_session_data(msg_info)->mbox_flags_store,
270 msg_info->msg_index); 271 msg_info->msg_index);
271 272
272 if (flags == NULL) { 273 if (flags == NULL) {
273 folder = get_mbox_session(msg_info); 274 folder = get_mbox_session(msg_info);
274 if (folder == NULL) { 275 if (folder == NULL) {
275 res = MAIL_ERROR_BAD_STATE; 276 res = MAIL_ERROR_BAD_STATE;
276 goto err; 277 goto err;
277 } 278 }
278 279
279 cached_data = get_cached_session_data(msg_info); 280 cached_data = get_cached_session_data(msg_info);
280 if (cached_data->mbox_quoted_mb == NULL) { 281 if (cached_data->mbox_quoted_mb == NULL) {
281 res = MAIL_ERROR_BAD_STATE; 282 res = MAIL_ERROR_BAD_STATE;
282 goto err; 283 goto err;
283 } 284 }
284 285
285 snprintf(filename_flags, PATH_MAX, "%s/%s/%s", 286 snprintf(filename_flags, PATH_MAX, "%s/%s/%s",
286 cached_data->mbox_flags_directory, 287 cached_data->mbox_flags_directory,
287 cached_data->mbox_quoted_mb, FLAGS_NAME); 288 cached_data->mbox_quoted_mb, FLAGS_NAME);
288 289
289 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 290 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
290 if (r < 0) { 291 if (r < 0) {
291 res = MAIL_ERROR_MEMORY; 292 res = MAIL_ERROR_MEMORY;
292 goto err; 293 goto err;
293 } 294 }
294 295
295 mmapstr = mmap_string_new(""); 296 mmapstr = mmap_string_new("");
296 if (mmapstr == NULL) { 297 if (mmapstr == NULL) {
297 res = MAIL_ERROR_MEMORY; 298 res = MAIL_ERROR_MEMORY;
298 goto close_db_flags; 299 goto close_db_flags;
299 } 300 }
300 301
301 if (msg_info->msg_index > folder->mb_written_uid) { 302 if (msg_info->msg_index > folder->mb_written_uid) {
302 flags = mail_flags_new_empty(); 303 flags = mail_flags_new_empty();
303 } 304 }
304 else { 305 else {
305 r = mboxdriver_get_cached_flags(cache_db_flags, mmapstr, 306 r = mboxdriver_get_cached_flags(cache_db_flags, mmapstr,
306 msg_info->msg_session, 307 msg_info->msg_session,
307 msg_info->msg_index, &flags); 308 msg_info->msg_index, &flags);
308 if (r != MAIL_NO_ERROR) { 309 if (r != MAIL_NO_ERROR) {
309 flags = mail_flags_new_empty(); 310 flags = mail_flags_new_empty();
310 if (flags == NULL) { 311 if (flags == NULL) {
311 res = MAIL_ERROR_MEMORY; 312 res = MAIL_ERROR_MEMORY;
312 goto free_mmapstr; 313 goto free_mmapstr;
313 } 314 }
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
@@ -1,225 +1,225 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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
51static int mbox_prefetch(mailmessage * msg_info); 51static int mbox_prefetch(mailmessage * msg_info);
52 52
53static void mbox_prefetch_free(struct generic_message_t * msg); 53static void mbox_prefetch_free(struct generic_message_t * msg);
54 54
55static int mbox_initialize(mailmessage * msg_info); 55static int mbox_initialize(mailmessage * msg_info);
56 56
57static int mbox_fetch_size(mailmessage * msg_info, 57static int mbox_fetch_size(mailmessage * msg_info,
58 size_t * result); 58 size_t * result);
59 59
60static int mbox_fetch_header(mailmessage * msg_info, 60static int mbox_fetch_header(mailmessage * msg_info,
61 char ** result, 61 char ** result,
62 size_t * result_len); 62 size_t * result_len);
63 63
64static mailmessage_driver local_mbox_message_driver = { 64static mailmessage_driver local_mbox_message_driver = {
65 .msg_name = "mbox", 65 .msg_name = "mbox",
66 66
67 .msg_initialize = mbox_initialize, 67 .msg_initialize = mbox_initialize,
68 .msg_uninitialize = mailmessage_generic_uninitialize, 68 .msg_uninitialize = mailmessage_generic_uninitialize,
69 69
70 .msg_flush = mailmessage_generic_flush, 70 .msg_flush = mailmessage_generic_flush,
71 .msg_check = NULL, 71 .msg_check = NULL,
72 72
73 .msg_fetch_result_free = mailmessage_generic_fetch_result_free, 73 .msg_fetch_result_free = mailmessage_generic_fetch_result_free,
74 74
75 .msg_fetch = mailmessage_generic_fetch, 75 .msg_fetch = mailmessage_generic_fetch,
76 .msg_fetch_header = mbox_fetch_header, 76 .msg_fetch_header = mbox_fetch_header,
77 .msg_fetch_body = mailmessage_generic_fetch_body, 77 .msg_fetch_body = mailmessage_generic_fetch_body,
78 .msg_fetch_size = mbox_fetch_size, 78 .msg_fetch_size = mbox_fetch_size,
79 .msg_get_bodystructure = mailmessage_generic_get_bodystructure, 79 .msg_get_bodystructure = mailmessage_generic_get_bodystructure,
80 .msg_fetch_section = mailmessage_generic_fetch_section, 80 .msg_fetch_section = mailmessage_generic_fetch_section,
81 .msg_fetch_section_header = mailmessage_generic_fetch_section_header, 81 .msg_fetch_section_header = mailmessage_generic_fetch_section_header,
82 .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, 82 .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime,
83 .msg_fetch_section_body = mailmessage_generic_fetch_section_body, 83 .msg_fetch_section_body = mailmessage_generic_fetch_section_body,
84 .msg_fetch_envelope = mailmessage_generic_fetch_envelope, 84 .msg_fetch_envelope = mailmessage_generic_fetch_envelope,
85 85
86 .msg_get_flags = NULL, 86 .msg_get_flags = NULL,
87}; 87};
88 88
89mailmessage_driver * mbox_message_driver = &local_mbox_message_driver; 89mailmessage_driver * mbox_message_driver = &local_mbox_message_driver;
90 90
91static inline struct mbox_session_state_data * get_data(mailmessage * msg) 91static inline struct mbox_session_state_data * get_data(mailmessage * msg)
92{ 92{
93 return msg->msg_session->sess_data; 93 return msg->msg_session->sess_data;
94} 94}
95 95
96static inline struct mailmbox_folder * get_mbox_session(mailmessage * msg) 96static inline struct mailmbox_folder * get_mbox_session(mailmessage * msg)
97{ 97{
98 return get_data(msg)->mbox_folder; 98 return get_data(msg)->mbox_folder;
99} 99}
100 100
101 101
102static int mbox_prefetch(mailmessage * msg_info) 102static int mbox_prefetch(mailmessage * msg_info)
103{ 103{
104 struct generic_message_t * msg; 104 struct generic_message_t * msg;
105 int r; 105 int r;
106 char * msg_content; 106 char * msg_content;
107 size_t msg_length; 107 size_t msg_length;
108 108
109 r = mboxdriver_fetch_msg(msg_info->msg_session, msg_info->msg_index, 109 r = mboxdriver_fetch_msg(msg_info->msg_session, msg_info->msg_index,
110 &msg_content, &msg_length); 110 &msg_content, &msg_length);
111 if (r != MAIL_NO_ERROR) 111 if (r != MAIL_NO_ERROR)
112 return r; 112 return r;
113 113
114 msg = msg_info->msg_data; 114 msg = msg_info->msg_data;
115 115
116 msg->msg_message = msg_content; 116 msg->msg_message = msg_content;
117 msg->msg_length = msg_length; 117 msg->msg_length = msg_length;
118 118
119 return MAIL_NO_ERROR; 119 return MAIL_NO_ERROR;
120} 120}
121 121
122static void mbox_prefetch_free(struct generic_message_t * msg) 122static void mbox_prefetch_free(struct generic_message_t * msg)
123{ 123{
124 if (msg->msg_message != NULL) { 124 if (msg->msg_message != NULL) {
125 mmap_string_unref(msg->msg_message); 125 mmap_string_unref(msg->msg_message);
126 msg->msg_message = NULL; 126 msg->msg_message = NULL;
127 } 127 }
128} 128}
129 129
130static int mbox_initialize(mailmessage * msg_info) 130static int mbox_initialize(mailmessage * msg_info)
131{ 131{
132 struct generic_message_t * msg; 132 struct generic_message_t * msg;
133 int r; 133 int r;
134 char * uid; 134 char * uid;
135 char static_uid[PATH_MAX]; 135 char static_uid[PATH_MAX];
136 struct mailmbox_msg_info * info; 136 struct mailmbox_msg_info * info;
137 struct mailmbox_folder * folder; 137 struct mailmbox_folder * folder;
138 int res; 138 int res;
139 chashdatum key; 139 chashdatum key;
140 chashdatum data; 140 chashdatum data;
141 141
142 folder = get_mbox_session(msg_info); 142 folder = get_mbox_session(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;
177 msg_info->msg_uid = uid; 177 msg_info->msg_uid = uid;
178 178
179 return MAIL_NO_ERROR; 179 return MAIL_NO_ERROR;
180 180
181 err: 181 err:
182 return res; 182 return res;
183} 183}
184 184
185static int mbox_fetch_size(mailmessage * msg_info, 185static int mbox_fetch_size(mailmessage * msg_info,
186 size_t * result) 186 size_t * result)
187{ 187{
188 int r; 188 int r;
189 size_t size; 189 size_t size;
190 190
191 r = mboxdriver_fetch_size(msg_info->msg_session, 191 r = mboxdriver_fetch_size(msg_info->msg_session,
192 msg_info->msg_index, &size); 192 msg_info->msg_index, &size);
193 if (r != MAIL_NO_ERROR) 193 if (r != MAIL_NO_ERROR)
194 return r; 194 return r;
195 195
196 * result = size; 196 * result = size;
197 197
198 return MAIL_NO_ERROR; 198 return MAIL_NO_ERROR;
199} 199}
200 200
201static int mbox_fetch_header(mailmessage * msg_info, 201static int mbox_fetch_header(mailmessage * msg_info,
202 char ** result, 202 char ** result,
203 size_t * result_len) 203 size_t * result_len)
204{ 204{
205 struct generic_message_t * msg; 205 struct generic_message_t * msg;
206 int r; 206 int r;
207 char * msg_content; 207 char * msg_content;
208 size_t msg_length; 208 size_t msg_length;
209 209
210 msg = msg_info->msg_data; 210 msg = msg_info->msg_data;
211 if (msg->msg_message != NULL) { 211 if (msg->msg_message != NULL) {
212 return mailmessage_generic_fetch_header(msg_info, result, result_len); 212 return mailmessage_generic_fetch_header(msg_info, result, result_len);
213 } 213 }
214 else { 214 else {
215 r = mboxdriver_fetch_header(msg_info->msg_session, msg_info->msg_index, 215 r = mboxdriver_fetch_header(msg_info->msg_session, msg_info->msg_index,
216 &msg_content, &msg_length); 216 &msg_content, &msg_length);
217 if (r != MAIL_NO_ERROR) 217 if (r != MAIL_NO_ERROR)
218 return r; 218 return r;
219 219
220 * result = msg_content; 220 * result = msg_content;
221 * result_len = msg_length; 221 * result_len = msg_length;
222 222
223 return MAIL_NO_ERROR; 223 return MAIL_NO_ERROR;
224 } 224 }
225} 225}
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
@@ -92,257 +92,258 @@ int mboxdriver_mbox_error_to_mail_error(int error)
92 case MAILMBOX_NO_ERROR: 92 case MAILMBOX_NO_ERROR:
93 return MAIL_NO_ERROR; 93 return MAIL_NO_ERROR;
94 94
95 case MAILMBOX_ERROR_PARSE: 95 case MAILMBOX_ERROR_PARSE:
96 return MAIL_ERROR_PARSE; 96 return MAIL_ERROR_PARSE;
97 97
98 case MAILMBOX_ERROR_INVAL: 98 case MAILMBOX_ERROR_INVAL:
99 return MAIL_ERROR_INVAL; 99 return MAIL_ERROR_INVAL;
100 100
101 case MAILMBOX_ERROR_FILE_NOT_FOUND: 101 case MAILMBOX_ERROR_FILE_NOT_FOUND:
102 return MAIL_ERROR_PARSE; 102 return MAIL_ERROR_PARSE;
103 103
104 case MAILMBOX_ERROR_MEMORY: 104 case MAILMBOX_ERROR_MEMORY:
105 return MAIL_ERROR_MEMORY; 105 return MAIL_ERROR_MEMORY;
106 106
107 case MAILMBOX_ERROR_TEMPORARY_FILE: 107 case MAILMBOX_ERROR_TEMPORARY_FILE:
108 return MAIL_ERROR_PARSE; 108 return MAIL_ERROR_PARSE;
109 109
110 case MAILMBOX_ERROR_FILE: 110 case MAILMBOX_ERROR_FILE:
111 return MAIL_ERROR_FILE; 111 return MAIL_ERROR_FILE;
112 112
113 case MAILMBOX_ERROR_MSG_NOT_FOUND: 113 case MAILMBOX_ERROR_MSG_NOT_FOUND:
114 return MAIL_ERROR_MSG_NOT_FOUND; 114 return MAIL_ERROR_MSG_NOT_FOUND;
115 115
116 case MAILMBOX_ERROR_READONLY: 116 case MAILMBOX_ERROR_READONLY:
117 return MAIL_ERROR_READONLY; 117 return MAIL_ERROR_READONLY;
118 118
119 default: 119 default:
120 return MAIL_ERROR_INVAL; 120 return MAIL_ERROR_INVAL;
121 } 121 }
122} 122}
123 123
124int mboxdriver_fetch_msg(mailsession * session, uint32_t index, 124int mboxdriver_fetch_msg(mailsession * session, uint32_t index,
125 char ** result, size_t * result_len) 125 char ** result, size_t * result_len)
126{ 126{
127 int r; 127 int r;
128 char * msg_content; 128 char * msg_content;
129 size_t msg_length; 129 size_t msg_length;
130 struct mailmbox_folder * folder; 130 struct mailmbox_folder * folder;
131 131
132 folder = session_get_mbox_session(session); 132 folder = session_get_mbox_session(session);
133 if (folder == NULL) 133 if (folder == NULL)
134 return MAIL_ERROR_BAD_STATE; 134 return MAIL_ERROR_BAD_STATE;
135 135
136 r = mailmbox_fetch_msg(folder, index, &msg_content, &msg_length); 136 r = mailmbox_fetch_msg(folder, index, &msg_content, &msg_length);
137 if (r != MAILMBOX_NO_ERROR) 137 if (r != MAILMBOX_NO_ERROR)
138 return mboxdriver_mbox_error_to_mail_error(r); 138 return mboxdriver_mbox_error_to_mail_error(r);
139 139
140 * result = msg_content; 140 * result = msg_content;
141 * result_len = msg_length; 141 * result_len = msg_length;
142 142
143 return MAIL_NO_ERROR; 143 return MAIL_NO_ERROR;
144} 144}
145 145
146 146
147int mboxdriver_fetch_size(mailsession * session, uint32_t index, 147int mboxdriver_fetch_size(mailsession * session, uint32_t index,
148 size_t * result) 148 size_t * result)
149{ 149{
150 struct mailmbox_folder * folder; 150 struct mailmbox_folder * folder;
151 int r; 151 int r;
152 char * data; 152 char * data;
153 size_t len; 153 size_t len;
154 int res; 154 int res;
155 155
156 folder = session_get_mbox_session(session); 156 folder = session_get_mbox_session(session);
157 if (folder == NULL) { 157 if (folder == NULL) {
158 res = MAIL_ERROR_FETCH; 158 res = MAIL_ERROR_FETCH;
159 goto err; 159 goto err;
160 } 160 }
161 161
162 r = mailmbox_validate_read_lock(folder); 162 r = mailmbox_validate_read_lock(folder);
163 if (r != MAILMBOX_NO_ERROR) { 163 if (r != MAILMBOX_NO_ERROR) {
164 res = mboxdriver_mbox_error_to_mail_error(r); 164 res = mboxdriver_mbox_error_to_mail_error(r);
165 goto err; 165 goto err;
166 } 166 }
167 167
168 r = mailmbox_fetch_msg_no_lock(folder, index, &data, &len); 168 r = mailmbox_fetch_msg_no_lock(folder, index, &data, &len);
169 if (r != MAILMBOX_NO_ERROR) { 169 if (r != MAILMBOX_NO_ERROR) {
170 res = mboxdriver_mbox_error_to_mail_error(r); 170 res = mboxdriver_mbox_error_to_mail_error(r);
171 goto unlock; 171 goto unlock;
172 } 172 }
173 173
174 mailmbox_read_unlock(folder); 174 mailmbox_read_unlock(folder);
175 175
176 * result = len; 176 * result = len;
177 177
178 return MAIL_NO_ERROR; 178 return MAIL_NO_ERROR;
179 179
180 unlock: 180 unlock:
181 mailmbox_read_unlock(folder); 181 mailmbox_read_unlock(folder);
182 err: 182 err:
183 return res; 183 return res;
184} 184}
185 185
186 186
187int 187int
188mboxdriver_get_cached_flags(struct mail_cache_db * cache_db, 188mboxdriver_get_cached_flags(struct mail_cache_db * cache_db,
189 MMAPString * mmapstr, 189 MMAPString * mmapstr,
190 mailsession * session, 190 mailsession * session,
191 uint32_t num, 191 uint32_t num,
192 struct mail_flags ** result) 192 struct mail_flags ** result)
193{ 193{
194 int r; 194 int r;
195 char keyname[PATH_MAX]; 195 char keyname[PATH_MAX];
196 struct mail_flags * flags; 196 struct mail_flags * flags;
197 int res; 197 int res;
198 struct mailmbox_msg_info * info; 198 struct mailmbox_msg_info * info;
199 struct mailmbox_folder * folder; 199 struct mailmbox_folder * folder;
200 chashdatum key; 200 chashdatum key;
201 chashdatum data; 201 chashdatum data;
202 202
203 folder = cached_session_get_mbox_session(session); 203 folder = cached_session_get_mbox_session(session);
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 = &num; 209 key.data = &num;
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
236int 237int
237mboxdriver_write_cached_flags(struct mail_cache_db * cache_db, 238mboxdriver_write_cached_flags(struct mail_cache_db * cache_db,
238 MMAPString * mmapstr, 239 MMAPString * mmapstr,
239 char * uid, 240 char * uid,
240 struct mail_flags * flags) 241 struct mail_flags * flags)
241{ 242{
242 int r; 243 int r;
243 char keyname[PATH_MAX]; 244 char keyname[PATH_MAX];
244 int res; 245 int res;
245 246
246 snprintf(keyname, PATH_MAX, "%s-flags", uid); 247 snprintf(keyname, PATH_MAX, "%s-flags", uid);
247 248
248 r = generic_cache_flags_write(cache_db, mmapstr, keyname, flags); 249 r = generic_cache_flags_write(cache_db, mmapstr, keyname, flags);
249 if (r != MAIL_NO_ERROR) { 250 if (r != MAIL_NO_ERROR) {
250 res = r; 251 res = r;
251 goto err; 252 goto err;
252 } 253 }
253 254
254 return MAIL_NO_ERROR; 255 return MAIL_NO_ERROR;
255 256
256 err: 257 err:
257 return res; 258 return res;
258} 259}
259 260
260 261
261int mboxdriver_fetch_header(mailsession * session, uint32_t index, 262int mboxdriver_fetch_header(mailsession * session, uint32_t index,
262 char ** result, size_t * result_len) 263 char ** result, size_t * result_len)
263{ 264{
264 int r; 265 int r;
265 char * msg_content; 266 char * msg_content;
266 size_t msg_length; 267 size_t msg_length;
267 struct mailmbox_folder * folder; 268 struct mailmbox_folder * folder;
268 269
269 folder = session_get_mbox_session(session); 270 folder = session_get_mbox_session(session);
270 if (folder == NULL) 271 if (folder == NULL)
271 return MAIL_ERROR_BAD_STATE; 272 return MAIL_ERROR_BAD_STATE;
272 273
273 r = mailmbox_fetch_msg_headers(folder, index, &msg_content, &msg_length); 274 r = mailmbox_fetch_msg_headers(folder, index, &msg_content, &msg_length);
274 if (r != MAILMBOX_NO_ERROR) 275 if (r != MAILMBOX_NO_ERROR)
275 return mboxdriver_mbox_error_to_mail_error(r); 276 return mboxdriver_mbox_error_to_mail_error(r);
276 277
277 * result = msg_content; 278 * result = msg_content;
278 * result_len = msg_length; 279 * result_len = msg_length;
279 280
280 return MAIL_NO_ERROR; 281 return MAIL_NO_ERROR;
281} 282}
282 283
283int mbox_get_locked_messages_list(struct mailmbox_folder * folder, 284int mbox_get_locked_messages_list(struct mailmbox_folder * folder,
284 mailsession * session, 285 mailsession * session,
285 mailmessage_driver * driver, 286 mailmessage_driver * driver,
286 int (* lock)(struct mailmbox_folder *), 287 int (* lock)(struct mailmbox_folder *),
287 int (* unlock)(struct mailmbox_folder *), 288 int (* unlock)(struct mailmbox_folder *),
288 struct mailmessage_list ** result) 289 struct mailmessage_list ** result)
289{ 290{
290 struct mailmessage_list * env_list; 291 struct mailmessage_list * env_list;
291 unsigned int i; 292 unsigned int i;
292 int r; 293 int r;
293 int res; 294 int res;
294 carray * tab; 295 carray * tab;
295 296
296 tab = carray_new(128); 297 tab = carray_new(128);
297 if (tab == NULL) { 298 if (tab == NULL) {
298 res = MAIL_ERROR_MEMORY; 299 res = MAIL_ERROR_MEMORY;
299 goto err; 300 goto err;
300 } 301 }
301 302
302 r = lock(folder); 303 r = lock(folder);
303 if (r != MAIL_NO_ERROR) { 304 if (r != MAIL_NO_ERROR) {
304 res = r; 305 res = r;
305 goto free; 306 goto free;
306 } 307 }
307 308
308 for(i = 0 ; i < carray_count(folder->mb_tab) ; i ++) { 309 for(i = 0 ; i < carray_count(folder->mb_tab) ; i ++) {
309 struct mailmbox_msg_info * msg_info; 310 struct mailmbox_msg_info * msg_info;
310 mailmessage * msg; 311 mailmessage * msg;
311 312
312 msg_info = carray_get(folder->mb_tab, i); 313 msg_info = carray_get(folder->mb_tab, i);
313 if (msg_info == NULL) 314 if (msg_info == NULL)
314 continue; 315 continue;
315 316
316 if (msg_info->msg_deleted) 317 if (msg_info->msg_deleted)
317 continue; 318 continue;
318 319
319 msg = mailmessage_new(); 320 msg = mailmessage_new();
320 if (msg == NULL) { 321 if (msg == NULL) {
321 res = MAIL_ERROR_MEMORY; 322 res = MAIL_ERROR_MEMORY;
322 goto unlock; 323 goto unlock;
323 } 324 }
324 325
325 r = mailmessage_init(msg, session, driver, msg_info->msg_uid, 326 r = mailmessage_init(msg, session, driver, msg_info->msg_uid,
326 msg_info->msg_size - msg_info->msg_start_len); 327 msg_info->msg_size - msg_info->msg_start_len);
327 if (r != MAIL_NO_ERROR) { 328 if (r != MAIL_NO_ERROR) {
328 res = r; 329 res = r;
329 goto unlock; 330 goto unlock;
330 } 331 }
331 332
332 r = carray_add(tab, msg, NULL); 333 r = carray_add(tab, msg, NULL);
333 if (r < 0) { 334 if (r < 0) {
334 mailmessage_free(msg); 335 mailmessage_free(msg);
335 res = MAIL_ERROR_MEMORY; 336 res = MAIL_ERROR_MEMORY;
336 goto unlock; 337 goto unlock;
337 } 338 }
338 } 339 }
339 340
340 env_list = mailmessage_list_new(tab); 341 env_list = mailmessage_list_new(tab);
341 if (env_list == NULL) { 342 if (env_list == NULL) {
342 res = MAIL_ERROR_MEMORY; 343 res = MAIL_ERROR_MEMORY;
343 goto unlock; 344 goto unlock;
344 } 345 }
345 346
346 unlock(folder); 347 unlock(folder);
347 348
348 * result = env_list; 349 * result = env_list;
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
@@ -1,192 +1,192 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "mboxstorage.h" 36#include "mboxstorage.h"
37 37
38#include "mail.h" 38#include "mail.h"
39#include "mailmessage.h" 39#include "mailmessage.h"
40#include "mboxdriver.h" 40#include "mboxdriver.h"
41#include "mboxdriver_cached.h" 41#include "mboxdriver_cached.h"
42#include "maildriver.h" 42#include "maildriver.h"
43 43
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46 46
47/* mbox storage */ 47/* mbox storage */
48 48
49static int mbox_mailstorage_connect(struct mailstorage * storage); 49static int mbox_mailstorage_connect(struct mailstorage * storage);
50static int 50static int
51mbox_mailstorage_get_folder_session(struct mailstorage * storage, 51mbox_mailstorage_get_folder_session(struct mailstorage * storage,
52 char * pathname, mailsession ** result); 52 char * pathname, mailsession ** result);
53static void mbox_mailstorage_uninitialize(struct mailstorage * storage); 53static void mbox_mailstorage_uninitialize(struct mailstorage * storage);
54 54
55static mailstorage_driver mbox_mailstorage_driver = { 55static 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
62int mbox_mailstorage_init(struct mailstorage * storage, 62int 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);
85 if (mbox_storage->mbox_flags_directory == NULL) 85 if (mbox_storage->mbox_flags_directory == NULL)
86 goto free_cache_directory; 86 goto free_cache_directory;
87 } 87 }
88 else { 88 else {
89 mbox_storage->mbox_cached = FALSE; 89 mbox_storage->mbox_cached = FALSE;
90 mbox_storage->mbox_cache_directory = NULL; 90 mbox_storage->mbox_cache_directory = NULL;
91 mbox_storage->mbox_flags_directory = NULL; 91 mbox_storage->mbox_flags_directory = NULL;
92 } 92 }
93 93
94 storage->sto_data = mbox_storage; 94 storage->sto_data = mbox_storage;
95 storage->sto_driver = &mbox_mailstorage_driver; 95 storage->sto_driver = &mbox_mailstorage_driver;
96 96
97 return MAIL_NO_ERROR; 97 return MAIL_NO_ERROR;
98 98
99 free_cache_directory: 99 free_cache_directory:
100 free(mbox_storage->mbox_cache_directory); 100 free(mbox_storage->mbox_cache_directory);
101 free_pathname: 101 free_pathname:
102 free(mbox_storage->mbox_pathname); 102 free(mbox_storage->mbox_pathname);
103 free: 103 free:
104 free(mbox_storage); 104 free(mbox_storage);
105 err: 105 err:
106 return MAIL_ERROR_MEMORY; 106 return MAIL_ERROR_MEMORY;
107} 107}
108 108
109static void mbox_mailstorage_uninitialize(struct mailstorage * storage) 109static void mbox_mailstorage_uninitialize(struct mailstorage * storage)
110{ 110{
111 struct mbox_mailstorage * mbox_storage; 111 struct mbox_mailstorage * mbox_storage;
112 112
113 mbox_storage = storage->sto_data; 113 mbox_storage = storage->sto_data;
114 if (mbox_storage->mbox_flags_directory != NULL) 114 if (mbox_storage->mbox_flags_directory != NULL)
115 free(mbox_storage->mbox_flags_directory); 115 free(mbox_storage->mbox_flags_directory);
116 if (mbox_storage->mbox_cache_directory != NULL) 116 if (mbox_storage->mbox_cache_directory != NULL)
117 free(mbox_storage->mbox_cache_directory); 117 free(mbox_storage->mbox_cache_directory);
118 free(mbox_storage->mbox_pathname); 118 free(mbox_storage->mbox_pathname);
119 free(mbox_storage); 119 free(mbox_storage);
120 120
121 storage->sto_data = NULL; 121 storage->sto_data = NULL;
122} 122}
123 123
124static int mbox_mailstorage_connect(struct mailstorage * storage) 124static int mbox_mailstorage_connect(struct mailstorage * storage)
125{ 125{
126 struct mbox_mailstorage * mbox_storage; 126 struct mbox_mailstorage * mbox_storage;
127 mailsession_driver * driver; 127 mailsession_driver * driver;
128 int r; 128 int r;
129 int res; 129 int res;
130 mailsession * session; 130 mailsession * session;
131 131
132 mbox_storage = storage->sto_data; 132 mbox_storage = storage->sto_data;
133 133
134 if (mbox_storage->mbox_cached) 134 if (mbox_storage->mbox_cached)
135 driver = mbox_cached_session_driver; 135 driver = mbox_cached_session_driver;
136 else 136 else
137 driver = mbox_session_driver; 137 driver = mbox_session_driver;
138 138
139 session = mailsession_new(driver); 139 session = mailsession_new(driver);
140 if (session == NULL) { 140 if (session == NULL) {
141 res = MAIL_ERROR_MEMORY; 141 res = MAIL_ERROR_MEMORY;
142 goto err; 142 goto err;
143 } 143 }
144 144
145 if (mbox_storage->mbox_cached) { 145 if (mbox_storage->mbox_cached) {
146 r = mailsession_parameters(session, 146 r = mailsession_parameters(session,
147 MBOXDRIVER_CACHED_SET_CACHE_DIRECTORY, 147 MBOXDRIVER_CACHED_SET_CACHE_DIRECTORY,
148 mbox_storage->mbox_cache_directory); 148 mbox_storage->mbox_cache_directory);
149 if (r != MAIL_NO_ERROR) { 149 if (r != MAIL_NO_ERROR) {
150 res = r; 150 res = r;
151 goto free; 151 goto free;
152 } 152 }
153 153
154 r = mailsession_parameters(session, 154 r = mailsession_parameters(session,
155 MBOXDRIVER_CACHED_SET_FLAGS_DIRECTORY, 155 MBOXDRIVER_CACHED_SET_FLAGS_DIRECTORY,
156 mbox_storage->mbox_flags_directory); 156 mbox_storage->mbox_flags_directory);
157 if (r != MAIL_NO_ERROR) { 157 if (r != MAIL_NO_ERROR) {
158 res = r; 158 res = r;
159 goto free; 159 goto free;
160 } 160 }
161 } 161 }
162 162
163 r = mailsession_connect_path(session, mbox_storage->mbox_pathname); 163 r = mailsession_connect_path(session, mbox_storage->mbox_pathname);
164 switch (r) { 164 switch (r) {
165 case MAIL_NO_ERROR_NON_AUTHENTICATED: 165 case MAIL_NO_ERROR_NON_AUTHENTICATED:
166 case MAIL_NO_ERROR_AUTHENTICATED: 166 case MAIL_NO_ERROR_AUTHENTICATED:
167 case MAIL_NO_ERROR: 167 case MAIL_NO_ERROR:
168 break; 168 break;
169 default: 169 default:
170 res = r; 170 res = r;
171 goto free; 171 goto free;
172 } 172 }
173 173
174 storage->sto_session = session; 174 storage->sto_session = session;
175 175
176 return MAIL_NO_ERROR; 176 return MAIL_NO_ERROR;
177 177
178 free: 178 free:
179 mailsession_free(session); 179 mailsession_free(session);
180 err: 180 err:
181 return res; 181 return res;
182} 182}
183 183
184static int 184static int
185mbox_mailstorage_get_folder_session(struct mailstorage * storage, 185mbox_mailstorage_get_folder_session(struct mailstorage * storage,
186 char * pathname, mailsession ** result) 186 char * pathname, mailsession ** result)
187{ 187{
188 * result = storage->sto_session; 188 * result = storage->sto_session;
189 189
190 return MAIL_NO_ERROR; 190 return MAIL_NO_ERROR;
191} 191}
192 192
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
@@ -1,270 +1,273 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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.h" 36#include "mhdriver.h"
37 37
38#include <stdio.h> 38#include <stdio.h>
39#include <sys/types.h> 39#include <sys/types.h>
40#include <dirent.h> 40#include <dirent.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <sys/stat.h> 42#include <sys/stat.h>
43#include <ctype.h> 43#include <ctype.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <sys/mman.h> 45#include <sys/mman.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48 48
49#include "mailmh.h" 49#include "mailmh.h"
50#include "maildriver_tools.h" 50#include "maildriver_tools.h"
51#include "mhdriver_tools.h" 51#include "mhdriver_tools.h"
52#include "mhdriver_message.h" 52#include "mhdriver_message.h"
53#include "mailmessage.h" 53#include "mailmessage.h"
54 54
55static int mhdriver_initialize(mailsession * session); 55static int mhdriver_initialize(mailsession * session);
56 56
57static void mhdriver_uninitialize(mailsession * session); 57static void mhdriver_uninitialize(mailsession * session);
58 58
59static int mhdriver_connect_path(mailsession * session, char * path); 59static int mhdriver_connect_path(mailsession * session, char * path);
60static int mhdriver_logout(mailsession * session); 60static int mhdriver_logout(mailsession * session);
61 61
62static int mhdriver_build_folder_name(mailsession * session, char * mb, 62static int mhdriver_build_folder_name(mailsession * session, char * mb,
63 char * name, char ** result); 63 char * name, char ** result);
64static int mhdriver_create_folder(mailsession * session, char * mb); 64static int mhdriver_create_folder(mailsession * session, char * mb);
65 65
66static int mhdriver_delete_folder(mailsession * session, char * mb); 66static int mhdriver_delete_folder(mailsession * session, char * mb);
67 67
68static int mhdriver_rename_folder(mailsession * session, char * mb, 68static int mhdriver_rename_folder(mailsession * session, char * mb,
69 char * new_name); 69 char * new_name);
70 70
71static int mhdriver_select_folder(mailsession * session, char * mb); 71static int mhdriver_select_folder(mailsession * session, char * mb);
72 72
73static int mhdriver_status_folder(mailsession * session, char * mb, 73static int mhdriver_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
77static int mhdriver_messages_number(mailsession * session, char * mb, 77static int mhdriver_messages_number(mailsession * session, char * mb,
78 uint32_t * result); 78 uint32_t * result);
79 79
80static int mhdriver_list_folders(mailsession * session, char * mb, 80static int mhdriver_list_folders(mailsession * session, char * mb,
81 struct mail_list ** result); 81 struct mail_list ** result);
82 82
83static int mhdriver_lsub_folders(mailsession * session, char * mb, 83static int mhdriver_lsub_folders(mailsession * session, char * mb,
84 struct mail_list ** result); 84 struct mail_list ** result);
85 85
86static int mhdriver_subscribe_folder(mailsession * session, char * mb); 86static int mhdriver_subscribe_folder(mailsession * session, char * mb);
87 87
88static int mhdriver_unsubscribe_folder(mailsession * session, char * mb); 88static int mhdriver_unsubscribe_folder(mailsession * session, char * mb);
89 89
90static int mhdriver_append_message(mailsession * session, 90static int mhdriver_append_message(mailsession * session,
91 char * message, size_t size); 91 char * message, size_t size);
92static int mhdriver_append_message_flags(mailsession * session,
93 char * message, size_t size, struct mail_flags * flags);
92static int mhdriver_copy_message(mailsession * session, 94static int mhdriver_copy_message(mailsession * session,
93 uint32_t num, char * mb); 95 uint32_t num, char * mb);
94 96
95static int mhdriver_remove_message(mailsession * session, uint32_t num); 97static int mhdriver_remove_message(mailsession * session, uint32_t num);
96 98
97static int mhdriver_move_message(mailsession * session, 99static int mhdriver_move_message(mailsession * session,
98 uint32_t num, char * mb); 100 uint32_t num, char * mb);
99 101
100static int mhdriver_get_messages_list(mailsession * session, 102static int mhdriver_get_messages_list(mailsession * session,
101 struct mailmessage_list ** result); 103 struct mailmessage_list ** result);
102 104
103static int mhdriver_get_message(mailsession * session, 105static int mhdriver_get_message(mailsession * session,
104 uint32_t num, mailmessage ** result); 106 uint32_t num, mailmessage ** result);
105 107
106static int mhdriver_get_message_by_uid(mailsession * session, 108static int mhdriver_get_message_by_uid(mailsession * session,
107 const char * uid, 109 const char * uid,
108 mailmessage ** result); 110 mailmessage ** result);
109 111
110static mailsession_driver local_mh_session_driver = { 112static mailsession_driver local_mh_session_driver = {
111 .sess_name = "mh", 113 .sess_name = "mh",
112 114
113 .sess_initialize = mhdriver_initialize, 115 .sess_initialize = mhdriver_initialize,
114 .sess_uninitialize = mhdriver_uninitialize, 116 .sess_uninitialize = mhdriver_uninitialize,
115 117
116 .sess_parameters = NULL, 118 .sess_parameters = NULL,
117 119
118 .sess_connect_stream = NULL, 120 .sess_connect_stream = NULL,
119 .sess_connect_path = mhdriver_connect_path, 121 .sess_connect_path = mhdriver_connect_path,
120 .sess_starttls = NULL, 122 .sess_starttls = NULL,
121 .sess_login = NULL, 123 .sess_login = NULL,
122 .sess_logout = mhdriver_logout, 124 .sess_logout = mhdriver_logout,
123 .sess_noop = NULL, 125 .sess_noop = NULL,
124 126
125 .sess_build_folder_name = mhdriver_build_folder_name, 127 .sess_build_folder_name = mhdriver_build_folder_name,
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
157mailsession_driver * mh_session_driver = &local_mh_session_driver; 160mailsession_driver * mh_session_driver = &local_mh_session_driver;
158 161
159static inline struct mh_session_state_data * get_data(mailsession * session) 162static inline struct mh_session_state_data * get_data(mailsession * session)
160{ 163{
161 return session->sess_data; 164 return session->sess_data;
162} 165}
163 166
164static inline struct mailmh * get_mh_session(mailsession * session) 167static inline struct mailmh * get_mh_session(mailsession * session)
165{ 168{
166 return get_data(session)->mh_session; 169 return get_data(session)->mh_session;
167} 170}
168 171
169static inline struct mailmh_folder * get_mh_cur_folder(mailsession * session) 172static inline struct mailmh_folder * get_mh_cur_folder(mailsession * session)
170{ 173{
171 return get_data(session)->mh_cur_folder; 174 return get_data(session)->mh_cur_folder;
172} 175}
173 176
174static int add_to_list(mailsession * session, char * mb) 177static int add_to_list(mailsession * session, char * mb)
175{ 178{
176 char * new_mb; 179 char * new_mb;
177 struct mh_session_state_data * data; 180 struct mh_session_state_data * data;
178 int r; 181 int r;
179 182
180 data = get_data(session); 183 data = get_data(session);
181 184
182 new_mb = strdup(mb); 185 new_mb = strdup(mb);
183 if (new_mb == NULL) 186 if (new_mb == NULL)
184 return -1; 187 return -1;
185 188
186 r = clist_append(data->mh_subscribed_list, new_mb); 189 r = clist_append(data->mh_subscribed_list, new_mb);
187 if (r < 0) { 190 if (r < 0) {
188 free(mb); 191 free(mb);
189 return -1; 192 return -1;
190 } 193 }
191 194
192 return 0; 195 return 0;
193} 196}
194 197
195static int remove_from_list(mailsession * session, char * mb) 198static int remove_from_list(mailsession * session, char * mb)
196{ 199{
197 clistiter * cur; 200 clistiter * cur;
198 struct mh_session_state_data * data; 201 struct mh_session_state_data * data;
199 202
200 data = get_data(session); 203 data = get_data(session);
201 204
202 for(cur = clist_begin(data->mh_subscribed_list) ; 205 for(cur = clist_begin(data->mh_subscribed_list) ;
203 cur != NULL ; cur = clist_next(cur)) { 206 cur != NULL ; cur = clist_next(cur)) {
204 char * cur_name; 207 char * cur_name;
205 208
206 cur_name = clist_content(cur); 209 cur_name = clist_content(cur);
207 if (strcmp(cur_name, mb) == 0) { 210 if (strcmp(cur_name, mb) == 0) {
208 clist_delete(data->mh_subscribed_list, cur); 211 clist_delete(data->mh_subscribed_list, cur);
209 free(cur_name); 212 free(cur_name);
210 return 0; 213 return 0;
211 } 214 }
212 } 215 }
213 216
214 return -1; 217 return -1;
215} 218}
216 219
217static int mhdriver_initialize(mailsession * session) 220static int mhdriver_initialize(mailsession * session)
218{ 221{
219 struct mh_session_state_data * data; 222 struct mh_session_state_data * data;
220 223
221 data = malloc(sizeof(* data)); 224 data = malloc(sizeof(* data));
222 if (data == NULL) 225 if (data == NULL)
223 goto err; 226 goto err;
224 227
225 data->mh_session = NULL; 228 data->mh_session = NULL;
226 data->mh_cur_folder = NULL; 229 data->mh_cur_folder = NULL;
227 230
228 data->mh_subscribed_list = clist_new(); 231 data->mh_subscribed_list = clist_new();
229 if (data->mh_subscribed_list == NULL) 232 if (data->mh_subscribed_list == NULL)
230 goto free; 233 goto free;
231 234
232 session->sess_data = data; 235 session->sess_data = data;
233 236
234 return MAIL_NO_ERROR; 237 return MAIL_NO_ERROR;
235 238
236 free: 239 free:
237 free(data); 240 free(data);
238 err: 241 err:
239 return MAIL_ERROR_MEMORY; 242 return MAIL_ERROR_MEMORY;
240} 243}
241 244
242static void mhdriver_uninitialize(mailsession * session) 245static void mhdriver_uninitialize(mailsession * session)
243{ 246{
244 struct mh_session_state_data * data; 247 struct mh_session_state_data * data;
245 248
246 data = get_data(session); 249 data = get_data(session);
247 250
248 if (data->mh_session != NULL) 251 if (data->mh_session != NULL)
249 mailmh_free(data->mh_session); 252 mailmh_free(data->mh_session);
250 253
251 clist_foreach(data->mh_subscribed_list, (clist_func) free, NULL); 254 clist_foreach(data->mh_subscribed_list, (clist_func) free, NULL);
252 clist_free(data->mh_subscribed_list); 255 clist_free(data->mh_subscribed_list);
253 256
254 free(data); 257 free(data);
255 258
256 session->sess_data = NULL; 259 session->sess_data = NULL;
257} 260}
258 261
259 262
260static int mhdriver_connect_path(mailsession * session, char * path) 263static int mhdriver_connect_path(mailsession * session, char * path)
261{ 264{
262 struct mailmh * mh; 265 struct mailmh * mh;
263 266
264 if (get_mh_session(session) != NULL) 267 if (get_mh_session(session) != NULL)
265 return MAIL_ERROR_BAD_STATE; 268 return MAIL_ERROR_BAD_STATE;
266 269
267 mh = mailmh_new(path); 270 mh = mailmh_new(path);
268 if (mh == NULL) 271 if (mh == NULL)
269 return MAIL_ERROR_MEMORY; 272 return MAIL_ERROR_MEMORY;
270 273
@@ -559,256 +562,262 @@ static int mhdriver_list_folders(mailsession * session, char * mb,
559 int r; 562 int r;
560 struct mailmh * mh; 563 struct mailmh * mh;
561 struct mail_list * ml; 564 struct mail_list * ml;
562 565
563 mh = get_mh_session(session); 566 mh = get_mh_session(session);
564 567
565 if (mh == NULL) 568 if (mh == NULL)
566 return MAIL_ERROR_BAD_STATE; 569 return MAIL_ERROR_BAD_STATE;
567 570
568 list = clist_new(); 571 list = clist_new();
569 if (list == NULL) 572 if (list == NULL)
570 return MAIL_ERROR_MEMORY; 573 return MAIL_ERROR_MEMORY;
571 574
572 r = get_list_folders(mh->mh_main, &list); 575 r = get_list_folders(mh->mh_main, &list);
573 if (r != MAIL_NO_ERROR) 576 if (r != MAIL_NO_ERROR)
574 return r; 577 return r;
575 578
576 ml = mail_list_new(list); 579 ml = mail_list_new(list);
577 if (ml == NULL) 580 if (ml == NULL)
578 goto free; 581 goto free;
579 582
580 * result = ml; 583 * result = ml;
581 584
582 return MAIL_NO_ERROR; 585 return MAIL_NO_ERROR;
583 586
584 free: 587 free:
585 clist_foreach(list, (clist_func) free, NULL); 588 clist_foreach(list, (clist_func) free, NULL);
586 clist_free(list); 589 clist_free(list);
587 return MAIL_ERROR_MEMORY; 590 return MAIL_ERROR_MEMORY;
588} 591}
589 592
590static int mhdriver_lsub_folders(mailsession * session, char * mb, 593static int mhdriver_lsub_folders(mailsession * session, char * mb,
591 struct mail_list ** result) 594 struct mail_list ** result)
592{ 595{
593 clist * subscribed; 596 clist * subscribed;
594 clist * lsub_result; 597 clist * lsub_result;
595 clistiter * cur; 598 clistiter * cur;
596 struct mail_list * lsub; 599 struct mail_list * lsub;
597 size_t length; 600 size_t length;
598 int r; 601 int r;
599 602
600 length = strlen(mb); 603 length = strlen(mb);
601 604
602 subscribed = get_data(session)->mh_subscribed_list; 605 subscribed = get_data(session)->mh_subscribed_list;
603 606
604 lsub_result = clist_new(); 607 lsub_result = clist_new();
605 if (lsub_result == NULL) 608 if (lsub_result == NULL)
606 return MAIL_ERROR_MEMORY; 609 return MAIL_ERROR_MEMORY;
607 610
608 for(cur = clist_begin(subscribed) ; cur != NULL ; 611 for(cur = clist_begin(subscribed) ; cur != NULL ;
609 cur = clist_next(cur)) { 612 cur = clist_next(cur)) {
610 char * cur_mb; 613 char * cur_mb;
611 char * new_mb; 614 char * new_mb;
612 615
613 cur_mb = clist_content(cur); 616 cur_mb = clist_content(cur);
614 617
615 if (strncmp(mb, cur_mb, length) == 0) { 618 if (strncmp(mb, cur_mb, length) == 0) {
616 new_mb = strdup(cur_mb); 619 new_mb = strdup(cur_mb);
617 if (new_mb == NULL) 620 if (new_mb == NULL)
618 goto free_list; 621 goto free_list;
619 622
620 r = clist_append(lsub_result, new_mb); 623 r = clist_append(lsub_result, new_mb);
621 if (r < 0) { 624 if (r < 0) {
622 free(new_mb); 625 free(new_mb);
623 goto free_list; 626 goto free_list;
624 } 627 }
625 } 628 }
626 } 629 }
627 630
628 lsub = mail_list_new(lsub_result); 631 lsub = mail_list_new(lsub_result);
629 if (lsub == NULL) 632 if (lsub == NULL)
630 goto free_list; 633 goto free_list;
631 634
632 * result = lsub; 635 * result = lsub;
633 636
634 return MAIL_NO_ERROR; 637 return MAIL_NO_ERROR;
635 638
636 free_list: 639 free_list:
637 clist_foreach(lsub_result, (clist_func) free, NULL); 640 clist_foreach(lsub_result, (clist_func) free, NULL);
638 clist_free(lsub_result); 641 clist_free(lsub_result);
639 return MAIL_ERROR_MEMORY; 642 return MAIL_ERROR_MEMORY;
640} 643}
641 644
642static int mhdriver_subscribe_folder(mailsession * session, char * mb) 645static int mhdriver_subscribe_folder(mailsession * session, char * mb)
643{ 646{
644 int r; 647 int r;
645 648
646 r = add_to_list(session, mb); 649 r = add_to_list(session, mb);
647 if (r < 0) 650 if (r < 0)
648 return MAIL_ERROR_SUBSCRIBE; 651 return MAIL_ERROR_SUBSCRIBE;
649 652
650 return MAIL_NO_ERROR; 653 return MAIL_NO_ERROR;
651} 654}
652 655
653static int mhdriver_unsubscribe_folder(mailsession * session, char * mb) 656static int mhdriver_unsubscribe_folder(mailsession * session, char * mb)
654{ 657{
655 int r; 658 int r;
656 659
657 r = remove_from_list(session, mb); 660 r = remove_from_list(session, mb);
658 if (r < 0) 661 if (r < 0)
659 return MAIL_ERROR_UNSUBSCRIBE; 662 return MAIL_ERROR_UNSUBSCRIBE;
660 663
661 return MAIL_NO_ERROR; 664 return MAIL_NO_ERROR;
662} 665}
663 666
664/* messages operations */ 667/* messages operations */
665 668
666static int mhdriver_append_message(mailsession * session, 669static int mhdriver_append_message(mailsession * session,
667 char * message, size_t size) 670 char * message, size_t size)
668{ 671{
669 int r; 672 int r;
670 struct mailmh_folder * folder; 673 struct mailmh_folder * folder;
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
690static 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
687static int mhdriver_copy_message(mailsession * session, 696static 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);
703 if (folder == NULL) { 712 if (folder == NULL) {
704 res = MAIL_ERROR_BAD_STATE; 713 res = MAIL_ERROR_BAD_STATE;
705 goto err; 714 goto err;
706 } 715 }
707 716
708 r = mailmh_folder_get_message_fd(folder, num, O_RDONLY, &fd); 717 r = mailmh_folder_get_message_fd(folder, num, O_RDONLY, &fd);
709 if (r != MAIL_NO_ERROR) { 718 if (r != MAIL_NO_ERROR) {
710 res = r; 719 res = r;
711 goto err; 720 goto err;
712 } 721 }
713 722
714 folder = mailmh_folder_find(mh->mh_main, mb); 723 folder = mailmh_folder_find(mh->mh_main, mb);
715 if (folder == NULL) { 724 if (folder == NULL) {
716 res = MAIL_ERROR_FOLDER_NOT_FOUND; 725 res = MAIL_ERROR_FOLDER_NOT_FOUND;
717 goto close; 726 goto close;
718 } 727 }
719 728
720 r = mailmh_folder_add_message_file(folder, fd); 729 r = mailmh_folder_add_message_file(folder, fd);
721 if (r != MAIL_NO_ERROR) { 730 if (r != MAIL_NO_ERROR) {
722 res = MAIL_ERROR_COPY; 731 res = MAIL_ERROR_COPY;
723 goto close; 732 goto close;
724 } 733 }
725 734
726 close(fd); 735 close(fd);
727 736
728 return MAIL_NO_ERROR; 737 return MAIL_NO_ERROR;
729 738
730 close: 739 close:
731 close(fd); 740 close(fd);
732 err: 741 err:
733 return res; 742 return res;
734} 743}
735 744
736static int mhdriver_remove_message(mailsession * session, uint32_t num) 745static int mhdriver_remove_message(mailsession * session, uint32_t num)
737{ 746{
738 int r; 747 int r;
739 struct mailmh_folder * folder; 748 struct mailmh_folder * folder;
740 749
741 folder = get_mh_cur_folder(session); 750 folder = get_mh_cur_folder(session);
742 if (folder == NULL) 751 if (folder == NULL)
743 return MAIL_ERROR_DELETE; 752 return MAIL_ERROR_DELETE;
744 753
745 r = mailmh_folder_remove_message(folder, num); 754 r = mailmh_folder_remove_message(folder, num);
746 755
747 return mhdriver_mh_error_to_mail_error(r); 756 return mhdriver_mh_error_to_mail_error(r);
748} 757}
749 758
750static int mhdriver_move_message(mailsession * session, 759static int mhdriver_move_message(mailsession * session,
751 uint32_t num, char * mb) 760 uint32_t num, char * mb)
752{ 761{
753 int r; 762 int r;
754 struct mailmh_folder * src_folder; 763 struct mailmh_folder * src_folder;
755 struct mailmh_folder * dest_folder; 764 struct mailmh_folder * dest_folder;
756 struct mailmh * mh; 765 struct mailmh * mh;
757 766
758 mh = get_mh_session(session); 767 mh = get_mh_session(session);
759 if (mh == NULL) 768 if (mh == NULL)
760 return MAIL_ERROR_BAD_STATE; 769 return MAIL_ERROR_BAD_STATE;
761 770
762 src_folder = get_mh_cur_folder(session); 771 src_folder = get_mh_cur_folder(session);
763 if (src_folder == NULL) 772 if (src_folder == NULL)
764 return MAIL_ERROR_BAD_STATE; 773 return MAIL_ERROR_BAD_STATE;
765 774
766 dest_folder = mailmh_folder_find(mh->mh_main, mb); 775 dest_folder = mailmh_folder_find(mh->mh_main, mb);
767 if (dest_folder == NULL) 776 if (dest_folder == NULL)
768 return MAIL_ERROR_FOLDER_NOT_FOUND; 777 return MAIL_ERROR_FOLDER_NOT_FOUND;
769 778
770 r = mailmh_folder_move_message(dest_folder, src_folder, num); 779 r = mailmh_folder_move_message(dest_folder, src_folder, num);
771 780
772 return mhdriver_mh_error_to_mail_error(r); 781 return mhdriver_mh_error_to_mail_error(r);
773} 782}
774 783
775 784
776static int mhdriver_get_messages_list(mailsession * session, 785static int mhdriver_get_messages_list(mailsession * session,
777 struct mailmessage_list ** result) 786 struct mailmessage_list ** result)
778{ 787{
779 struct mailmh_folder * folder; 788 struct mailmh_folder * folder;
780 int res; 789 int res;
781 790
782 folder = get_mh_cur_folder(session); 791 folder = get_mh_cur_folder(session);
783 if (folder == NULL) { 792 if (folder == NULL) {
784 res = MAIL_ERROR_BAD_STATE; 793 res = MAIL_ERROR_BAD_STATE;
785 goto err; 794 goto err;
786 } 795 }
787 796
788 mailmh_folder_update(folder); 797 mailmh_folder_update(folder);
789 return mh_get_messages_list(folder, session, mh_message_driver, result); 798 return mh_get_messages_list(folder, session, mh_message_driver, result);
790 799
791 err: 800 err:
792 return res; 801 return res;
793} 802}
794 803
795static int mhdriver_get_message(mailsession * session, 804static int mhdriver_get_message(mailsession * session,
796 uint32_t num, mailmessage ** result) 805 uint32_t num, mailmessage ** result)
797{ 806{
798 mailmessage * msg_info; 807 mailmessage * msg_info;
799 int r; 808 int r;
800 809
801 msg_info = mailmessage_new(); 810 msg_info = mailmessage_new();
802 if (msg_info == NULL) 811 if (msg_info == NULL)
803 return MAIL_ERROR_MEMORY; 812 return MAIL_ERROR_MEMORY;
804 813
805 r = mailmessage_init(msg_info, session, mh_message_driver, num, 0); 814 r = mailmessage_init(msg_info, session, mh_message_driver, num, 0);
806 if (r != MAIL_NO_ERROR) { 815 if (r != MAIL_NO_ERROR) {
807 mailmessage_free(msg_info); 816 mailmessage_free(msg_info);
808 return r; 817 return r;
809 } 818 }
810 819
811 * result = msg_info; 820 * result = msg_info;
812 821
813 return MAIL_NO_ERROR; 822 return MAIL_NO_ERROR;
814} 823}
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
@@ -1,295 +1,298 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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_cached.h" 36#include "mhdriver_cached.h"
37 37
38#include <stdio.h> 38#include <stdio.h>
39#include <sys/types.h> 39#include <sys/types.h>
40#include <dirent.h> 40#include <dirent.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <sys/stat.h> 42#include <sys/stat.h>
43#include <ctype.h> 43#include <ctype.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <sys/mman.h> 45#include <sys/mman.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48 48
49#include "mail.h" 49#include "mail.h"
50#include "mail_cache_db.h" 50#include "mail_cache_db.h"
51 51
52#include "generic_cache.h" 52#include "generic_cache.h"
53#include "imfcache.h" 53#include "imfcache.h"
54#include "mhdriver.h" 54#include "mhdriver.h"
55 55
56#include "mhdriver_cached_message.h" 56#include "mhdriver_cached_message.h"
57#include "mailmh.h" 57#include "mailmh.h"
58#include "maildriver_tools.h" 58#include "maildriver_tools.h"
59#include "mhdriver_tools.h" 59#include "mhdriver_tools.h"
60#include "mailmessage.h" 60#include "mailmessage.h"
61 61
62static int mhdriver_cached_initialize(mailsession * session); 62static int mhdriver_cached_initialize(mailsession * session);
63 63
64static void mhdriver_cached_uninitialize(mailsession * session); 64static void mhdriver_cached_uninitialize(mailsession * session);
65 65
66static int mhdriver_cached_parameters(mailsession * session, 66static int mhdriver_cached_parameters(mailsession * session,
67 int id, void * value); 67 int id, void * value);
68 68
69static int mhdriver_cached_connect_path(mailsession * session, char * path); 69static int mhdriver_cached_connect_path(mailsession * session, char * path);
70static int mhdriver_cached_logout(mailsession * session); 70static int mhdriver_cached_logout(mailsession * session);
71 71
72static int mhdriver_cached_build_folder_name(mailsession * session, char * mb, 72static int mhdriver_cached_build_folder_name(mailsession * session, char * mb,
73 char * name, char ** result); 73 char * name, char ** result);
74static int mhdriver_cached_create_folder(mailsession * session, char * mb); 74static int mhdriver_cached_create_folder(mailsession * session, char * mb);
75 75
76static int mhdriver_cached_delete_folder(mailsession * session, char * mb); 76static int mhdriver_cached_delete_folder(mailsession * session, char * mb);
77 77
78static int mhdriver_cached_rename_folder(mailsession * session, char * mb, 78static int mhdriver_cached_rename_folder(mailsession * session, char * mb,
79 char * new_name); 79 char * new_name);
80 80
81static int mhdriver_cached_check_folder(mailsession * session); 81static int mhdriver_cached_check_folder(mailsession * session);
82 82
83static int mhdriver_cached_select_folder(mailsession * session, char * mb); 83static int mhdriver_cached_select_folder(mailsession * session, char * mb);
84 84
85static int mhdriver_cached_expunge_folder(mailsession * session); 85static int mhdriver_cached_expunge_folder(mailsession * session);
86 86
87static int mhdriver_cached_status_folder(mailsession * session, char * mb, 87static int mhdriver_cached_status_folder(mailsession * session, char * mb,
88 uint32_t * result_messages, uint32_t * result_recent, 88 uint32_t * result_messages, uint32_t * result_recent,
89 uint32_t * result_unseen); 89 uint32_t * result_unseen);
90 90
91static int mhdriver_cached_messages_number(mailsession * session, char * mb, 91static int mhdriver_cached_messages_number(mailsession * session, char * mb,
92 uint32_t * result); 92 uint32_t * result);
93static int mhdriver_cached_recent_number(mailsession * session, char * mb, 93static int mhdriver_cached_recent_number(mailsession * session, char * mb,
94 uint32_t * result); 94 uint32_t * result);
95static int mhdriver_cached_unseen_number(mailsession * session, char * mb, 95static int mhdriver_cached_unseen_number(mailsession * session, char * mb,
96 uint32_t * result); 96 uint32_t * result);
97 97
98static int mhdriver_cached_list_folders(mailsession * session, char * mb, 98static int mhdriver_cached_list_folders(mailsession * session, char * mb,
99 struct mail_list ** result); 99 struct mail_list ** result);
100 100
101static int mhdriver_cached_lsub_folders(mailsession * session, char * mb, 101static int mhdriver_cached_lsub_folders(mailsession * session, char * mb,
102 struct mail_list ** result); 102 struct mail_list ** result);
103 103
104static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb); 104static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb);
105 105
106static int mhdriver_cached_unsubscribe_folder(mailsession * session, 106static int mhdriver_cached_unsubscribe_folder(mailsession * session,
107 char * mb); 107 char * mb);
108 108
109static int mhdriver_cached_append_message(mailsession * session, 109static int mhdriver_cached_append_message(mailsession * session,
110 char * message, size_t size); 110 char * message, size_t size);
111static int mhdriver_cached_append_message_flags(mailsession * session,
112 char * message, size_t size, struct mail_flags * flags);
111static int mhdriver_cached_copy_message(mailsession * session, 113static int mhdriver_cached_copy_message(mailsession * session,
112 uint32_t num, char * mb); 114 uint32_t num, char * mb);
113 115
114static int mhdriver_cached_remove_message(mailsession * session, 116static int mhdriver_cached_remove_message(mailsession * session,
115 uint32_t num); 117 uint32_t num);
116 118
117static int mhdriver_cached_move_message(mailsession * session, 119static int mhdriver_cached_move_message(mailsession * session,
118 uint32_t num, char * mb); 120 uint32_t num, char * mb);
119 121
120static int 122static int
121mhdriver_cached_get_messages_list(mailsession * session, 123mhdriver_cached_get_messages_list(mailsession * session,
122 struct mailmessage_list ** result); 124 struct mailmessage_list ** result);
123 125
124static int 126static int
125mhdriver_cached_get_envelopes_list(mailsession * session, 127mhdriver_cached_get_envelopes_list(mailsession * session,
126 struct mailmessage_list * env_list); 128 struct mailmessage_list * env_list);
127 129
128static int mhdriver_cached_get_message(mailsession * session, 130static int mhdriver_cached_get_message(mailsession * session,
129 uint32_t num, mailmessage ** result); 131 uint32_t num, mailmessage ** result);
130 132
131static int mhdriver_cached_get_message_by_uid(mailsession * session, 133static int mhdriver_cached_get_message_by_uid(mailsession * session,
132 const char * uid, 134 const char * uid,
133 mailmessage ** result); 135 mailmessage ** result);
134 136
135static mailsession_driver local_mh_cached_session_driver = { 137static mailsession_driver local_mh_cached_session_driver = {
136 .sess_name = "mh-cached", 138 .sess_name = "mh-cached",
137 139
138 .sess_initialize = mhdriver_cached_initialize, 140 .sess_initialize = mhdriver_cached_initialize,
139 .sess_uninitialize = mhdriver_cached_uninitialize, 141 .sess_uninitialize = mhdriver_cached_uninitialize,
140 142
141 .sess_parameters = mhdriver_cached_parameters, 143 .sess_parameters = mhdriver_cached_parameters,
142 144
143 .sess_connect_stream = NULL, 145 .sess_connect_stream = NULL,
144 .sess_connect_path = mhdriver_cached_connect_path, 146 .sess_connect_path = mhdriver_cached_connect_path,
145 .sess_starttls = NULL, 147 .sess_starttls = NULL,
146 .sess_login = NULL, 148 .sess_login = NULL,
147 .sess_logout = mhdriver_cached_logout, 149 .sess_logout = mhdriver_cached_logout,
148 .sess_noop = NULL, 150 .sess_noop = NULL,
149 151
150 .sess_build_folder_name = mhdriver_cached_build_folder_name, 152 .sess_build_folder_name = mhdriver_cached_build_folder_name,
151 .sess_create_folder = mhdriver_cached_create_folder, 153 .sess_create_folder = mhdriver_cached_create_folder,
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
182mailsession_driver * mh_cached_session_driver = 185mailsession_driver * mh_cached_session_driver =
183&local_mh_cached_session_driver; 186&local_mh_cached_session_driver;
184 187
185#define ENV_NAME "env.db" 188#define ENV_NAME "env.db"
186#define FLAGS_NAME "flags.db" 189#define FLAGS_NAME "flags.db"
187 190
188 191
189static inline struct mh_cached_session_state_data * 192static inline struct mh_cached_session_state_data *
190get_cached_data(mailsession * session) 193get_cached_data(mailsession * session)
191{ 194{
192 return session->sess_data; 195 return session->sess_data;
193} 196}
194 197
195static inline mailsession * get_ancestor(mailsession * session) 198static inline mailsession * get_ancestor(mailsession * session)
196{ 199{
197 return get_cached_data(session)->mh_ancestor; 200 return get_cached_data(session)->mh_ancestor;
198} 201}
199 202
200static inline struct mh_session_state_data * 203static inline struct mh_session_state_data *
201get_ancestor_data(mailsession * session) 204get_ancestor_data(mailsession * session)
202{ 205{
203 return get_ancestor(session)->sess_data; 206 return get_ancestor(session)->sess_data;
204} 207}
205 208
206static inline struct mailmh * 209static inline struct mailmh *
207get_mh_session(mailsession * session) 210get_mh_session(mailsession * session)
208{ 211{
209 return get_ancestor_data(session)->mh_session; 212 return get_ancestor_data(session)->mh_session;
210} 213}
211 214
212static inline struct mailmh_folder * 215static inline struct mailmh_folder *
213get_mh_cur_folder(mailsession * session) 216get_mh_cur_folder(mailsession * session)
214{ 217{
215 return get_ancestor_data(session)->mh_cur_folder; 218 return get_ancestor_data(session)->mh_cur_folder;
216} 219}
217 220
218 221
219#define FILENAME_MAX_UID "max-uid" 222#define FILENAME_MAX_UID "max-uid"
220 223
221/* write max uid current value */ 224/* write max uid current value */
222 225
223static int write_max_uid_value(mailsession * session) 226static int write_max_uid_value(mailsession * session)
224{ 227{
225 int r; 228 int r;
226 char filename[PATH_MAX]; 229 char filename[PATH_MAX];
227 FILE * f; 230 FILE * f;
228 int res; 231 int res;
229 struct mh_cached_session_state_data * cached_data; 232 struct mh_cached_session_state_data * cached_data;
230 struct mh_session_state_data * ancestor_data; 233 struct mh_session_state_data * ancestor_data;
231 int fd; 234 int fd;
232 235
233 MMAPString * mmapstr; 236 MMAPString * mmapstr;
234 size_t cur_token; 237 size_t cur_token;
235 238
236 cached_data = get_cached_data(session); 239 cached_data = get_cached_data(session);
237 ancestor_data = get_ancestor_data(session); 240 ancestor_data = get_ancestor_data(session);
238 241
239 if (cached_data->mh_quoted_mb == NULL) 242 if (cached_data->mh_quoted_mb == NULL)
240 return MAIL_ERROR_BAD_STATE; 243 return MAIL_ERROR_BAD_STATE;
241 244
242 snprintf(filename, PATH_MAX, "%s/%s/%s", 245 snprintf(filename, PATH_MAX, "%s/%s/%s",
243 cached_data->mh_cache_directory, 246 cached_data->mh_cache_directory,
244 cached_data->mh_quoted_mb, FILENAME_MAX_UID); 247 cached_data->mh_quoted_mb, FILENAME_MAX_UID);
245 248
246 fd = creat(filename, S_IRUSR | S_IWUSR); 249 fd = creat(filename, S_IRUSR | S_IWUSR);
247 if (fd < 0) { 250 if (fd < 0) {
248 res = MAIL_ERROR_FILE; 251 res = MAIL_ERROR_FILE;
249 goto err; 252 goto err;
250 } 253 }
251 254
252 f = fdopen(fd, "w"); 255 f = fdopen(fd, "w");
253 if (f == NULL) { 256 if (f == NULL) {
254 close(fd); 257 close(fd);
255 res = MAIL_ERROR_FILE; 258 res = MAIL_ERROR_FILE;
256 goto err; 259 goto err;
257 } 260 }
258 261
259 mmapstr = mmap_string_new(""); 262 mmapstr = mmap_string_new("");
260 if (mmapstr == NULL) { 263 if (mmapstr == NULL) {
261 res = MAIL_ERROR_MEMORY; 264 res = MAIL_ERROR_MEMORY;
262 goto close; 265 goto close;
263 } 266 }
264 267
265 r = mail_serialize_clear(mmapstr, &cur_token); 268 r = mail_serialize_clear(mmapstr, &cur_token);
266 if (r != MAIL_NO_ERROR) { 269 if (r != MAIL_NO_ERROR) {
267 res = r; 270 res = r;
268 goto free_mmapstr; 271 goto free_mmapstr;
269 } 272 }
270 273
271 r = mailimf_cache_int_write(mmapstr, &cur_token, 274 r = mailimf_cache_int_write(mmapstr, &cur_token,
272 ancestor_data->mh_cur_folder->fl_max_index); 275 ancestor_data->mh_cur_folder->fl_max_index);
273 if (r != MAIL_NO_ERROR) { 276 if (r != MAIL_NO_ERROR) {
274 res = r; 277 res = r;
275 goto free_mmapstr; 278 goto free_mmapstr;
276 } 279 }
277 280
278 fwrite(mmapstr->str, 1, mmapstr->len, f); 281 fwrite(mmapstr->str, 1, mmapstr->len, f);
279 282
280 mmap_string_free(mmapstr); 283 mmap_string_free(mmapstr);
281 fclose(f); 284 fclose(f);
282 285
283 return MAIL_NO_ERROR; 286 return MAIL_NO_ERROR;
284 287
285 free_mmapstr: 288 free_mmapstr:
286 mmap_string_free(mmapstr); 289 mmap_string_free(mmapstr);
287 close: 290 close:
288 fclose(f); 291 fclose(f);
289 err: 292 err:
290 return res; 293 return res;
291} 294}
292 295
293static int read_max_uid_value(mailsession * session) 296static int read_max_uid_value(mailsession * session)
294{ 297{
295 int r; 298 int r;
@@ -758,373 +761,453 @@ static int mhdriver_cached_status_folder(mailsession * session, char * mb,
758 cached_data->mh_quoted_mb, FLAGS_NAME); 761 cached_data->mh_quoted_mb, FLAGS_NAME);
759 762
760 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 763 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
761 if (r < 0) { 764 if (r < 0) {
762 res = MAIL_ERROR_FILE; 765 res = MAIL_ERROR_FILE;
763 goto err; 766 goto err;
764 } 767 }
765 768
766 mmapstr = mmap_string_new(""); 769 mmapstr = mmap_string_new("");
767 if (mmapstr == NULL) { 770 if (mmapstr == NULL) {
768 res = MAIL_ERROR_MEMORY; 771 res = MAIL_ERROR_MEMORY;
769 goto close_db_flags; 772 goto close_db_flags;
770 } 773 }
771 774
772 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i++) { 775 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i++) {
773 struct mailmh_msg_info * mh_info; 776 struct mailmh_msg_info * mh_info;
774 struct mail_flags * flags; 777 struct mail_flags * flags;
775 778
776 mh_info = carray_get(folder->fl_msgs_tab, i); 779 mh_info = carray_get(folder->fl_msgs_tab, i);
777 if (mh_info == NULL) 780 if (mh_info == NULL)
778 continue; 781 continue;
779 782
780 count ++; 783 count ++;
781 784
782 r = mhdriver_get_cached_flags(cache_db_flags, mmapstr, 785 r = mhdriver_get_cached_flags(cache_db_flags, mmapstr,
783 session, mh_info->msg_index, 786 session, mh_info->msg_index,
784 &flags); 787 &flags);
785 788
786 if (r != MAIL_NO_ERROR) { 789 if (r != MAIL_NO_ERROR) {
787 recent ++; 790 recent ++;
788 unseen ++; 791 unseen ++;
789 continue; 792 continue;
790 } 793 }
791 794
792 if ((flags->fl_flags & MAIL_FLAG_NEW) != 0) { 795 if ((flags->fl_flags & MAIL_FLAG_NEW) != 0) {
793 recent ++; 796 recent ++;
794 } 797 }
795 if ((flags->fl_flags & MAIL_FLAG_SEEN) == 0) { 798 if ((flags->fl_flags & MAIL_FLAG_SEEN) == 0) {
796 unseen ++; 799 unseen ++;
797 } 800 }
798 mail_flags_free(flags); 801 mail_flags_free(flags);
799 } 802 }
800 803
801 mmap_string_free(mmapstr); 804 mmap_string_free(mmapstr);
802 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 805 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
803 806
804 * result_messages = count; 807 * result_messages = count;
805 * result_recent = recent; 808 * result_recent = recent;
806 * result_unseen = unseen; 809 * result_unseen = unseen;
807 810
808 return MAIL_NO_ERROR; 811 return MAIL_NO_ERROR;
809 812
810 close_db_flags: 813 close_db_flags:
811 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 814 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
812 err: 815 err:
813 return res; 816 return res;
814} 817}
815 818
816static int mhdriver_cached_messages_number(mailsession * session, char * mb, 819static int mhdriver_cached_messages_number(mailsession * session, char * mb,
817 uint32_t * result) 820 uint32_t * result)
818{ 821{
819 return mailsession_messages_number(get_ancestor(session), mb, result); 822 return mailsession_messages_number(get_ancestor(session), mb, result);
820} 823}
821 824
822static int mhdriver_cached_recent_number(mailsession * session, char * mb, 825static int mhdriver_cached_recent_number(mailsession * session, char * mb,
823 uint32_t * result) 826 uint32_t * result)
824{ 827{
825 uint32_t messages; 828 uint32_t messages;
826 uint32_t recent; 829 uint32_t recent;
827 uint32_t unseen; 830 uint32_t unseen;
828 int r; 831 int r;
829 832
830 r = mhdriver_cached_status_folder(session, mb, &messages, &recent, &unseen); 833 r = mhdriver_cached_status_folder(session, mb, &messages, &recent, &unseen);
831 if (r != MAIL_NO_ERROR) 834 if (r != MAIL_NO_ERROR)
832 return r; 835 return r;
833 836
834 * result = recent; 837 * result = recent;
835 838
836 return MAIL_NO_ERROR; 839 return MAIL_NO_ERROR;
837} 840}
838 841
839 842
840static int mhdriver_cached_unseen_number(mailsession * session, char * mb, 843static int mhdriver_cached_unseen_number(mailsession * session, char * mb,
841 uint32_t * result) 844 uint32_t * result)
842{ 845{
843 uint32_t messages; 846 uint32_t messages;
844 uint32_t recent; 847 uint32_t recent;
845 uint32_t unseen; 848 uint32_t unseen;
846 int r; 849 int r;
847 850
848 r = mhdriver_cached_status_folder(session, mb, &messages, &recent, &unseen); 851 r = mhdriver_cached_status_folder(session, mb, &messages, &recent, &unseen);
849 if (r != MAIL_NO_ERROR) 852 if (r != MAIL_NO_ERROR)
850 return r; 853 return r;
851 854
852 * result = recent; 855 * result = recent;
853 856
854 return MAIL_NO_ERROR; 857 return MAIL_NO_ERROR;
855} 858}
856 859
857 860
858static int mhdriver_cached_list_folders(mailsession * session, char * mb, 861static int mhdriver_cached_list_folders(mailsession * session, char * mb,
859 struct mail_list ** result) 862 struct mail_list ** result)
860{ 863{
861 return mailsession_list_folders(get_ancestor(session), mb, result); 864 return mailsession_list_folders(get_ancestor(session), mb, result);
862} 865}
863 866
864static int mhdriver_cached_lsub_folders(mailsession * session, char * mb, 867static int mhdriver_cached_lsub_folders(mailsession * session, char * mb,
865 struct mail_list ** result) 868 struct mail_list ** result)
866{ 869{
867 return mailsession_lsub_folders(get_ancestor(session), mb, result); 870 return mailsession_lsub_folders(get_ancestor(session), mb, result);
868} 871}
869 872
870static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb) 873static 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
875static int mhdriver_cached_unsubscribe_folder(mailsession * session, 878static 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
883static int mhdriver_cached_append_message(mailsession * session, 886static 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
893static 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
889static int mhdriver_cached_copy_message(mailsession * session, 970static 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
895static int mhdriver_cached_remove_message(mailsession * session, uint32_t num) 976static 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
900static int mhdriver_cached_move_message(mailsession * session, 981static int mhdriver_cached_move_message(mailsession * session,
901 uint32_t num, char * mb) 982 uint32_t num, char * mb)
902{ 983{
903 return mailsession_move_message(get_ancestor(session), num, mb); 984 return mailsession_move_message(get_ancestor(session), num, mb);
904} 985}
905 986
906static int 987static int
907mhdriver_cached_get_messages_list(mailsession * session, 988mhdriver_cached_get_messages_list(mailsession * session,
908 struct mailmessage_list ** result) 989 struct mailmessage_list ** result)
909{ 990{
910 struct mailmh_folder * folder; 991 struct mailmh_folder * folder;
911 int res; 992 int res;
912 993
913 folder = get_mh_cur_folder(session); 994 folder = get_mh_cur_folder(session);
914 if (folder == NULL) { 995 if (folder == NULL) {
915 res = MAIL_ERROR_BAD_STATE; 996 res = MAIL_ERROR_BAD_STATE;
916 goto err; 997 goto err;
917 } 998 }
918 999
919 return mh_get_messages_list(folder, session, 1000 return mh_get_messages_list(folder, session,
920 mh_cached_message_driver, result); 1001 mh_cached_message_driver, result);
921 1002
922 err: 1003 err:
923 return res; 1004 return res;
924} 1005}
925 1006
926 1007
927 1008
928static int 1009static int
929get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, 1010get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr,
930 mailsession * session, uint32_t num, 1011 mailsession * session, uint32_t num,
931 struct mailimf_fields ** result) 1012 struct mailimf_fields ** result)
932{ 1013{
933 int r; 1014 int r;
934 char keyname[PATH_MAX]; 1015 char keyname[PATH_MAX];
935 struct mailimf_fields * fields; 1016 struct mailimf_fields * fields;
936 int res; 1017 int res;
937 struct mailmh_folder * folder; 1018 struct mailmh_folder * folder;
938 struct mailmh_msg_info * msg_info; 1019 struct mailmh_msg_info * msg_info;
939 chashdatum key; 1020 chashdatum key;
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 = &num; 1030 key.data = &num;
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
973static int 1055static int
974write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, 1056write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr,
975 mailsession * session, uint32_t num, 1057 mailsession * session, uint32_t num,
976 struct mailimf_fields * fields) 1058 struct mailimf_fields * fields)
977{ 1059{
978 int r; 1060 int r;
979 char keyname[PATH_MAX]; 1061 char keyname[PATH_MAX];
980 int res; 1062 int res;
981 struct mailmh_folder * folder; 1063 struct mailmh_folder * folder;
982 chashdatum key; 1064 chashdatum key;
983 chashdatum data; 1065 chashdatum data;
984 struct mailmh_msg_info * msg_info; 1066 struct mailmh_msg_info * msg_info;
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 = &num; 1076 key.data = &num;
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
1016static int 1099static int
1017mhdriver_cached_get_envelopes_list(mailsession * session, 1100mhdriver_cached_get_envelopes_list(mailsession * session,
1018 struct mailmessage_list * env_list) 1101 struct mailmessage_list * env_list)
1019{ 1102{
1020 int r; 1103 int r;
1021 unsigned int i; 1104 unsigned int i;
1022 char filename_env[PATH_MAX]; 1105 char filename_env[PATH_MAX];
1023 char filename_flags[PATH_MAX]; 1106 char filename_flags[PATH_MAX];
1024 struct mail_cache_db * cache_db_env; 1107 struct mail_cache_db * cache_db_env;
1025 struct mail_cache_db * cache_db_flags; 1108 struct mail_cache_db * cache_db_flags;
1026 MMAPString * mmapstr; 1109 MMAPString * mmapstr;
1027 int res; 1110 int res;
1028 struct mh_cached_session_state_data * cached_data; 1111 struct mh_cached_session_state_data * cached_data;
1029 1112
1030 cached_data = get_cached_data(session); 1113 cached_data = get_cached_data(session);
1031 if (cached_data->mh_quoted_mb == NULL) { 1114 if (cached_data->mh_quoted_mb == NULL) {
1032 res = MAIL_ERROR_BAD_STATE; 1115 res = MAIL_ERROR_BAD_STATE;
1033 goto err; 1116 goto err;
1034 } 1117 }
1035 1118
1036 mh_flags_store_process(cached_data->mh_flags_directory, 1119 mh_flags_store_process(cached_data->mh_flags_directory,
1037 cached_data->mh_quoted_mb, 1120 cached_data->mh_quoted_mb,
1038 cached_data->mh_flags_store); 1121 cached_data->mh_flags_store);
1039 1122
1040 mmapstr = mmap_string_new(""); 1123 mmapstr = mmap_string_new("");
1041 if (mmapstr == NULL) { 1124 if (mmapstr == NULL) {
1042 res = MAIL_ERROR_MEMORY; 1125 res = MAIL_ERROR_MEMORY;
1043 goto err; 1126 goto err;
1044 } 1127 }
1045 1128
1046 snprintf(filename_env, PATH_MAX, "%s/%s/%s", 1129 snprintf(filename_env, PATH_MAX, "%s/%s/%s",
1047 cached_data->mh_cache_directory, 1130 cached_data->mh_cache_directory,
1048 cached_data->mh_quoted_mb, ENV_NAME); 1131 cached_data->mh_quoted_mb, ENV_NAME);
1049 1132
1050 r = mail_cache_db_open_lock(filename_env, &cache_db_env); 1133 r = mail_cache_db_open_lock(filename_env, &cache_db_env);
1051 if (r < 0) { 1134 if (r < 0) {
1052 res = MAIL_ERROR_MEMORY; 1135 res = MAIL_ERROR_MEMORY;
1053 goto free_mmapstr; 1136 goto free_mmapstr;
1054 } 1137 }
1055 1138
1056 snprintf(filename_flags, PATH_MAX, "%s/%s/%s", 1139 snprintf(filename_flags, PATH_MAX, "%s/%s/%s",
1057 cached_data->mh_flags_directory, cached_data->mh_quoted_mb, FLAGS_NAME); 1140 cached_data->mh_flags_directory, cached_data->mh_quoted_mb, FLAGS_NAME);
1058 1141
1059 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 1142 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
1060 if (r < 0) { 1143 if (r < 0) {
1061 res = MAIL_ERROR_MEMORY; 1144 res = MAIL_ERROR_MEMORY;
1062 goto close_db_env; 1145 goto close_db_env;
1063 } 1146 }
1064 1147
1065 /* fill with cached */ 1148 /* fill with cached */
1066 1149
1067 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 1150 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
1068 mailmessage * msg; 1151 mailmessage * msg;
1069 struct mailimf_fields * fields; 1152 struct mailimf_fields * fields;
1070 struct mail_flags * flags; 1153 struct mail_flags * flags;
1071 1154
1072 msg = carray_get(env_list->msg_tab, i); 1155 msg = carray_get(env_list->msg_tab, i);
1073 1156
1074 if (msg->msg_fields == NULL) { 1157 if (msg->msg_fields == NULL) {
1075 r = get_cached_envelope(cache_db_env, mmapstr, 1158 r = get_cached_envelope(cache_db_env, mmapstr,
1076 msg->msg_session, msg->msg_index, &fields); 1159 msg->msg_session, msg->msg_index, &fields);
1077 if (r == MAIL_NO_ERROR) { 1160 if (r == MAIL_NO_ERROR) {
1078 msg->msg_cached = TRUE; 1161 msg->msg_cached = TRUE;
1079 msg->msg_fields = fields; 1162 msg->msg_fields = fields;
1080 } 1163 }
1081 } 1164 }
1082 1165
1083 if (msg->msg_flags == NULL) { 1166 if (msg->msg_flags == NULL) {
1084 r = mhdriver_get_cached_flags(cache_db_flags, mmapstr, 1167 r = mhdriver_get_cached_flags(cache_db_flags, mmapstr,
1085 session, msg->msg_index, &flags); 1168 session, msg->msg_index, &flags);
1086 if (r == MAIL_NO_ERROR) { 1169 if (r == MAIL_NO_ERROR) {
1087 msg->msg_flags = flags; 1170 msg->msg_flags = flags;
1088 } 1171 }
1089 } 1172 }
1090 } 1173 }
1091 1174
1092 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 1175 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
1093 mail_cache_db_close_unlock(filename_env, cache_db_env); 1176 mail_cache_db_close_unlock(filename_env, cache_db_env);
1094 1177
1095 r = mailsession_get_envelopes_list(get_ancestor(session), env_list); 1178 r = mailsession_get_envelopes_list(get_ancestor(session), env_list);
1096 1179
1097 if (r != MAIL_NO_ERROR) { 1180 if (r != MAIL_NO_ERROR) {
1098 res = r; 1181 res = r;
1099 goto free_mmapstr; 1182 goto free_mmapstr;
1100 } 1183 }
1101 1184
1102 r = mail_cache_db_open_lock(filename_env, &cache_db_env); 1185 r = mail_cache_db_open_lock(filename_env, &cache_db_env);
1103 if (r < 0) { 1186 if (r < 0) {
1104 res = MAIL_ERROR_MEMORY; 1187 res = MAIL_ERROR_MEMORY;
1105 goto free_mmapstr; 1188 goto free_mmapstr;
1106 } 1189 }
1107 1190
1108 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 1191 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
1109 if (r < 0) { 1192 if (r < 0) {
1110 res = MAIL_ERROR_MEMORY; 1193 res = MAIL_ERROR_MEMORY;
1111 goto close_db_env; 1194 goto close_db_env;
1112 } 1195 }
1113 1196
1114 /* add flags */ 1197 /* add flags */
1115 1198
1116 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 1199 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
1117 mailmessage * msg; 1200 mailmessage * msg;
1118 1201
1119 msg = carray_get(env_list->msg_tab, i); 1202 msg = carray_get(env_list->msg_tab, i);
1120 1203
1121 if (msg->msg_flags == NULL) 1204 if (msg->msg_flags == NULL)
1122 msg->msg_flags = mail_flags_new_empty(); 1205 msg->msg_flags = mail_flags_new_empty();
1123 } 1206 }
1124 1207
1125 /* must write cache */ 1208 /* must write cache */
1126 1209
1127 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 1210 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
1128 mailmessage * msg; 1211 mailmessage * msg;
1129 1212
1130 msg = carray_get(env_list->msg_tab, i); 1213 msg = carray_get(env_list->msg_tab, i);
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
@@ -54,258 +54,258 @@
54static int mh_prefetch(mailmessage * msg_info); 54static int mh_prefetch(mailmessage * msg_info);
55 55
56static void mh_prefetch_free(struct generic_message_t * msg); 56static void mh_prefetch_free(struct generic_message_t * msg);
57 57
58static int mh_initialize(mailmessage * msg_info); 58static int mh_initialize(mailmessage * msg_info);
59 59
60static int mh_fetch_size(mailmessage * msg_info, 60static int mh_fetch_size(mailmessage * msg_info,
61 size_t * result); 61 size_t * result);
62 62
63static int mh_get_flags(mailmessage * msg_info, 63static int mh_get_flags(mailmessage * msg_info,
64 struct mail_flags ** result); 64 struct mail_flags ** result);
65 65
66static void mh_uninitialize(mailmessage * msg_info); 66static void mh_uninitialize(mailmessage * msg_info);
67 67
68static void mh_flush(mailmessage * msg_info); 68static void mh_flush(mailmessage * msg_info);
69 69
70static void mh_check(mailmessage * msg_info); 70static void mh_check(mailmessage * msg_info);
71 71
72static int mh_fetch_header(mailmessage * msg_info, 72static int mh_fetch_header(mailmessage * msg_info,
73 char ** result, 73 char ** result,
74 size_t * result_len); 74 size_t * result_len);
75 75
76static mailmessage_driver local_mh_cached_message_driver = { 76static mailmessage_driver local_mh_cached_message_driver = {
77 .msg_name = "mh-cached", 77 .msg_name = "mh-cached",
78 78
79 .msg_initialize = mh_initialize, 79 .msg_initialize = mh_initialize,
80 .msg_uninitialize = mh_uninitialize, 80 .msg_uninitialize = mh_uninitialize,
81 81
82 .msg_flush = mh_flush, 82 .msg_flush = mh_flush,
83 .msg_check = mh_check, 83 .msg_check = mh_check,
84 84
85 .msg_fetch_result_free = mailmessage_generic_fetch_result_free, 85 .msg_fetch_result_free = mailmessage_generic_fetch_result_free,
86 86
87 .msg_fetch = mailmessage_generic_fetch, 87 .msg_fetch = mailmessage_generic_fetch,
88 .msg_fetch_header = mh_fetch_header, 88 .msg_fetch_header = mh_fetch_header,
89 .msg_fetch_body = mailmessage_generic_fetch_body, 89 .msg_fetch_body = mailmessage_generic_fetch_body,
90 .msg_fetch_size = mh_fetch_size, 90 .msg_fetch_size = mh_fetch_size,
91 .msg_get_bodystructure = mailmessage_generic_get_bodystructure, 91 .msg_get_bodystructure = mailmessage_generic_get_bodystructure,
92 .msg_fetch_section = mailmessage_generic_fetch_section, 92 .msg_fetch_section = mailmessage_generic_fetch_section,
93 .msg_fetch_section_header = mailmessage_generic_fetch_section_header, 93 .msg_fetch_section_header = mailmessage_generic_fetch_section_header,
94 .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, 94 .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime,
95 .msg_fetch_section_body = mailmessage_generic_fetch_section_body, 95 .msg_fetch_section_body = mailmessage_generic_fetch_section_body,
96 .msg_fetch_envelope = mailmessage_generic_fetch_envelope, 96 .msg_fetch_envelope = mailmessage_generic_fetch_envelope,
97 97
98 .msg_get_flags = mh_get_flags, 98 .msg_get_flags = mh_get_flags,
99}; 99};
100 100
101mailmessage_driver * mh_cached_message_driver = 101mailmessage_driver * mh_cached_message_driver =
102&local_mh_cached_message_driver; 102&local_mh_cached_message_driver;
103 103
104static inline struct mh_cached_session_state_data * 104static inline struct mh_cached_session_state_data *
105get_cached_session_data(mailmessage * msg) 105get_cached_session_data(mailmessage * msg)
106{ 106{
107 return msg->msg_session->sess_data; 107 return msg->msg_session->sess_data;
108} 108}
109 109
110static inline mailsession * get_ancestor_session(mailmessage * msg) 110static inline mailsession * get_ancestor_session(mailmessage * msg)
111{ 111{
112 return get_cached_session_data(msg)->mh_ancestor; 112 return get_cached_session_data(msg)->mh_ancestor;
113} 113}
114 114
115static inline struct mh_session_state_data * 115static inline struct mh_session_state_data *
116get_ancestor_session_data(mailmessage * msg) 116get_ancestor_session_data(mailmessage * msg)
117{ 117{
118 return get_ancestor_session(msg)->sess_data; 118 return get_ancestor_session(msg)->sess_data;
119} 119}
120 120
121static inline struct mailmh * 121static inline struct mailmh *
122get_mh_session(mailmessage * msg) 122get_mh_session(mailmessage * msg)
123{ 123{
124 return get_ancestor_session_data(msg)->mh_session; 124 return get_ancestor_session_data(msg)->mh_session;
125} 125}
126 126
127static inline struct mailmh_folder * 127static inline struct mailmh_folder *
128get_mh_cur_folder(mailmessage * msg) 128get_mh_cur_folder(mailmessage * msg)
129{ 129{
130 return get_ancestor_session_data(msg)->mh_cur_folder; 130 return get_ancestor_session_data(msg)->mh_cur_folder;
131} 131}
132 132
133static int mh_prefetch(mailmessage * msg_info) 133static int mh_prefetch(mailmessage * msg_info)
134{ 134{
135 struct generic_message_t * msg; 135 struct generic_message_t * msg;
136 int r; 136 int r;
137 char * msg_content; 137 char * msg_content;
138 size_t msg_length; 138 size_t msg_length;
139 139
140 r = mhdriver_fetch_message(get_ancestor_session(msg_info), 140 r = mhdriver_fetch_message(get_ancestor_session(msg_info),
141 msg_info->msg_index, &msg_content, &msg_length); 141 msg_info->msg_index, &msg_content, &msg_length);
142 if (r != MAIL_NO_ERROR) 142 if (r != MAIL_NO_ERROR)
143 return r; 143 return r;
144 144
145 msg = msg_info->msg_data; 145 msg = msg_info->msg_data;
146 146
147 msg->msg_message = msg_content; 147 msg->msg_message = msg_content;
148 msg->msg_length = msg_length; 148 msg->msg_length = msg_length;
149 149
150 return MAIL_NO_ERROR; 150 return MAIL_NO_ERROR;
151} 151}
152 152
153static void mh_prefetch_free(struct generic_message_t * msg) 153static void mh_prefetch_free(struct generic_message_t * msg)
154{ 154{
155 if (msg->msg_message != NULL) { 155 if (msg->msg_message != NULL) {
156 mmap_string_unref(msg->msg_message); 156 mmap_string_unref(msg->msg_message);
157 msg->msg_message = NULL; 157 msg->msg_message = NULL;
158 } 158 }
159} 159}
160 160
161static int mh_initialize(mailmessage * msg_info) 161static int mh_initialize(mailmessage * msg_info)
162{ 162{
163 struct generic_message_t * msg; 163 struct generic_message_t * msg;
164 int r; 164 int r;
165 char * uid; 165 char * uid;
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;
200} 200}
201 201
202static void mh_uninitialize(mailmessage * msg_info) 202static void mh_uninitialize(mailmessage * msg_info)
203{ 203{
204 mailmessage_generic_uninitialize(msg_info); 204 mailmessage_generic_uninitialize(msg_info);
205} 205}
206 206
207 207
208#define FLAGS_NAME "flags.db" 208#define FLAGS_NAME "flags.db"
209 209
210static void mh_flush(mailmessage * msg_info) 210static void mh_flush(mailmessage * msg_info)
211{ 211{
212 mailmessage_generic_flush(msg_info); 212 mailmessage_generic_flush(msg_info);
213} 213}
214 214
215static void mh_check(mailmessage * msg_info) 215static void mh_check(mailmessage * msg_info)
216{ 216{
217 int r; 217 int r;
218 218
219 if (msg_info->msg_flags != NULL) { 219 if (msg_info->msg_flags != NULL) {
220 r = mail_flags_store_set(get_cached_session_data(msg_info)->mh_flags_store, 220 r = mail_flags_store_set(get_cached_session_data(msg_info)->mh_flags_store,
221 msg_info); 221 msg_info);
222 /* ignore errors */ 222 /* ignore errors */
223 } 223 }
224} 224}
225 225
226static int mh_fetch_size(mailmessage * msg_info, 226static int mh_fetch_size(mailmessage * msg_info,
227 size_t * result) 227 size_t * result)
228{ 228{
229 int r; 229 int r;
230 size_t size; 230 size_t size;
231 231
232 r = mhdriver_fetch_size(get_ancestor_session(msg_info), 232 r = mhdriver_fetch_size(get_ancestor_session(msg_info),
233 msg_info->msg_index, &size); 233 msg_info->msg_index, &size);
234 if (r != MAIL_NO_ERROR) 234 if (r != MAIL_NO_ERROR)
235 return r; 235 return r;
236 236
237 * result = size; 237 * result = size;
238 238
239 return MAIL_NO_ERROR; 239 return MAIL_NO_ERROR;
240} 240}
241 241
242static int mh_get_flags(mailmessage * msg_info, 242static int mh_get_flags(mailmessage * msg_info,
243 struct mail_flags ** result) 243 struct mail_flags ** result)
244{ 244{
245 int r; 245 int r;
246 struct mail_flags * flags; 246 struct mail_flags * flags;
247 struct mail_cache_db * cache_db_flags; 247 struct mail_cache_db * cache_db_flags;
248 char filename_flags[PATH_MAX]; 248 char filename_flags[PATH_MAX];
249 int res; 249 int res;
250 struct mh_cached_session_state_data * cached_data; 250 struct mh_cached_session_state_data * cached_data;
251 MMAPString * mmapstr; 251 MMAPString * mmapstr;
252 252
253 if (msg_info->msg_flags != NULL) { 253 if (msg_info->msg_flags != NULL) {
254 * result = msg_info->msg_flags; 254 * result = msg_info->msg_flags;
255 255
256 return MAIL_NO_ERROR; 256 return MAIL_NO_ERROR;
257 } 257 }
258 258
259 cached_data = get_cached_session_data(msg_info); 259 cached_data = get_cached_session_data(msg_info);
260 260
261 flags = mail_flags_store_get(cached_data->mh_flags_store, 261 flags = mail_flags_store_get(cached_data->mh_flags_store,
262 msg_info->msg_index); 262 msg_info->msg_index);
263 263
264 if (flags == NULL) { 264 if (flags == NULL) {
265 if (cached_data->mh_quoted_mb == NULL) { 265 if (cached_data->mh_quoted_mb == NULL) {
266 res = MAIL_ERROR_BAD_STATE; 266 res = MAIL_ERROR_BAD_STATE;
267 goto err; 267 goto err;
268 } 268 }
269 269
270 snprintf(filename_flags, PATH_MAX, "%s/%s/%s", 270 snprintf(filename_flags, PATH_MAX, "%s/%s/%s",
271 cached_data->mh_flags_directory, 271 cached_data->mh_flags_directory,
272 cached_data->mh_quoted_mb, FLAGS_NAME); 272 cached_data->mh_quoted_mb, FLAGS_NAME);
273 273
274 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 274 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
275 if (r < 0) { 275 if (r < 0) {
276 res = MAIL_ERROR_MEMORY; 276 res = MAIL_ERROR_MEMORY;
277 goto err; 277 goto err;
278 } 278 }
279 279
280 mmapstr = mmap_string_new(""); 280 mmapstr = mmap_string_new("");
281 if (mmapstr == NULL) { 281 if (mmapstr == NULL) {
282 res = MAIL_ERROR_MEMORY; 282 res = MAIL_ERROR_MEMORY;
283 goto close_db_flags; 283 goto close_db_flags;
284 } 284 }
285 285
286 r = mhdriver_get_cached_flags(cache_db_flags, mmapstr, 286 r = mhdriver_get_cached_flags(cache_db_flags, mmapstr,
287 msg_info->msg_session, msg_info->msg_index, &flags); 287 msg_info->msg_session, msg_info->msg_index, &flags);
288 if (r != MAIL_NO_ERROR) { 288 if (r != MAIL_NO_ERROR) {
289 flags = mail_flags_new_empty(); 289 flags = mail_flags_new_empty();
290 if (flags == NULL) { 290 if (flags == NULL) {
291 res = MAIL_ERROR_MEMORY; 291 res = MAIL_ERROR_MEMORY;
292 goto free_mmapstr; 292 goto free_mmapstr;
293 } 293 }
294 } 294 }
295 295
296 mmap_string_free(mmapstr); 296 mmap_string_free(mmapstr);
297 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 297 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
298 } 298 }
299 299
300 msg_info->msg_flags = flags; 300 msg_info->msg_flags = flags;
301 301
302 * result = flags; 302 * result = flags;
303 303
304 return MAIL_NO_ERROR; 304 return MAIL_NO_ERROR;
305 305
306 free_mmapstr: 306 free_mmapstr:
307 mmap_string_free(mmapstr); 307 mmap_string_free(mmapstr);
308 close_db_flags: 308 close_db_flags:
309 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 309 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
310 err: 310 err:
311 return res; 311 return res;
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
@@ -19,194 +19,195 @@
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "mhdriver_message.h"
37 37
38#include "mailmessage_tools.h" 38#include "mailmessage_tools.h"
39#include "mhdriver_tools.h" 39#include "mhdriver_tools.h"
40#include "mhdriver.h" 40#include "mhdriver.h"
41#include "mailmh.h" 41#include "mailmh.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
51static int mh_prefetch(mailmessage * msg_info); 51static int mh_prefetch(mailmessage * msg_info);
52 52
53static void mh_prefetch_free(struct generic_message_t * msg); 53static void mh_prefetch_free(struct generic_message_t * msg);
54 54
55static int mh_initialize(mailmessage * msg_info); 55static int mh_initialize(mailmessage * msg_info);
56 56
57static int mh_fetch_size(mailmessage * msg_info, 57static int mh_fetch_size(mailmessage * msg_info,
58 size_t * result); 58 size_t * result);
59 59
60static int mh_fetch_header(mailmessage * msg_info, 60static int mh_fetch_header(mailmessage * msg_info,
61 char ** result, 61 char ** result,
62 size_t * result_len); 62 size_t * result_len);
63 63
64static mailmessage_driver local_mh_message_driver = { 64static mailmessage_driver local_mh_message_driver = {
65 .msg_name = "mh", 65 .msg_name = "mh",
66 66
67 .msg_initialize = mh_initialize, 67 .msg_initialize = mh_initialize,
68 .msg_uninitialize = mailmessage_generic_uninitialize, 68 .msg_uninitialize = mailmessage_generic_uninitialize,
69 69
70 .msg_flush = mailmessage_generic_flush, 70 .msg_flush = mailmessage_generic_flush,
71 .msg_check = NULL, 71 .msg_check = NULL,
72 72
73 .msg_fetch_result_free = mailmessage_generic_fetch_result_free, 73 .msg_fetch_result_free = mailmessage_generic_fetch_result_free,
74 74
75 .msg_fetch = mailmessage_generic_fetch, 75 .msg_fetch = mailmessage_generic_fetch,
76 .msg_fetch_header = mh_fetch_header, 76 .msg_fetch_header = mh_fetch_header,
77 .msg_fetch_body = mailmessage_generic_fetch_body, 77 .msg_fetch_body = mailmessage_generic_fetch_body,
78 .msg_fetch_size = mh_fetch_size, 78 .msg_fetch_size = mh_fetch_size,
79 .msg_get_bodystructure = mailmessage_generic_get_bodystructure, 79 .msg_get_bodystructure = mailmessage_generic_get_bodystructure,
80 .msg_fetch_section = mailmessage_generic_fetch_section, 80 .msg_fetch_section = mailmessage_generic_fetch_section,
81 .msg_fetch_section_header = mailmessage_generic_fetch_section_header, 81 .msg_fetch_section_header = mailmessage_generic_fetch_section_header,
82 .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, 82 .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime,
83 .msg_fetch_section_body = mailmessage_generic_fetch_section_body, 83 .msg_fetch_section_body = mailmessage_generic_fetch_section_body,
84 .msg_fetch_envelope = mailmessage_generic_fetch_envelope, 84 .msg_fetch_envelope = mailmessage_generic_fetch_envelope,
85 85
86 .msg_get_flags = NULL, 86 .msg_get_flags = NULL,
87}; 87};
88 88
89mailmessage_driver * mh_message_driver = &local_mh_message_driver; 89mailmessage_driver * mh_message_driver = &local_mh_message_driver;
90 90
91static int mh_prefetch(mailmessage * msg_info) 91static int mh_prefetch(mailmessage * msg_info)
92{ 92{
93 struct generic_message_t * msg; 93 struct generic_message_t * msg;
94 int r; 94 int r;
95 char * msg_content; 95 char * msg_content;
96 size_t msg_length; 96 size_t msg_length;
97 97
98 r = mhdriver_fetch_message(msg_info->msg_session, msg_info->msg_index, 98 r = mhdriver_fetch_message(msg_info->msg_session, msg_info->msg_index,
99 &msg_content, &msg_length); 99 &msg_content, &msg_length);
100 if (r != MAIL_NO_ERROR) 100 if (r != MAIL_NO_ERROR)
101 return r; 101 return r;
102 102
103 msg = msg_info->msg_data; 103 msg = msg_info->msg_data;
104 104
105 msg->msg_message = msg_content; 105 msg->msg_message = msg_content;
106 msg->msg_length = msg_length; 106 msg->msg_length = msg_length;
107 107
108 return MAIL_NO_ERROR; 108 return MAIL_NO_ERROR;
109} 109}
110 110
111static void mh_prefetch_free(struct generic_message_t * msg) 111static void mh_prefetch_free(struct generic_message_t * msg)
112{ 112{
113 if (msg->msg_message != NULL) { 113 if (msg->msg_message != NULL) {
114 mmap_string_unref(msg->msg_message); 114 mmap_string_unref(msg->msg_message);
115 msg->msg_message = NULL; 115 msg->msg_message = NULL;
116 } 116 }
117} 117}
118 118
119static inline struct mh_session_state_data * get_data(mailmessage * msg) 119static inline struct mh_session_state_data * get_data(mailmessage * msg)
120{ 120{
121 return msg->msg_session->sess_data; 121 return msg->msg_session->sess_data;
122} 122}
123 123
124static inline struct mailmh_folder * get_mh_cur_folder(mailmessage * msg) 124static inline struct mailmh_folder * get_mh_cur_folder(mailmessage * msg)
125{ 125{
126 return get_data(msg)->mh_cur_folder; 126 return get_data(msg)->mh_cur_folder;
127} 127}
128 128
129static int mh_initialize(mailmessage * msg_info) 129static int mh_initialize(mailmessage * msg_info)
130{ 130{
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;
165} 166}
166 167
167 168
168static int mh_fetch_size(mailmessage * msg_info, 169static int mh_fetch_size(mailmessage * msg_info,
169 size_t * result) 170 size_t * result)
170{ 171{
171 int r; 172 int r;
172 size_t size; 173 size_t size;
173 174
174 r = mhdriver_fetch_size(msg_info->msg_session, msg_info->msg_index, &size); 175 r = mhdriver_fetch_size(msg_info->msg_session, msg_info->msg_index, &size);
175 if (r != MAIL_NO_ERROR) 176 if (r != MAIL_NO_ERROR)
176 return r; 177 return r;
177 178
178 * result = size; 179 * result = size;
179 180
180 return MAIL_NO_ERROR; 181 return MAIL_NO_ERROR;
181} 182}
182 183
183 184
184 185
185 186
186static int mh_fetch_header(mailmessage * msg_info, 187static int mh_fetch_header(mailmessage * msg_info,
187 char ** result, 188 char ** result,
188 size_t * result_len) 189 size_t * result_len)
189{ 190{
190 struct generic_message_t * msg; 191 struct generic_message_t * msg;
191 int r; 192 int r;
192 char * msg_content; 193 char * msg_content;
193 size_t msg_length; 194 size_t msg_length;
194 195
195 msg = msg_info->msg_data; 196 msg = msg_info->msg_data;
196 if (msg->msg_message != NULL) { 197 if (msg->msg_message != NULL) {
197 198
198 r = mailmessage_generic_fetch_header(msg_info, result, result_len); 199 r = mailmessage_generic_fetch_header(msg_info, result, result_len);
199 return r; 200 return r;
200 } 201 }
201 else { 202 else {
202 r = mhdriver_fetch_header(msg_info->msg_session, msg_info->msg_index, 203 r = mhdriver_fetch_header(msg_info->msg_session, msg_info->msg_index,
203 &msg_content, &msg_length); 204 &msg_content, &msg_length);
204 if (r != MAIL_NO_ERROR) 205 if (r != MAIL_NO_ERROR)
205 return r; 206 return r;
206 207
207 * result = msg_content; 208 * result = msg_content;
208 * result_len = msg_length; 209 * result_len = msg_length;
209 210
210 return MAIL_NO_ERROR; 211 return MAIL_NO_ERROR;
211 } 212 }
212} 213}
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
@@ -244,232 +244,233 @@ int mhdriver_fetch_header(mailsession * session, uint32_t index,
244 default: 244 default:
245 res = mhdriver_mh_error_to_mail_error(r); 245 res = mhdriver_mh_error_to_mail_error(r);
246 goto close; 246 goto close;
247 } 247 }
248 248
249 str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); 249 str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
250 if (str == MAP_FAILED) { 250 if (str == MAP_FAILED) {
251 res = MAIL_ERROR_FETCH; 251 res = MAIL_ERROR_FETCH;
252 goto close; 252 goto close;
253 } 253 }
254 254
255 /* strip "From " header for broken implementations */ 255 /* strip "From " header for broken implementations */
256 cur_token = 0; 256 cur_token = 0;
257 if (size > 5) { 257 if (size > 5) {
258 if (strncmp("From ", str, size) == 0) { 258 if (strncmp("From ", str, size) == 0) {
259 cur_token += 5; 259 cur_token += 5;
260 260
261 while (str[cur_token] != '\n') { 261 while (str[cur_token] != '\n') {
262 if (cur_token >= size) 262 if (cur_token >= size)
263 break; 263 break;
264 cur_token ++; 264 cur_token ++;
265 } 265 }
266 } 266 }
267 } 267 }
268 268
269 begin = cur_token; 269 begin = cur_token;
270 270
271 while (1) { 271 while (1) {
272 r = mailimf_ignore_field_parse(str, size, &cur_token); 272 r = mailimf_ignore_field_parse(str, size, &cur_token);
273 if (r == MAILIMF_NO_ERROR) { 273 if (r == MAILIMF_NO_ERROR) {
274 /* do nothing */ 274 /* do nothing */
275 } 275 }
276 else 276 else
277 break; 277 break;
278 } 278 }
279 mailimf_crlf_parse(str, size, &cur_token); 279 mailimf_crlf_parse(str, size, &cur_token);
280 280
281 mmapstr = mmap_string_new_len(str + begin, cur_token - begin); 281 mmapstr = mmap_string_new_len(str + begin, cur_token - begin);
282 if (mmapstr == NULL) { 282 if (mmapstr == NULL) {
283 res = MAIL_ERROR_MEMORY; 283 res = MAIL_ERROR_MEMORY;
284 goto unmap; 284 goto unmap;
285 } 285 }
286 286
287 if (mmap_string_ref(mmapstr) != 0) { 287 if (mmap_string_ref(mmapstr) != 0) {
288 res = MAIL_ERROR_MEMORY; 288 res = MAIL_ERROR_MEMORY;
289 goto free_str; 289 goto free_str;
290 } 290 }
291 291
292 munmap(str, size); 292 munmap(str, size);
293 close(fd); 293 close(fd);
294 294
295 * result = mmapstr->str; 295 * result = mmapstr->str;
296 * result_len = mmapstr->len; 296 * result_len = mmapstr->len;
297 297
298 return MAIL_NO_ERROR; 298 return MAIL_NO_ERROR;
299 299
300 free_str: 300 free_str:
301 mmap_string_free(mmapstr); 301 mmap_string_free(mmapstr);
302 unmap: 302 unmap:
303 munmap(str, size); 303 munmap(str, size);
304 close: 304 close:
305 close(fd); 305 close(fd);
306 err: 306 err:
307 return res; 307 return res;
308} 308}
309 309
310 310
311int mhdriver_fetch_size(mailsession * session, uint32_t index, 311int mhdriver_fetch_size(mailsession * session, uint32_t index,
312 size_t * result) 312 size_t * result)
313{ 313{
314 struct mailmh_folder * folder; 314 struct mailmh_folder * folder;
315 int r; 315 int r;
316 struct stat buf; 316 struct stat buf;
317 char * name; 317 char * name;
318 318
319 folder = get_mh_cur_folder(session); 319 folder = get_mh_cur_folder(session);
320 if (folder == NULL) 320 if (folder == NULL)
321 return MAIL_ERROR_FETCH; 321 return MAIL_ERROR_FETCH;
322 322
323 r = mailmh_folder_get_message_filename(folder, index, &name); 323 r = mailmh_folder_get_message_filename(folder, index, &name);
324 324
325 switch (r) { 325 switch (r) {
326 case MAILMH_NO_ERROR: 326 case MAILMH_NO_ERROR:
327 break; 327 break;
328 328
329 default: 329 default:
330 return mhdriver_mh_error_to_mail_error(r); 330 return mhdriver_mh_error_to_mail_error(r);
331 } 331 }
332 332
333 r = stat(name, &buf); 333 r = stat(name, &buf);
334 free(name); 334 free(name);
335 if (r == -1) 335 if (r == -1)
336 return MAIL_ERROR_FETCH; 336 return MAIL_ERROR_FETCH;
337 337
338 * result = buf.st_size; 338 * result = buf.st_size;
339 339
340 return MAIL_NO_ERROR; 340 return MAIL_NO_ERROR;
341} 341}
342 342
343int 343int
344mhdriver_get_cached_flags(struct mail_cache_db * cache_db, 344mhdriver_get_cached_flags(struct mail_cache_db * cache_db,
345 MMAPString * mmapstr, 345 MMAPString * mmapstr,
346 mailsession * session, 346 mailsession * session,
347 uint32_t num, 347 uint32_t num,
348 struct mail_flags ** result) 348 struct mail_flags ** result)
349{ 349{
350 int r; 350 int r;
351 char keyname[PATH_MAX]; 351 char keyname[PATH_MAX];
352 struct mail_flags * flags; 352 struct mail_flags * flags;
353 int res; 353 int res;
354 struct mailmh_msg_info * msg_info; 354 struct mailmh_msg_info * msg_info;
355 chashdatum key; 355 chashdatum key;
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 = &num; 365 key.data = &num;
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
389int 390int
390mhdriver_write_cached_flags(struct mail_cache_db * cache_db, 391mhdriver_write_cached_flags(struct mail_cache_db * cache_db,
391 MMAPString * mmapstr, 392 MMAPString * mmapstr,
392 char * uid, 393 char * uid,
393 struct mail_flags * flags) 394 struct mail_flags * flags)
394{ 395{
395 int r; 396 int r;
396 char keyname[PATH_MAX]; 397 char keyname[PATH_MAX];
397 int res; 398 int res;
398 399
399 snprintf(keyname, PATH_MAX, "%s-flags", uid); 400 snprintf(keyname, PATH_MAX, "%s-flags", uid);
400 401
401 r = generic_cache_flags_write(cache_db, mmapstr, keyname, flags); 402 r = generic_cache_flags_write(cache_db, mmapstr, keyname, flags);
402 if (r != MAIL_NO_ERROR) { 403 if (r != MAIL_NO_ERROR) {
403 res = r; 404 res = r;
404 goto err; 405 goto err;
405 } 406 }
406 407
407 return MAIL_NO_ERROR; 408 return MAIL_NO_ERROR;
408 409
409 err: 410 err:
410 return res; 411 return res;
411} 412}
412 413
413 414
414int mh_get_messages_list(struct mailmh_folder * folder, 415int mh_get_messages_list(struct mailmh_folder * folder,
415 mailsession * session, mailmessage_driver * driver, 416 mailsession * session, mailmessage_driver * driver,
416 struct mailmessage_list ** result) 417 struct mailmessage_list ** result)
417{ 418{
418 unsigned int i; 419 unsigned int i;
419 struct mailmessage_list * env_list; 420 struct mailmessage_list * env_list;
420 int r; 421 int r;
421 carray * tab; 422 carray * tab;
422 int res; 423 int res;
423 424
424 tab = carray_new(128); 425 tab = carray_new(128);
425 if (tab == NULL) { 426 if (tab == NULL) {
426 res = MAIL_ERROR_MEMORY; 427 res = MAIL_ERROR_MEMORY;
427 goto err; 428 goto err;
428 } 429 }
429 430
430 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i++) { 431 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i++) {
431 struct mailmh_msg_info * mh_info; 432 struct mailmh_msg_info * mh_info;
432 mailmessage * msg; 433 mailmessage * msg;
433 434
434 mh_info = carray_get(folder->fl_msgs_tab, i); 435 mh_info = carray_get(folder->fl_msgs_tab, i);
435 if (mh_info == NULL) 436 if (mh_info == NULL)
436 continue; 437 continue;
437 438
438 msg = mailmessage_new(); 439 msg = mailmessage_new();
439 if (msg == NULL) { 440 if (msg == NULL) {
440 res = MAIL_ERROR_MEMORY; 441 res = MAIL_ERROR_MEMORY;
441 goto free_list; 442 goto free_list;
442 } 443 }
443 444
444 r = mailmessage_init(msg, session, driver, 445 r = mailmessage_init(msg, session, driver,
445 mh_info->msg_index, mh_info->msg_size); 446 mh_info->msg_index, mh_info->msg_size);
446 if (r != MAIL_NO_ERROR) { 447 if (r != MAIL_NO_ERROR) {
447 res = r; 448 res = r;
448 goto free_list; 449 goto free_list;
449 } 450 }
450 451
451 r = carray_add(tab, msg, NULL); 452 r = carray_add(tab, msg, NULL);
452 if (r < 0) { 453 if (r < 0) {
453 mailmessage_free(msg); 454 mailmessage_free(msg);
454 res = MAIL_ERROR_MEMORY; 455 res = MAIL_ERROR_MEMORY;
455 goto free_list; 456 goto free_list;
456 } 457 }
457 } 458 }
458 459
459 env_list = mailmessage_list_new(tab); 460 env_list = mailmessage_list_new(tab);
460 if (env_list == NULL) { 461 if (env_list == NULL) {
461 res = MAIL_ERROR_MEMORY; 462 res = MAIL_ERROR_MEMORY;
462 goto free_list; 463 goto free_list;
463 } 464 }
464 465
465 * result = env_list; 466 * result = env_list;
466 467
467 return MAIL_NO_ERROR; 468 return MAIL_NO_ERROR;
468 469
469 free_list: 470 free_list:
470 for(i = 0 ; i < carray_count(tab) ; i ++) 471 for(i = 0 ; i < carray_count(tab) ; i ++)
471 mailmessage_free(carray_get(tab, i)); 472 mailmessage_free(carray_get(tab, i));
472 carray_free(tab); 473 carray_free(tab);
473 err: 474 err:
474 return res; 475 return res;
475} 476}
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
@@ -1,192 +1,192 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "mhstorage.h" 36#include "mhstorage.h"
37 37
38#include "mhdriver.h" 38#include "mhdriver.h"
39#include "mhdriver_cached.h" 39#include "mhdriver_cached.h"
40#include "mail.h" 40#include "mail.h"
41 41
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44 44
45/* mh storage */ 45/* mh storage */
46 46
47static int mh_mailstorage_connect(struct mailstorage * storage); 47static int mh_mailstorage_connect(struct mailstorage * storage);
48static int mh_mailstorage_get_folder_session(struct mailstorage * storage, 48static int mh_mailstorage_get_folder_session(struct mailstorage * storage,
49 char * pathname, mailsession ** result); 49 char * pathname, mailsession ** result);
50static void mh_mailstorage_uninitialize(struct mailstorage * storage); 50static void mh_mailstorage_uninitialize(struct mailstorage * storage);
51 51
52static mailstorage_driver mh_mailstorage_driver = { 52static 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
59int mh_mailstorage_init(struct mailstorage * storage, 59int 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)
82 goto free_cache_directory; 82 goto free_cache_directory;
83 } 83 }
84 else { 84 else {
85 mh_storage->mh_cached = FALSE; 85 mh_storage->mh_cached = FALSE;
86 mh_storage->mh_cache_directory = NULL; 86 mh_storage->mh_cache_directory = NULL;
87 mh_storage->mh_flags_directory = NULL; 87 mh_storage->mh_flags_directory = NULL;
88 } 88 }
89 89
90 storage->sto_data = mh_storage; 90 storage->sto_data = mh_storage;
91 storage->sto_driver = &mh_mailstorage_driver; 91 storage->sto_driver = &mh_mailstorage_driver;
92 92
93 return MAIL_NO_ERROR; 93 return MAIL_NO_ERROR;
94 94
95 free_cache_directory: 95 free_cache_directory:
96 free(mh_storage->mh_cache_directory); 96 free(mh_storage->mh_cache_directory);
97 free_pathname: 97 free_pathname:
98 free(mh_storage->mh_pathname); 98 free(mh_storage->mh_pathname);
99 free: 99 free:
100 free(mh_storage); 100 free(mh_storage);
101 err: 101 err:
102 return MAIL_ERROR_MEMORY; 102 return MAIL_ERROR_MEMORY;
103} 103}
104 104
105static void mh_mailstorage_uninitialize(struct mailstorage * storage) 105static void mh_mailstorage_uninitialize(struct mailstorage * storage)
106{ 106{
107 struct mh_mailstorage * mh_storage; 107 struct mh_mailstorage * mh_storage;
108 108
109 mh_storage = storage->sto_data; 109 mh_storage = storage->sto_data;
110 if (mh_storage->mh_flags_directory != NULL) 110 if (mh_storage->mh_flags_directory != NULL)
111 free(mh_storage->mh_flags_directory); 111 free(mh_storage->mh_flags_directory);
112 if (mh_storage->mh_cache_directory != NULL) 112 if (mh_storage->mh_cache_directory != NULL)
113 free(mh_storage->mh_cache_directory); 113 free(mh_storage->mh_cache_directory);
114 free(mh_storage->mh_pathname); 114 free(mh_storage->mh_pathname);
115 free(mh_storage); 115 free(mh_storage);
116 116
117 storage->sto_data = NULL; 117 storage->sto_data = NULL;
118} 118}
119 119
120static int mh_mailstorage_connect(struct mailstorage * storage) 120static int mh_mailstorage_connect(struct mailstorage * storage)
121{ 121{
122 struct mh_mailstorage * mh_storage; 122 struct mh_mailstorage * mh_storage;
123 mailsession_driver * driver; 123 mailsession_driver * driver;
124 int r; 124 int r;
125 int res; 125 int res;
126 mailsession * session; 126 mailsession * session;
127 127
128 mh_storage = storage->sto_data; 128 mh_storage = storage->sto_data;
129 129
130 if (mh_storage->mh_cached) 130 if (mh_storage->mh_cached)
131 driver = mh_cached_session_driver; 131 driver = mh_cached_session_driver;
132 else 132 else
133 driver = mh_session_driver; 133 driver = mh_session_driver;
134 134
135 session = mailsession_new(driver); 135 session = mailsession_new(driver);
136 if (session == NULL) { 136 if (session == NULL) {
137 res = MAIL_ERROR_MEMORY; 137 res = MAIL_ERROR_MEMORY;
138 goto err; 138 goto err;
139 } 139 }
140 140
141 if (mh_storage->mh_cached) { 141 if (mh_storage->mh_cached) {
142 r = mailsession_parameters(session, 142 r = mailsession_parameters(session,
143 MHDRIVER_CACHED_SET_CACHE_DIRECTORY, 143 MHDRIVER_CACHED_SET_CACHE_DIRECTORY,
144 mh_storage->mh_cache_directory); 144 mh_storage->mh_cache_directory);
145 if (r != MAIL_NO_ERROR) { 145 if (r != MAIL_NO_ERROR) {
146 res = r; 146 res = r;
147 goto free; 147 goto free;
148 } 148 }
149 149
150 r = mailsession_parameters(session, 150 r = mailsession_parameters(session,
151 MHDRIVER_CACHED_SET_FLAGS_DIRECTORY, 151 MHDRIVER_CACHED_SET_FLAGS_DIRECTORY,
152 mh_storage->mh_flags_directory); 152 mh_storage->mh_flags_directory);
153 if (r != MAIL_NO_ERROR) { 153 if (r != MAIL_NO_ERROR) {
154 res = r; 154 res = r;
155 goto free; 155 goto free;
156 } 156 }
157 } 157 }
158 158
159 r = mailsession_connect_path(session, mh_storage->mh_pathname); 159 r = mailsession_connect_path(session, mh_storage->mh_pathname);
160 switch (r) { 160 switch (r) {
161 case MAIL_NO_ERROR_NON_AUTHENTICATED: 161 case MAIL_NO_ERROR_NON_AUTHENTICATED:
162 case MAIL_NO_ERROR_AUTHENTICATED: 162 case MAIL_NO_ERROR_AUTHENTICATED:
163 case MAIL_NO_ERROR: 163 case MAIL_NO_ERROR:
164 break; 164 break;
165 default: 165 default:
166 res = r; 166 res = r;
167 goto free; 167 goto free;
168 } 168 }
169 169
170 storage->sto_session = session; 170 storage->sto_session = session;
171 171
172 return MAIL_NO_ERROR; 172 return MAIL_NO_ERROR;
173 173
174 free: 174 free:
175 mailsession_free(session); 175 mailsession_free(session);
176 err: 176 err:
177 return res; 177 return res;
178} 178}
179 179
180static int mh_mailstorage_get_folder_session(struct mailstorage * storage, 180static int mh_mailstorage_get_folder_session(struct mailstorage * storage,
181 char * pathname, mailsession ** result) 181 char * pathname, mailsession ** result)
182{ 182{
183 int r; 183 int r;
184 184
185 r = mailsession_select_folder(storage->sto_session, pathname); 185 r = mailsession_select_folder(storage->sto_session, pathname);
186 if (r != MAIL_NO_ERROR) 186 if (r != MAIL_NO_ERROR)
187 return r; 187 return r;
188 188
189 * result = storage->sto_session; 189 * result = storage->sto_session;
190 190
191 return MAIL_NO_ERROR; 191 return MAIL_NO_ERROR;
192} 192}
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
@@ -1,259 +1,263 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "nntpdriver.h" 36#include "nntpdriver.h"
37 37
38#include <string.h> 38#include <string.h>
39#include <stdlib.h> 39#include <stdlib.h>
40 40
41#include "mail.h" 41#include "mail.h"
42#include "mailmessage.h" 42#include "mailmessage.h"
43#include "nntpdriver_tools.h" 43#include "nntpdriver_tools.h"
44#include "maildriver_tools.h" 44#include "maildriver_tools.h"
45#include "nntpdriver_message.h" 45#include "nntpdriver_message.h"
46 46
47static int nntpdriver_initialize(mailsession * session); 47static int nntpdriver_initialize(mailsession * session);
48 48
49static void nntpdriver_uninitialize(mailsession * session); 49static void nntpdriver_uninitialize(mailsession * session);
50 50
51static int nntpdriver_parameters(mailsession * session, 51static int nntpdriver_parameters(mailsession * session,
52 int id, void * value); 52 int id, void * value);
53 53
54static int nntpdriver_connect_stream(mailsession * session, mailstream * s); 54static int nntpdriver_connect_stream(mailsession * session, mailstream * s);
55 55
56static int nntpdriver_login(mailsession * session, 56static int nntpdriver_login(mailsession * session,
57 char * userid, char * password); 57 char * userid, char * password);
58 58
59static int nntpdriver_logout(mailsession * session); 59static int nntpdriver_logout(mailsession * session);
60 60
61static int nntpdriver_status_folder(mailsession * session, char * mb, 61static 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
66static int nntpdriver_messages_number(mailsession * session, char * mb, 66static int nntpdriver_messages_number(mailsession * session, char * mb,
67 uint32_t * result); 67 uint32_t * result);
68 68
69static int nntpdriver_append_message(mailsession * session, 69static int nntpdriver_append_message(mailsession * session,
70 char * message, size_t size); 70 char * message, size_t size);
71 71
72static int nntpdriver_append_message_flags(mailsession * session,
73 char * message, size_t size, struct mail_flags * flags);
74
72static int 75static int
73nntpdriver_get_envelopes_list(mailsession * session, 76nntpdriver_get_envelopes_list(mailsession * session,
74 struct mailmessage_list * env_list); 77 struct mailmessage_list * env_list);
75 78
76 79
77static int nntpdriver_get_messages_list(mailsession * session, 80static int nntpdriver_get_messages_list(mailsession * session,
78 struct mailmessage_list ** result); 81 struct mailmessage_list ** result);
79 82
80static int nntpdriver_list_folders(mailsession * session, char * mb, 83static int nntpdriver_list_folders(mailsession * session, char * mb,
81 struct mail_list ** result); 84 struct mail_list ** result);
82 85
83static int nntpdriver_lsub_folders(mailsession * session, char * mb, 86static int nntpdriver_lsub_folders(mailsession * session, char * mb,
84 struct mail_list ** result); 87 struct mail_list ** result);
85 88
86static int nntpdriver_subscribe_folder(mailsession * session, char * mb); 89static int nntpdriver_subscribe_folder(mailsession * session, char * mb);
87 90
88static int nntpdriver_unsubscribe_folder(mailsession * session, char * mb); 91static int nntpdriver_unsubscribe_folder(mailsession * session, char * mb);
89 92
90static int nntpdriver_get_message(mailsession * session, 93static int nntpdriver_get_message(mailsession * session,
91 uint32_t num, mailmessage ** result); 94 uint32_t num, mailmessage ** result);
92 95
93static int nntpdriver_get_message_by_uid(mailsession * session, 96static int nntpdriver_get_message_by_uid(mailsession * session,
94 const char * uid, 97 const char * uid,
95 mailmessage ** result); 98 mailmessage ** result);
96 99
97static int nntpdriver_noop(mailsession * session); 100static int nntpdriver_noop(mailsession * session);
98 101
99static mailsession_driver local_nntp_session_driver = { 102static mailsession_driver local_nntp_session_driver = {
100 .sess_name = "nntp", 103 .sess_name = "nntp",
101 104
102 .sess_initialize = nntpdriver_initialize, 105 .sess_initialize = nntpdriver_initialize,
103 .sess_uninitialize = nntpdriver_uninitialize, 106 .sess_uninitialize = nntpdriver_uninitialize,
104 107
105 .sess_parameters = nntpdriver_parameters, 108 .sess_parameters = nntpdriver_parameters,
106 109
107 .sess_connect_stream = nntpdriver_connect_stream, 110 .sess_connect_stream = nntpdriver_connect_stream,
108 .sess_connect_path = NULL, 111 .sess_connect_path = NULL,
109 .sess_starttls = NULL, 112 .sess_starttls = NULL,
110 .sess_login = nntpdriver_login, 113 .sess_login = nntpdriver_login,
111 .sess_logout = nntpdriver_logout, 114 .sess_logout = nntpdriver_logout,
112 .sess_noop = nntpdriver_noop, 115 .sess_noop = nntpdriver_noop,
113 116
114 .sess_build_folder_name = NULL, 117 .sess_build_folder_name = NULL,
115 .sess_create_folder = NULL, 118 .sess_create_folder = NULL,
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
147mailsession_driver * nntp_session_driver = &local_nntp_session_driver; 151mailsession_driver * nntp_session_driver = &local_nntp_session_driver;
148 152
149static inline struct nntp_session_state_data * 153static inline struct nntp_session_state_data *
150get_data(mailsession * session) 154get_data(mailsession * session)
151{ 155{
152 return session->sess_data; 156 return session->sess_data;
153} 157}
154 158
155static inline newsnntp * get_nntp_session(mailsession * session) 159static inline newsnntp * get_nntp_session(mailsession * session)
156{ 160{
157 return get_data(session)->nntp_session; 161 return get_data(session)->nntp_session;
158} 162}
159 163
160static int nntpdriver_initialize(mailsession * session) 164static int nntpdriver_initialize(mailsession * session)
161{ 165{
162 struct nntp_session_state_data * data; 166 struct nntp_session_state_data * data;
163 newsnntp * nntp; 167 newsnntp * nntp;
164 168
165 nntp = newsnntp_new(0, NULL); 169 nntp = newsnntp_new(0, NULL);
166 if (nntp == NULL) 170 if (nntp == NULL)
167 goto err; 171 goto err;
168 172
169 data = malloc(sizeof(* data)); 173 data = malloc(sizeof(* data));
170 if (data == NULL) 174 if (data == NULL)
171 goto free; 175 goto free;
172 176
173 data->nntp_session = nntp; 177 data->nntp_session = nntp;
174 178
175 data->nntp_userid = NULL; 179 data->nntp_userid = NULL;
176 data->nntp_password = NULL; 180 data->nntp_password = NULL;
177 181
178 data->nntp_group_info = NULL; 182 data->nntp_group_info = NULL;
179 data->nntp_group_name = NULL; 183 data->nntp_group_name = NULL;
180 184
181 data->nntp_subscribed_list = clist_new(); 185 data->nntp_subscribed_list = clist_new();
182 if (data->nntp_subscribed_list == NULL) 186 if (data->nntp_subscribed_list == NULL)
183 goto free_data; 187 goto free_data;
184 188
185 data->nntp_max_articles = 0; 189 data->nntp_max_articles = 0;
186 190
187 data->nntp_mode_reader = FALSE; 191 data->nntp_mode_reader = FALSE;
188 192
189 session->sess_data = data; 193 session->sess_data = data;
190 194
191 return MAIL_NO_ERROR; 195 return MAIL_NO_ERROR;
192 196
193 free_data: 197 free_data:
194 free(data); 198 free(data);
195 free: 199 free:
196 newsnntp_free(nntp); 200 newsnntp_free(nntp);
197 err: 201 err:
198 return MAIL_ERROR_MEMORY; 202 return MAIL_ERROR_MEMORY;
199} 203}
200 204
201static void nntpdriver_uninitialize(mailsession * session) 205static void nntpdriver_uninitialize(mailsession * session)
202{ 206{
203 struct nntp_session_state_data * data; 207 struct nntp_session_state_data * data;
204 208
205 data = get_data(session); 209 data = get_data(session);
206 210
207 clist_foreach(data->nntp_subscribed_list, (clist_func) free, NULL); 211 clist_foreach(data->nntp_subscribed_list, (clist_func) free, NULL);
208 clist_free(data->nntp_subscribed_list); 212 clist_free(data->nntp_subscribed_list);
209 213
210 if (data->nntp_group_info != NULL) 214 if (data->nntp_group_info != NULL)
211 newsnntp_group_free(data->nntp_group_info); 215 newsnntp_group_free(data->nntp_group_info);
212 216
213 if (data->nntp_group_name != NULL) 217 if (data->nntp_group_name != NULL)
214 free(data->nntp_group_name); 218 free(data->nntp_group_name);
215 219
216 if (data->nntp_userid != NULL) 220 if (data->nntp_userid != NULL)
217 free(data->nntp_userid); 221 free(data->nntp_userid);
218 222
219 if (data->nntp_password != NULL) 223 if (data->nntp_password != NULL)
220 free(data->nntp_password); 224 free(data->nntp_password);
221 225
222 newsnntp_free(data->nntp_session); 226 newsnntp_free(data->nntp_session);
223 free(data); 227 free(data);
224 228
225 session->sess_data = NULL; 229 session->sess_data = NULL;
226} 230}
227 231
228 232
229static int nntpdriver_parameters(mailsession * session, 233static int nntpdriver_parameters(mailsession * session,
230 int id, void * value) 234 int id, void * value)
231{ 235{
232 struct nntp_session_state_data * data; 236 struct nntp_session_state_data * data;
233 237
234 data = get_data(session); 238 data = get_data(session);
235 239
236 switch (id) { 240 switch (id) {
237 case NNTPDRIVER_SET_MAX_ARTICLES: 241 case NNTPDRIVER_SET_MAX_ARTICLES:
238 { 242 {
239 uint32_t * param; 243 uint32_t * param;
240 244
241 param = value; 245 param = value;
242 246
243 data->nntp_max_articles = * param; 247 data->nntp_max_articles = * param;
244 return MAIL_NO_ERROR; 248 return MAIL_NO_ERROR;
245 } 249 }
246 } 250 }
247 251
248 return MAIL_ERROR_INVAL; 252 return MAIL_ERROR_INVAL;
249} 253}
250 254
251 255
252static int add_to_list(mailsession * session, char * mb) 256static int add_to_list(mailsession * session, char * mb)
253{ 257{
254 char * new_mb; 258 char * new_mb;
255 int r; 259 int r;
256 struct nntp_session_state_data * data; 260 struct nntp_session_state_data * data;
257 261
258 data = get_data(session); 262 data = get_data(session);
259 263
@@ -505,256 +509,262 @@ static int nntpdriver_list_folders(mailsession * session, char * mb,
505 509
506 free_list: 510 free_list:
507 clist_foreach(list, (clist_func) free, NULL); 511 clist_foreach(list, (clist_func) free, NULL);
508 clist_free(list); 512 clist_free(list);
509 newsnntp_list_free(group_list); 513 newsnntp_list_free(group_list);
510 err: 514 err:
511 return res; 515 return res;
512} 516}
513 517
514static int nntpdriver_lsub_folders(mailsession * session, char * mb, 518static int nntpdriver_lsub_folders(mailsession * session, char * mb,
515 struct mail_list ** result) 519 struct mail_list ** result)
516{ 520{
517 clist * subscribed; 521 clist * subscribed;
518 clist * lsub_result; 522 clist * lsub_result;
519 clistiter * cur; 523 clistiter * cur;
520 struct mail_list * lsub; 524 struct mail_list * lsub;
521 size_t length; 525 size_t length;
522 int res; 526 int res;
523 int r; 527 int r;
524 struct nntp_session_state_data * data; 528 struct nntp_session_state_data * data;
525 529
526 length = strlen(mb); 530 length = strlen(mb);
527 531
528 data = get_data(session); 532 data = get_data(session);
529 533
530 subscribed = data->nntp_subscribed_list; 534 subscribed = data->nntp_subscribed_list;
531 lsub_result = clist_new(); 535 lsub_result = clist_new();
532 if (lsub_result == NULL) { 536 if (lsub_result == NULL) {
533 res = MAIL_ERROR_MEMORY; 537 res = MAIL_ERROR_MEMORY;
534 goto err; 538 goto err;
535 } 539 }
536 540
537 for(cur = clist_begin(subscribed) ; cur != NULL ; 541 for(cur = clist_begin(subscribed) ; cur != NULL ;
538 cur = clist_next(cur)) { 542 cur = clist_next(cur)) {
539 char * cur_mb; 543 char * cur_mb;
540 char * new_mb; 544 char * new_mb;
541 545
542 cur_mb = clist_content(cur); 546 cur_mb = clist_content(cur);
543 547
544 if (strncmp(mb, cur_mb, length) == 0) { 548 if (strncmp(mb, cur_mb, length) == 0) {
545 new_mb = strdup(cur_mb); 549 new_mb = strdup(cur_mb);
546 if (new_mb == NULL) { 550 if (new_mb == NULL) {
547 res = MAIL_ERROR_MEMORY; 551 res = MAIL_ERROR_MEMORY;
548 goto free_list; 552 goto free_list;
549 } 553 }
550 554
551 r = clist_append(lsub_result, new_mb); 555 r = clist_append(lsub_result, new_mb);
552 if (r < 0) { 556 if (r < 0) {
553 free(new_mb); 557 free(new_mb);
554 res = MAIL_ERROR_MEMORY; 558 res = MAIL_ERROR_MEMORY;
555 goto free_list; 559 goto free_list;
556 } 560 }
557 } 561 }
558 } 562 }
559 563
560 lsub = mail_list_new(lsub_result); 564 lsub = mail_list_new(lsub_result);
561 if (lsub == NULL) { 565 if (lsub == NULL) {
562 res = MAIL_ERROR_MEMORY; 566 res = MAIL_ERROR_MEMORY;
563 goto free_list; 567 goto free_list;
564 } 568 }
565 569
566 * result = lsub; 570 * result = lsub;
567 571
568 return MAIL_NO_ERROR; 572 return MAIL_NO_ERROR;
569 573
570 free_list: 574 free_list:
571 clist_foreach(lsub_result, (clist_func) free, NULL); 575 clist_foreach(lsub_result, (clist_func) free, NULL);
572 clist_free(lsub_result); 576 clist_free(lsub_result);
573 err: 577 err:
574 return res; 578 return res;
575} 579}
576 580
577static int nntpdriver_subscribe_folder(mailsession * session, char * mb) 581static int nntpdriver_subscribe_folder(mailsession * session, char * mb)
578{ 582{
579 int r; 583 int r;
580 584
581 r = add_to_list(session, mb); 585 r = add_to_list(session, mb);
582 if (r < 0) 586 if (r < 0)
583 return MAIL_ERROR_SUBSCRIBE; 587 return MAIL_ERROR_SUBSCRIBE;
584 588
585 return MAIL_NO_ERROR; 589 return MAIL_NO_ERROR;
586} 590}
587 591
588static int nntpdriver_unsubscribe_folder(mailsession * session, char * mb) 592static int nntpdriver_unsubscribe_folder(mailsession * session, char * mb)
589{ 593{
590 int r; 594 int r;
591 595
592 r = remove_from_list(session, mb); 596 r = remove_from_list(session, mb);
593 if (r < 0) 597 if (r < 0)
594 return MAIL_ERROR_UNSUBSCRIBE; 598 return MAIL_ERROR_UNSUBSCRIBE;
595 599
596 return MAIL_NO_ERROR; 600 return MAIL_NO_ERROR;
597} 601}
598 602
599 603
600 604
601/* messages operations */ 605/* messages operations */
602 606
603static int nntpdriver_append_message(mailsession * session, 607static int nntpdriver_append_message(mailsession * session,
604 char * message, size_t size) 608 char * message, size_t size)
605{ 609{
606 int r; 610 int r;
607 struct nntp_session_state_data * data; 611 struct nntp_session_state_data * data;
608 612
609 data = get_data(session); 613 data = get_data(session);
610 614
611 do { 615 do {
612 r = newsnntp_post(get_nntp_session(session), message, size); 616 r = newsnntp_post(get_nntp_session(session), message, size);
613 switch (r) { 617 switch (r) {
614 case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_USERNAME: 618 case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_USERNAME:
615 r = nntpdriver_authenticate_user(session); 619 r = nntpdriver_authenticate_user(session);
616 if (r != MAIL_NO_ERROR) 620 if (r != MAIL_NO_ERROR)
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
637static 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
634static int xover_resp_to_fields(struct newsnntp_xover_resp_item * item, 644static 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
638static int 648static int
639nntpdriver_get_envelopes_list(mailsession * session, 649nntpdriver_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;
649 unsigned int i; 659 unsigned int i;
650 660
651 nntp = get_nntp_session(session); 661 nntp = get_nntp_session(session);
652 662
653 data = get_data(session); 663 data = get_data(session);
654 664
655 if (data->nntp_group_info == NULL) 665 if (data->nntp_group_info == NULL)
656 return MAIL_ERROR_BAD_STATE; 666 return MAIL_ERROR_BAD_STATE;
657 667
658 first_seq = data->nntp_group_info->grp_first; 668 first_seq = data->nntp_group_info->grp_first;
659 669
660 if (carray_count(env_list->msg_tab) > 0) { 670 if (carray_count(env_list->msg_tab) > 0) {
661 mailmessage * msg; 671 mailmessage * msg;
662 672
663 msg = carray_get(env_list->msg_tab, 0); 673 msg = carray_get(env_list->msg_tab, 0);
664 674
665 first_seq = msg->msg_index; 675 first_seq = msg->msg_index;
666 } 676 }
667 677
668 if (carray_count(env_list->msg_tab) > 0) { 678 if (carray_count(env_list->msg_tab) > 0) {
669 i = carray_count(env_list->msg_tab) - 1; 679 i = carray_count(env_list->msg_tab) - 1;
670 while (1) { 680 while (1) {
671 mailmessage * msg; 681 mailmessage * msg;
672 682
673 msg = carray_get(env_list->msg_tab, i); 683 msg = carray_get(env_list->msg_tab, i);
674 684
675 if (msg->msg_fields != NULL) { 685 if (msg->msg_fields != NULL) {
676 first_seq = msg->msg_index + 1; 686 first_seq = msg->msg_index + 1;
677 break; 687 break;
678 } 688 }
679 689
680 if (i == 0) 690 if (i == 0)
681 break; 691 break;
682 692
683 i --; 693 i --;
684 } 694 }
685 } 695 }
686 696
687 if (first_seq > data->nntp_group_info->grp_last) { 697 if (first_seq > data->nntp_group_info->grp_last) {
688 list = NULL; 698 list = NULL;
689 } 699 }
690 else { 700 else {
691 done = FALSE; 701 done = FALSE;
692 do { 702 do {
693 r = newsnntp_xover_range(nntp, first_seq, 703 r = newsnntp_xover_range(nntp, first_seq,
694 data->nntp_group_info->grp_last, &list); 704 data->nntp_group_info->grp_last, &list);
695 705
696 switch (r) { 706 switch (r) {
697 case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_USERNAME: 707 case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_USERNAME:
698 r = nntpdriver_authenticate_user(session); 708 r = nntpdriver_authenticate_user(session);
699 if (r != MAIL_NO_ERROR) 709 if (r != MAIL_NO_ERROR)
700 return r; 710 return r;
701 break; 711 break;
702 712
703 case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD: 713 case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD:
704 r = nntpdriver_authenticate_password(session); 714 r = nntpdriver_authenticate_password(session);
705 if (r != MAIL_NO_ERROR) 715 if (r != MAIL_NO_ERROR)
706 return r; 716 return r;
707 break; 717 break;
708 718
709 case NEWSNNTP_NO_ERROR: 719 case NEWSNNTP_NO_ERROR:
710 done = TRUE; 720 done = TRUE;
711 break; 721 break;
712 722
713 default: 723 default:
714 return nntpdriver_nntp_error_to_mail_error(r); 724 return nntpdriver_nntp_error_to_mail_error(r);
715 } 725 }
716 } 726 }
717 while (!done); 727 while (!done);
718 } 728 }
719 729
720#if 0 730#if 0
721 i = 0; 731 i = 0;
722 j = 0; 732 j = 0;
723 733
724 if (list != NULL) { 734 if (list != NULL) {
725 for(cur = clist_begin(list) ; cur != NULL ; cur = clist_next(cur)) { 735 for(cur = clist_begin(list) ; cur != NULL ; cur = clist_next(cur)) {
726 struct newsnntp_xover_resp_item * item; 736 struct newsnntp_xover_resp_item * item;
727 struct mailimf_fields * fields; 737 struct mailimf_fields * fields;
728 738
729 item = clist_content(cur); 739 item = clist_content(cur);
730 740
731 while (i < carray_count(env_list->msg_tab)) { 741 while (i < carray_count(env_list->msg_tab)) {
732 mailmessage * info; 742 mailmessage * info;
733 743
734 info = carray_get(env_list->msg_tab, i); 744 info = carray_get(env_list->msg_tab, i);
735 745
736 if (item->ovr_article == info->msg_index) { 746 if (item->ovr_article == info->msg_index) {
737 747
738 if (info->fields == NULL) { 748 if (info->fields == NULL) {
739 r = xover_resp_to_fields(item, &fields); 749 r = xover_resp_to_fields(item, &fields);
740 if (r == MAIL_NO_ERROR) { 750 if (r == MAIL_NO_ERROR) {
741 info->fields = fields; 751 info->fields = fields;
742 } 752 }
743 753
744 info->size = item->ovr_size; 754 info->size = item->ovr_size;
745 755
746 carray_set(env_list->msg_tab, j, info); 756 carray_set(env_list->msg_tab, j, info);
747 j ++; 757 j ++;
748 i ++; 758 i ++;
749 break; 759 break;
750 } 760 }
751 else { 761 else {
752 carray_set(env_list->msg_tab, j, info); 762 carray_set(env_list->msg_tab, j, info);
753 j ++; 763 j ++;
754 } 764 }
755 } 765 }
756 else { 766 else {
757 if (info->fields != NULL) { 767 if (info->fields != NULL) {
758 carray_set(env_list->msg_tab, j, info); 768 carray_set(env_list->msg_tab, j, info);
759 j ++; 769 j ++;
760 } 770 }
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
@@ -1,289 +1,293 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "nntpdriver_cached.h" 36#include "nntpdriver_cached.h"
37 37
38#include "libetpan-config.h" 38#include "libetpan-config.h"
39 39
40#include <string.h> 40#include <string.h>
41#include <stdio.h> 41#include <stdio.h>
42#include <sys/types.h> 42#include <sys/types.h>
43#include <sys/stat.h> 43#include <sys/stat.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <unistd.h> 45#include <unistd.h>
46#include <stdlib.h> 46#include <stdlib.h>
47 47
48#include "mail_cache_db.h" 48#include "mail_cache_db.h"
49 49
50#include "mail.h" 50#include "mail.h"
51#include "mailmessage.h" 51#include "mailmessage.h"
52#include "maildriver_tools.h" 52#include "maildriver_tools.h"
53#include "nntpdriver.h" 53#include "nntpdriver.h"
54#include "maildriver.h" 54#include "maildriver.h"
55#include "newsnntp.h" 55#include "newsnntp.h"
56#include "generic_cache.h" 56#include "generic_cache.h"
57#include "imfcache.h" 57#include "imfcache.h"
58#include "maillock.h" 58#include "maillock.h"
59#include "nntpdriver_cached_message.h" 59#include "nntpdriver_cached_message.h"
60#include "nntpdriver_tools.h" 60#include "nntpdriver_tools.h"
61 61
62static int nntpdriver_cached_initialize(mailsession * session); 62static int nntpdriver_cached_initialize(mailsession * session);
63 63
64static void nntpdriver_cached_uninitialize(mailsession * session); 64static void nntpdriver_cached_uninitialize(mailsession * session);
65 65
66static int nntpdriver_cached_parameters(mailsession * session, 66static int nntpdriver_cached_parameters(mailsession * session,
67 int id, void * value); 67 int id, void * value);
68 68
69static int nntpdriver_cached_connect_stream(mailsession * session, 69static int nntpdriver_cached_connect_stream(mailsession * session,
70 mailstream * s); 70 mailstream * s);
71 71
72static int nntpdriver_cached_login(mailsession * session, 72static int nntpdriver_cached_login(mailsession * session,
73 char * userid, char * password); 73 char * userid, char * password);
74 74
75static int nntpdriver_cached_logout(mailsession * session); 75static int nntpdriver_cached_logout(mailsession * session);
76 76
77static int nntpdriver_cached_check_folder(mailsession * session); 77static int nntpdriver_cached_check_folder(mailsession * session);
78 78
79static int nntpdriver_cached_select_folder(mailsession * session, char * mb); 79static int nntpdriver_cached_select_folder(mailsession * session, char * mb);
80 80
81static int nntpdriver_cached_status_folder(mailsession * session, 81static int nntpdriver_cached_status_folder(mailsession * session,
82 char * mb, 82 char * mb,
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
87static int nntpdriver_cached_messages_number(mailsession * session, char * mb, 87static int nntpdriver_cached_messages_number(mailsession * session, char * mb,
88 uint32_t * result); 88 uint32_t * result);
89 89
90static int nntpdriver_cached_recent_number(mailsession * session, char * mb, 90static int nntpdriver_cached_recent_number(mailsession * session, char * mb,
91 uint32_t * result); 91 uint32_t * result);
92 92
93static int nntpdriver_cached_unseen_number(mailsession * session, char * mb, 93static int nntpdriver_cached_unseen_number(mailsession * session, char * mb,
94 uint32_t * result); 94 uint32_t * result);
95 95
96static int nntpdriver_cached_append_message(mailsession * session, 96static int nntpdriver_cached_append_message(mailsession * session,
97 char * message, size_t size); 97 char * message, size_t size);
98 98
99static int nntpdriver_cached_append_message_flags(mailsession * session,
100 char * message, size_t size, struct mail_flags * flags);
101
99static int 102static int
100nntpdriver_cached_get_envelopes_list(mailsession * session, 103nntpdriver_cached_get_envelopes_list(mailsession * session,
101 struct mailmessage_list * env_list); 104 struct mailmessage_list * env_list);
102 105
103 106
104static int 107static int
105nntpdriver_cached_get_messages_list(mailsession * session, 108nntpdriver_cached_get_messages_list(mailsession * session,
106 struct mailmessage_list ** result); 109 struct mailmessage_list ** result);
107 110
108static int nntpdriver_cached_list_folders(mailsession * session, char * mb, 111static int nntpdriver_cached_list_folders(mailsession * session, char * mb,
109 struct mail_list ** result); 112 struct mail_list ** result);
110 113
111static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb, 114static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb,
112 struct mail_list ** result); 115 struct mail_list ** result);
113 116
114static int nntpdriver_cached_subscribe_folder(mailsession * session, 117static int nntpdriver_cached_subscribe_folder(mailsession * session,
115 char * mb); 118 char * mb);
116 119
117static int nntpdriver_cached_unsubscribe_folder(mailsession * session, 120static int nntpdriver_cached_unsubscribe_folder(mailsession * session,
118 char * mb); 121 char * mb);
119 122
120static int nntpdriver_cached_get_message(mailsession * session, 123static int nntpdriver_cached_get_message(mailsession * session,
121 uint32_t num, mailmessage ** result); 124 uint32_t num, mailmessage ** result);
122 125
123static int nntpdriver_cached_noop(mailsession * session); 126static int nntpdriver_cached_noop(mailsession * session);
124 127
125static int nntpdriver_cached_get_message_by_uid(mailsession * session, 128static int nntpdriver_cached_get_message_by_uid(mailsession * session,
126 const char * uid, 129 const char * uid,
127 mailmessage ** result); 130 mailmessage ** result);
128 131
129static mailsession_driver local_nntp_cached_session_driver = { 132static mailsession_driver local_nntp_cached_session_driver = {
130 .sess_name = "nntp-cached", 133 .sess_name = "nntp-cached",
131 134
132 .sess_initialize = nntpdriver_cached_initialize, 135 .sess_initialize = nntpdriver_cached_initialize,
133 .sess_uninitialize = nntpdriver_cached_uninitialize, 136 .sess_uninitialize = nntpdriver_cached_uninitialize,
134 137
135 .sess_parameters = nntpdriver_cached_parameters, 138 .sess_parameters = nntpdriver_cached_parameters,
136 139
137 .sess_connect_stream = nntpdriver_cached_connect_stream, 140 .sess_connect_stream = nntpdriver_cached_connect_stream,
138 .sess_connect_path = NULL, 141 .sess_connect_path = NULL,
139 .sess_starttls = NULL, 142 .sess_starttls = NULL,
140 .sess_login = nntpdriver_cached_login, 143 .sess_login = nntpdriver_cached_login,
141 .sess_logout = nntpdriver_cached_logout, 144 .sess_logout = nntpdriver_cached_logout,
142 .sess_noop = nntpdriver_cached_noop, 145 .sess_noop = nntpdriver_cached_noop,
143 146
144 .sess_build_folder_name = NULL, 147 .sess_build_folder_name = NULL,
145 .sess_create_folder = NULL, 148 .sess_create_folder = NULL,
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
177mailsession_driver * nntp_cached_session_driver = 181mailsession_driver * nntp_cached_session_driver =
178&local_nntp_cached_session_driver; 182&local_nntp_cached_session_driver;
179 183
180#define ENV_NAME "env.db" 184#define ENV_NAME "env.db"
181#define FLAGS_NAME "flags.db" 185#define FLAGS_NAME "flags.db"
182 186
183 187
184 188
185static void read_article_seq(mailsession * session, 189static void read_article_seq(mailsession * session,
186 uint32_t * pfirst, uint32_t * plast); 190 uint32_t * pfirst, uint32_t * plast);
187 191
188static void write_article_seq(mailsession * session, 192static void write_article_seq(mailsession * session,
189 uint32_t first, uint32_t last); 193 uint32_t first, uint32_t last);
190 194
191 195
192static inline struct nntp_cached_session_state_data * 196static inline struct nntp_cached_session_state_data *
193get_cached_data(mailsession * session) 197get_cached_data(mailsession * session)
194{ 198{
195 return session->sess_data; 199 return session->sess_data;
196} 200}
197 201
198static inline mailsession * get_ancestor(mailsession * session) 202static inline mailsession * get_ancestor(mailsession * session)
199{ 203{
200 return get_cached_data(session)->nntp_ancestor; 204 return get_cached_data(session)->nntp_ancestor;
201} 205}
202 206
203static inline struct nntp_session_state_data * 207static inline struct nntp_session_state_data *
204get_ancestor_data(mailsession * session) 208get_ancestor_data(mailsession * session)
205{ 209{
206 return get_ancestor(session)->sess_data; 210 return get_ancestor(session)->sess_data;
207} 211}
208 212
209static inline newsnntp * get_nntp_session(mailsession * session) 213static inline newsnntp * get_nntp_session(mailsession * session)
210{ 214{
211 return get_ancestor_data(session)->nntp_session; 215 return get_ancestor_data(session)->nntp_session;
212} 216}
213 217
214static int nntpdriver_cached_initialize(mailsession * session) 218static int nntpdriver_cached_initialize(mailsession * session)
215{ 219{
216 struct nntp_cached_session_state_data * data; 220 struct nntp_cached_session_state_data * data;
217 221
218 data = malloc(sizeof(* data)); 222 data = malloc(sizeof(* data));
219 if (data == NULL) 223 if (data == NULL)
220 goto err; 224 goto err;
221 225
222 data->nntp_flags_store = mail_flags_store_new(); 226 data->nntp_flags_store = mail_flags_store_new();
223 if (data->nntp_flags_store == NULL) 227 if (data->nntp_flags_store == NULL)
224 goto free; 228 goto free;
225 229
226 data->nntp_ancestor = mailsession_new(nntp_session_driver); 230 data->nntp_ancestor = mailsession_new(nntp_session_driver);
227 if (data->nntp_ancestor == NULL) 231 if (data->nntp_ancestor == NULL)
228 goto free_store; 232 goto free_store;
229 233
230 session->sess_data = data; 234 session->sess_data = data;
231 235
232 return MAIL_NO_ERROR; 236 return MAIL_NO_ERROR;
233 237
234 free_store: 238 free_store:
235 mail_flags_store_free(data->nntp_flags_store); 239 mail_flags_store_free(data->nntp_flags_store);
236 free: 240 free:
237 free(data); 241 free(data);
238 err: 242 err:
239 return MAIL_ERROR_MEMORY; 243 return MAIL_ERROR_MEMORY;
240} 244}
241 245
242static int nntp_flags_store_process(char * flags_directory, char * group_name, 246static int nntp_flags_store_process(char * flags_directory, char * group_name,
243 struct mail_flags_store * flags_store) 247 struct mail_flags_store * flags_store)
244{ 248{
245 char filename_flags[PATH_MAX]; 249 char filename_flags[PATH_MAX];
246 struct mail_cache_db * cache_db_flags; 250 struct mail_cache_db * cache_db_flags;
247 MMAPString * mmapstr; 251 MMAPString * mmapstr;
248 unsigned int i; 252 unsigned int i;
249 int r; 253 int r;
250 int res; 254 int res;
251 255
252 if (carray_count(flags_store->fls_tab) == 0) 256 if (carray_count(flags_store->fls_tab) == 0)
253 return MAIL_NO_ERROR; 257 return MAIL_NO_ERROR;
254 258
255 if (group_name == NULL) 259 if (group_name == NULL)
256 return MAIL_NO_ERROR; 260 return MAIL_NO_ERROR;
257 261
258 snprintf(filename_flags, PATH_MAX, "%s/%s/%s", 262 snprintf(filename_flags, PATH_MAX, "%s/%s/%s",
259 flags_directory, group_name, FLAGS_NAME); 263 flags_directory, group_name, FLAGS_NAME);
260 264
261 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 265 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
262 if (r < 0) { 266 if (r < 0) {
263 res = MAIL_ERROR_FILE; 267 res = MAIL_ERROR_FILE;
264 goto err; 268 goto err;
265 } 269 }
266 270
267 mmapstr = mmap_string_new(""); 271 mmapstr = mmap_string_new("");
268 if (mmapstr == NULL) { 272 if (mmapstr == NULL) {
269 res = MAIL_ERROR_MEMORY; 273 res = MAIL_ERROR_MEMORY;
270 goto close_db_flags; 274 goto close_db_flags;
271 } 275 }
272 276
273 for(i = 0 ; i < carray_count(flags_store->fls_tab) ; i ++) { 277 for(i = 0 ; i < carray_count(flags_store->fls_tab) ; i ++) {
274 mailmessage * msg; 278 mailmessage * msg;
275 279
276 msg = carray_get(flags_store->fls_tab, i); 280 msg = carray_get(flags_store->fls_tab, i);
277 281
278 r = nntpdriver_write_cached_flags(cache_db_flags, mmapstr, 282 r = nntpdriver_write_cached_flags(cache_db_flags, mmapstr,
279 msg->msg_index, msg->msg_flags); 283 msg->msg_index, msg->msg_flags);
280 } 284 }
281 285
282 mmap_string_free(mmapstr); 286 mmap_string_free(mmapstr);
283 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 287 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
284 288
285 mail_flags_store_clear(flags_store); 289 mail_flags_store_clear(flags_store);
286 290
287 return MAIL_NO_ERROR; 291 return MAIL_NO_ERROR;
288 292
289 close_db_flags: 293 close_db_flags:
@@ -506,256 +510,262 @@ static int nntpdriver_cached_status_folder(mailsession * session,
506 510
507 count ++; 511 count ++;
508 if ((flags->fl_flags & MAIL_FLAG_NEW) != 0) { 512 if ((flags->fl_flags & MAIL_FLAG_NEW) != 0) {
509 recent ++; 513 recent ++;
510 } 514 }
511 if ((flags->fl_flags & MAIL_FLAG_SEEN) == 0) { 515 if ((flags->fl_flags & MAIL_FLAG_SEEN) == 0) {
512 unseen ++; 516 unseen ++;
513 } 517 }
514 mail_flags_free(flags); 518 mail_flags_free(flags);
515 } 519 }
516 } 520 }
517 521
518 if ((count == 0) && (first != last)) { 522 if ((count == 0) && (first != last)) {
519 count = last - first + 1; 523 count = last - first + 1;
520 recent = count; 524 recent = count;
521 unseen = count; 525 unseen = count;
522 } 526 }
523 527
524 additionnal = ancestor_data->nntp_group_info->grp_last - last; 528 additionnal = ancestor_data->nntp_group_info->grp_last - last;
525 recent += additionnal; 529 recent += additionnal;
526 unseen += additionnal; 530 unseen += additionnal;
527 531
528 mmap_string_free(mmapstr); 532 mmap_string_free(mmapstr);
529 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 533 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
530 534
531 * result_messages = count; 535 * result_messages = count;
532 * result_recent = recent; 536 * result_recent = recent;
533 * result_unseen = unseen; 537 * result_unseen = unseen;
534 538
535 return MAIL_NO_ERROR; 539 return MAIL_NO_ERROR;
536 540
537 close_db_flags: 541 close_db_flags:
538 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 542 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
539 err: 543 err:
540 return res; 544 return res;
541} 545}
542 546
543static int nntpdriver_cached_messages_number(mailsession * session, 547static int nntpdriver_cached_messages_number(mailsession * session,
544 char * mb, 548 char * mb,
545 uint32_t * result) 549 uint32_t * result)
546{ 550{
547 uint32_t messages; 551 uint32_t messages;
548 uint32_t recent; 552 uint32_t recent;
549 uint32_t unseen; 553 uint32_t unseen;
550 int r; 554 int r;
551 555
552 r = nntpdriver_cached_status_folder(session, mb, 556 r = nntpdriver_cached_status_folder(session, mb,
553 &messages, &recent, &unseen); 557 &messages, &recent, &unseen);
554 if (r != MAIL_NO_ERROR) 558 if (r != MAIL_NO_ERROR)
555 return r; 559 return r;
556 560
557 * result = messages; 561 * result = messages;
558 562
559 return MAIL_NO_ERROR; 563 return MAIL_NO_ERROR;
560} 564}
561 565
562static int nntpdriver_cached_recent_number(mailsession * session, 566static int nntpdriver_cached_recent_number(mailsession * session,
563 char * mb, 567 char * mb,
564 uint32_t * result) 568 uint32_t * result)
565{ 569{
566 uint32_t messages; 570 uint32_t messages;
567 uint32_t recent; 571 uint32_t recent;
568 uint32_t unseen; 572 uint32_t unseen;
569 int r; 573 int r;
570 574
571 r = nntpdriver_cached_status_folder(session, mb, 575 r = nntpdriver_cached_status_folder(session, mb,
572 &messages, &recent, &unseen); 576 &messages, &recent, &unseen);
573 if (r != MAIL_NO_ERROR) 577 if (r != MAIL_NO_ERROR)
574 return r; 578 return r;
575 579
576 * result = recent; 580 * result = recent;
577 581
578 return MAIL_NO_ERROR; 582 return MAIL_NO_ERROR;
579} 583}
580 584
581static int nntpdriver_cached_unseen_number(mailsession * session, 585static int nntpdriver_cached_unseen_number(mailsession * session,
582 char * mb, 586 char * mb,
583 uint32_t * result) 587 uint32_t * result)
584{ 588{
585 uint32_t messages; 589 uint32_t messages;
586 uint32_t recent; 590 uint32_t recent;
587 uint32_t unseen; 591 uint32_t unseen;
588 int r; 592 int r;
589 593
590 r = nntpdriver_cached_status_folder(session, mb, 594 r = nntpdriver_cached_status_folder(session, mb,
591 &messages, &recent, &unseen); 595 &messages, &recent, &unseen);
592 if (r != MAIL_NO_ERROR) 596 if (r != MAIL_NO_ERROR)
593 return r; 597 return r;
594 598
595 * result = unseen; 599 * result = unseen;
596 600
597 return MAIL_NO_ERROR; 601 return MAIL_NO_ERROR;
598} 602}
599 603
600static int nntpdriver_cached_list_folders(mailsession * session, char * mb, 604static int nntpdriver_cached_list_folders(mailsession * session, char * mb,
601 struct mail_list ** result) 605 struct mail_list ** result)
602{ 606{
603 return mailsession_list_folders(get_ancestor(session), mb, result); 607 return mailsession_list_folders(get_ancestor(session), mb, result);
604} 608}
605 609
606static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb, 610static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb,
607 struct mail_list ** result) 611 struct mail_list ** result)
608{ 612{
609 return mailsession_lsub_folders(get_ancestor(session), mb, result); 613 return mailsession_lsub_folders(get_ancestor(session), mb, result);
610} 614}
611 615
612static int nntpdriver_cached_subscribe_folder(mailsession * session, 616static int nntpdriver_cached_subscribe_folder(mailsession * session,
613 char * mb) 617 char * mb)
614{ 618{
615 return mailsession_subscribe_folder(get_ancestor(session), mb); 619 return mailsession_subscribe_folder(get_ancestor(session), mb);
616} 620}
617 621
618static int nntpdriver_cached_unsubscribe_folder(mailsession * session, 622static 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
628static int nntpdriver_cached_append_message(mailsession * session, 632static 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
638static 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
636static int 646static int
637get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, 647get_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) {
650 res = r; 660 res = r;
651 goto err; 661 goto err;
652 } 662 }
653 663
654 * result = fields; 664 * result = fields;
655 665
656 return MAIL_NO_ERROR; 666 return MAIL_NO_ERROR;
657 667
658 err: 668 err:
659 return res; 669 return res;
660} 670}
661 671
662static int 672static int
663write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, 673write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr,
664 mailsession * session, uint32_t num, 674 mailsession * session, uint32_t num,
665 struct mailimf_fields * fields) 675 struct mailimf_fields * fields)
666{ 676{
667 int r; 677 int r;
668 int res; 678 int res;
669 char keyname[PATH_MAX]; 679 char keyname[PATH_MAX];
670 680
671 snprintf(keyname, PATH_MAX, "%i-envelope", num); 681 snprintf(keyname, PATH_MAX, "%i-envelope", num);
672 682
673 r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields); 683 r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields);
674 if (r != MAIL_NO_ERROR) { 684 if (r != MAIL_NO_ERROR) {
675 res = r; 685 res = r;
676 goto err; 686 goto err;
677 } 687 }
678 688
679 return MAIL_NO_ERROR; 689 return MAIL_NO_ERROR;
680 690
681 err: 691 err:
682 return res; 692 return res;
683} 693}
684 694
685#define SEQ_FILENAME "articles-seq" 695#define SEQ_FILENAME "articles-seq"
686 696
687static void read_article_seq(mailsession * session, 697static void read_article_seq(mailsession * session,
688 uint32_t * pfirst, uint32_t * plast) 698 uint32_t * pfirst, uint32_t * plast)
689{ 699{
690 FILE * f; 700 FILE * f;
691 struct nntp_session_state_data * ancestor_data; 701 struct nntp_session_state_data * ancestor_data;
692 uint32_t first; 702 uint32_t first;
693 uint32_t last; 703 uint32_t last;
694 char seq_filename[PATH_MAX]; 704 char seq_filename[PATH_MAX];
695 struct nntp_cached_session_state_data * cached_data; 705 struct nntp_cached_session_state_data * cached_data;
696 int r; 706 int r;
697 707
698 first = 0; 708 first = 0;
699 last = 0; 709 last = 0;
700 710
701 cached_data = get_cached_data(session); 711 cached_data = get_cached_data(session);
702 ancestor_data = get_ancestor_data(session); 712 ancestor_data = get_ancestor_data(session);
703 713
704 if (ancestor_data->nntp_group_name == NULL) 714 if (ancestor_data->nntp_group_name == NULL)
705 return; 715 return;
706 716
707 snprintf(seq_filename, PATH_MAX, "%s/%s/%s", 717 snprintf(seq_filename, PATH_MAX, "%s/%s/%s",
708 cached_data->nntp_cache_directory, 718 cached_data->nntp_cache_directory,
709 ancestor_data->nntp_group_name, SEQ_FILENAME); 719 ancestor_data->nntp_group_name, SEQ_FILENAME);
710 f = fopen(seq_filename, "r"); 720 f = fopen(seq_filename, "r");
711 721
712 if (f != NULL) { 722 if (f != NULL) {
713 int fd; 723 int fd;
714 724
715 fd = fileno(f); 725 fd = fileno(f);
716 726
717 r = maillock_read_lock(seq_filename, fd); 727 r = maillock_read_lock(seq_filename, fd);
718 if (r == 0) { 728 if (r == 0) {
719 MMAPString * mmapstr; 729 MMAPString * mmapstr;
720 size_t cur_token; 730 size_t cur_token;
721 char buf[sizeof(uint32_t) * 2]; 731 char buf[sizeof(uint32_t) * 2];
722 size_t read_size; 732 size_t read_size;
723 733
724 read_size = fread(buf, 1, sizeof(uint32_t) * 2, f); 734 read_size = fread(buf, 1, sizeof(uint32_t) * 2, f);
725 mmapstr = mmap_string_new_len(buf, read_size); 735 mmapstr = mmap_string_new_len(buf, read_size);
726 if (mmapstr != NULL) { 736 if (mmapstr != NULL) {
727 cur_token = 0; 737 cur_token = 0;
728 r = mailimf_cache_int_read(mmapstr, &cur_token, &first); 738 r = mailimf_cache_int_read(mmapstr, &cur_token, &first);
729 r = mailimf_cache_int_read(mmapstr, &cur_token, &last); 739 r = mailimf_cache_int_read(mmapstr, &cur_token, &last);
730 740
731 mmap_string_free(mmapstr); 741 mmap_string_free(mmapstr);
732 } 742 }
733 743
734 maillock_read_unlock(seq_filename, fd); 744 maillock_read_unlock(seq_filename, fd);
735 } 745 }
736 fclose(f); 746 fclose(f);
737 } 747 }
738 748
739 * pfirst = first; 749 * pfirst = first;
740 * plast = last; 750 * plast = last;
741} 751}
742 752
743static void write_article_seq(mailsession * session, 753static void write_article_seq(mailsession * session,
744 uint32_t first, uint32_t last) 754 uint32_t first, uint32_t last)
745{ 755{
746 FILE * f; 756 FILE * f;
747 struct nntp_session_state_data * ancestor_data; 757 struct nntp_session_state_data * ancestor_data;
748 char seq_filename[PATH_MAX]; 758 char seq_filename[PATH_MAX];
749 struct nntp_cached_session_state_data * cached_data; 759 struct nntp_cached_session_state_data * cached_data;
750 int r; 760 int r;
751 int fd; 761 int fd;
752 762
753 cached_data = get_cached_data(session); 763 cached_data = get_cached_data(session);
754 ancestor_data = get_ancestor_data(session); 764 ancestor_data = get_ancestor_data(session);
755 765
756 if (ancestor_data->nntp_group_name == NULL) 766 if (ancestor_data->nntp_group_name == NULL)
757 return; 767 return;
758 768
759 snprintf(seq_filename, PATH_MAX, "%s/%s/%s", 769 snprintf(seq_filename, PATH_MAX, "%s/%s/%s",
760 cached_data->nntp_cache_directory, 770 cached_data->nntp_cache_directory,
761 ancestor_data->nntp_group_name, SEQ_FILENAME); 771 ancestor_data->nntp_group_name, SEQ_FILENAME);
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
@@ -1,202 +1,202 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "nntpstorage.h" 36#include "nntpstorage.h"
37 37
38#include <stdlib.h> 38#include <stdlib.h>
39#include <string.h> 39#include <string.h>
40 40
41#include "maildriver.h" 41#include "maildriver.h"
42#include "nntpdriver.h" 42#include "nntpdriver.h"
43#include "nntpdriver_cached.h" 43#include "nntpdriver_cached.h"
44#include "mailstorage_tools.h" 44#include "mailstorage_tools.h"
45#include "mail.h" 45#include "mail.h"
46 46
47/* nntp storage */ 47/* nntp storage */
48 48
49#define NNTP_DEFAULT_PORT 119 49#define NNTP_DEFAULT_PORT 119
50#define NNTPS_DEFAULT_PORT 563 50#define NNTPS_DEFAULT_PORT 563
51 51
52static int nntp_mailstorage_connect(struct mailstorage * storage); 52static int nntp_mailstorage_connect(struct mailstorage * storage);
53static int nntp_mailstorage_get_folder_session(struct mailstorage * storage, 53static int nntp_mailstorage_get_folder_session(struct mailstorage * storage,
54 char * pathname, mailsession ** result); 54 char * pathname, mailsession ** result);
55static void nntp_mailstorage_uninitialize(struct mailstorage * storage); 55static void nntp_mailstorage_uninitialize(struct mailstorage * storage);
56 56
57static mailstorage_driver nntp_mailstorage_driver = { 57static 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
64int nntp_mailstorage_init(struct mailstorage * storage, 64int 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:
91 case CONNECTION_TYPE_COMMAND: 91 case CONNECTION_TYPE_COMMAND:
92 nn_port = NNTP_DEFAULT_PORT; 92 nn_port = NNTP_DEFAULT_PORT;
93 break; 93 break;
94 94
95 case CONNECTION_TYPE_TLS: 95 case CONNECTION_TYPE_TLS:
96 case CONNECTION_TYPE_COMMAND_TLS: 96 case CONNECTION_TYPE_COMMAND_TLS:
97 nn_port = NNTPS_DEFAULT_PORT; 97 nn_port = NNTPS_DEFAULT_PORT;
98 break; 98 break;
99 99
100 default: 100 default:
101 res = MAIL_ERROR_INVAL; 101 res = MAIL_ERROR_INVAL;
102 goto free_servername; 102 goto free_servername;
103 } 103 }
104 } 104 }
105 105
106 nntp_storage->nntp_port = nn_port; 106 nntp_storage->nntp_port = nn_port;
107 107
108 if (nn_command != NULL) { 108 if (nn_command != NULL) {
109 nntp_storage->nntp_command = strdup(nn_command); 109 nntp_storage->nntp_command = strdup(nn_command);
110 if (nntp_storage->nntp_command == NULL) { 110 if (nntp_storage->nntp_command == NULL) {
111 res = MAIL_ERROR_MEMORY; 111 res = MAIL_ERROR_MEMORY;
112 goto free_servername; 112 goto free_servername;
113 } 113 }
114 } 114 }
115 else 115 else
116 nntp_storage->nntp_command = NULL; 116 nntp_storage->nntp_command = NULL;
117 117
118 nntp_storage->nntp_auth_type = nn_auth_type; 118 nntp_storage->nntp_auth_type = nn_auth_type;
119 119
120 if (nn_login != NULL) { 120 if (nn_login != NULL) {
121 nntp_storage->nntp_login = strdup(nn_login); 121 nntp_storage->nntp_login = strdup(nn_login);
122 if (nntp_storage->nntp_login == NULL) { 122 if (nntp_storage->nntp_login == NULL) {
123 res = MAIL_ERROR_MEMORY; 123 res = MAIL_ERROR_MEMORY;
124 goto free_command; 124 goto free_command;
125 } 125 }
126 } 126 }
127 else 127 else
128 nntp_storage->nntp_login = NULL; 128 nntp_storage->nntp_login = NULL;
129 129
130 if (nn_password != NULL) { 130 if (nn_password != NULL) {
131 nntp_storage->nntp_password = strdup(nn_password); 131 nntp_storage->nntp_password = strdup(nn_password);
132 if (nntp_storage->nntp_password == NULL) { 132 if (nntp_storage->nntp_password == NULL) {
133 res = MAIL_ERROR_MEMORY; 133 res = MAIL_ERROR_MEMORY;
134 goto free_login; 134 goto free_login;
135 } 135 }
136 } 136 }
137 else 137 else
138 nntp_storage->nntp_password = NULL; 138 nntp_storage->nntp_password = NULL;
139 139
140 nntp_storage->nntp_cached = nn_cached; 140 nntp_storage->nntp_cached = nn_cached;
141 141
142 if (nn_cached && (nn_cache_directory != NULL) && 142 if (nn_cached && (nn_cache_directory != NULL) &&
143 (nn_flags_directory != NULL)) { 143 (nn_flags_directory != NULL)) {
144 nntp_storage->nntp_cache_directory = strdup(nn_cache_directory); 144 nntp_storage->nntp_cache_directory = strdup(nn_cache_directory);
145 if (nntp_storage->nntp_cache_directory == NULL) { 145 if (nntp_storage->nntp_cache_directory == NULL) {
146 res = MAIL_ERROR_MEMORY; 146 res = MAIL_ERROR_MEMORY;
147 goto free_password; 147 goto free_password;
148 } 148 }
149 nntp_storage->nntp_flags_directory = strdup(nn_flags_directory); 149 nntp_storage->nntp_flags_directory = strdup(nn_flags_directory);
150 if (nntp_storage->nntp_flags_directory == NULL) { 150 if (nntp_storage->nntp_flags_directory == NULL) {
151 res = MAIL_ERROR_MEMORY; 151 res = MAIL_ERROR_MEMORY;
152 goto free_cache_directory; 152 goto free_cache_directory;
153 } 153 }
154 } 154 }
155 else { 155 else {
156 nntp_storage->nntp_cached = FALSE; 156 nntp_storage->nntp_cached = FALSE;
157 nntp_storage->nntp_cache_directory = NULL; 157 nntp_storage->nntp_cache_directory = NULL;
158 nntp_storage->nntp_flags_directory = NULL; 158 nntp_storage->nntp_flags_directory = NULL;
159 } 159 }
160 160
161 storage->sto_data = nntp_storage; 161 storage->sto_data = nntp_storage;
162 storage->sto_driver = &nntp_mailstorage_driver; 162 storage->sto_driver = &nntp_mailstorage_driver;
163 163
164 return MAIL_NO_ERROR; 164 return MAIL_NO_ERROR;
165 165
166 free_cache_directory: 166 free_cache_directory:
167 free(nntp_storage->nntp_cache_directory); 167 free(nntp_storage->nntp_cache_directory);
168 free_password: 168 free_password:
169 free(nntp_storage->nntp_password); 169 free(nntp_storage->nntp_password);
170 free_login: 170 free_login:
171 free(nntp_storage->nntp_login); 171 free(nntp_storage->nntp_login);
172 free_command: 172 free_command:
173 free(nn_command); 173 free(nn_command);
174 free_servername: 174 free_servername:
175 free(nntp_storage->nntp_servername); 175 free(nntp_storage->nntp_servername);
176 free: 176 free:
177 free(nntp_storage); 177 free(nntp_storage);
178 err: 178 err:
179 return res; 179 return res;
180} 180}
181 181
182static void nntp_mailstorage_uninitialize(struct mailstorage * storage) 182static void nntp_mailstorage_uninitialize(struct mailstorage * storage)
183{ 183{
184 struct nntp_mailstorage * nntp_storage; 184 struct nntp_mailstorage * nntp_storage;
185 185
186 nntp_storage = storage->sto_data; 186 nntp_storage = storage->sto_data;
187 187
188 if (nntp_storage->nntp_flags_directory != NULL) 188 if (nntp_storage->nntp_flags_directory != NULL)
189 free(nntp_storage->nntp_flags_directory); 189 free(nntp_storage->nntp_flags_directory);
190 if (nntp_storage->nntp_cache_directory != NULL) 190 if (nntp_storage->nntp_cache_directory != NULL)
191 free(nntp_storage->nntp_cache_directory); 191 free(nntp_storage->nntp_cache_directory);
192 if (nntp_storage->nntp_password != NULL) 192 if (nntp_storage->nntp_password != NULL)
193 free(nntp_storage->nntp_password); 193 free(nntp_storage->nntp_password);
194 if (nntp_storage->nntp_login != NULL) 194 if (nntp_storage->nntp_login != NULL)
195 free(nntp_storage->nntp_login); 195 free(nntp_storage->nntp_login);
196 if (nntp_storage->nntp_command != NULL) 196 if (nntp_storage->nntp_command != NULL)
197 free(nntp_storage->nntp_command); 197 free(nntp_storage->nntp_command);
198 free(nntp_storage->nntp_servername); 198 free(nntp_storage->nntp_servername);
199 free(nntp_storage); 199 free(nntp_storage);
200 200
201 storage->sto_data = NULL; 201 storage->sto_data = NULL;
202} 202}
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
@@ -1,239 +1,240 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "pop3driver.h" 36#include "pop3driver.h"
37 37
38#include <string.h> 38#include <string.h>
39#include <stdlib.h> 39#include <stdlib.h>
40 40
41#include "pop3driver_message.h" 41#include "pop3driver_message.h"
42#include "maildriver_tools.h" 42#include "maildriver_tools.h"
43#include "pop3driver_tools.h" 43#include "pop3driver_tools.h"
44#include "mailmessage.h" 44#include "mailmessage.h"
45 45
46static int pop3driver_initialize(mailsession * session); 46static int pop3driver_initialize(mailsession * session);
47 47
48static void pop3driver_uninitialize(mailsession * session); 48static void pop3driver_uninitialize(mailsession * session);
49 49
50static int pop3driver_parameters(mailsession * session, 50static int pop3driver_parameters(mailsession * session,
51 int id, void * value); 51 int id, void * value);
52 52
53static int pop3driver_connect_stream(mailsession * session, mailstream * s); 53static int pop3driver_connect_stream(mailsession * session, mailstream * s);
54 54
55static int pop3driver_starttls(mailsession * session); 55static int pop3driver_starttls(mailsession * session);
56 56
57static int pop3driver_login(mailsession * session, 57static int pop3driver_login(mailsession * session,
58 char * userid, char * password); 58 char * userid, char * password);
59 59
60static int pop3driver_logout(mailsession * session); 60static int pop3driver_logout(mailsession * session);
61 61
62static int pop3driver_noop(mailsession * session); 62static int pop3driver_noop(mailsession * session);
63 63
64static int pop3driver_status_folder(mailsession * session, char * mb, 64static int pop3driver_status_folder(mailsession * session, char * mb,
65 uint32_t * result_messages, uint32_t * result_recent, 65 uint32_t * result_messages, uint32_t * result_recent,
66 uint32_t * result_unseen); 66 uint32_t * result_unseen);
67 67
68static int pop3driver_messages_number(mailsession * session, char * mb, 68static int pop3driver_messages_number(mailsession * session, char * mb,
69 uint32_t * result); 69 uint32_t * result);
70 70
71static int pop3driver_remove_message(mailsession * session, uint32_t num); 71static int pop3driver_remove_message(mailsession * session, uint32_t num);
72 72
73static int pop3driver_get_messages_list(mailsession * session, 73static int pop3driver_get_messages_list(mailsession * session,
74 struct mailmessage_list ** result); 74 struct mailmessage_list ** result);
75 75
76static int pop3driver_get_message(mailsession * session, 76static int pop3driver_get_message(mailsession * session,
77 uint32_t num, mailmessage ** result); 77 uint32_t num, mailmessage ** result);
78 78
79static mailsession_driver local_pop3_session_driver = { 79static mailsession_driver local_pop3_session_driver = {
80 .sess_name = "pop3", 80 .sess_name = "pop3",
81 81
82 .sess_initialize = pop3driver_initialize, 82 .sess_initialize = pop3driver_initialize,
83 .sess_uninitialize = pop3driver_uninitialize, 83 .sess_uninitialize = pop3driver_uninitialize,
84 84
85 .sess_parameters = pop3driver_parameters, 85 .sess_parameters = pop3driver_parameters,
86 86
87 .sess_connect_stream = pop3driver_connect_stream, 87 .sess_connect_stream = pop3driver_connect_stream,
88 .sess_connect_path = NULL, 88 .sess_connect_path = NULL,
89 .sess_starttls = pop3driver_starttls, 89 .sess_starttls = pop3driver_starttls,
90 .sess_login = pop3driver_login, 90 .sess_login = pop3driver_login,
91 .sess_logout = pop3driver_logout, 91 .sess_logout = pop3driver_logout,
92 .sess_noop = pop3driver_noop, 92 .sess_noop = pop3driver_noop,
93 93
94 .sess_build_folder_name = NULL, 94 .sess_build_folder_name = NULL,
95 .sess_create_folder = NULL, 95 .sess_create_folder = NULL,
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
126mailsession_driver * pop3_session_driver = &local_pop3_session_driver; 127mailsession_driver * pop3_session_driver = &local_pop3_session_driver;
127 128
128static inline struct pop3_session_state_data * 129static inline struct pop3_session_state_data *
129get_data(mailsession * session) 130get_data(mailsession * session)
130{ 131{
131 return session->sess_data; 132 return session->sess_data;
132} 133}
133 134
134static mailpop3 * get_pop3_session(mailsession * session) 135static mailpop3 * get_pop3_session(mailsession * session)
135{ 136{
136 return get_data(session)->pop3_session; 137 return get_data(session)->pop3_session;
137} 138}
138 139
139static int pop3driver_initialize(mailsession * session) 140static int pop3driver_initialize(mailsession * session)
140{ 141{
141 struct pop3_session_state_data * data; 142 struct pop3_session_state_data * data;
142 mailpop3 * pop3; 143 mailpop3 * pop3;
143 144
144 pop3 = mailpop3_new(0, NULL); 145 pop3 = mailpop3_new(0, NULL);
145 if (session == NULL) 146 if (session == NULL)
146 goto err; 147 goto err;
147 148
148 data = malloc(sizeof(* data)); 149 data = malloc(sizeof(* data));
149 if (data == NULL) 150 if (data == NULL)
150 goto free; 151 goto free;
151 152
152 data->pop3_session = pop3; 153 data->pop3_session = pop3;
153 data->pop3_auth_type = POP3DRIVER_AUTH_TYPE_PLAIN; 154 data->pop3_auth_type = POP3DRIVER_AUTH_TYPE_PLAIN;
154 155
155 session->sess_data = data; 156 session->sess_data = data;
156 157
157 return MAIL_NO_ERROR; 158 return MAIL_NO_ERROR;
158 159
159 free: 160 free:
160 mailpop3_free(pop3); 161 mailpop3_free(pop3);
161 err: 162 err:
162 return MAIL_ERROR_MEMORY; 163 return MAIL_ERROR_MEMORY;
163} 164}
164 165
165static void pop3driver_uninitialize(mailsession * session) 166static void pop3driver_uninitialize(mailsession * session)
166{ 167{
167 struct pop3_session_state_data * data; 168 struct pop3_session_state_data * data;
168 169
169 data = get_data(session); 170 data = get_data(session);
170 171
171 mailpop3_free(data->pop3_session); 172 mailpop3_free(data->pop3_session);
172 free(data); 173 free(data);
173 174
174 session->sess_data = data; 175 session->sess_data = data;
175} 176}
176 177
177static int pop3driver_connect_stream(mailsession * session, mailstream * s) 178static int pop3driver_connect_stream(mailsession * session, mailstream * s)
178{ 179{
179 int r; 180 int r;
180 181
181 r = mailpop3_connect(get_pop3_session(session), s); 182 r = mailpop3_connect(get_pop3_session(session), s);
182 183
183 switch (r) { 184 switch (r) {
184 case MAILPOP3_NO_ERROR: 185 case MAILPOP3_NO_ERROR:
185 return MAIL_NO_ERROR_NON_AUTHENTICATED; 186 return MAIL_NO_ERROR_NON_AUTHENTICATED;
186 187
187 default: 188 default:
188 return pop3driver_pop3_error_to_mail_error(r); 189 return pop3driver_pop3_error_to_mail_error(r);
189 } 190 }
190} 191}
191 192
192static int pop3driver_starttls(mailsession * session) 193static int pop3driver_starttls(mailsession * session)
193{ 194{
194 int r; 195 int r;
195 int fd; 196 int fd;
196 mailstream_low * low; 197 mailstream_low * low;
197 mailstream_low * new_low; 198 mailstream_low * new_low;
198 mailpop3 * pop3; 199 mailpop3 * pop3;
199 200
200 pop3 = get_pop3_session(session); 201 pop3 = get_pop3_session(session);
201 202
202 r = mailpop3_stls(pop3); 203 r = mailpop3_stls(pop3);
203 204
204 switch (r) { 205 switch (r) {
205 case MAILPOP3_NO_ERROR: 206 case MAILPOP3_NO_ERROR:
206 break; 207 break;
207 default: 208 default:
208 return pop3driver_pop3_error_to_mail_error(r); 209 return pop3driver_pop3_error_to_mail_error(r);
209 } 210 }
210 211
211 low = mailstream_get_low(pop3->pop3_stream); 212 low = mailstream_get_low(pop3->pop3_stream);
212 fd = mailstream_low_get_fd(low); 213 fd = mailstream_low_get_fd(low);
213 if (fd == -1) 214 if (fd == -1)
214 return MAIL_ERROR_STREAM; 215 return MAIL_ERROR_STREAM;
215 216
216 new_low = mailstream_low_ssl_open(fd); 217 new_low = mailstream_low_ssl_open(fd);
217 if (new_low == NULL) 218 if (new_low == NULL)
218 return MAIL_ERROR_STREAM; 219 return MAIL_ERROR_STREAM;
219 mailstream_low_free(low); 220 mailstream_low_free(low);
220 mailstream_set_low(pop3->pop3_stream, new_low); 221 mailstream_set_low(pop3->pop3_stream, new_low);
221 222
222 return MAIL_NO_ERROR; 223 return MAIL_NO_ERROR;
223} 224}
224 225
225static int pop3driver_parameters(mailsession * session, 226static int pop3driver_parameters(mailsession * session,
226 int id, void * value) 227 int id, void * value)
227{ 228{
228 struct pop3_session_state_data * data; 229 struct pop3_session_state_data * data;
229 230
230 data = get_data(session); 231 data = get_data(session);
231 232
232 switch (id) { 233 switch (id) {
233 case POP3DRIVER_SET_AUTH_TYPE: 234 case POP3DRIVER_SET_AUTH_TYPE:
234 { 235 {
235 int * param; 236 int * param;
236 237
237 param = value; 238 param = value;
238 239
239 data->pop3_auth_type = * param; 240 data->pop3_auth_type = * param;
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
@@ -1,285 +1,289 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "pop3driver_cached.h" 36#include "pop3driver_cached.h"
37 37
38#include "libetpan-config.h" 38#include "libetpan-config.h"
39 39
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/stat.h> 41#include <sys/stat.h>
42#include <fcntl.h> 42#include <fcntl.h>
43#include <string.h> 43#include <string.h>
44#include <unistd.h> 44#include <unistd.h>
45#include <stdlib.h> 45#include <stdlib.h>
46 46
47#include "mail.h" 47#include "mail.h"
48#include "mail_cache_db.h" 48#include "mail_cache_db.h"
49 49
50#include "maildriver.h" 50#include "maildriver.h"
51#include "mailmessage.h" 51#include "mailmessage.h"
52#include "pop3driver.h" 52#include "pop3driver.h"
53#include "mailpop3.h" 53#include "mailpop3.h"
54#include "generic_cache.h" 54#include "generic_cache.h"
55#include "imfcache.h" 55#include "imfcache.h"
56#include "pop3driver_cached_message.h" 56#include "pop3driver_cached_message.h"
57#include "pop3driver_tools.h" 57#include "pop3driver_tools.h"
58#include "maildriver_tools.h" 58#include "maildriver_tools.h"
59 59
60static int pop3driver_cached_initialize(mailsession * session); 60static int pop3driver_cached_initialize(mailsession * session);
61 61
62static void pop3driver_cached_uninitialize(mailsession * session); 62static void pop3driver_cached_uninitialize(mailsession * session);
63 63
64static int pop3driver_cached_parameters(mailsession * session, 64static int pop3driver_cached_parameters(mailsession * session,
65 int id, void * value); 65 int id, void * value);
66 66
67static int pop3driver_cached_connect_stream(mailsession * session, 67static int pop3driver_cached_connect_stream(mailsession * session,
68 mailstream * s); 68 mailstream * s);
69 69
70static int pop3driver_cached_starttls(mailsession * session); 70static int pop3driver_cached_starttls(mailsession * session);
71 71
72static int pop3driver_cached_login(mailsession * session, 72static int pop3driver_cached_login(mailsession * session,
73 char * userid, char * password); 73 char * userid, char * password);
74 74
75static int pop3driver_cached_logout(mailsession * session); 75static int pop3driver_cached_logout(mailsession * session);
76 76
77static int pop3driver_cached_check_folder(mailsession * session); 77static int pop3driver_cached_check_folder(mailsession * session);
78 78
79static int pop3driver_cached_noop(mailsession * session); 79static int pop3driver_cached_noop(mailsession * session);
80 80
81static int pop3driver_cached_expunge_folder(mailsession * session); 81static int pop3driver_cached_expunge_folder(mailsession * session);
82 82
83static int pop3driver_cached_status_folder(mailsession * session, 83static int pop3driver_cached_status_folder(mailsession * session,
84 char * mb, uint32_t * result_messages, uint32_t * result_recent, 84 char * mb, uint32_t * result_messages, uint32_t * result_recent,
85 uint32_t * result_unseen); 85 uint32_t * result_unseen);
86 86
87static int pop3driver_cached_messages_number(mailsession * session, 87static int pop3driver_cached_messages_number(mailsession * session,
88 char * mb, 88 char * mb,
89 uint32_t * result); 89 uint32_t * result);
90 90
91static int pop3driver_cached_recent_number(mailsession * session, 91static int pop3driver_cached_recent_number(mailsession * session,
92 char * mb, 92 char * mb,
93 uint32_t * result); 93 uint32_t * result);
94 94
95static int pop3driver_cached_unseen_number(mailsession * session, 95static int pop3driver_cached_unseen_number(mailsession * session,
96 char * mb, 96 char * mb,
97 uint32_t * result); 97 uint32_t * result);
98 98
99static int pop3driver_cached_remove_message(mailsession * session, 99static int pop3driver_cached_remove_message(mailsession * session,
100 uint32_t num); 100 uint32_t num);
101 101
102static int 102static int
103pop3driver_cached_get_messages_list(mailsession * session, 103pop3driver_cached_get_messages_list(mailsession * session,
104 struct mailmessage_list ** result); 104 struct mailmessage_list ** result);
105 105
106static int 106static int
107pop3driver_cached_get_envelopes_list(mailsession * session, 107pop3driver_cached_get_envelopes_list(mailsession * session,
108 struct mailmessage_list * env_list); 108 struct mailmessage_list * env_list);
109 109
110static int pop3driver_cached_get_message(mailsession * session, 110static int pop3driver_cached_get_message(mailsession * session,
111 uint32_t num, mailmessage ** result); 111 uint32_t num, mailmessage ** result);
112 112
113static int pop3driver_cached_get_message_by_uid(mailsession * session,
114 const char * uid, mailmessage ** result);
115
113static mailsession_driver local_pop3_cached_session_driver = { 116static 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,
129 .sess_create_folder = NULL, 132 .sess_create_folder = NULL,
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
160mailsession_driver * pop3_cached_session_driver = 164mailsession_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
167static inline struct pop3_cached_session_state_data * 171static inline struct pop3_cached_session_state_data *
168get_cached_data(mailsession * session) 172get_cached_data(mailsession * session)
169{ 173{
170 return session->sess_data; 174 return session->sess_data;
171} 175}
172 176
173static inline mailsession * get_ancestor(mailsession * session) 177static inline mailsession * get_ancestor(mailsession * session)
174{ 178{
175 return get_cached_data(session)->pop3_ancestor; 179 return get_cached_data(session)->pop3_ancestor;
176} 180}
177 181
178static inline struct pop3_session_state_data * 182static inline struct pop3_session_state_data *
179get_ancestor_data(mailsession * session) 183get_ancestor_data(mailsession * session)
180{ 184{
181 return get_ancestor(session)->sess_data; 185 return get_ancestor(session)->sess_data;
182} 186}
183 187
184static inline mailpop3 * get_pop3_session(mailsession * session) 188static inline mailpop3 * get_pop3_session(mailsession * session)
185{ 189{
186 return get_ancestor_data(session)->pop3_session; 190 return get_ancestor_data(session)->pop3_session;
187} 191}
188 192
189static int pop3driver_cached_initialize(mailsession * session) 193static int pop3driver_cached_initialize(mailsession * session)
190{ 194{
191 struct pop3_cached_session_state_data * data; 195 struct pop3_cached_session_state_data * data;
192 196
193 data = malloc(sizeof(* data)); 197 data = malloc(sizeof(* data));
194 if (data == NULL) 198 if (data == NULL)
195 goto err; 199 goto err;
196 200
197 data->pop3_flags_store = mail_flags_store_new(); 201 data->pop3_flags_store = mail_flags_store_new();
198 if (data->pop3_flags_store == NULL) 202 if (data->pop3_flags_store == NULL)
199 goto free_data; 203 goto free_data;
200 204
201 data->pop3_ancestor = mailsession_new(pop3_session_driver); 205 data->pop3_ancestor = mailsession_new(pop3_session_driver);
202 if (data->pop3_ancestor == NULL) 206 if (data->pop3_ancestor == NULL)
203 goto free_store; 207 goto free_store;
204 208
205 data->pop3_flags_hash = chash_new(128, CHASH_COPYNONE); 209 data->pop3_flags_hash = chash_new(128, CHASH_COPYNONE);
206 if (data->pop3_flags_hash == NULL) 210 if (data->pop3_flags_hash == NULL)
207 goto free_session; 211 goto free_session;
208 212
209 session->sess_data = data; 213 session->sess_data = data;
210 214
211 return MAIL_NO_ERROR; 215 return MAIL_NO_ERROR;
212 216
213 free_session: 217 free_session:
214 mailsession_free(data->pop3_ancestor); 218 mailsession_free(data->pop3_ancestor);
215 free_store: 219 free_store:
216 mail_flags_store_free(data->pop3_flags_store); 220 mail_flags_store_free(data->pop3_flags_store);
217 free_data: 221 free_data:
218 free(data); 222 free(data);
219 err: 223 err:
220 return MAIL_ERROR_MEMORY; 224 return MAIL_ERROR_MEMORY;
221} 225}
222 226
223static int pop3_flags_store_process(char * flags_directory, 227static int pop3_flags_store_process(char * flags_directory,
224 struct mail_flags_store * flags_store) 228 struct mail_flags_store * flags_store)
225{ 229{
226 char filename_flags[PATH_MAX]; 230 char filename_flags[PATH_MAX];
227 struct mail_cache_db * cache_db_flags; 231 struct mail_cache_db * cache_db_flags;
228 MMAPString * mmapstr; 232 MMAPString * mmapstr;
229 unsigned int i; 233 unsigned int i;
230 int r; 234 int r;
231 int res; 235 int res;
232 236
233 if (carray_count(flags_store->fls_tab) == 0) 237 if (carray_count(flags_store->fls_tab) == 0)
234 return MAIL_NO_ERROR; 238 return MAIL_NO_ERROR;
235 239
236 snprintf(filename_flags, PATH_MAX, "%s/%s", 240 snprintf(filename_flags, PATH_MAX, "%s/%s",
237 flags_directory, FLAGS_NAME); 241 flags_directory, FLAGS_NAME);
238 242
239 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 243 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
240 if (r < 0) { 244 if (r < 0) {
241 res = MAIL_ERROR_FILE; 245 res = MAIL_ERROR_FILE;
242 goto err; 246 goto err;
243 } 247 }
244 248
245 mmapstr = mmap_string_new(""); 249 mmapstr = mmap_string_new("");
246 if (mmapstr == NULL) { 250 if (mmapstr == NULL) {
247 res = MAIL_ERROR_MEMORY; 251 res = MAIL_ERROR_MEMORY;
248 goto close_db_flags; 252 goto close_db_flags;
249 } 253 }
250 254
251 for(i = 0 ; i < carray_count(flags_store->fls_tab) ; i ++) { 255 for(i = 0 ; i < carray_count(flags_store->fls_tab) ; i ++) {
252 mailmessage * msg; 256 mailmessage * msg;
253 257
254 msg = carray_get(flags_store->fls_tab, i); 258 msg = carray_get(flags_store->fls_tab, i);
255 259
256 r = pop3driver_write_cached_flags(cache_db_flags, mmapstr, 260 r = pop3driver_write_cached_flags(cache_db_flags, mmapstr,
257 msg->msg_uid, msg->msg_flags); 261 msg->msg_uid, msg->msg_flags);
258 } 262 }
259 263
260 mmap_string_free(mmapstr); 264 mmap_string_free(mmapstr);
261 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 265 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
262 266
263 mail_flags_store_clear(flags_store); 267 mail_flags_store_clear(flags_store);
264 268
265 return MAIL_NO_ERROR; 269 return MAIL_NO_ERROR;
266 270
267 close_db_flags: 271 close_db_flags:
268 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 272 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
269 err: 273 err:
270 return res; 274 return res;
271} 275}
272 276
273static void pop3driver_cached_uninitialize(mailsession * session) 277static void pop3driver_cached_uninitialize(mailsession * session)
274{ 278{
275 struct pop3_cached_session_state_data * data; 279 struct pop3_cached_session_state_data * data;
276 280
277 data = get_cached_data(session); 281 data = get_cached_data(session);
278 282
279 pop3_flags_store_process(data->pop3_flags_directory, 283 pop3_flags_store_process(data->pop3_flags_directory,
280 data->pop3_flags_store); 284 data->pop3_flags_store);
281 285
282 mail_flags_store_free(data->pop3_flags_store); 286 mail_flags_store_free(data->pop3_flags_store);
283 287
284 chash_free(data->pop3_flags_hash); 288 chash_free(data->pop3_flags_hash);
285 mailsession_free(data->pop3_ancestor); 289 mailsession_free(data->pop3_ancestor);
@@ -730,128 +734,166 @@ pop3driver_cached_get_envelopes_list(mailsession * session,
730 if (r < 0) { 734 if (r < 0) {
731 res = MAIL_ERROR_MEMORY; 735 res = MAIL_ERROR_MEMORY;
732 goto close_db_env; 736 goto close_db_env;
733 } 737 }
734 738
735 /* fill with cached */ 739 /* fill with cached */
736 740
737 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 741 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
738 mailmessage * msg; 742 mailmessage * msg;
739 struct mailimf_fields * fields; 743 struct mailimf_fields * fields;
740 struct mail_flags * flags; 744 struct mail_flags * flags;
741 745
742 msg = carray_get(env_list->msg_tab, i); 746 msg = carray_get(env_list->msg_tab, i);
743 747
744 if (msg->msg_fields == NULL) { 748 if (msg->msg_fields == NULL) {
745 r = get_cached_envelope(cache_db_env, mmapstr, 749 r = get_cached_envelope(cache_db_env, mmapstr,
746 session, msg->msg_index, &fields); 750 session, msg->msg_index, &fields);
747 if (r == MAIL_NO_ERROR) { 751 if (r == MAIL_NO_ERROR) {
748 msg->msg_cached = TRUE; 752 msg->msg_cached = TRUE;
749 msg->msg_fields = fields; 753 msg->msg_fields = fields;
750 } 754 }
751 } 755 }
752 756
753 if (msg->msg_flags == NULL) { 757 if (msg->msg_flags == NULL) {
754 r = pop3driver_get_cached_flags(cache_db_flags, mmapstr, 758 r = pop3driver_get_cached_flags(cache_db_flags, mmapstr,
755 session, msg->msg_index, &flags); 759 session, msg->msg_index, &flags);
756 if (r == MAIL_NO_ERROR) { 760 if (r == MAIL_NO_ERROR) {
757 msg->msg_flags = flags; 761 msg->msg_flags = flags;
758 } 762 }
759 } 763 }
760 } 764 }
761 765
762 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 766 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
763 mail_cache_db_close_unlock(filename_env, cache_db_env); 767 mail_cache_db_close_unlock(filename_env, cache_db_env);
764 768
765 r = maildriver_generic_get_envelopes_list(session, env_list); 769 r = maildriver_generic_get_envelopes_list(session, env_list);
766 770
767 if (r != MAIL_NO_ERROR) { 771 if (r != MAIL_NO_ERROR) {
768 res = r; 772 res = r;
769 goto free_mmapstr; 773 goto free_mmapstr;
770 } 774 }
771 775
772 /* add flags */ 776 /* add flags */
773 777
774 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 778 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
775 mailmessage * msg; 779 mailmessage * msg;
776 780
777 msg = carray_get(env_list->msg_tab, i); 781 msg = carray_get(env_list->msg_tab, i);
778 782
779 if (msg->msg_flags == NULL) 783 if (msg->msg_flags == NULL)
780 msg->msg_flags = mail_flags_new_empty(); 784 msg->msg_flags = mail_flags_new_empty();
781 } 785 }
782 786
783 r = mail_cache_db_open_lock(filename_env, &cache_db_env); 787 r = mail_cache_db_open_lock(filename_env, &cache_db_env);
784 if (r < 0) { 788 if (r < 0) {
785 res = MAIL_ERROR_MEMORY; 789 res = MAIL_ERROR_MEMORY;
786 goto free_mmapstr; 790 goto free_mmapstr;
787 } 791 }
788 792
789 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); 793 r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
790 if (r < 0) { 794 if (r < 0) {
791 res = MAIL_ERROR_MEMORY; 795 res = MAIL_ERROR_MEMORY;
792 goto close_db_env; 796 goto close_db_env;
793 } 797 }
794 798
795 /* must write cache */ 799 /* must write cache */
796 800
797 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { 801 for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
798 mailmessage * msg; 802 mailmessage * msg;
799 803
800 msg = carray_get(env_list->msg_tab, i); 804 msg = carray_get(env_list->msg_tab, i);
801 805
802 if (msg->msg_fields != NULL) { 806 if (msg->msg_fields != NULL) {
803 if (!msg->msg_cached) { 807 if (!msg->msg_cached) {
804 r = write_cached_envelope(cache_db_env, mmapstr, 808 r = write_cached_envelope(cache_db_env, mmapstr,
805 session, msg->msg_index, msg->msg_fields); 809 session, msg->msg_index, msg->msg_fields);
806 } 810 }
807 } 811 }
808 812
809 if (msg->msg_flags != NULL) { 813 if (msg->msg_flags != NULL) {
810 r = pop3driver_write_cached_flags(cache_db_flags, mmapstr, 814 r = pop3driver_write_cached_flags(cache_db_flags, mmapstr,
811 msg->msg_uid, msg->msg_flags); 815 msg->msg_uid, msg->msg_flags);
812 } 816 }
813 } 817 }
814 818
815 /* flush cache */ 819 /* flush cache */
816 820
817 maildriver_cache_clean_up(cache_db_env, cache_db_flags, env_list); 821 maildriver_cache_clean_up(cache_db_env, cache_db_flags, env_list);
818 822
819 mail_cache_db_close_unlock(filename_flags, cache_db_flags); 823 mail_cache_db_close_unlock(filename_flags, cache_db_flags);
820 mail_cache_db_close_unlock(filename_env, cache_db_env); 824 mail_cache_db_close_unlock(filename_env, cache_db_env);
821 mmap_string_free(mmapstr); 825 mmap_string_free(mmapstr);
822 826
823 /* remove cache files */ 827 /* remove cache files */
824 828
825 maildriver_message_cache_clean_up(cached_data->pop3_cache_directory, 829 maildriver_message_cache_clean_up(cached_data->pop3_cache_directory,
826 env_list, get_uid_from_filename); 830 env_list, get_uid_from_filename);
827 831
828 return MAIL_NO_ERROR; 832 return MAIL_NO_ERROR;
829 833
830 close_db_env: 834 close_db_env:
831 mail_cache_db_close_unlock(filename_env, cache_db_env); 835 mail_cache_db_close_unlock(filename_env, cache_db_env);
832 free_mmapstr: 836 free_mmapstr:
833 mmap_string_free(mmapstr); 837 mmap_string_free(mmapstr);
834 err: 838 err:
835 return res; 839 return res;
836} 840}
837 841
838static int pop3driver_cached_get_message(mailsession * session, 842static int pop3driver_cached_get_message(mailsession * session,
839 uint32_t num, mailmessage ** result) 843 uint32_t num, mailmessage ** result)
840{ 844{
841 mailmessage * msg_info; 845 mailmessage * msg_info;
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
863static 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
@@ -1,159 +1,193 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "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
43static int pop3_prefetch(mailmessage * msg_info); 45static int pop3_prefetch(mailmessage * msg_info);
44 46
45static void pop3_prefetch_free(struct generic_message_t * msg); 47static void pop3_prefetch_free(struct generic_message_t * msg);
46 48
47static int pop3_initialize(mailmessage * msg_info); 49static int pop3_initialize(mailmessage * msg_info);
48 50
49static int pop3_fetch_header(mailmessage * msg_info, 51static 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
53static int pop3_fetch_size(mailmessage * msg_info, 55static int pop3_fetch_size(mailmessage * msg_info,
54 size_t * result); 56 size_t * result);
55 57
56static mailmessage_driver local_pop3_message_driver = { 58static mailmessage_driver local_pop3_message_driver = {
57 .msg_name = "pop3", 59 .msg_name = "pop3",
58 60
59 .msg_initialize = pop3_initialize, 61 .msg_initialize = pop3_initialize,
60 .msg_uninitialize = mailmessage_generic_uninitialize, 62 .msg_uninitialize = mailmessage_generic_uninitialize,
61 63
62 .msg_flush = mailmessage_generic_flush, 64 .msg_flush = mailmessage_generic_flush,
63 .msg_check = NULL, 65 .msg_check = NULL,
64 66
65 .msg_fetch_result_free = mailmessage_generic_fetch_result_free, 67 .msg_fetch_result_free = mailmessage_generic_fetch_result_free,
66 68
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
81mailmessage_driver * pop3_message_driver = &local_pop3_message_driver; 83mailmessage_driver * pop3_message_driver = &local_pop3_message_driver;
82 84
85static inline struct pop3_session_state_data *
86get_data(mailsession * session)
87{
88 return session->sess_data;
89}
90
91
92static mailpop3 * get_pop3_session(mailsession * session)
93{
94 return get_data(session)->pop3_session;
95}
96
83 97
84static int pop3_prefetch(mailmessage * msg_info) 98static 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;
99 msg->msg_length = msg_length; 113 msg->msg_length = msg_length;
100 114
101 return MAIL_NO_ERROR; 115 return MAIL_NO_ERROR;
102} 116}
103 117
104static void pop3_prefetch_free(struct generic_message_t * msg) 118static 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
112static int pop3_initialize(mailmessage * msg_info) 126static 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
129static int pop3_fetch_header(mailmessage * msg_info, 163static 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
140 if (msg->msg_message != NULL) 174 if (msg->msg_message != NULL)
141 return mailmessage_generic_fetch_header(msg_info, 175 return mailmessage_generic_fetch_header(msg_info,
142 result, result_len); 176 result, result_len);
143 177
144 r = pop3driver_header(msg_info->msg_session, msg_info->msg_index, 178 r = pop3driver_header(msg_info->msg_session, msg_info->msg_index,
145 &headers, &headers_length); 179 &headers, &headers_length);
146 if (r != MAIL_NO_ERROR) 180 if (r != MAIL_NO_ERROR)
147 return r; 181 return r;
148 182
149 * result = headers; 183 * result = headers;
150 * result_len = headers_length; 184 * result_len = headers_length;
151 185
152 return MAIL_NO_ERROR; 186 return MAIL_NO_ERROR;
153} 187}
154 188
155static int pop3_fetch_size(mailmessage * msg_info, 189static int pop3_fetch_size(mailmessage * msg_info,
156 size_t * result) 190 size_t * result)
157{ 191{
158 return pop3driver_size(msg_info->msg_session, msg_info->msg_index, result); 192 return pop3driver_size(msg_info->msg_session, msg_info->msg_index, result);
159} 193}
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
@@ -1,199 +1,199 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "pop3storage.h" 36#include "pop3storage.h"
37 37
38#include <stdlib.h> 38#include <stdlib.h>
39#include <string.h> 39#include <string.h>
40 40
41#include "mail.h" 41#include "mail.h"
42#include "mailstorage_tools.h" 42#include "mailstorage_tools.h"
43#include "maildriver.h" 43#include "maildriver.h"
44 44
45/* pop3 storage */ 45/* pop3 storage */
46 46
47#define POP3_DEFAULT_PORT 110 47#define POP3_DEFAULT_PORT 110
48#define POP3S_DEFAULT_PORT 995 48#define POP3S_DEFAULT_PORT 995
49 49
50static int pop3_mailstorage_connect(struct mailstorage * storage); 50static int pop3_mailstorage_connect(struct mailstorage * storage);
51static int pop3_mailstorage_get_folder_session(struct mailstorage * storage, 51static int pop3_mailstorage_get_folder_session(struct mailstorage * storage,
52 char * pathname, mailsession ** result); 52 char * pathname, mailsession ** result);
53static void pop3_mailstorage_uninitialize(struct mailstorage * storage); 53static void pop3_mailstorage_uninitialize(struct mailstorage * storage);
54 54
55static mailstorage_driver pop3_mailstorage_driver = { 55static 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
62int pop3_mailstorage_init(struct mailstorage * storage, 62int 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:
88 case CONNECTION_TYPE_COMMAND_STARTTLS: 88 case CONNECTION_TYPE_COMMAND_STARTTLS:
89 pop3_port = POP3_DEFAULT_PORT; 89 pop3_port = POP3_DEFAULT_PORT;
90 break; 90 break;
91 91
92 case CONNECTION_TYPE_TLS: 92 case CONNECTION_TYPE_TLS:
93 case CONNECTION_TYPE_COMMAND_TLS: 93 case CONNECTION_TYPE_COMMAND_TLS:
94 pop3_port = POP3S_DEFAULT_PORT; 94 pop3_port = POP3S_DEFAULT_PORT;
95 break; 95 break;
96 } 96 }
97 } 97 }
98 98
99 pop3_storage->pop3_port = pop3_port; 99 pop3_storage->pop3_port = pop3_port;
100 100
101 if (pop3_command != NULL) { 101 if (pop3_command != NULL) {
102 pop3_storage->pop3_command = strdup(pop3_command); 102 pop3_storage->pop3_command = strdup(pop3_command);
103 if (pop3_storage->pop3_command == NULL) 103 if (pop3_storage->pop3_command == NULL)
104 goto free_servername; 104 goto free_servername;
105 } 105 }
106 else 106 else
107 pop3_storage->pop3_command = NULL; 107 pop3_storage->pop3_command = NULL;
108 108
109 pop3_storage->pop3_auth_type = pop3_auth_type; 109 pop3_storage->pop3_auth_type = pop3_auth_type;
110 110
111 if (pop3_login != NULL) { 111 if (pop3_login != NULL) {
112 pop3_storage->pop3_login = strdup(pop3_login); 112 pop3_storage->pop3_login = strdup(pop3_login);
113 if (pop3_storage->pop3_login == NULL) 113 if (pop3_storage->pop3_login == NULL)
114 goto free_command; 114 goto free_command;
115 } 115 }
116 else 116 else
117 pop3_storage->pop3_login = NULL; 117 pop3_storage->pop3_login = NULL;
118 118
119 if (pop3_password != NULL) { 119 if (pop3_password != NULL) {
120 pop3_storage->pop3_password = strdup(pop3_password); 120 pop3_storage->pop3_password = strdup(pop3_password);
121 if (pop3_storage->pop3_password == NULL) 121 if (pop3_storage->pop3_password == NULL)
122 goto free_login; 122 goto free_login;
123 } 123 }
124 else 124 else
125 pop3_storage->pop3_password = NULL; 125 pop3_storage->pop3_password = NULL;
126 126
127 pop3_storage->pop3_cached = pop3_cached; 127 pop3_storage->pop3_cached = pop3_cached;
128 128
129 if (pop3_cached && (pop3_cache_directory != NULL) && 129 if (pop3_cached && (pop3_cache_directory != NULL) &&
130 (pop3_flags_directory != NULL)) { 130 (pop3_flags_directory != NULL)) {
131 pop3_storage->pop3_cache_directory = strdup(pop3_cache_directory); 131 pop3_storage->pop3_cache_directory = strdup(pop3_cache_directory);
132 if (pop3_storage->pop3_cache_directory == NULL) 132 if (pop3_storage->pop3_cache_directory == NULL)
133 goto free_password; 133 goto free_password;
134 pop3_storage->pop3_flags_directory = strdup(pop3_flags_directory); 134 pop3_storage->pop3_flags_directory = strdup(pop3_flags_directory);
135 if (pop3_storage->pop3_flags_directory == NULL) 135 if (pop3_storage->pop3_flags_directory == NULL)
136 goto free_cache_directory; 136 goto free_cache_directory;
137 } 137 }
138 else { 138 else {
139 pop3_storage->pop3_cached = FALSE; 139 pop3_storage->pop3_cached = FALSE;
140 pop3_storage->pop3_cache_directory = NULL; 140 pop3_storage->pop3_cache_directory = NULL;
141 pop3_storage->pop3_flags_directory = NULL; 141 pop3_storage->pop3_flags_directory = NULL;
142 } 142 }
143 143
144 storage->sto_data = pop3_storage; 144 storage->sto_data = pop3_storage;
145 storage->sto_driver = &pop3_mailstorage_driver; 145 storage->sto_driver = &pop3_mailstorage_driver;
146 146
147 return MAIL_NO_ERROR; 147 return MAIL_NO_ERROR;
148 148
149 free_cache_directory: 149 free_cache_directory:
150 free(pop3_storage->pop3_cache_directory); 150 free(pop3_storage->pop3_cache_directory);
151 free_password: 151 free_password:
152 if (pop3_storage->pop3_password != NULL) 152 if (pop3_storage->pop3_password != NULL)
153 free(pop3_storage->pop3_password); 153 free(pop3_storage->pop3_password);
154 free_login: 154 free_login:
155 if (pop3_storage->pop3_login != NULL) 155 if (pop3_storage->pop3_login != NULL)
156 free(pop3_storage->pop3_login); 156 free(pop3_storage->pop3_login);
157 free_command: 157 free_command:
158 if (pop3_storage->pop3_command != NULL) 158 if (pop3_storage->pop3_command != NULL)
159 free(pop3_storage->pop3_command); 159 free(pop3_storage->pop3_command);
160 free_servername: 160 free_servername:
161 if (pop3_storage->pop3_servername != NULL) 161 if (pop3_storage->pop3_servername != NULL)
162 free(pop3_storage->pop3_servername); 162 free(pop3_storage->pop3_servername);
163 free: 163 free:
164 free(pop3_storage); 164 free(pop3_storage);
165 err: 165 err:
166 return MAIL_ERROR_MEMORY; 166 return MAIL_ERROR_MEMORY;
167} 167}
168 168
169static void pop3_mailstorage_uninitialize(struct mailstorage * storage) 169static void pop3_mailstorage_uninitialize(struct mailstorage * storage)
170{ 170{
171 struct pop3_mailstorage * pop3_storage; 171 struct pop3_mailstorage * pop3_storage;
172 172
173 pop3_storage = storage->sto_data; 173 pop3_storage = storage->sto_data;
174 174
175 if (pop3_storage->pop3_flags_directory != NULL) 175 if (pop3_storage->pop3_flags_directory != NULL)
176 free(pop3_storage->pop3_flags_directory); 176 free(pop3_storage->pop3_flags_directory);
177 if (pop3_storage->pop3_cache_directory != NULL) 177 if (pop3_storage->pop3_cache_directory != NULL)
178 free(pop3_storage->pop3_cache_directory); 178 free(pop3_storage->pop3_cache_directory);
179 if (pop3_storage->pop3_password != NULL) 179 if (pop3_storage->pop3_password != NULL)
180 free(pop3_storage->pop3_password); 180 free(pop3_storage->pop3_password);
181 if (pop3_storage->pop3_login != NULL) 181 if (pop3_storage->pop3_login != NULL)
182 free(pop3_storage->pop3_login); 182 free(pop3_storage->pop3_login);
183 if (pop3_storage->pop3_command != NULL) 183 if (pop3_storage->pop3_command != NULL)
184 free(pop3_storage->pop3_command); 184 free(pop3_storage->pop3_command);
185 free(pop3_storage->pop3_servername); 185 free(pop3_storage->pop3_servername);
186 free(pop3_storage); 186 free(pop3_storage);
187 187
188 storage->sto_data = pop3_storage; 188 storage->sto_data = pop3_storage;
189} 189}
190 190
191static int pop3_mailstorage_connect(struct mailstorage * storage) 191static int pop3_mailstorage_connect(struct mailstorage * storage)
192{ 192{
193 struct pop3_mailstorage * pop3_storage; 193 struct pop3_mailstorage * pop3_storage;
194 mailsession_driver * driver; 194 mailsession_driver * driver;
195 int r; 195 int r;
196 int res; 196 int res;
197 mailsession * session; 197 mailsession * session;
198 int auth_type; 198 int auth_type;
199 199
diff --git a/kmicromail/libetpan/imap/mailimap.c b/kmicromail/libetpan/imap/mailimap.c
index c8fbfee..76d9454 100644
--- a/kmicromail/libetpan/imap/mailimap.c
+++ b/kmicromail/libetpan/imap/mailimap.c
@@ -1782,257 +1782,257 @@ mailimap_store(mailimap * session,
1782 return MAILIMAP_ERROR_STREAM; 1782 return MAILIMAP_ERROR_STREAM;
1783 1783
1784 if (read_line(session) == NULL) 1784 if (read_line(session) == NULL)
1785 return MAILIMAP_ERROR_STREAM; 1785 return MAILIMAP_ERROR_STREAM;
1786 1786
1787 r = parse_response(session, &response); 1787 r = parse_response(session, &response);
1788 if (r != MAILIMAP_NO_ERROR) 1788 if (r != MAILIMAP_NO_ERROR)
1789 return r; 1789 return r;
1790 1790
1791 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type; 1791 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
1792 1792
1793 mailimap_response_free(response); 1793 mailimap_response_free(response);
1794 1794
1795 switch (error_code) { 1795 switch (error_code) {
1796 case MAILIMAP_RESP_COND_STATE_OK: 1796 case MAILIMAP_RESP_COND_STATE_OK:
1797 return MAILIMAP_NO_ERROR; 1797 return MAILIMAP_NO_ERROR;
1798 1798
1799 default: 1799 default:
1800 return MAILIMAP_ERROR_STORE; 1800 return MAILIMAP_ERROR_STORE;
1801 } 1801 }
1802} 1802}
1803 1803
1804int 1804int
1805mailimap_uid_store(mailimap * session, 1805mailimap_uid_store(mailimap * session,
1806 struct mailimap_set * set, 1806 struct mailimap_set * set,
1807 struct mailimap_store_att_flags * store_att_flags) 1807 struct mailimap_store_att_flags * store_att_flags)
1808{ 1808{
1809 struct mailimap_response * response; 1809 struct mailimap_response * response;
1810 int r; 1810 int r;
1811 int error_code; 1811 int error_code;
1812 1812
1813 if (session->imap_state != MAILIMAP_STATE_SELECTED) 1813 if (session->imap_state != MAILIMAP_STATE_SELECTED)
1814 return MAILIMAP_ERROR_BAD_STATE; 1814 return MAILIMAP_ERROR_BAD_STATE;
1815 1815
1816 r = send_current_tag(session); 1816 r = send_current_tag(session);
1817 if (r != MAILIMAP_NO_ERROR) 1817 if (r != MAILIMAP_NO_ERROR)
1818 return r; 1818 return r;
1819 1819
1820 r = mailimap_uid_store_send(session->imap_stream, set, store_att_flags); 1820 r = mailimap_uid_store_send(session->imap_stream, set, store_att_flags);
1821 if (r != MAILIMAP_NO_ERROR) 1821 if (r != MAILIMAP_NO_ERROR)
1822 return r; 1822 return r;
1823 1823
1824 r = mailimap_crlf_send(session->imap_stream); 1824 r = mailimap_crlf_send(session->imap_stream);
1825 if (r != MAILIMAP_NO_ERROR) 1825 if (r != MAILIMAP_NO_ERROR)
1826 return r; 1826 return r;
1827 1827
1828 if (mailstream_flush(session->imap_stream) == -1) 1828 if (mailstream_flush(session->imap_stream) == -1)
1829 return MAILIMAP_ERROR_STREAM; 1829 return MAILIMAP_ERROR_STREAM;
1830 1830
1831 if (read_line(session) == NULL) 1831 if (read_line(session) == NULL)
1832 return MAILIMAP_ERROR_STREAM; 1832 return MAILIMAP_ERROR_STREAM;
1833 1833
1834 r = parse_response(session, &response); 1834 r = parse_response(session, &response);
1835 if (r != MAILIMAP_NO_ERROR) 1835 if (r != MAILIMAP_NO_ERROR)
1836 return r; 1836 return r;
1837 1837
1838 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type; 1838 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
1839 1839
1840 mailimap_response_free(response); 1840 mailimap_response_free(response);
1841 1841
1842 switch (error_code) { 1842 switch (error_code) {
1843 case MAILIMAP_RESP_COND_STATE_OK: 1843 case MAILIMAP_RESP_COND_STATE_OK:
1844 return MAILIMAP_NO_ERROR; 1844 return MAILIMAP_NO_ERROR;
1845 1845
1846 default: 1846 default:
1847 return MAILIMAP_ERROR_UID_STORE; 1847 return MAILIMAP_ERROR_UID_STORE;
1848 } 1848 }
1849} 1849}
1850 1850
1851int mailimap_subscribe(mailimap * session, const char * mb) 1851int mailimap_subscribe(mailimap * session, const char * mb)
1852{ 1852{
1853 struct mailimap_response * response; 1853 struct mailimap_response * response;
1854 int r; 1854 int r;
1855 int error_code; 1855 int error_code;
1856 1856
1857 if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) && 1857 if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
1858 (session->imap_state != MAILIMAP_STATE_SELECTED)) 1858 (session->imap_state != MAILIMAP_STATE_SELECTED))
1859 return MAILIMAP_ERROR_BAD_STATE; 1859 return MAILIMAP_ERROR_BAD_STATE;
1860 1860
1861 r = send_current_tag(session); 1861 r = send_current_tag(session);
1862 if (r != MAILIMAP_NO_ERROR) 1862 if (r != MAILIMAP_NO_ERROR)
1863 return r; 1863 return r;
1864 1864
1865 r = mailimap_subscribe_send(session->imap_stream, mb); 1865 r = mailimap_subscribe_send(session->imap_stream, mb);
1866 if (r != MAILIMAP_NO_ERROR) 1866 if (r != MAILIMAP_NO_ERROR)
1867 return r; 1867 return r;
1868 1868
1869 r = mailimap_crlf_send(session->imap_stream); 1869 r = mailimap_crlf_send(session->imap_stream);
1870 if (r != MAILIMAP_NO_ERROR) 1870 if (r != MAILIMAP_NO_ERROR)
1871 return r; 1871 return r;
1872 1872
1873 if (mailstream_flush(session->imap_stream) == -1) 1873 if (mailstream_flush(session->imap_stream) == -1)
1874 return MAILIMAP_ERROR_STREAM; 1874 return MAILIMAP_ERROR_STREAM;
1875 1875
1876 if (read_line(session) == NULL) 1876 if (read_line(session) == NULL)
1877 return MAILIMAP_ERROR_STREAM; 1877 return MAILIMAP_ERROR_STREAM;
1878 1878
1879 r = parse_response(session, &response); 1879 r = parse_response(session, &response);
1880 if (r != MAILIMAP_NO_ERROR) 1880 if (r != MAILIMAP_NO_ERROR)
1881 return r; 1881 return r;
1882 1882
1883 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type; 1883 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
1884 1884
1885 mailimap_response_free(response); 1885 mailimap_response_free(response);
1886 1886
1887 switch (error_code) { 1887 switch (error_code) {
1888 case MAILIMAP_RESP_COND_STATE_OK: 1888 case MAILIMAP_RESP_COND_STATE_OK:
1889 return MAILIMAP_NO_ERROR; 1889 return MAILIMAP_NO_ERROR;
1890 1890
1891 default: 1891 default:
1892 return MAILIMAP_ERROR_SUBSCRIBE; 1892 return MAILIMAP_ERROR_SUBSCRIBE;
1893 } 1893 }
1894} 1894}
1895 1895
1896int mailimap_unsubscribe(mailimap * session, const char * mb) 1896int mailimap_unsubscribe(mailimap * session, const char * mb)
1897{ 1897{
1898 struct mailimap_response * response; 1898 struct mailimap_response * response;
1899 int r; 1899 int r;
1900 int error_code; 1900 int error_code;
1901 1901
1902 if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) && 1902 if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
1903 (session->imap_state != MAILIMAP_STATE_SELECTED)) 1903 (session->imap_state != MAILIMAP_STATE_SELECTED))
1904 return MAILIMAP_ERROR_BAD_STATE; 1904 return MAILIMAP_ERROR_BAD_STATE;
1905 1905
1906 r = send_current_tag(session); 1906 r = send_current_tag(session);
1907 if (r != MAILIMAP_NO_ERROR) 1907 if (r != MAILIMAP_NO_ERROR)
1908 return r; 1908 return r;
1909 1909
1910 r = mailimap_subscribe_send(session->imap_stream, mb); 1910 r = mailimap_unsubscribe_send(session->imap_stream, mb);
1911 if (r != MAILIMAP_NO_ERROR) 1911 if (r != MAILIMAP_NO_ERROR)
1912 return r; 1912 return r;
1913 1913
1914 r = mailimap_crlf_send(session->imap_stream); 1914 r = mailimap_crlf_send(session->imap_stream);
1915 if (r != MAILIMAP_NO_ERROR) 1915 if (r != MAILIMAP_NO_ERROR)
1916 return r; 1916 return r;
1917 1917
1918 if (mailstream_flush(session->imap_stream) == -1) 1918 if (mailstream_flush(session->imap_stream) == -1)
1919 return MAILIMAP_ERROR_STREAM; 1919 return MAILIMAP_ERROR_STREAM;
1920 1920
1921 if (read_line(session) == NULL) 1921 if (read_line(session) == NULL)
1922 return MAILIMAP_ERROR_STREAM; 1922 return MAILIMAP_ERROR_STREAM;
1923 1923
1924 r = parse_response(session, &response); 1924 r = parse_response(session, &response);
1925 if (r != MAILIMAP_NO_ERROR) 1925 if (r != MAILIMAP_NO_ERROR)
1926 return r; 1926 return r;
1927 1927
1928 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type; 1928 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
1929 1929
1930 mailimap_response_free(response); 1930 mailimap_response_free(response);
1931 1931
1932 switch (error_code) { 1932 switch (error_code) {
1933 case MAILIMAP_RESP_COND_STATE_OK: 1933 case MAILIMAP_RESP_COND_STATE_OK:
1934 return MAILIMAP_NO_ERROR; 1934 return MAILIMAP_NO_ERROR;
1935 1935
1936 default: 1936 default:
1937 return MAILIMAP_ERROR_UNSUBSCRIBE; 1937 return MAILIMAP_ERROR_UNSUBSCRIBE;
1938 } 1938 }
1939} 1939}
1940 1940
1941 1941
1942int mailimap_starttls(mailimap * session) 1942int mailimap_starttls(mailimap * session)
1943{ 1943{
1944 struct mailimap_response * response; 1944 struct mailimap_response * response;
1945 int r; 1945 int r;
1946 int error_code; 1946 int error_code;
1947 1947
1948 r = send_current_tag(session); 1948 r = send_current_tag(session);
1949 if (r != MAILIMAP_NO_ERROR) 1949 if (r != MAILIMAP_NO_ERROR)
1950 return r; 1950 return r;
1951 1951
1952 r = mailimap_starttls_send(session->imap_stream); 1952 r = mailimap_starttls_send(session->imap_stream);
1953 if (r != MAILIMAP_NO_ERROR) 1953 if (r != MAILIMAP_NO_ERROR)
1954 return r; 1954 return r;
1955 1955
1956 r = mailimap_crlf_send(session->imap_stream); 1956 r = mailimap_crlf_send(session->imap_stream);
1957 if (r != MAILIMAP_NO_ERROR) 1957 if (r != MAILIMAP_NO_ERROR)
1958 return r; 1958 return r;
1959 1959
1960 if (mailstream_flush(session->imap_stream) == -1) 1960 if (mailstream_flush(session->imap_stream) == -1)
1961 return MAILIMAP_ERROR_STREAM; 1961 return MAILIMAP_ERROR_STREAM;
1962 1962
1963 if (read_line(session) == NULL) 1963 if (read_line(session) == NULL)
1964 return MAILIMAP_ERROR_STREAM; 1964 return MAILIMAP_ERROR_STREAM;
1965 1965
1966 r = parse_response(session, &response); 1966 r = parse_response(session, &response);
1967 if (r != MAILIMAP_NO_ERROR) 1967 if (r != MAILIMAP_NO_ERROR)
1968 return r; 1968 return r;
1969 1969
1970 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type; 1970 error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
1971 1971
1972 mailimap_response_free(response); 1972 mailimap_response_free(response);
1973 1973
1974 switch (error_code) { 1974 switch (error_code) {
1975 case MAILIMAP_RESP_COND_STATE_OK: 1975 case MAILIMAP_RESP_COND_STATE_OK:
1976 return MAILIMAP_NO_ERROR; 1976 return MAILIMAP_NO_ERROR;
1977 1977
1978 default: 1978 default:
1979 return MAILIMAP_ERROR_STARTTLS; 1979 return MAILIMAP_ERROR_STARTTLS;
1980 } 1980 }
1981} 1981}
1982 1982
1983 1983
1984 1984
1985static char * read_line(mailimap * session) 1985static char * read_line(mailimap * session)
1986{ 1986{
1987 return mailstream_read_line(session->imap_stream, session->imap_stream_buffer); 1987 return mailstream_read_line(session->imap_stream, session->imap_stream_buffer);
1988} 1988}
1989 1989
1990static int send_current_tag(mailimap * session) 1990static int send_current_tag(mailimap * session)
1991{ 1991{
1992 char tag_str[15]; 1992 char tag_str[15];
1993 int r; 1993 int r;
1994 1994
1995 session->imap_tag ++; 1995 session->imap_tag ++;
1996 snprintf(tag_str, 15, "%i", session->imap_tag); 1996 snprintf(tag_str, 15, "%i", session->imap_tag);
1997 1997
1998 r = mailimap_tag_send(session->imap_stream, tag_str); 1998 r = mailimap_tag_send(session->imap_stream, tag_str);
1999 if (r != MAILIMAP_NO_ERROR) 1999 if (r != MAILIMAP_NO_ERROR)
2000 return r; 2000 return r;
2001 2001
2002 r = mailimap_space_send(session->imap_stream); 2002 r = mailimap_space_send(session->imap_stream);
2003 if (r != MAILIMAP_NO_ERROR) 2003 if (r != MAILIMAP_NO_ERROR)
2004 return r; 2004 return r;
2005 2005
2006 return MAILIMAP_NO_ERROR; 2006 return MAILIMAP_NO_ERROR;
2007} 2007}
2008 2008
2009static int parse_response(mailimap * session, 2009static int parse_response(mailimap * session,
2010 struct mailimap_response ** result) 2010 struct mailimap_response ** result)
2011{ 2011{
2012 size_t index; 2012 size_t index;
2013 struct mailimap_response * response; 2013 struct mailimap_response * response;
2014 char tag_str[15]; 2014 char tag_str[15];
2015 int r; 2015 int r;
2016 2016
2017 index = 0; 2017 index = 0;
2018 2018
2019 session->imap_response = NULL; 2019 session->imap_response = NULL;
2020 2020
2021 r = mailimap_response_parse(session->imap_stream, 2021 r = mailimap_response_parse(session->imap_stream,
2022 session->imap_stream_buffer, 2022 session->imap_stream_buffer,
2023 &index, &response, 2023 &index, &response,
2024 session->imap_progr_rate, session->imap_progr_fun); 2024 session->imap_progr_rate, session->imap_progr_fun);
2025 if (r != MAILIMAP_NO_ERROR) 2025 if (r != MAILIMAP_NO_ERROR)
2026 return r; 2026 return r;
2027 2027
2028#if 0 2028#if 0
2029 mailimap_response_print(response); 2029 mailimap_response_print(response);
2030#endif 2030#endif
2031 2031
2032 response_store(session, response); 2032 response_store(session, response);
2033 2033
2034 if (mmap_string_assign(session->imap_response_buffer, 2034 if (mmap_string_assign(session->imap_response_buffer,
2035 response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_text->rsp_text) 2035 response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_text->rsp_text)
2036 == NULL) 2036 == NULL)
2037 return MAILIMAP_ERROR_MEMORY; 2037 return MAILIMAP_ERROR_MEMORY;
2038 2038
diff --git a/kmicromail/libetpan/imap/mailimap_keywords.c b/kmicromail/libetpan/imap/mailimap_keywords.c
index b277aed..4ec156e 100644
--- a/kmicromail/libetpan/imap/mailimap_keywords.c
+++ b/kmicromail/libetpan/imap/mailimap_keywords.c
@@ -1,184 +1,184 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "mailimap_keywords.h" 36#include "mailimap_keywords.h"
37#include "mailimap_types.h" 37#include "mailimap_types.h"
38#include <string.h> 38#include <string.h>
39#include <stdio.h> 39#include <stdio.h>
40 40
41#ifndef UNSTRICT_SYNTAX 41#ifndef UNSTRICT_SYNTAX
42#define UNSTRICT_SYNTAX 42#define UNSTRICT_SYNTAX
43#endif 43#endif
44 44
45struct mailimap_token_value { 45struct mailimap_token_value {
46 int value; 46 int value;
47 const char * str; 47 const char * str;
48}; 48};
49 49
50int mailimap_token_case_insensitive_parse(mailstream * fd, 50int mailimap_token_case_insensitive_parse(mailstream * fd,
51 MMAPString * buffer, 51 MMAPString * buffer,
52 size_t * index, 52 size_t * index,
53 const char * token) 53 const char * token)
54{ 54{
55 int len; 55 int len;
56 int cur_token; 56 size_t cur_token;
57 int r; 57 int r;
58 58
59 cur_token = * index; 59 cur_token = * index;
60 len = strlen(token); 60 len = strlen(token);
61 61
62#ifdef UNSTRICT_SYNTAX 62#ifdef UNSTRICT_SYNTAX
63 r = mailimap_space_parse(fd, buffer, &cur_token); 63 r = mailimap_space_parse(fd, buffer, &cur_token);
64 if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE)) 64 if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE))
65 return r; 65 return r;
66#endif 66#endif
67 67
68 if (strncasecmp(buffer->str + cur_token, token, len) == 0) { 68 if (strncasecmp(buffer->str + cur_token, token, len) == 0) {
69 cur_token += len; 69 cur_token += len;
70 * index = cur_token; 70 * index = cur_token;
71 return MAILIMAP_NO_ERROR; 71 return MAILIMAP_NO_ERROR;
72 } 72 }
73 else 73 else
74 return MAILIMAP_ERROR_PARSE; 74 return MAILIMAP_ERROR_PARSE;
75} 75}
76 76
77 77
78static int is_space_or_tab(char ch) 78static int is_space_or_tab(char ch)
79{ 79{
80 return (ch == ' ') || (ch == '\t'); 80 return (ch == ' ') || (ch == '\t');
81} 81}
82 82
83int mailimap_char_parse(mailstream * fd, MMAPString * buffer, 83int mailimap_char_parse(mailstream * fd, MMAPString * buffer,
84 size_t * index, char token) 84 size_t * index, char token)
85{ 85{
86 int cur_token; 86 int cur_token;
87 87
88 cur_token = * index; 88 cur_token = * index;
89 89
90 if (buffer->str[cur_token] == token) { 90 if (buffer->str[cur_token] == token) {
91 cur_token ++; 91 cur_token ++;
92 * index = cur_token; 92 * index = cur_token;
93 return MAILIMAP_NO_ERROR; 93 return MAILIMAP_NO_ERROR;
94 } 94 }
95 else 95 else
96 return MAILIMAP_ERROR_PARSE; 96 return MAILIMAP_ERROR_PARSE;
97} 97}
98 98
99int mailimap_space_parse(mailstream * fd, MMAPString * buffer, 99int mailimap_space_parse(mailstream * fd, MMAPString * buffer,
100 size_t * index) 100 size_t * index)
101{ 101{
102#ifdef UNSTRICT_SYNTAX 102#ifdef UNSTRICT_SYNTAX
103 103
104 /* can accept unstrict syntax */ 104 /* can accept unstrict syntax */
105 size_t cur_token; 105 size_t cur_token;
106 106
107 cur_token = * index; 107 cur_token = * index;
108 108
109 while (is_space_or_tab(* (buffer->str + cur_token))) 109 while (is_space_or_tab(* (buffer->str + cur_token)))
110 cur_token ++; 110 cur_token ++;
111 111
112 if (cur_token == * index) 112 if (cur_token == * index)
113 return MAILIMAP_ERROR_PARSE; 113 return MAILIMAP_ERROR_PARSE;
114 114
115 * index = cur_token; 115 * index = cur_token;
116 116
117 return MAILIMAP_NO_ERROR; 117 return MAILIMAP_NO_ERROR;
118 118
119#else 119#else
120 return mailimap_char_parse(fd, buffer, index, ' '); 120 return mailimap_char_parse(fd, buffer, index, ' ');
121#endif 121#endif
122} 122}
123 123
124 124
125 125
126#define mailimap_get_token_str(index, tab) \ 126#define mailimap_get_token_str(index, tab) \
127 mailimap_get_token_str_size(index, tab, \ 127 mailimap_get_token_str_size(index, tab, \
128 sizeof(tab) / sizeof(struct mailimap_token_value)) 128 sizeof(tab) / sizeof(struct mailimap_token_value))
129 129
130#define mailimap_get_token_value(fd, buffer, index, tab) \ 130#define mailimap_get_token_value(fd, buffer, index, tab) \
131 mailimap_get_token_value_size(fd, buffer, index, tab, \ 131 mailimap_get_token_value_size(fd, buffer, index, tab, \
132 sizeof(tab) / sizeof(struct mailimap_token_value)) 132 sizeof(tab) / sizeof(struct mailimap_token_value))
133 133
134 134
135static const char * mailimap_get_token_str_size(int index, 135static const char * mailimap_get_token_str_size(int index,
136 struct mailimap_token_value * tab, 136 struct mailimap_token_value * tab,
137 size_t size) 137 size_t size)
138{ 138{
139 size_t i; 139 size_t i;
140 140
141 for(i = 0 ; i < size ; i++) 141 for(i = 0 ; i < size ; i++)
142 if (index == tab[i].value) 142 if (index == tab[i].value)
143 return tab[i].str; 143 return tab[i].str;
144 144
145 return NULL; 145 return NULL;
146} 146}
147 147
148 148
149 149
150static int mailimap_get_token_value_size(mailstream * fd, MMAPString * buffer, 150static int mailimap_get_token_value_size(mailstream * fd, MMAPString * buffer,
151 size_t * index, 151 size_t * index,
152 struct mailimap_token_value * tab, 152 struct mailimap_token_value * tab,
153 size_t size) 153 size_t size)
154{ 154{
155 size_t i; 155 size_t i;
156 int r; 156 int r;
157 157
158#ifdef UNSTRICT_SYNTAX 158#ifdef UNSTRICT_SYNTAX
159 /* can accept unstrict syntax */ 159 /* can accept unstrict syntax */
160 r = mailimap_space_parse(fd, buffer, index); 160 r = mailimap_space_parse(fd, buffer, index);
161 if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE)) 161 if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE))
162 return r; 162 return r;
163#endif 163#endif
164 164
165 for(i = 0 ; i < size ; i++) { 165 for(i = 0 ; i < size ; i++) {
166 r = mailimap_token_case_insensitive_parse(fd, buffer, index, tab[i].str); 166 r = mailimap_token_case_insensitive_parse(fd, buffer, index, tab[i].str);
167 if (r == MAILIMAP_NO_ERROR) 167 if (r == MAILIMAP_NO_ERROR)
168 return tab[i].value; 168 return tab[i].value;
169 } 169 }
170 170
171 return -1; 171 return -1;
172} 172}
173 173
174 174
175static struct mailimap_token_value status_att_tab[] = { 175static struct mailimap_token_value status_att_tab[] = {
176 {MAILIMAP_STATUS_ATT_MESSAGES, "MESSAGES"}, 176 {MAILIMAP_STATUS_ATT_MESSAGES, "MESSAGES"},
177 {MAILIMAP_STATUS_ATT_RECENT, "RECENT"}, 177 {MAILIMAP_STATUS_ATT_RECENT, "RECENT"},
178 {MAILIMAP_STATUS_ATT_UIDNEXT, "UIDNEXT"}, 178 {MAILIMAP_STATUS_ATT_UIDNEXT, "UIDNEXT"},
179 {MAILIMAP_STATUS_ATT_UIDVALIDITY, "UIDVALIDITY"}, 179 {MAILIMAP_STATUS_ATT_UIDVALIDITY, "UIDVALIDITY"},
180 {MAILIMAP_STATUS_ATT_UNSEEN, "UNSEEN"} 180 {MAILIMAP_STATUS_ATT_UNSEEN, "UNSEEN"}
181}; 181};
182 182
183int mailimap_status_att_get_token_value(mailstream * fd, MMAPString * buffer, 183int mailimap_status_att_get_token_value(mailstream * fd, MMAPString * buffer,
184 size_t * index) 184 size_t * index)
diff --git a/kmicromail/libetpan/imf/mailimf.c b/kmicromail/libetpan/imf/mailimf.c
index 84d81a1..e0164b8 100644
--- a/kmicromail/libetpan/imf/mailimf.c
+++ b/kmicromail/libetpan/imf/mailimf.c
@@ -1,179 +1,179 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "mailimf.h" 36#include "mailimf.h"
37 37
38/* 38/*
39 RFC 2822 39 RFC 2822
40 40
41 RFC 2821 ... 41 RFC 2821 ...
42 A message-originating SMTP system SHOULD NOT send a message that 42 A message-originating SMTP system SHOULD NOT send a message that
43 already contains a Return-path header. SMTP servers performing a 43 already contains a Return-path header. SMTP servers performing a
44 relay function MUST NOT inspect the message data, and especially not 44 relay function MUST NOT inspect the message data, and especially not
45 to the extent needed to determine if Return-path headers are present. 45 to the extent needed to determine if Return-path headers are present.
46 SMTP servers making final delivery MAY remove Return-path headers 46 SMTP servers making final delivery MAY remove Return-path headers
47 before adding their own. 47 before adding their own.
48*/ 48*/
49 49
50#include <ctype.h> 50#include <ctype.h>
51#include <mmapstring.h> 51#include "mmapstring.h"
52#include <stdlib.h> 52#include <stdlib.h>
53#include <string.h> 53#include <string.h>
54 54
55#ifndef TRUE 55#ifndef TRUE
56#define TRUE 1 56#define TRUE 1
57#endif 57#endif
58 58
59#ifndef FALSE 59#ifndef FALSE
60#define FALSE 0 60#define FALSE 0
61#endif 61#endif
62 62
63 63
64 64
65 65
66 66
67 67
68 68
69static inline int is_dtext(char ch); 69static inline int is_dtext(char ch);
70 70
71static int mailimf_quoted_pair_parse(const char * message, size_t length, 71static int mailimf_quoted_pair_parse(const char * message, size_t length,
72 size_t * index, char * result); 72 size_t * index, char * result);
73 73
74static int mailimf_ccontent_parse(const char * message, size_t length, 74static int mailimf_ccontent_parse(const char * message, size_t length,
75 size_t * index); 75 size_t * index);
76 76
77static int 77static int
78mailimf_comment_fws_ccontent_parse(const char * message, size_t length, 78mailimf_comment_fws_ccontent_parse(const char * message, size_t length,
79 size_t * index); 79 size_t * index);
80 80
81static inline int mailimf_comment_parse(const char * message, size_t length, 81static inline int mailimf_comment_parse(const char * message, size_t length,
82 size_t * index); 82 size_t * index);
83 83
84static int mailimf_qcontent_parse(const char * message, size_t length, 84static int mailimf_qcontent_parse(const char * message, size_t length,
85 size_t * index, char * ch); 85 size_t * index, char * ch);
86 86
87static int mailimf_phrase_parse(const char * message, size_t length, 87static int mailimf_phrase_parse(const char * message, size_t length,
88 size_t * index, char ** result); 88 size_t * index, char ** result);
89 89
90static int mailimf_unstructured_parse(const char * message, size_t length, 90static int mailimf_unstructured_parse(const char * message, size_t length,
91 size_t * index, char ** result); 91 size_t * index, char ** result);
92 92
93static int mailimf_ignore_unstructured_parse(const char * message, size_t length, 93static int mailimf_ignore_unstructured_parse(const char * message, size_t length,
94 size_t * index); 94 size_t * index);
95 95
96static int mailimf_day_of_week_parse(const char * message, size_t length, 96static int mailimf_day_of_week_parse(const char * message, size_t length,
97 size_t * index, int * result); 97 size_t * index, int * result);
98 98
99static int mailimf_day_name_parse(const char * message, size_t length, 99static int mailimf_day_name_parse(const char * message, size_t length,
100 size_t * index, int * result); 100 size_t * index, int * result);
101 101
102static int mailimf_date_parse(const char * message, size_t length, 102static int mailimf_date_parse(const char * message, size_t length,
103 size_t * index, 103 size_t * index,
104 int * pday, int * pmonth, int * pyear); 104 int * pday, int * pmonth, int * pyear);
105 105
106static int mailimf_year_parse(const char * message, size_t length, 106static int mailimf_year_parse(const char * message, size_t length,
107 size_t * index, int * result); 107 size_t * index, int * result);
108 108
109static int mailimf_month_parse(const char * message, size_t length, 109static int mailimf_month_parse(const char * message, size_t length,
110 size_t * index, int * result); 110 size_t * index, int * result);
111 111
112static int mailimf_month_name_parse(const char * message, size_t length, 112static int mailimf_month_name_parse(const char * message, size_t length,
113 size_t * index, int * result); 113 size_t * index, int * result);
114 114
115static int mailimf_day_parse(const char * message, size_t length, 115static int mailimf_day_parse(const char * message, size_t length,
116 size_t * index, int * result); 116 size_t * index, int * result);
117 117
118static int mailimf_time_parse(const char * message, size_t length, 118static int mailimf_time_parse(const char * message, size_t length,
119 size_t * index, 119 size_t * index,
120 int * phour, int * pmin, 120 int * phour, int * pmin,
121 int * psec, 121 int * psec,
122 int * zone); 122 int * zone);
123static int mailimf_time_of_day_parse(const char * message, size_t length, 123static int mailimf_time_of_day_parse(const char * message, size_t length,
124 size_t * index, 124 size_t * index,
125 int * phour, int * pmin, 125 int * phour, int * pmin,
126 int * psec); 126 int * psec);
127 127
128static int mailimf_hour_parse(const char * message, size_t length, 128static int mailimf_hour_parse(const char * message, size_t length,
129 size_t * index, int * result); 129 size_t * index, int * result);
130 130
131static int mailimf_minute_parse(const char * message, size_t length, 131static int mailimf_minute_parse(const char * message, size_t length,
132 size_t * index, int * result); 132 size_t * index, int * result);
133 133
134static int mailimf_second_parse(const char * message, size_t length, 134static int mailimf_second_parse(const char * message, size_t length,
135 size_t * index, int * result); 135 size_t * index, int * result);
136 136
137static int mailimf_zone_parse(const char * message, size_t length, 137static int mailimf_zone_parse(const char * message, size_t length,
138 size_t * index, int * result); 138 size_t * index, int * result);
139 139
140static int mailimf_name_addr_parse(const char * message, size_t length, 140static int mailimf_name_addr_parse(const char * message, size_t length,
141 size_t * index, 141 size_t * index,
142 char ** pdisplay_name, 142 char ** pdisplay_name,
143 char ** pangle_addr); 143 char ** pangle_addr);
144 144
145static int mailimf_angle_addr_parse(const char * message, size_t length, 145static int mailimf_angle_addr_parse(const char * message, size_t length,
146 size_t * index, char ** result); 146 size_t * index, char ** result);
147 147
148static int mailimf_group_parse(const char * message, size_t length, 148static int mailimf_group_parse(const char * message, size_t length,
149 size_t * index, 149 size_t * index,
150 struct mailimf_group ** result); 150 struct mailimf_group ** result);
151 151
152static int mailimf_display_name_parse(const char * message, size_t length, 152static int mailimf_display_name_parse(const char * message, size_t length,
153 size_t * index, char ** result); 153 size_t * index, char ** result);
154 154
155static int mailimf_addr_spec_parse(const char * message, size_t length, 155static int mailimf_addr_spec_parse(const char * message, size_t length,
156 size_t * index, 156 size_t * index,
157 char ** address); 157 char ** address);
158 158
159#if 0 159#if 0
160static int mailimf_local_part_parse(const char * message, size_t length, 160static int mailimf_local_part_parse(const char * message, size_t length,
161 size_t * index, 161 size_t * index,
162 char ** result); 162 char ** result);
163 163
164static int mailimf_domain_parse(const char * message, size_t length, 164static int mailimf_domain_parse(const char * message, size_t length,
165 size_t * index, 165 size_t * index,
166 char ** result); 166 char ** result);
167#endif 167#endif
168 168
169#if 0 169#if 0
170static int mailimf_domain_literal_parse(const char * message, size_t length, 170static int mailimf_domain_literal_parse(const char * message, size_t length,
171 size_t * index, char ** result); 171 size_t * index, char ** result);
172#endif 172#endif
173 173
174#if 0 174#if 0
175static int mailimf_dcontent_parse(const char * message, size_t length, 175static int mailimf_dcontent_parse(const char * message, size_t length,
176 size_t * index, char * result); 176 size_t * index, char * result);
177#endif 177#endif
178 178
179static int 179static int
diff --git a/kmicromail/libetpan/include/libetpan/libetpan.h b/kmicromail/libetpan/include/libetpan/libetpan.h
index 3b4a107..fe5637d 100644
--- a/kmicromail/libetpan/include/libetpan/libetpan.h
+++ b/kmicromail/libetpan/include/libetpan/libetpan.h
@@ -1,104 +1,116 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef LIBETPAN_H 36#ifndef LIBETPAN_H
37 37
38#define LIBETPAN_H 38#define LIBETPAN_H
39 39
40#ifdef __cplusplus 40#ifdef __cplusplus
41extern "C" { 41extern "C" {
42#endif 42#endif
43 43
44#include <libetpan/libetpan_version.h> 44#include <libetpan/libetpan_version.h>
45#include <libetpan/maildriver.h> 45#include <libetpan/maildriver.h>
46#include <libetpan/mailmessage.h> 46#include <libetpan/mailmessage.h>
47#include <libetpan/mailfolder.h>
47#include <libetpan/mailstorage.h> 48#include <libetpan/mailstorage.h>
48#include <libetpan/mailthread.h> 49#include <libetpan/mailthread.h>
49#include <libetpan/mailsmtp.h> 50#include <libetpan/mailsmtp.h>
50#include <libetpan/charconv.h> 51#include <libetpan/charconv.h>
51 52
52/* mbox driver */ 53/* mbox driver */
53#include <libetpan/mboxdriver.h> 54#include <libetpan/mboxdriver.h>
54#include <libetpan/mboxdriver_message.h> 55#include <libetpan/mboxdriver_message.h>
55#include <libetpan/mboxdriver_cached.h> 56#include <libetpan/mboxdriver_cached.h>
56#include <libetpan/mboxdriver_cached_message.h> 57#include <libetpan/mboxdriver_cached_message.h>
57#include <libetpan/mboxstorage.h> 58#include <libetpan/mboxstorage.h>
58 59
59/* MH driver */ 60/* MH driver */
60#include <libetpan/mhdriver.h> 61#include <libetpan/mhdriver.h>
61#include <libetpan/mhdriver_message.h> 62#include <libetpan/mhdriver_message.h>
62#include <libetpan/mhdriver_cached.h> 63#include <libetpan/mhdriver_cached.h>
63#include <libetpan/mhdriver_cached_message.h> 64#include <libetpan/mhdriver_cached_message.h>
64#include <libetpan/mhstorage.h> 65#include <libetpan/mhstorage.h>
65 66
66/* IMAP4rev1 driver */ 67/* IMAP4rev1 driver */
67#include <libetpan/imapdriver.h> 68#include <libetpan/imapdriver.h>
68#include <libetpan/imapdriver_message.h> 69#include <libetpan/imapdriver_message.h>
69#include <libetpan/imapdriver_cached.h> 70#include <libetpan/imapdriver_cached.h>
70#include <libetpan/imapdriver_cached_message.h> 71#include <libetpan/imapdriver_cached_message.h>
71#include <libetpan/imapstorage.h> 72#include <libetpan/imapstorage.h>
72 73
73/* POP3 driver */ 74/* POP3 driver */
74#include <libetpan/pop3driver.h> 75#include <libetpan/pop3driver.h>
75#include <libetpan/pop3driver_message.h> 76#include <libetpan/pop3driver_message.h>
76#include <libetpan/pop3driver_cached.h> 77#include <libetpan/pop3driver_cached.h>
77#include <libetpan/pop3driver_cached_message.h> 78#include <libetpan/pop3driver_cached_message.h>
78#include <libetpan/pop3storage.h> 79#include <libetpan/pop3storage.h>
79 80
80/* NNTP driver */ 81/* NNTP driver */
81#include <libetpan/nntpdriver.h> 82#include <libetpan/nntpdriver.h>
82#include <libetpan/nntpdriver_message.h> 83#include <libetpan/nntpdriver_message.h>
83#include <libetpan/nntpdriver_cached.h> 84#include <libetpan/nntpdriver_cached.h>
84#include <libetpan/nntpdriver_cached_message.h> 85#include <libetpan/nntpdriver_cached_message.h>
85#include <libetpan/nntpstorage.h> 86#include <libetpan/nntpstorage.h>
86 87
87/* maildir driver */ 88/* maildir driver */
88#include <libetpan/maildirdriver.h> 89#include <libetpan/maildirdriver.h>
89#include <libetpan/maildirdriver_message.h> 90#include <libetpan/maildirdriver_message.h>
90#include <libetpan/maildirdriver_cached.h> 91#include <libetpan/maildirdriver_cached.h>
91#include <libetpan/maildirdriver_cached_message.h> 92#include <libetpan/maildirdriver_cached_message.h>
92#include <libetpan/maildirstorage.h> 93#include <libetpan/maildirstorage.h>
93 94
95/* db driver */
96#include <libetpan/dbdriver.h>
97#include <libetpan/dbdriver_message.h>
98#include <libetpan/dbstorage.h>
99
94/* message which content is given by a MIME structure */ 100/* message which content is given by a MIME structure */
95#include <libetpan/mime_message_driver.h> 101#include <libetpan/mime_message_driver.h>
96 102
97/* message which content given by a string */ 103/* message which content given by a string */
98#include <libetpan/data_message_driver.h> 104#include <libetpan/data_message_driver.h>
99 105
106/* engine */
107#include <libetpan/mailprivacy.h>
108#include <libetpan/mailengine.h>
109#include <libetpan/mailprivacy_gnupg.h>
110#include <libetpan/mailprivacy_smime.h>
111
100#ifdef __cplusplus 112#ifdef __cplusplus
101} 113}
102#endif 114#endif
103 115
104#endif 116#endif
diff --git a/kmicromail/libetpan/include/libetpan/maildir.h b/kmicromail/libetpan/include/libetpan/maildir.h
index b782484..268dda1 100644
--- a/kmicromail/libetpan/include/libetpan/maildir.h
+++ b/kmicromail/libetpan/include/libetpan/maildir.h
@@ -1,60 +1,67 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001 - 2003 - DINH Viet Hoa 4 * Copyright (C) 2001 - 2003 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAILDIR_H 36#ifndef MAILDIR_H
37 37
38#define MAILDIR_H 38#define MAILDIR_H
39 39
40#include <libetpan/maildir_types.h> 40#include <libetpan/maildir_types.h>
41 41
42struct maildir * maildir_new(const char * path); 42struct maildir * maildir_new(const char * path);
43 43
44void maildir_free(struct maildir * md); 44void maildir_free(struct maildir * md);
45 45
46int maildir_update(struct maildir * md); 46int maildir_update(struct maildir * md);
47 47
48int maildir_message_add_uid(struct maildir * md,
49 const char * message, size_t size,
50 char * uid, size_t max_uid_len);
51
48int maildir_message_add(struct maildir * md, 52int maildir_message_add(struct maildir * md,
49 const char * message, size_t size); 53 const char * message, size_t size);
50 54
55int maildir_message_add_file_uid(struct maildir * md, int fd,
56 char * uid, size_t max_uid_len);
57
51int maildir_message_add_file(struct maildir * md, int fd); 58int maildir_message_add_file(struct maildir * md, int fd);
52 59
53char * maildir_message_get(struct maildir * md, const char * uid); 60char * maildir_message_get(struct maildir * md, const char * uid);
54 61
55int maildir_message_remove(struct maildir * md, const char * uid); 62int maildir_message_remove(struct maildir * md, const char * uid);
56 63
57int maildir_message_change_flags(struct maildir * md, 64int maildir_message_change_flags(struct maildir * md,
58 const char * uid, int new_flags); 65 const char * uid, int new_flags);
59 66
60#endif 67#endif
diff --git a/kmicromail/libetpan/include/libetpan/maildirstorage.h b/kmicromail/libetpan/include/libetpan/maildirstorage.h
index d17ea2c..73d7b20 100644
--- a/kmicromail/libetpan/include/libetpan/maildirstorage.h
+++ b/kmicromail/libetpan/include/libetpan/maildirstorage.h
@@ -1,69 +1,69 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#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
43extern "C" { 43extern "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
61int maildir_mailstorage_init(struct mailstorage * storage, 61int 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);
64 64
65#ifdef __cplusplus 65#ifdef __cplusplus
66} 66}
67#endif 67#endif
68 68
69#endif 69#endif
diff --git a/kmicromail/libetpan/include/libetpan/maildriver.h b/kmicromail/libetpan/include/libetpan/maildriver.h
index 7da9aea..c773190 100644
--- a/kmicromail/libetpan/include/libetpan/maildriver.h
+++ b/kmicromail/libetpan/include/libetpan/maildriver.h
@@ -275,256 +275,259 @@ int mailsession_expunge_folder(mailsession * session);
275*/ 275*/
276 276
277int mailsession_status_folder(mailsession * session, char * mb, 277int mailsession_status_folder(mailsession * session, char * mb,
278 uint32_t * result_messages, uint32_t * result_recent, 278 uint32_t * result_messages, uint32_t * result_recent,
279 uint32_t * result_unseen); 279 uint32_t * result_unseen);
280 280
281 281
282/* 282/*
283 mailsession_messages_number queries the number of messages in the folder 283 mailsession_messages_number queries the number of messages in the folder
284 284
285 @param session the session 285 @param session the session
286 @param mb mailbox to query 286 @param mb mailbox to query
287 @param result the number of messages is stored in (* result) 287 @param result the number of messages is stored in (* result)
288 288
289 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 289 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
290 on error 290 on error
291*/ 291*/
292 292
293int mailsession_messages_number(mailsession * session, char * mb, 293int mailsession_messages_number(mailsession * session, char * mb,
294 uint32_t * result); 294 uint32_t * result);
295 295
296/* 296/*
297 mailsession_recent_number queries the number of recent messages in the folder 297 mailsession_recent_number queries the number of recent messages in the folder
298 298
299 @param session the session 299 @param session the session
300 @param mb mailbox to query 300 @param mb mailbox to query
301 @param result the number of recent messages is stored in (* result) 301 @param result the number of recent messages is stored in (* result)
302 302
303 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 303 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
304 on error 304 on error
305*/ 305*/
306 306
307int mailsession_recent_number(mailsession * session, 307int mailsession_recent_number(mailsession * session,
308 char * mb, uint32_t * result); 308 char * mb, uint32_t * result);
309 309
310/* 310/*
311 mailsession_unseen_number queries the number of unseen messages in the folder 311 mailsession_unseen_number queries the number of unseen messages in the folder
312 312
313 @param session the session 313 @param session the session
314 @param mb mailbox to query 314 @param mb mailbox to query
315 @param result the number of unseen messages is stored in (* result) 315 @param result the number of unseen messages is stored in (* result)
316 316
317 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 317 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
318 on error 318 on error
319*/ 319*/
320 320
321int mailsession_unseen_number(mailsession * session, char * mb, 321int mailsession_unseen_number(mailsession * session, char * mb,
322 uint32_t * result); 322 uint32_t * result);
323 323
324/* 324/*
325 NOTE: driver's specific should be used 325 NOTE: driver's specific should be used
326 326
327 mailsession_list_folders returns the list of all sub-mailboxes 327 mailsession_list_folders returns the list of all sub-mailboxes
328 of the given mailbox 328 of the given mailbox
329 329
330 @param session the session 330 @param session the session
331 @param mb the mailbox 331 @param mb the mailbox
332 @param result list of mailboxes if stored in (* result), 332 @param result list of mailboxes if stored in (* result),
333 this structure have to be freed with mail_list_free() 333 this structure have to be freed with mail_list_free()
334 334
335 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 335 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
336 on error 336 on error
337*/ 337*/
338 338
339int mailsession_list_folders(mailsession * session, char * mb, 339int mailsession_list_folders(mailsession * session, char * mb,
340 struct mail_list ** result); 340 struct mail_list ** result);
341 341
342/* 342/*
343 NOTE: driver's specific should be used 343 NOTE: driver's specific should be used
344 344
345 mailsession_lsub_folders returns the list of subscribed 345 mailsession_lsub_folders returns the list of subscribed
346 sub-mailboxes of the given mailbox 346 sub-mailboxes of the given mailbox
347 347
348 @param session the session 348 @param session the session
349 @param mb the mailbox 349 @param mb the mailbox
350 @param result list of mailboxes if stored in (* result), 350 @param result list of mailboxes if stored in (* result),
351 this structure have to be freed with mail_list_free() 351 this structure have to be freed with mail_list_free()
352 352
353 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 353 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
354 on error 354 on error
355*/ 355*/
356 356
357int mailsession_lsub_folders(mailsession * session, char * mb, 357int mailsession_lsub_folders(mailsession * session, char * mb,
358 struct mail_list ** result); 358 struct mail_list ** result);
359 359
360/* 360/*
361 NOTE: driver's specific should be used 361 NOTE: driver's specific should be used
362 362
363 mailsession_subscribe_folder subscribes to the given mailbox 363 mailsession_subscribe_folder subscribes to the given mailbox
364 364
365 @param session the session 365 @param session the session
366 @param mb the mailbox 366 @param mb the mailbox
367 367
368 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 368 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
369 on error 369 on error
370*/ 370*/
371 371
372int mailsession_subscribe_folder(mailsession * session, char * mb); 372int mailsession_subscribe_folder(mailsession * session, char * mb);
373 373
374/* 374/*
375 NOTE: driver's specific should be used 375 NOTE: driver's specific should be used
376 376
377 mailsession_unsubscribe_folder unsubscribes to the given mailbox 377 mailsession_unsubscribe_folder unsubscribes to the given mailbox
378 378
379 @param session the session 379 @param session the session
380 @param mb the mailbox 380 @param mb the mailbox
381 381
382 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 382 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
383 on error 383 on error
384*/ 384*/
385 385
386int mailsession_unsubscribe_folder(mailsession * session, char * mb); 386int 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
400int mailsession_append_message(mailsession * session, 400int mailsession_append_message(mailsession * session,
401 char * message, size_t size); 401 char * message, size_t size);
402 402
403int 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
417int mailsession_copy_message(mailsession * session, 420int mailsession_copy_message(mailsession * session,
418 uint32_t num, char * mb); 421 uint32_t num, char * mb);
419 422
420/* 423/*
421 NOTE: some drivers does not implement this 424 NOTE: some drivers does not implement this
422 425
423 mailsession_move_message copies a message whose number is given to 426 mailsession_move_message copies a message whose number is given to
424 a given mailbox. The mailbox must be accessible from the same session. 427 a given mailbox. The mailbox must be accessible from the same session.
425 428
426 @param session the session 429 @param session the session
427 @param num the message number 430 @param num the message number
428 @param mb the destination mailbox 431 @param mb the destination mailbox
429 432
430 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 433 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
431 on error 434 on error
432*/ 435*/
433 436
434int mailsession_move_message(mailsession * session, 437int mailsession_move_message(mailsession * session,
435 uint32_t num, char * mb); 438 uint32_t num, char * mb);
436 439
437/* 440/*
438 mailsession_get_messages_list returns the list of message numbers 441 mailsession_get_messages_list returns the list of message numbers
439 of the current mailbox. 442 of the current mailbox.
440 443
441 @param session the session 444 @param session the session
442 @param result the list of message numbers will be stored in (* result), 445 @param result the list of message numbers will be stored in (* result),
443 this structure have to be freed with mailmessage_list_free() 446 this structure have to be freed with mailmessage_list_free()
444 447
445 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 448 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
446 on error 449 on error
447*/ 450*/
448 451
449int mailsession_get_messages_list(mailsession * session, 452int mailsession_get_messages_list(mailsession * session,
450 struct mailmessage_list ** result); 453 struct mailmessage_list ** result);
451 454
452/* 455/*
453 mailsession_get_envelopes_list fills the parsed fields in the 456 mailsession_get_envelopes_list fills the parsed fields in the
454 mailmessage structures of the mailmessage_list. 457 mailmessage structures of the mailmessage_list.
455 458
456 @param session the session 459 @param session the session
457 @param result this is the list of mailmessage structures 460 @param result this is the list of mailmessage structures
458 461
459 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 462 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
460 on error 463 on error
461*/ 464*/
462 465
463int mailsession_get_envelopes_list(mailsession * session, 466int mailsession_get_envelopes_list(mailsession * session,
464 struct mailmessage_list * result); 467 struct mailmessage_list * result);
465 468
466/* 469/*
467 NOTE: some drivers does not implement this 470 NOTE: some drivers does not implement this
468 471
469 mailsession_remove_message removes the given message from the mailbox. 472 mailsession_remove_message removes the given message from the mailbox.
470 The message is permanently deleted. 473 The message is permanently deleted.
471 474
472 @param session the session 475 @param session the session
473 @param num is the message number 476 @param num is the message number
474 477
475 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 478 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
476 on error 479 on error
477*/ 480*/
478 481
479int mailsession_remove_message(mailsession * session, uint32_t num); 482int mailsession_remove_message(mailsession * session, uint32_t num);
480 483
481 484
482/* 485/*
483 NOTE: this function is not implemented in most drivers 486 NOTE: this function is not implemented in most drivers
484 487
485 mailsession_search_message returns a list of message numbers that 488 mailsession_search_message returns a list of message numbers that
486 corresponds to the given criteria. 489 corresponds to the given criteria.
487 490
488 @param session the session 491 @param session the session
489 @param charset is the charset to use (it can be NULL) 492 @param charset is the charset to use (it can be NULL)
490 @param key is the list of criteria 493 @param key is the list of criteria
491 @param result the search result is stored in (* result), 494 @param result the search result is stored in (* result),
492 this structure have to be freed with mail_search_result_free() 495 this structure have to be freed with mail_search_result_free()
493 496
494 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 497 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
495 on error 498 on error
496*/ 499*/
497 500
498#if 0 501#if 0
499int mailsession_search_messages(mailsession * session, char * charset, 502int mailsession_search_messages(mailsession * session, char * charset,
500 struct mail_search_key * key, 503 struct mail_search_key * key,
501 struct mail_search_result ** result); 504 struct mail_search_result ** result);
502#endif 505#endif
503 506
504/* 507/*
505 mailsession_get_message returns a mailmessage structure that corresponds 508 mailsession_get_message returns a mailmessage structure that corresponds
506 to the given message number. 509 to the given message number.
507 * WARNING * mailsession_get_message_by_uid() should be used instead. 510 * WARNING * mailsession_get_message_by_uid() should be used instead.
508 511
509 @param session the session 512 @param session the session
510 @param num the message number 513 @param num the message number
511 @param result the allocated mailmessage structure will be stored 514 @param result the allocated mailmessage structure will be stored
512 in (* result), this structure have to be freed with mailmessage_free() 515 in (* result), this structure have to be freed with mailmessage_free()
513 516
514 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned 517 @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
515 on error 518 on error
516*/ 519*/
517 520
518int mailsession_get_message(mailsession * session, 521int mailsession_get_message(mailsession * session,
519 uint32_t num, mailmessage ** result); 522 uint32_t num, mailmessage ** result);
520 523
521/* 524/*
522 mailsession_get_message_by_uid returns a mailmessage structure 525 mailsession_get_message_by_uid returns a mailmessage structure
523 that corresponds to the given message unique identifier. 526 that corresponds to the given message unique identifier.
524 This is currently implemented only for cached drivers. 527 This is currently implemented only for cached drivers.
525 * WARNING * That will deprecates the use of mailsession_get_message() 528 * WARNING * That will deprecates the use of mailsession_get_message()
526 529
527 @param session the session 530 @param session the session
528 @param uid the message unique identifier 531 @param uid the message unique identifier
529 @param result the allocated mailmessage structure will be stored 532 @param result the allocated mailmessage structure will be stored
530 in (* result), this structure have to be freed with mailmessage_free() 533 in (* result), this structure have to be freed with mailmessage_free()
diff --git a/kmicromail/libetpan/include/libetpan/maildriver_types.h b/kmicromail/libetpan/include/libetpan/maildriver_types.h
index 3ff9440..9eab4d6 100644
--- a/kmicromail/libetpan/include/libetpan/maildriver_types.h
+++ b/kmicromail/libetpan/include/libetpan/maildriver_types.h
@@ -382,256 +382,258 @@ void mail_search_result_free(struct mail_search_result * search_result);
382 382
383 - messages_number() queries the number of messages in the folder 383 - messages_number() queries the number of messages in the folder
384 384
385 - recent_number() queries the number of recent messages in the folder 385 - recent_number() queries the number of recent messages in the folder
386 386
387 - unseen_number() queries the number of unseen messages in the folder 387 - unseen_number() queries the number of unseen messages in the folder
388 388
389 - list_folders() returns the list of all sub-mailboxes 389 - list_folders() returns the list of all sub-mailboxes
390 of the given mailbox 390 of the given mailbox
391 391
392 - lsub_folders() returns the list of subscribed 392 - lsub_folders() returns the list of subscribed
393 sub-mailboxes of the given mailbox 393 sub-mailboxes of the given mailbox
394 394
395 - subscribe_folder() subscribes to the given mailbox 395 - subscribe_folder() subscribes to the given mailbox
396 396
397 - unsubscribe_folder() unsubscribes to the given mailbox 397 - unsubscribe_folder() unsubscribes to the given mailbox
398 398
399 - append_message() adds a RFC 2822 message to the current 399 - append_message() adds a RFC 2822 message to the current
400 given mailbox 400 given mailbox
401 401
402 - copy_message() copies a message whose number is given to 402 - copy_message() copies a message whose number is given to
403 a given mailbox. The mailbox must be accessible from 403 a given mailbox. The mailbox must be accessible from
404 the same session. 404 the same session.
405 405
406 - move_message() copies a message whose number is given to 406 - move_message() copies a message whose number is given to
407 a given mailbox. The mailbox must be accessible from the 407 a given mailbox. The mailbox must be accessible from the
408 same session. 408 same session.
409 409
410 - get_messages_list() returns the list of message numbers 410 - get_messages_list() returns the list of message numbers
411 of the current mailbox. 411 of the current mailbox.
412 412
413 - get_envelopes_list() fills the parsed fields in the 413 - get_envelopes_list() fills the parsed fields in the
414 mailmessage structures of the mailmessage_list. 414 mailmessage structures of the mailmessage_list.
415 415
416 - remove_message() removes the given message from the mailbox. 416 - remove_message() removes the given message from the mailbox.
417 The message is permanently deleted. 417 The message is permanently deleted.
418 418
419 - search_message() returns a list of message numbers that 419 - search_message() returns a list of message numbers that
420 corresponds to the given criteria. 420 corresponds to the given criteria.
421 421
422 - get_message returns a mailmessage structure that corresponds 422 - get_message returns a mailmessage structure that corresponds
423 to the given message number. 423 to the given message number.
424 424
425 - get_message_by_uid returns a mailmessage structure that corresponds 425 - get_message_by_uid returns a mailmessage structure that corresponds
426 to the given message unique identifier. 426 to the given message unique identifier.
427 427
428 * mandatory functions are the following : 428 * mandatory functions are the following :
429 429
430 - connect_stream() of connect_path() 430 - connect_stream() of connect_path()
431 - logout() 431 - logout()
432 - get_messages_list() 432 - get_messages_list()
433 - get_envelopes_list() 433 - get_envelopes_list()
434 434
435 * we advise you to implement these functions : 435 * we advise you to implement these functions :
436 436
437 - select_folder() (in case a session can access several folders) 437 - select_folder() (in case a session can access several folders)
438 - noop() (to check if the server is responding) 438 - noop() (to check if the server is responding)
439 - check_folder() (to make a checkpoint of the session) 439 - check_folder() (to make a checkpoint of the session)
440 - status_folder(), messages_number(), recent_number(), unseen_number() 440 - status_folder(), messages_number(), recent_number(), unseen_number()
441 (to get stat of the folder) 441 (to get stat of the folder)
442 - append_message() (but can't be done in the case of POP3 at least) 442 - append_message() (but can't be done in the case of POP3 at least)
443 - login() in a case of an authenticated driver. 443 - login() in a case of an authenticated driver.
444 - starttls() in a case of a stream driver, if the procotol supports 444 - starttls() in a case of a stream driver, if the procotol supports
445 STARTTLS. 445 STARTTLS.
446 - get_message_by_uid() so that the application can remember the message 446 - get_message_by_uid() so that the application can remember the message
447 by UID and build its own list of messages. 447 by UID and build its own list of messages.
448 448
449 * drivers' specific : 449 * drivers' specific :
450 450
451 Everything that is specific to the driver will be implemented in this 451 Everything that is specific to the driver will be implemented in this
452 function : 452 function :
453 453
454 - parameters() 454 - parameters()
455*/ 455*/
456 456
457struct mailsession_driver { 457struct mailsession_driver {
458 char * sess_name; 458 char * sess_name;
459 459
460 int (* sess_initialize)(mailsession * session); 460 int (* sess_initialize)(mailsession * session);
461 void (* sess_uninitialize)(mailsession * session); 461 void (* sess_uninitialize)(mailsession * session);
462 462
463 int (* sess_parameters)(mailsession * session, 463 int (* sess_parameters)(mailsession * session,
464 int id, void * value); 464 int id, void * value);
465 465
466 int (* sess_connect_stream)(mailsession * session, mailstream * s); 466 int (* sess_connect_stream)(mailsession * session, mailstream * s);
467 int (* sess_connect_path)(mailsession * session, char * path); 467 int (* sess_connect_path)(mailsession * session, char * path);
468 468
469 int (* sess_starttls)(mailsession * session); 469 int (* sess_starttls)(mailsession * session);
470 470
471 int (* sess_login)(mailsession * session, char * userid, char * password); 471 int (* sess_login)(mailsession * session, char * userid, char * password);
472 int (* sess_logout)(mailsession * session); 472 int (* sess_logout)(mailsession * session);
473 int (* sess_noop)(mailsession * session); 473 int (* sess_noop)(mailsession * session);
474 474
475 /* folders operations */ 475 /* folders operations */
476 476
477 int (* sess_build_folder_name)(mailsession * session, char * mb, 477 int (* sess_build_folder_name)(mailsession * session, char * mb,
478 char * name, char ** result); 478 char * name, char ** result);
479 479
480 int (* sess_create_folder)(mailsession * session, char * mb); 480 int (* sess_create_folder)(mailsession * session, char * mb);
481 int (* sess_delete_folder)(mailsession * session, char * mb); 481 int (* sess_delete_folder)(mailsession * session, char * mb);
482 int (* sess_rename_folder)(mailsession * session, char * mb, 482 int (* sess_rename_folder)(mailsession * session, char * mb,
483 char * new_name); 483 char * new_name);
484 int (* sess_check_folder)(mailsession * session); 484 int (* sess_check_folder)(mailsession * session);
485 int (* sess_examine_folder)(mailsession * session, char * mb); 485 int (* sess_examine_folder)(mailsession * session, char * mb);
486 int (* sess_select_folder)(mailsession * session, char * mb); 486 int (* sess_select_folder)(mailsession * session, char * mb);
487 int (* sess_expunge_folder)(mailsession * session); 487 int (* sess_expunge_folder)(mailsession * session);
488 int (* sess_status_folder)(mailsession * session, char * mb, 488 int (* sess_status_folder)(mailsession * session, char * mb,
489 uint32_t * result_num, uint32_t * result_recent, 489 uint32_t * result_num, uint32_t * result_recent,
490 uint32_t * result_unseen); 490 uint32_t * result_unseen);
491 int (* sess_messages_number)(mailsession * session, char * mb, 491 int (* sess_messages_number)(mailsession * session, char * mb,
492 uint32_t * result); 492 uint32_t * result);
493 int (* sess_recent_number)(mailsession * session, char * mb, 493 int (* sess_recent_number)(mailsession * session, char * mb,
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);
526#if 0 528#if 0
527 int (* sess_search_messages)(mailsession * session, char * charset, 529 int (* sess_search_messages)(mailsession * session, char * charset,
528 struct mail_search_key * key, 530 struct mail_search_key * key,
529 struct mail_search_result ** result); 531 struct mail_search_result ** result);
530#endif 532#endif
531}; 533};
532 534
533 535
534/* 536/*
535 session is the data structure for a mail session. 537 session is the data structure for a mail session.
536 538
537 - data is the internal data structure used by the driver 539 - data is the internal data structure used by the driver
538 It is called when initializing the mailsession structure. 540 It is called when initializing the mailsession structure.
539 541
540 - driver is the driver used for the session 542 - driver is the driver used for the session
541*/ 543*/
542 544
543struct mailsession { 545struct mailsession {
544 void * sess_data; 546 void * sess_data;
545 mailsession_driver * sess_driver; 547 mailsession_driver * sess_driver;
546}; 548};
547 549
548 550
549 551
550 552
551/* 553/*
552 mailmessage_driver is the driver structure to get information from messages. 554 mailmessage_driver is the driver structure to get information from messages.
553 555
554 - name is the name of the driver 556 - name is the name of the driver
555 557
556 - initialize() is the function that will initializes a data structure 558 - initialize() is the function that will initializes a data structure
557 specific to the driver, it returns a value that will be stored 559 specific to the driver, it returns a value that will be stored
558 in the field data of the mailsession. 560 in the field data of the mailsession.
559 The field data of the session is the state of the session, 561 The field data of the session is the state of the session,
560 the internal data structure used by the driver. 562 the internal data structure used by the driver.
561 It is called when initializing the mailmessage structure with 563 It is called when initializing the mailmessage structure with
562 mailmessage_init(). 564 mailmessage_init().
563 565
564 - uninitialize() frees the structure created with initialize(). 566 - uninitialize() frees the structure created with initialize().
565 It will be called by mailmessage_free(). 567 It will be called by mailmessage_free().
566 568
567 - flush() will free from memory all temporary structures of the message 569 - flush() will free from memory all temporary structures of the message
568 (for example, the MIME structure of the message). 570 (for example, the MIME structure of the message).
569 571
570 - fetch_result_free() will free all strings resulted by fetch() or 572 - fetch_result_free() will free all strings resulted by fetch() or
571 any fetch_xxx() functions that returns a string. 573 any fetch_xxx() functions that returns a string.
572 574
573 - fetch() returns the content of the message (headers and text). 575 - fetch() returns the content of the message (headers and text).
574 576
575 - fetch_header() returns the content of the headers. 577 - fetch_header() returns the content of the headers.
576 578
577 - fetch_body() returns the message text (message content without headers) 579 - fetch_body() returns the message text (message content without headers)
578 580
579 - fetch_size() returns the size of the message content. 581 - fetch_size() returns the size of the message content.
580 582
581 - get_bodystructure() returns the MIME structure of the message. 583 - get_bodystructure() returns the MIME structure of the message.
582 584
583 - fetch_section() returns the content of a given MIME part 585 - fetch_section() returns the content of a given MIME part
584 586
585 - fetch_section_header() returns the header of the message 587 - fetch_section_header() returns the header of the message
586 contained by the given MIME part. 588 contained by the given MIME part.
587 589
588 - fetch_section_mime() returns the MIME headers of the 590 - fetch_section_mime() returns the MIME headers of the
589 given MIME part. 591 given MIME part.
590 592
591 - fetch_section_body() returns the text (if this is a message, this is the 593 - fetch_section_body() returns the text (if this is a message, this is the
592 message content without headers) of the given MIME part. 594 message content without headers) of the given MIME part.
593 595
594 - fetch_envelope() returns a mailimf_fields structure, with a list of 596 - fetch_envelope() returns a mailimf_fields structure, with a list of
595 fields chosen by the driver. 597 fields chosen by the driver.
596 598
597 - get_flags() returns a the flags related to the message. 599 - get_flags() returns a the flags related to the message.
598 When you want to get flags of a message, you have to make sure to 600 When you want to get flags of a message, you have to make sure to
599 call get_flags() at least once before using directly message->flags. 601 call get_flags() at least once before using directly message->flags.
600*/ 602*/
601 603
602#define LIBETPAN_MAIL_MESSAGE_CHECK 604#define LIBETPAN_MAIL_MESSAGE_CHECK
603 605
604struct mailmessage_driver { 606struct mailmessage_driver {
605 char * msg_name; 607 char * msg_name;
606 608
607 int (* msg_initialize)(mailmessage * msg_info); 609 int (* msg_initialize)(mailmessage * msg_info);
608 610
609 void (* msg_uninitialize)(mailmessage * msg_info); 611 void (* msg_uninitialize)(mailmessage * msg_info);
610 612
611 void (* msg_flush)(mailmessage * msg_info); 613 void (* msg_flush)(mailmessage * msg_info);
612 614
613 void (* msg_check)(mailmessage * msg_info); 615 void (* msg_check)(mailmessage * msg_info);
614 616
615 void (* msg_fetch_result_free)(mailmessage * msg_info, 617 void (* msg_fetch_result_free)(mailmessage * msg_info,
616 char * msg); 618 char * msg);
617 619
618 int (* msg_fetch)(mailmessage * msg_info, 620 int (* msg_fetch)(mailmessage * msg_info,
619 char ** result, 621 char ** result,
620 size_t * result_len); 622 size_t * result_len);
621 623
622 int (* msg_fetch_header)(mailmessage * msg_info, 624 int (* msg_fetch_header)(mailmessage * msg_info,
623 char ** result, 625 char ** result,
624 size_t * result_len); 626 size_t * result_len);
625 627
626 int (* msg_fetch_body)(mailmessage * msg_info, 628 int (* msg_fetch_body)(mailmessage * msg_info,
627 char ** result, size_t * result_len); 629 char ** result, size_t * result_len);
628 630
629 int (* msg_fetch_size)(mailmessage * msg_info, 631 int (* msg_fetch_size)(mailmessage * msg_info,
630 size_t * result); 632 size_t * result);
631 633
632 int (* msg_get_bodystructure)(mailmessage * msg_info, 634 int (* msg_get_bodystructure)(mailmessage * msg_info,
633 struct mailmime ** result); 635 struct mailmime ** result);
634 636
635 int (* msg_fetch_section)(mailmessage * msg_info, 637 int (* msg_fetch_section)(mailmessage * msg_info,
636 struct mailmime * mime, 638 struct mailmime * mime,
637 char ** result, size_t * result_len); 639 char ** result, size_t * result_len);
diff --git a/kmicromail/libetpan/include/libetpan/mailfolder.h b/kmicromail/libetpan/include/libetpan/mailfolder.h
index 3ecad23..ff53470 100644
--- a/kmicromail/libetpan/include/libetpan/mailfolder.h
+++ b/kmicromail/libetpan/include/libetpan/mailfolder.h
@@ -1,32 +1,35 @@
1#ifndef MAILFOLDER_H 1#ifndef MAILFOLDER_H
2 2
3#define MAILFOLDER_H 3#define MAILFOLDER_H
4 4
5#include "mailstorage_types.h" 5#include "mailstorage_types.h"
6 6
7int mailfolder_noop(struct mailfolder * folder); 7int mailfolder_noop(struct mailfolder * folder);
8 8
9int mailfolder_check(struct mailfolder * folder); 9int mailfolder_check(struct mailfolder * folder);
10 10
11int mailfolder_expunge(struct mailfolder * folder); 11int mailfolder_expunge(struct mailfolder * folder);
12 12
13int mailfolder_status(struct mailfolder * folder, 13int 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
17int mailfolder_append_message(struct mailfolder * folder, 17int mailfolder_append_message(struct mailfolder * folder,
18 char * message, size_t size); 18 char * message, size_t size);
19 19
20int mailfolder_append_message_flags(struct mailfolder * folder,
21 char * message, size_t size, struct mail_flags * flags);
22
20int mailfolder_get_messages_list(struct mailfolder * folder, 23int mailfolder_get_messages_list(struct mailfolder * folder,
21 struct mailmessage_list ** result); 24 struct mailmessage_list ** result);
22 25
23int mailfolder_get_envelopes_list(struct mailfolder * folder, 26int mailfolder_get_envelopes_list(struct mailfolder * folder,
24 struct mailmessage_list * result); 27 struct mailmessage_list * result);
25 28
26int mailfolder_get_message(struct mailfolder * folder, 29int mailfolder_get_message(struct mailfolder * folder,
27 uint32_t num, mailmessage ** result); 30 uint32_t num, mailmessage ** result);
28 31
29int mailfolder_get_message_by_uid(struct mailfolder * folder, 32int 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/include/libetpan/mailmbox.h b/kmicromail/libetpan/include/libetpan/mailmbox.h
index 8be086c..0427f1f 100644
--- a/kmicromail/libetpan/include/libetpan/mailmbox.h
+++ b/kmicromail/libetpan/include/libetpan/mailmbox.h
@@ -1,140 +1,144 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAILMBOX_H 36#ifndef MAILMBOX_H
37 37
38#define MAILMBOX_H 38#define MAILMBOX_H
39 39
40#ifdef __cplusplus 40#ifdef __cplusplus
41extern "C" { 41extern "C" {
42#endif 42#endif
43 43
44#include <libetpan/mailmbox_types.h> 44#include <libetpan/mailmbox_types.h>
45 45
46int 46int
47mailmbox_append_message_list(struct mailmbox_folder * folder, 47mailmbox_append_message_list(struct mailmbox_folder * folder,
48 carray * append_tab); 48 carray * append_tab);
49 49
50int 50int
51mailmbox_append_message(struct mailmbox_folder * folder, 51mailmbox_append_message(struct mailmbox_folder * folder,
52 const char * data, size_t len); 52 const char * data, size_t len);
53 53
54int
55mailmbox_append_message_uid(struct mailmbox_folder * folder,
56 const char * data, size_t len, unsigned int * puid);
57
54int mailmbox_fetch_msg(struct mailmbox_folder * folder, 58int mailmbox_fetch_msg(struct mailmbox_folder * folder,
55 uint32_t num, char ** result, 59 uint32_t num, char ** result,
56 size_t * result_len); 60 size_t * result_len);
57 61
58int mailmbox_fetch_msg_headers(struct mailmbox_folder * folder, 62int mailmbox_fetch_msg_headers(struct mailmbox_folder * folder,
59 uint32_t num, char ** result, 63 uint32_t num, char ** result,
60 size_t * result_len); 64 size_t * result_len);
61 65
62void mailmbox_fetch_result_free(char * msg); 66void mailmbox_fetch_result_free(char * msg);
63 67
64int mailmbox_copy_msg_list(struct mailmbox_folder * dest_folder, 68int mailmbox_copy_msg_list(struct mailmbox_folder * dest_folder,
65 struct mailmbox_folder * src_folder, 69 struct mailmbox_folder * src_folder,
66 carray * tab); 70 carray * tab);
67 71
68int mailmbox_copy_msg(struct mailmbox_folder * dest_folder, 72int mailmbox_copy_msg(struct mailmbox_folder * dest_folder,
69 struct mailmbox_folder * src_folder, 73 struct mailmbox_folder * src_folder,
70 uint32_t uid); 74 uint32_t uid);
71 75
72int mailmbox_expunge(struct mailmbox_folder * folder); 76int mailmbox_expunge(struct mailmbox_folder * folder);
73 77
74int mailmbox_delete_msg(struct mailmbox_folder * folder, uint32_t uid); 78int mailmbox_delete_msg(struct mailmbox_folder * folder, uint32_t uid);
75 79
76int mailmbox_init(const char * filename, 80int mailmbox_init(const char * filename,
77 int force_readonly, 81 int force_readonly,
78 int force_no_uid, 82 int force_no_uid,
79 uint32_t default_written_uid, 83 uint32_t default_written_uid,
80 struct mailmbox_folder ** result_folder); 84 struct mailmbox_folder ** result_folder);
81 85
82void mailmbox_done(struct mailmbox_folder * folder); 86void mailmbox_done(struct mailmbox_folder * folder);
83 87
84/* low-level access primitives */ 88/* low-level access primitives */
85 89
86int mailmbox_write_lock(struct mailmbox_folder * folder); 90int mailmbox_write_lock(struct mailmbox_folder * folder);
87 91
88int mailmbox_write_unlock(struct mailmbox_folder * folder); 92int mailmbox_write_unlock(struct mailmbox_folder * folder);
89 93
90int mailmbox_read_lock(struct mailmbox_folder * folder); 94int mailmbox_read_lock(struct mailmbox_folder * folder);
91 95
92int mailmbox_read_unlock(struct mailmbox_folder * folder); 96int mailmbox_read_unlock(struct mailmbox_folder * folder);
93 97
94 98
95/* memory map */ 99/* memory map */
96 100
97int mailmbox_map(struct mailmbox_folder * folder); 101int mailmbox_map(struct mailmbox_folder * folder);
98 102
99void mailmbox_unmap(struct mailmbox_folder * folder); 103void mailmbox_unmap(struct mailmbox_folder * folder);
100 104
101void mailmbox_sync(struct mailmbox_folder * folder); 105void mailmbox_sync(struct mailmbox_folder * folder);
102 106
103 107
104/* open & close file */ 108/* open & close file */
105 109
106int mailmbox_open(struct mailmbox_folder * folder); 110int mailmbox_open(struct mailmbox_folder * folder);
107 111
108void mailmbox_close(struct mailmbox_folder * folder); 112void mailmbox_close(struct mailmbox_folder * folder);
109 113
110 114
111/* validate cache */ 115/* validate cache */
112 116
113int mailmbox_validate_write_lock(struct mailmbox_folder * folder); 117int mailmbox_validate_write_lock(struct mailmbox_folder * folder);
114 118
115int mailmbox_validate_read_lock(struct mailmbox_folder * folder); 119int mailmbox_validate_read_lock(struct mailmbox_folder * folder);
116 120
117 121
118/* fetch message */ 122/* fetch message */
119 123
120int mailmbox_fetch_msg_no_lock(struct mailmbox_folder * folder, 124int mailmbox_fetch_msg_no_lock(struct mailmbox_folder * folder,
121 uint32_t num, char ** result, 125 uint32_t num, char ** result,
122 size_t * result_len); 126 size_t * result_len);
123 127
124int mailmbox_fetch_msg_headers_no_lock(struct mailmbox_folder * folder, 128int mailmbox_fetch_msg_headers_no_lock(struct mailmbox_folder * folder,
125 uint32_t num, char ** result, 129 uint32_t num, char ** result,
126 size_t * result_len); 130 size_t * result_len);
127 131
128/* append message */ 132/* append message */
129 133
130int 134int
131mailmbox_append_message_list_no_lock(struct mailmbox_folder * folder, 135mailmbox_append_message_list_no_lock(struct mailmbox_folder * folder,
132 carray * append_tab); 136 carray * append_tab);
133 137
134int mailmbox_expunge_no_lock(struct mailmbox_folder * folder); 138int mailmbox_expunge_no_lock(struct mailmbox_folder * folder);
135 139
136#ifdef __cplusplus 140#ifdef __cplusplus
137} 141}
138#endif 142#endif
139 143
140#endif 144#endif
diff --git a/kmicromail/libetpan/include/libetpan/mailmbox_types.h b/kmicromail/libetpan/include/libetpan/mailmbox_types.h
index dd6758c..bd6ee30 100644
--- a/kmicromail/libetpan/include/libetpan/mailmbox_types.h
+++ b/kmicromail/libetpan/include/libetpan/mailmbox_types.h
@@ -3,140 +3,141 @@
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAILMBOX_TYPES_H 36#ifndef MAILMBOX_TYPES_H
37 37
38#define MAILMBOX_TYPES_H 38#define MAILMBOX_TYPES_H
39 39
40#ifdef __cplusplus 40#ifdef __cplusplus
41extern "C" { 41extern "C" {
42#endif 42#endif
43 43
44#include <sys/types.h> 44#include <sys/types.h>
45 45
46#include <libetpan/libetpan-config.h> 46#include <libetpan/libetpan-config.h>
47 47
48#include <libetpan/mailimf.h> 48#include <libetpan/mailimf.h>
49#include <libetpan/carray.h> 49#include <libetpan/carray.h>
50#include <libetpan/chash.h> 50#include <libetpan/chash.h>
51 51
52enum { 52enum {
53 MAILMBOX_NO_ERROR = 0, 53 MAILMBOX_NO_ERROR = 0,
54 MAILMBOX_ERROR_PARSE, 54 MAILMBOX_ERROR_PARSE,
55 MAILMBOX_ERROR_INVAL, 55 MAILMBOX_ERROR_INVAL,
56 MAILMBOX_ERROR_FILE_NOT_FOUND, 56 MAILMBOX_ERROR_FILE_NOT_FOUND,
57 MAILMBOX_ERROR_MEMORY, 57 MAILMBOX_ERROR_MEMORY,
58 MAILMBOX_ERROR_TEMPORARY_FILE, 58 MAILMBOX_ERROR_TEMPORARY_FILE,
59 MAILMBOX_ERROR_FILE, 59 MAILMBOX_ERROR_FILE,
60 MAILMBOX_ERROR_MSG_NOT_FOUND, 60 MAILMBOX_ERROR_MSG_NOT_FOUND,
61 MAILMBOX_ERROR_READONLY, 61 MAILMBOX_ERROR_READONLY,
62}; 62};
63 63
64 64
65struct mailmbox_folder { 65struct mailmbox_folder {
66 char mb_filename[PATH_MAX]; 66 char mb_filename[PATH_MAX];
67 67
68 time_t mb_mtime; 68 time_t mb_mtime;
69 69
70 int mb_fd; 70 int mb_fd;
71 int mb_read_only; 71 int mb_read_only;
72 int mb_no_uid; 72 int mb_no_uid;
73 73
74 int mb_changed; 74 int mb_changed;
75 unsigned int mb_deleted_count; 75 unsigned int mb_deleted_count;
76 76
77 char * mb_mapping; 77 char * mb_mapping;
78 size_t mb_mapping_size; 78 size_t mb_mapping_size;
79 79
80 uint32_t mb_written_uid; 80 uint32_t mb_written_uid;
81 uint32_t mb_max_uid; 81 uint32_t mb_max_uid;
82 82
83 chash * mb_hash; 83 chash * mb_hash;
84 carray * mb_tab; 84 carray * mb_tab;
85}; 85};
86 86
87struct mailmbox_folder * mailmbox_folder_new(const char * mb_filename); 87struct mailmbox_folder * mailmbox_folder_new(const char * mb_filename);
88void mailmbox_folder_free(struct mailmbox_folder * folder); 88void mailmbox_folder_free(struct mailmbox_folder * folder);
89 89
90 90
91struct mailmbox_msg_info { 91struct mailmbox_msg_info {
92 unsigned int msg_index; 92 unsigned int msg_index;
93 uint32_t msg_uid; 93 uint32_t msg_uid;
94 int msg_written_uid; 94 int msg_written_uid;
95 int msg_deleted; 95 int msg_deleted;
96 96
97 size_t msg_start; 97 size_t msg_start;
98 size_t msg_start_len; 98 size_t msg_start_len;
99 99
100 size_t msg_headers; 100 size_t msg_headers;
101 size_t msg_headers_len; 101 size_t msg_headers_len;
102 102
103 size_t msg_body; 103 size_t msg_body;
104 size_t msg_body_len; 104 size_t msg_body_len;
105 105
106 size_t msg_size; 106 size_t msg_size;
107 107
108 size_t msg_padding; 108 size_t msg_padding;
109}; 109};
110 110
111 111
112int mailmbox_msg_info_update(struct mailmbox_folder * folder, 112int mailmbox_msg_info_update(struct mailmbox_folder * folder,
113 size_t msg_start, size_t msg_start_len, 113 size_t msg_start, size_t msg_start_len,
114 size_t msg_headers, size_t msg_headers_len, 114 size_t msg_headers, size_t msg_headers_len,
115 size_t msg_body, size_t msg_body_len, 115 size_t msg_body, size_t msg_body_len,
116 size_t msg_size, size_t msg_padding, 116 size_t msg_size, size_t msg_padding,
117 uint32_t msg_uid); 117 uint32_t msg_uid);
118 118
119struct mailmbox_msg_info * 119struct mailmbox_msg_info *
120mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len, 120mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len,
121 size_t msg_headers, size_t msg_headers_len, 121 size_t msg_headers, size_t msg_headers_len,
122 size_t msg_body, size_t msg_body_len, 122 size_t msg_body, size_t msg_body_len,
123 size_t msg_size, size_t msg_padding, 123 size_t msg_size, size_t msg_padding,
124 uint32_t msg_uid); 124 uint32_t msg_uid);
125 125
126void mailmbox_msg_info_free(struct mailmbox_msg_info * info); 126void mailmbox_msg_info_free(struct mailmbox_msg_info * info);
127 127
128struct mailmbox_append_info { 128struct mailmbox_append_info {
129 const char * ai_message; 129 const char * ai_message;
130 size_t ai_size; 130 size_t ai_size;
131 unsigned int ai_uid;
131}; 132};
132 133
133struct mailmbox_append_info * 134struct mailmbox_append_info *
134mailmbox_append_info_new(const char * ai_message, size_t ai_size); 135mailmbox_append_info_new(const char * ai_message, size_t ai_size);
135 136
136void mailmbox_append_info_free(struct mailmbox_append_info * info); 137void mailmbox_append_info_free(struct mailmbox_append_info * info);
137 138
138#ifdef __cplusplus 139#ifdef __cplusplus
139} 140}
140#endif 141#endif
141 142
142#endif 143#endif
diff --git a/kmicromail/libetpan/include/libetpan/mailmh.h b/kmicromail/libetpan/include/libetpan/mailmh.h
index 40432cb..00199b8 100644
--- a/kmicromail/libetpan/include/libetpan/mailmh.h
+++ b/kmicromail/libetpan/include/libetpan/mailmh.h
@@ -1,143 +1,150 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAILMH_H 36#ifndef MAILMH_H
37 37
38#define MAILMH_H 38#define MAILMH_H
39 39
40#ifdef __cplusplus 40#ifdef __cplusplus
41extern "C" { 41extern "C" {
42#endif 42#endif
43 43
44#include <sys/types.h> 44#include <sys/types.h>
45#include <inttypes.h> 45#include <inttypes.h>
46#include <libetpan/carray.h> 46#include <libetpan/carray.h>
47#include <libetpan/cinthash.h> 47#include <libetpan/cinthash.h>
48#include <libetpan/chash.h> 48#include <libetpan/chash.h>
49 49
50enum { 50enum {
51 MAILMH_NO_ERROR = 0, 51 MAILMH_NO_ERROR = 0,
52 MAILMH_ERROR_FOLDER, 52 MAILMH_ERROR_FOLDER,
53 MAILMH_ERROR_MEMORY, 53 MAILMH_ERROR_MEMORY,
54 MAILMH_ERROR_FILE, 54 MAILMH_ERROR_FILE,
55 MAILMH_ERROR_COULD_NOT_ALLOC_MSG, 55 MAILMH_ERROR_COULD_NOT_ALLOC_MSG,
56 MAILMH_ERROR_RENAME, 56 MAILMH_ERROR_RENAME,
57 MAILMH_ERROR_MSG_NOT_FOUND, 57 MAILMH_ERROR_MSG_NOT_FOUND,
58}; 58};
59 59
60struct mailmh { 60struct mailmh {
61 struct mailmh_folder * mh_main; 61 struct mailmh_folder * mh_main;
62}; 62};
63 63
64struct mailmh_msg_info { 64struct mailmh_msg_info {
65 unsigned int msg_array_index; 65 unsigned int msg_array_index;
66 uint32_t msg_index; 66 uint32_t msg_index;
67 size_t msg_size; 67 size_t msg_size;
68 time_t msg_mtime; 68 time_t msg_mtime;
69}; 69};
70 70
71struct mailmh_folder { 71struct mailmh_folder {
72 char * fl_filename; 72 char * fl_filename;
73 unsigned int fl_array_index; 73 unsigned int fl_array_index;
74 74
75 char * fl_name; 75 char * fl_name;
76 time_t fl_mtime; 76 time_t fl_mtime;
77 struct mailmh_folder * fl_parent; 77 struct mailmh_folder * fl_parent;
78 uint32_t fl_max_index; 78 uint32_t fl_max_index;
79 79
80 carray * fl_msgs_tab; 80 carray * fl_msgs_tab;
81#if 0 81#if 0
82 cinthash_t * fl_msgs_hash; 82 cinthash_t * fl_msgs_hash;
83#endif 83#endif
84 chash * fl_msgs_hash; 84 chash * fl_msgs_hash;
85 85
86 carray * fl_subfolders_tab; 86 carray * fl_subfolders_tab;
87 chash * fl_subfolders_hash; 87 chash * fl_subfolders_hash;
88}; 88};
89 89
90struct mailmh * mailmh_new(const char * foldername); 90struct mailmh * mailmh_new(const char * foldername);
91void mailmh_free(struct mailmh * f); 91void mailmh_free(struct mailmh * f);
92 92
93struct mailmh_msg_info * 93struct mailmh_msg_info *
94mailmh_msg_info_new(uint32_t index, size_t size, time_t mtime); 94mailmh_msg_info_new(uint32_t index, size_t size, time_t mtime);
95void mailmh_msg_info_free(struct mailmh_msg_info * msg_info); 95void mailmh_msg_info_free(struct mailmh_msg_info * msg_info);
96 96
97struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent, 97struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent,
98 const char * name); 98 const char * name);
99void mailmh_folder_free(struct mailmh_folder * folder); 99void mailmh_folder_free(struct mailmh_folder * folder);
100 100
101int mailmh_folder_add_subfolder(struct mailmh_folder * parent, 101int mailmh_folder_add_subfolder(struct mailmh_folder * parent,
102 const char * name); 102 const char * name);
103 103
104struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root, 104struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root,
105 const char * filename); 105 const char * filename);
106 106
107int mailmh_folder_remove_subfolder(struct mailmh_folder * folder); 107int mailmh_folder_remove_subfolder(struct mailmh_folder * folder);
108 108
109int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder, 109int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder,
110 struct mailmh_folder * dst_folder, 110 struct mailmh_folder * dst_folder,
111 const char * new_name); 111 const char * new_name);
112 112
113int mailmh_folder_get_message_filename(struct mailmh_folder * folder, 113int mailmh_folder_get_message_filename(struct mailmh_folder * folder,
114 uint32_t index, char ** result); 114 uint32_t index, char ** result);
115 115
116int mailmh_folder_get_message_fd(struct mailmh_folder * folder, 116int mailmh_folder_get_message_fd(struct mailmh_folder * folder,
117 uint32_t index, int flags, int * result); 117 uint32_t index, int flags, int * result);
118 118
119int mailmh_folder_get_message_size(struct mailmh_folder * folder, 119int mailmh_folder_get_message_size(struct mailmh_folder * folder,
120 uint32_t index, size_t * result); 120 uint32_t index, size_t * result);
121 121
122int mailmh_folder_add_message_uid(struct mailmh_folder * folder,
123 const char * message, size_t size,
124 uint32_t * pindex);
125
122int mailmh_folder_add_message(struct mailmh_folder * folder, 126int mailmh_folder_add_message(struct mailmh_folder * folder,
123 const char * message, size_t size); 127 const char * message, size_t size);
124 128
129int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder,
130 int fd, uint32_t * pindex);
131
125int mailmh_folder_add_message_file(struct mailmh_folder * folder, 132int mailmh_folder_add_message_file(struct mailmh_folder * folder,
126 int fd); 133 int fd);
127 134
128int mailmh_folder_remove_message(struct mailmh_folder * folder, 135int mailmh_folder_remove_message(struct mailmh_folder * folder,
129 uint32_t index); 136 uint32_t index);
130 137
131int mailmh_folder_move_message(struct mailmh_folder * dest_folder, 138int mailmh_folder_move_message(struct mailmh_folder * dest_folder,
132 struct mailmh_folder * src_folder, 139 struct mailmh_folder * src_folder,
133 uint32_t index); 140 uint32_t index);
134 141
135int mailmh_folder_update(struct mailmh_folder * folder); 142int mailmh_folder_update(struct mailmh_folder * folder);
136 143
137unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder); 144unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder);
138 145
139#ifdef __cplusplus 146#ifdef __cplusplus
140} 147}
141#endif 148#endif
142 149
143#endif 150#endif
diff --git a/kmicromail/libetpan/include/libetpan/mailstorage.h b/kmicromail/libetpan/include/libetpan/mailstorage.h
index d56aef1..4c57883 100644
--- a/kmicromail/libetpan/include/libetpan/mailstorage.h
+++ b/kmicromail/libetpan/include/libetpan/mailstorage.h
@@ -1,98 +1,99 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAIL_STORAGE_H 36#ifndef MAIL_STORAGE_H
37 37
38#define MAIL_STORAGE_H 38#define MAIL_STORAGE_H
39 39
40#include <libetpan/maildriver_types.h> 40#include <libetpan/maildriver_types.h>
41#include <libetpan/mailstorage_types.h> 41#include <libetpan/mailstorage_types.h>
42 42
43#ifdef __cplusplus 43#ifdef __cplusplus
44extern "C" { 44extern "C" {
45#endif 45#endif
46 46
47/* storage */ 47/* storage */
48 48
49/* 49/*
50 mailstorage_new 50 mailstorage_new
51 51
52 This function creates an empty storage. This storage have to be initialized. 52 This function creates an empty storage. This storage have to be initialized.
53 The "driver" and "data" fields should be initialized. 53 The "driver" and "data" fields should be initialized.
54 54
55 @param id is the name of the storage. It can be NULL. 55 @param id is the name of the storage. It can be NULL.
56 The given parameter is no more needed when the creation is finished. 56 The given parameter is no more needed when the creation is finished.
57 The given string is duplicated. 57 The given string is duplicated.
58 58
59 @return The mail storage is returned. 59 @return The mail storage is returned.
60*/ 60*/
61 61
62struct mailstorage * mailstorage_new(char * sto_id); 62struct mailstorage * mailstorage_new(char * sto_id);
63 63
64void mailstorage_free(struct mailstorage * storage); 64void 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
70int mailstorage_connect(struct mailstorage * storage); 70int mailstorage_connect(struct mailstorage * storage);
71 71
72void mailstorage_disconnect(struct mailstorage * storage); 72void mailstorage_disconnect(struct mailstorage * storage);
73 73
74int mailstorage_noop(struct mailstorage * storage);
75
74 76
75/* folder */ 77/* folder */
76 78
77struct mailfolder * mailfolder_new(struct mailstorage * fld_storage, 79struct 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
80void mailfolder_free(struct mailfolder * folder); 82void mailfolder_free(struct mailfolder * folder);
81 83
82int mailfolder_add_child(struct mailfolder * parent, 84int mailfolder_add_child(struct mailfolder * parent,
83 struct mailfolder * child); 85 struct mailfolder * child);
84 86
85int mailfolder_detach_parent(struct mailfolder * folder); 87int mailfolder_detach_parent(struct mailfolder * folder);
86 88
87int mailfolder_connect(struct mailfolder * folder); 89int mailfolder_connect(struct mailfolder * folder);
88 90
89void mailfolder_disconnect(struct mailfolder * folder); 91void 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/maildir/maildir.c b/kmicromail/libetpan/maildir/maildir.c
index 320ef81..0e038b1 100644
--- a/kmicromail/libetpan/maildir/maildir.c
+++ b/kmicromail/libetpan/maildir/maildir.c
@@ -305,385 +305,404 @@ static int add_message(struct maildir * md,
305 return res; 305 return res;
306} 306}
307 307
308static int add_directory(struct maildir * md, char * path, int is_new) 308static int add_directory(struct maildir * md, char * path, int is_new)
309{ 309{
310 DIR * d; 310 DIR * d;
311 struct dirent * entry; 311 struct dirent * entry;
312 int res; 312 int res;
313 int r; 313 int r;
314 char filename[PATH_MAX]; 314 char filename[PATH_MAX];
315 315
316 d = opendir(path); 316 d = opendir(path);
317 if (d == NULL) { 317 if (d == NULL) {
318 res = MAILDIR_ERROR_DIRECTORY; 318 res = MAILDIR_ERROR_DIRECTORY;
319 goto err; 319 goto err;
320 } 320 }
321 321
322 while ((entry = readdir(d)) != NULL) { 322 while ((entry = readdir(d)) != NULL) {
323 struct stat stat_info; 323 struct stat stat_info;
324 324
325 snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name); 325 snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name);
326 r = stat(filename, &stat_info); 326 r = stat(filename, &stat_info);
327 if (r < 0) 327 if (r < 0)
328 continue; 328 continue;
329 329
330 if (S_ISDIR(stat_info.st_mode)) 330 if (S_ISDIR(stat_info.st_mode))
331 continue; 331 continue;
332 332
333 r = add_message(md, entry->d_name, is_new); 333 r = add_message(md, entry->d_name, is_new);
334 if (r != MAILDIR_NO_ERROR) { 334 if (r != MAILDIR_NO_ERROR) {
335 /* ignore errors */ 335 /* ignore errors */
336 } 336 }
337 } 337 }
338 338
339 closedir(d); 339 closedir(d);
340 340
341 return MAILDIR_NO_ERROR; 341 return MAILDIR_NO_ERROR;
342 342
343 err: 343 err:
344 return res; 344 return res;
345} 345}
346 346
347int maildir_update(struct maildir * md) 347int maildir_update(struct maildir * md)
348{ 348{
349 struct stat stat_info; 349 struct stat stat_info;
350 char path_new[PATH_MAX]; 350 char path_new[PATH_MAX];
351 char path_cur[PATH_MAX]; 351 char path_cur[PATH_MAX];
352 int r; 352 int r;
353 int res; 353 int res;
354 354
355 snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path); 355 snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path);
356 snprintf(path_cur, sizeof(path_cur), "%s/cur", md->mdir_path); 356 snprintf(path_cur, sizeof(path_cur), "%s/cur", md->mdir_path);
357 357
358 /* did new/ changed ? */ 358 /* did new/ changed ? */
359 359
360 r = stat(path_new, &stat_info); 360 r = stat(path_new, &stat_info);
361 if (r < 0) { 361 if (r < 0) {
362 res = MAILDIR_ERROR_DIRECTORY; 362 res = MAILDIR_ERROR_DIRECTORY;
363 goto free; 363 goto free;
364 } 364 }
365 365
366 if (md->mdir_mtime_new != stat_info.st_mtime) { 366 if (md->mdir_mtime_new != stat_info.st_mtime) {
367 md->mdir_mtime_new = stat_info.st_mtime; 367 md->mdir_mtime_new = stat_info.st_mtime;
368 368
369 maildir_flush(md, 1); 369 maildir_flush(md, 1);
370 370
371 /* messages in new */ 371 /* messages in new */
372 r = add_directory(md, path_new, 1); 372 r = add_directory(md, path_new, 1);
373 if (r != MAILDIR_NO_ERROR) { 373 if (r != MAILDIR_NO_ERROR) {
374 res = r; 374 res = r;
375 goto free; 375 goto free;
376 } 376 }
377 } 377 }
378 378
379 /* did cur/ changed ? */ 379 /* did cur/ changed ? */
380 380
381 r = stat(path_cur, &stat_info); 381 r = stat(path_cur, &stat_info);
382 if (r < 0) { 382 if (r < 0) {
383 res = MAILDIR_ERROR_DIRECTORY; 383 res = MAILDIR_ERROR_DIRECTORY;
384 goto free; 384 goto free;
385 } 385 }
386 386
387 if (md->mdir_mtime_cur != stat_info.st_mtime) { 387 if (md->mdir_mtime_cur != stat_info.st_mtime) {
388 md->mdir_mtime_cur = stat_info.st_mtime; 388 md->mdir_mtime_cur = stat_info.st_mtime;
389 389
390 maildir_flush(md, 0); 390 maildir_flush(md, 0);
391 391
392 /* messages in cur */ 392 /* messages in cur */
393 r = add_directory(md, path_cur, 0); 393 r = add_directory(md, path_cur, 0);
394 if (r != MAILDIR_NO_ERROR) { 394 if (r != MAILDIR_NO_ERROR) {
395 res = r; 395 res = r;
396 goto free; 396 goto free;
397 } 397 }
398 } 398 }
399 399
400 return MAILDIR_NO_ERROR; 400 return MAILDIR_NO_ERROR;
401 401
402 free: 402 free:
403 maildir_flush(md, 0); 403 maildir_flush(md, 0);
404 maildir_flush(md, 1); 404 maildir_flush(md, 1);
405 md->mdir_mtime_cur = (time_t) -1; 405 md->mdir_mtime_cur = (time_t) -1;
406 md->mdir_mtime_new = (time_t) -1; 406 md->mdir_mtime_new = (time_t) -1;
407 return res; 407 return res;
408} 408}
409 409
410#ifndef LIBETPAN_SYSTEM_BASENAME 410#ifndef LIBETPAN_SYSTEM_BASENAME
411static char * libetpan_basename(char * filename) 411static char * libetpan_basename(char * filename)
412{ 412{
413 char * next; 413 char * next;
414 char * p; 414 char * p;
415 415
416 p = filename; 416 p = filename;
417 next = strchr(p, '/'); 417 next = strchr(p, '/');
418 418
419 while (next != NULL) { 419 while (next != NULL) {
420 p = next; 420 p = next;
421 next = strchr(p + 1, '/'); 421 next = strchr(p + 1, '/');
422 } 422 }
423 423
424 if (p == filename) 424 if (p == filename)
425 return filename; 425 return filename;
426 else 426 else
427 return p + 1; 427 return p + 1;
428} 428}
429#else 429#else
430#define libetpan_basename(a) basename(a) 430#define libetpan_basename(a) basename(a)
431#endif 431#endif
432 432
433int maildir_message_add(struct maildir * md, 433int maildir_message_add_uid(struct maildir * md,
434 const char * message, size_t size) 434 const char * message, size_t size,
435 char * uid, size_t max_uid_len)
435{ 436{
436 char path_new[PATH_MAX]; 437 char path_new[PATH_MAX];
437 char tmpname[PATH_MAX]; 438 char tmpname[PATH_MAX];
438 int fd; 439 int fd;
439 int r; 440 int r;
440 char * mapping; 441 char * mapping;
441 char * delivery_tmp_name; 442 char * delivery_tmp_name;
442 char * delivery_tmp_basename; 443 char * delivery_tmp_basename;
443 char delivery_new_name[PATH_MAX]; 444 char delivery_new_name[PATH_MAX];
444 char * delivery_new_basename; 445 char * delivery_new_basename;
445 int res; 446 int res;
446 struct stat stat_info; 447 struct stat stat_info;
447 448
448 r = maildir_update(md); 449 r = maildir_update(md);
449 if (r != MAILDIR_NO_ERROR) { 450 if (r != MAILDIR_NO_ERROR) {
450 res = r; 451 res = r;
451 goto err; 452 goto err;
452 } 453 }
453 454
454 /* write to tmp/ with a classic temporary file */ 455 /* write to tmp/ with a classic temporary file */
455 456
456 snprintf(tmpname, sizeof(tmpname), "%s/tmp/etpan-maildir-XXXXXX", md->mdir_path); 457 snprintf(tmpname, sizeof(tmpname), "%s/tmp/etpan-maildir-XXXXXX",
458 md->mdir_path);
457 fd = mkstemp(tmpname); 459 fd = mkstemp(tmpname);
458 if (fd < 0) { 460 if (fd < 0) {
459 res = MAILDIR_ERROR_FILE; 461 res = MAILDIR_ERROR_FILE;
460 goto err; 462 goto err;
461 } 463 }
462 464
463 r = ftruncate(fd, size); 465 r = ftruncate(fd, size);
464 if (r < 0) { 466 if (r < 0) {
465 res = MAILDIR_ERROR_FILE; 467 res = MAILDIR_ERROR_FILE;
466 goto close; 468 goto close;
467 } 469 }
468 470
469 mapping = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 471 mapping = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
470 if (mapping == MAP_FAILED) { 472 if (mapping == MAP_FAILED) {
471 res = MAILDIR_ERROR_FILE; 473 res = MAILDIR_ERROR_FILE;
472 goto close; 474 goto close;
473 } 475 }
474 476
475 memcpy(mapping, message, size); 477 memcpy(mapping, message, size);
476 478
477 msync(mapping, size, MS_SYNC); 479 msync(mapping, size, MS_SYNC);
478 munmap(mapping, size); 480 munmap(mapping, size);
479 481
480 close(fd); 482 close(fd);
481 483
482 /* write to tmp/ with maildir standard name */ 484 /* write to tmp/ with maildir standard name */
483 485
484 delivery_tmp_name = maildir_get_new_message_filename(md, tmpname); 486 delivery_tmp_name = maildir_get_new_message_filename(md, tmpname);
485 if (delivery_tmp_name == NULL) { 487 if (delivery_tmp_name == NULL) {
486 res = MAILDIR_ERROR_FILE; 488 res = MAILDIR_ERROR_FILE;
487 goto unlink; 489 goto unlink;
488 } 490 }
489 491
490 /* write to new/ with maildir standard name */ 492 /* write to new/ with maildir standard name */
491 493
492 strncpy(tmpname, delivery_tmp_name, sizeof(tmpname)); 494 strncpy(tmpname, delivery_tmp_name, sizeof(tmpname));
493 tmpname[sizeof(tmpname) - 1] = '\0'; 495 tmpname[sizeof(tmpname) - 1] = '\0';
494 496
495 delivery_tmp_basename = libetpan_basename(tmpname); 497 delivery_tmp_basename = libetpan_basename(tmpname);
496 498
497 snprintf(delivery_new_name, sizeof(delivery_new_name), "%s/new/%s", 499 snprintf(delivery_new_name, sizeof(delivery_new_name), "%s/new/%s",
498 md->mdir_path, delivery_tmp_basename); 500 md->mdir_path, delivery_tmp_basename);
499 501
500 r = link(delivery_tmp_name, delivery_new_name); 502 r = link(delivery_tmp_name, delivery_new_name);
501 if (r < 0) { 503 if (r < 0) {
502 res = MAILDIR_ERROR_FILE; 504 res = MAILDIR_ERROR_FILE;
503 goto unlink_tmp; 505 goto unlink_tmp;
504 } 506 }
505 507
506 snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path); 508 snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path);
507 r = stat(path_new, &stat_info); 509 r = stat(path_new, &stat_info);
508 if (r < 0) { 510 if (r < 0) {
509 unlink(delivery_new_name); 511 unlink(delivery_new_name);
510 res = MAILDIR_ERROR_FILE; 512 res = MAILDIR_ERROR_FILE;
511 goto unlink_tmp; 513 goto unlink_tmp;
512 } 514 }
513 515
514 md->mdir_mtime_new = stat_info.st_mtime; 516 md->mdir_mtime_new = stat_info.st_mtime;
515 517
516 delivery_new_basename = libetpan_basename(delivery_new_name); 518 delivery_new_basename = libetpan_basename(delivery_new_name);
517 519
518 r = add_message(md, delivery_new_basename, 1); 520 r = add_message(md, delivery_new_basename, 1);
519 if (r != MAILDIR_NO_ERROR) { 521 if (r != MAILDIR_NO_ERROR) {
520 unlink(delivery_new_name); 522 unlink(delivery_new_name);
521 res = MAILDIR_ERROR_FILE; 523 res = MAILDIR_ERROR_FILE;
522 goto unlink_tmp; 524 goto unlink_tmp;
523 } 525 }
524 526
527 if (uid != NULL)
528 strncpy(uid, delivery_new_basename, max_uid_len);
529
525 unlink(delivery_tmp_name); 530 unlink(delivery_tmp_name);
526 free(delivery_tmp_name); 531 free(delivery_tmp_name);
527 532
528 return MAILDIR_NO_ERROR; 533 return MAILDIR_NO_ERROR;
529 534
530 unlink_tmp: 535 unlink_tmp:
531 unlink(delivery_tmp_name); 536 unlink(delivery_tmp_name);
532 free(delivery_tmp_name); 537 free(delivery_tmp_name);
533 goto err; 538 goto err;
534 close: 539 close:
535 close(fd); 540 close(fd);
536 unlink: 541 unlink:
537 unlink(tmpname); 542 unlink(tmpname);
538 err: 543 err:
539 return res; 544 return res;
540} 545}
541 546
542int maildir_message_add_file(struct maildir * md, int fd) 547int maildir_message_add(struct maildir * md,
548 const char * message, size_t size)
549{
550 return maildir_message_add_uid(md, message, size,
551 NULL, 0);
552}
553
554int maildir_message_add_file_uid(struct maildir * md, int fd,
555 char * uid, size_t max_uid_len)
543{ 556{
544 char * message; 557 char * message;
545 struct stat buf; 558 struct stat buf;
546 int r; 559 int r;
547 560
548 if (fstat(fd, &buf) == -1) 561 if (fstat(fd, &buf) == -1)
549 return MAILDIR_ERROR_FILE; 562 return MAILDIR_ERROR_FILE;
550 563
551 message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 564 message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
552 if (message == MAP_FAILED) 565 if (message == MAP_FAILED)
553 return MAILDIR_ERROR_FILE; 566 return MAILDIR_ERROR_FILE;
554 567
555 r = maildir_message_add(md, message, buf.st_size); 568 r = maildir_message_add_uid(md, message, buf.st_size, uid, max_uid_len);
556 569
557 munmap(message, buf.st_size); 570 munmap(message, buf.st_size);
558 571
559 return r; 572 return r;
560} 573}
561 574
575int maildir_message_add_file(struct maildir * md, int fd)
576{
577 return maildir_message_add_file_uid(md, fd,
578 NULL, 0);
579}
580
562char * maildir_message_get(struct maildir * md, const char * uid) 581char * maildir_message_get(struct maildir * md, const char * uid)
563{ 582{
564 chashdatum key; 583 chashdatum key;
565 chashdatum value; 584 chashdatum value;
566 char filename[PATH_MAX]; 585 char filename[PATH_MAX];
567 char * dup_filename; 586 char * dup_filename;
568 struct maildir_msg * msg; 587 struct maildir_msg * msg;
569 char * dir; 588 char * dir;
570 int r; 589 int r;
571 590
572 key.data = (void *) uid; 591 key.data = (void *) uid;
573 key.len = strlen(uid); 592 key.len = strlen(uid);
574 r = chash_get(md->mdir_msg_hash, &key, &value); 593 r = chash_get(md->mdir_msg_hash, &key, &value);
575 if (r < 0) 594 if (r < 0)
576 return NULL; 595 return NULL;
577 596
578 msg = value.data; 597 msg = value.data;
579 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) 598 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0)
580 dir = "new"; 599 dir = "new";
581 else 600 else
582 dir = "cur"; 601 dir = "cur";
583 602
584 snprintf(filename, sizeof(filename), "%s/%s/%s", 603 snprintf(filename, sizeof(filename), "%s/%s/%s",
585 md->mdir_path, dir, msg->msg_filename); 604 md->mdir_path, dir, msg->msg_filename);
586 605
587 dup_filename = strdup(filename); 606 dup_filename = strdup(filename);
588 if (dup_filename == NULL) 607 if (dup_filename == NULL)
589 return NULL; 608 return NULL;
590 609
591 return dup_filename; 610 return dup_filename;
592} 611}
593 612
594int maildir_message_remove(struct maildir * md, const char * uid) 613int maildir_message_remove(struct maildir * md, const char * uid)
595{ 614{
596 chashdatum key; 615 chashdatum key;
597 chashdatum value; 616 chashdatum value;
598 char filename[PATH_MAX]; 617 char filename[PATH_MAX];
599 struct maildir_msg * msg; 618 struct maildir_msg * msg;
600 char * dir; 619 char * dir;
601 int r; 620 int r;
602 int res; 621 int res;
603 622
604 key.data = (void *) uid; 623 key.data = (void *) uid;
605 key.len = strlen(uid); 624 key.len = strlen(uid);
606 r = chash_get(md->mdir_msg_hash, &key, &value); 625 r = chash_get(md->mdir_msg_hash, &key, &value);
607 if (r < 0) { 626 if (r < 0) {
608 res = MAILDIR_ERROR_NOT_FOUND; 627 res = MAILDIR_ERROR_NOT_FOUND;
609 goto err; 628 goto err;
610 } 629 }
611 630
612 msg = value.data; 631 msg = value.data;
613 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) 632 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0)
614 dir = "new"; 633 dir = "new";
615 else 634 else
616 dir = "cur"; 635 dir = "cur";
617 636
618 snprintf(filename, sizeof(filename), "%s/%s/%s", 637 snprintf(filename, sizeof(filename), "%s/%s/%s",
619 md->mdir_path, dir, msg->msg_filename); 638 md->mdir_path, dir, msg->msg_filename);
620 639
621 r = unlink(filename); 640 r = unlink(filename);
622 if (r < 0) { 641 if (r < 0) {
623 res = MAILDIR_ERROR_FILE; 642 res = MAILDIR_ERROR_FILE;
624 goto err; 643 goto err;
625 } 644 }
626 645
627 return MAILDIR_NO_ERROR; 646 return MAILDIR_NO_ERROR;
628 647
629 err: 648 err:
630 return res; 649 return res;
631} 650}
632 651
633int maildir_message_change_flags(struct maildir * md, 652int maildir_message_change_flags(struct maildir * md,
634 const char * uid, int new_flags) 653 const char * uid, int new_flags)
635{ 654{
636 chashdatum key; 655 chashdatum key;
637 chashdatum value; 656 chashdatum value;
638 char filename[PATH_MAX]; 657 char filename[PATH_MAX];
639 struct maildir_msg * msg; 658 struct maildir_msg * msg;
640 char * dir; 659 char * dir;
641 int r; 660 int r;
642 char new_filename[PATH_MAX]; 661 char new_filename[PATH_MAX];
643 char flag_str[5]; 662 char flag_str[5];
644 size_t i; 663 size_t i;
645 int res; 664 int res;
646 665
647 key.data = (void *) uid; 666 key.data = (void *) uid;
648 key.len = strlen(uid); 667 key.len = strlen(uid);
649 r = chash_get(md->mdir_msg_hash, &key, &value); 668 r = chash_get(md->mdir_msg_hash, &key, &value);
650 if (r < 0) { 669 if (r < 0) {
651 res = MAILDIR_ERROR_NOT_FOUND; 670 res = MAILDIR_ERROR_NOT_FOUND;
652 goto err; 671 goto err;
653 } 672 }
654 673
655 msg = value.data; 674 msg = value.data;
656 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) 675 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0)
657 dir = "new"; 676 dir = "new";
658 else 677 else
659 dir = "cur"; 678 dir = "cur";
660 679
661 snprintf(filename, sizeof(filename), "%s/%s/%s", 680 snprintf(filename, sizeof(filename), "%s/%s/%s",
662 md->mdir_path, dir, msg->msg_filename); 681 md->mdir_path, dir, msg->msg_filename);
663 682
664 if ((new_flags & MAILDIR_FLAG_NEW) != 0) 683 if ((new_flags & MAILDIR_FLAG_NEW) != 0)
665 dir = "new"; 684 dir = "new";
666 else 685 else
667 dir = "cur"; 686 dir = "cur";
668 687
669 i = 0; 688 i = 0;
670 if ((new_flags & MAILDIR_FLAG_SEEN) != 0) { 689 if ((new_flags & MAILDIR_FLAG_SEEN) != 0) {
671 flag_str[i] = 'S'; 690 flag_str[i] = 'S';
672 i ++; 691 i ++;
673 } 692 }
674 if ((new_flags & MAILDIR_FLAG_REPLIED) != 0) { 693 if ((new_flags & MAILDIR_FLAG_REPLIED) != 0) {
675 flag_str[i] = 'R'; 694 flag_str[i] = 'R';
676 i ++; 695 i ++;
677 } 696 }
678 if ((new_flags & MAILDIR_FLAG_FLAGGED) != 0) { 697 if ((new_flags & MAILDIR_FLAG_FLAGGED) != 0) {
679 flag_str[i] = 'F'; 698 flag_str[i] = 'F';
680 i ++; 699 i ++;
681 } 700 }
682 if ((new_flags & MAILDIR_FLAG_TRASHED) != 0) { 701 if ((new_flags & MAILDIR_FLAG_TRASHED) != 0) {
683 flag_str[i] = 'T'; 702 flag_str[i] = 'T';
684 i ++; 703 i ++;
685 } 704 }
686 flag_str[i] = 0; 705 flag_str[i] = 0;
687 706
688 if (flag_str[0] == '\0') 707 if (flag_str[0] == '\0')
689 snprintf(new_filename, sizeof(new_filename), "%s/%s/%s", 708 snprintf(new_filename, sizeof(new_filename), "%s/%s/%s",
diff --git a/kmicromail/libetpan/maildir/maildir.h b/kmicromail/libetpan/maildir/maildir.h
index b782484..268dda1 100644
--- a/kmicromail/libetpan/maildir/maildir.h
+++ b/kmicromail/libetpan/maildir/maildir.h
@@ -1,60 +1,67 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001 - 2003 - DINH Viet Hoa 4 * Copyright (C) 2001 - 2003 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAILDIR_H 36#ifndef MAILDIR_H
37 37
38#define MAILDIR_H 38#define MAILDIR_H
39 39
40#include <libetpan/maildir_types.h> 40#include <libetpan/maildir_types.h>
41 41
42struct maildir * maildir_new(const char * path); 42struct maildir * maildir_new(const char * path);
43 43
44void maildir_free(struct maildir * md); 44void maildir_free(struct maildir * md);
45 45
46int maildir_update(struct maildir * md); 46int maildir_update(struct maildir * md);
47 47
48int maildir_message_add_uid(struct maildir * md,
49 const char * message, size_t size,
50 char * uid, size_t max_uid_len);
51
48int maildir_message_add(struct maildir * md, 52int maildir_message_add(struct maildir * md,
49 const char * message, size_t size); 53 const char * message, size_t size);
50 54
55int maildir_message_add_file_uid(struct maildir * md, int fd,
56 char * uid, size_t max_uid_len);
57
51int maildir_message_add_file(struct maildir * md, int fd); 58int maildir_message_add_file(struct maildir * md, int fd);
52 59
53char * maildir_message_get(struct maildir * md, const char * uid); 60char * maildir_message_get(struct maildir * md, const char * uid);
54 61
55int maildir_message_remove(struct maildir * md, const char * uid); 62int maildir_message_remove(struct maildir * md, const char * uid);
56 63
57int maildir_message_change_flags(struct maildir * md, 64int maildir_message_change_flags(struct maildir * md,
58 const char * uid, int new_flags); 65 const char * uid, int new_flags);
59 66
60#endif 67#endif
diff --git a/kmicromail/libetpan/mbox/mailmbox.c b/kmicromail/libetpan/mbox/mailmbox.c
index 280c313..b3fce02 100644
--- a/kmicromail/libetpan/mbox/mailmbox.c
+++ b/kmicromail/libetpan/mbox/mailmbox.c
@@ -72,256 +72,259 @@
72 72
73#ifndef FALSE 73#ifndef FALSE
74#define FALSE 0 74#define FALSE 0
75#endif 75#endif
76 76
77int mailmbox_write_lock(struct mailmbox_folder * folder) 77int mailmbox_write_lock(struct mailmbox_folder * folder)
78{ 78{
79 int r; 79 int r;
80 80
81 if (folder->mb_read_only) 81 if (folder->mb_read_only)
82 return MAILMBOX_ERROR_READONLY; 82 return MAILMBOX_ERROR_READONLY;
83 83
84 r = maillock_write_lock(folder->mb_filename, folder->mb_fd); 84 r = maillock_write_lock(folder->mb_filename, folder->mb_fd);
85 if (r == 0) 85 if (r == 0)
86 return MAILMBOX_NO_ERROR; 86 return MAILMBOX_NO_ERROR;
87 else 87 else
88 return MAILMBOX_ERROR_FILE; 88 return MAILMBOX_ERROR_FILE;
89} 89}
90 90
91int mailmbox_write_unlock(struct mailmbox_folder * folder) 91int mailmbox_write_unlock(struct mailmbox_folder * folder)
92{ 92{
93 int r; 93 int r;
94 94
95 r = maillock_write_unlock(folder->mb_filename, folder->mb_fd); 95 r = maillock_write_unlock(folder->mb_filename, folder->mb_fd);
96 if (r == 0) 96 if (r == 0)
97 return MAILMBOX_NO_ERROR; 97 return MAILMBOX_NO_ERROR;
98 else 98 else
99 return MAILMBOX_ERROR_FILE; 99 return MAILMBOX_ERROR_FILE;
100} 100}
101 101
102int mailmbox_read_lock(struct mailmbox_folder * folder) 102int mailmbox_read_lock(struct mailmbox_folder * folder)
103{ 103{
104 int r; 104 int r;
105 105
106 r = maillock_read_lock(folder->mb_filename, folder->mb_fd); 106 r = maillock_read_lock(folder->mb_filename, folder->mb_fd);
107 if (r == 0) 107 if (r == 0)
108 return MAILMBOX_NO_ERROR; 108 return MAILMBOX_NO_ERROR;
109 else 109 else
110 return MAILMBOX_ERROR_FILE; 110 return MAILMBOX_ERROR_FILE;
111} 111}
112 112
113int mailmbox_read_unlock(struct mailmbox_folder * folder) 113int mailmbox_read_unlock(struct mailmbox_folder * folder)
114{ 114{
115 int r; 115 int r;
116 116
117 r = maillock_read_unlock(folder->mb_filename, folder->mb_fd); 117 r = maillock_read_unlock(folder->mb_filename, folder->mb_fd);
118 if (r == 0) 118 if (r == 0)
119 return MAILMBOX_NO_ERROR; 119 return MAILMBOX_NO_ERROR;
120 else 120 else
121 return MAILMBOX_ERROR_FILE; 121 return MAILMBOX_ERROR_FILE;
122} 122}
123 123
124 124
125/* 125/*
126 map the file into memory. 126 map the file into memory.
127 the file must be locked. 127 the file must be locked.
128*/ 128*/
129 129
130int mailmbox_map(struct mailmbox_folder * folder) 130int mailmbox_map(struct mailmbox_folder * folder)
131{ 131{
132 char * str; 132 char * str;
133 struct stat buf; 133 struct stat buf;
134 int res; 134 int res;
135 int r; 135 int r;
136 136
137 r = stat(folder->mb_filename, &buf); 137 r = stat(folder->mb_filename, &buf);
138 if (r < 0) { 138 if (r < 0) {
139 res = MAILMBOX_ERROR_FILE; 139 res = MAILMBOX_ERROR_FILE;
140 goto err; 140 goto err;
141 } 141 }
142 142
143 if (folder->mb_read_only) 143 if (folder->mb_read_only)
144 str = (char *) mmap(0, buf.st_size, PROT_READ, 144 str = (char *) mmap(0, buf.st_size, PROT_READ,
145 MAP_PRIVATE, folder->mb_fd, 0); 145 MAP_PRIVATE, folder->mb_fd, 0);
146 else 146 else
147 str = (char *) mmap(0, buf.st_size, PROT_READ | PROT_WRITE, 147 str = (char *) mmap(0, buf.st_size, PROT_READ | PROT_WRITE,
148 MAP_SHARED, folder->mb_fd, 0); 148 MAP_SHARED, folder->mb_fd, 0);
149 if (str == MAP_FAILED) { 149 if (str == MAP_FAILED) {
150 res = MAILMBOX_ERROR_FILE; 150 res = MAILMBOX_ERROR_FILE;
151 goto err; 151 goto err;
152 } 152 }
153 153
154 folder->mb_mapping = str; 154 folder->mb_mapping = str;
155 folder->mb_mapping_size = buf.st_size; 155 folder->mb_mapping_size = buf.st_size;
156 156
157 return MAILMBOX_NO_ERROR; 157 return MAILMBOX_NO_ERROR;
158 158
159 err: 159 err:
160 return res; 160 return res;
161} 161}
162 162
163/* 163/*
164 unmap the file 164 unmap the file
165*/ 165*/
166 166
167void mailmbox_unmap(struct mailmbox_folder * folder) 167void mailmbox_unmap(struct mailmbox_folder * folder)
168{ 168{
169 munmap(folder->mb_mapping, folder->mb_mapping_size); 169 munmap(folder->mb_mapping, folder->mb_mapping_size);
170 folder->mb_mapping = NULL; 170 folder->mb_mapping = NULL;
171 folder->mb_mapping_size = 0; 171 folder->mb_mapping_size = 0;
172} 172}
173 173
174void mailmbox_sync(struct mailmbox_folder * folder) 174void mailmbox_sync(struct mailmbox_folder * folder)
175{ 175{
176 msync(folder->mb_mapping, folder->mb_mapping_size, MS_SYNC); 176 msync(folder->mb_mapping, folder->mb_mapping_size, MS_SYNC);
177} 177}
178 178
179void mailmbox_timestamp(struct mailmbox_folder * folder) 179void mailmbox_timestamp(struct mailmbox_folder * folder)
180{ 180{
181 int r; 181 int r;
182 struct stat buf; 182 struct stat buf;
183 183
184 r = stat(folder->mb_filename, &buf); 184 r = stat(folder->mb_filename, &buf);
185 if (r < 0) 185 if (r < 0)
186 folder->mb_mtime = (time_t) -1; 186 folder->mb_mtime = (time_t) -1;
187 else 187 else
188 folder->mb_mtime = buf.st_mtime; 188 folder->mb_mtime = buf.st_mtime;
189} 189}
190 190
191/* 191/*
192 open the file 192 open the file
193*/ 193*/
194 194
195int mailmbox_open(struct mailmbox_folder * folder) 195int mailmbox_open(struct mailmbox_folder * folder)
196{ 196{
197 int fd; 197 int fd;
198 int read_only; 198 int read_only;
199 199
200 fd = -1;
201 read_only = TRUE;
202
200 if (!folder->mb_read_only) { 203 if (!folder->mb_read_only) {
201 read_only = FALSE; 204 read_only = FALSE;
202 fd = open(folder->mb_filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 205 fd = open(folder->mb_filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
203 } 206 }
204 207
205 if (folder->mb_read_only || (fd < 0)) { 208 if (folder->mb_read_only || (fd < 0)) {
206 read_only = TRUE; 209 read_only = TRUE;
207 fd = open(folder->mb_filename, O_RDONLY); 210 fd = open(folder->mb_filename, O_RDONLY);
208 if (fd < 0) 211 if (fd < 0)
209 return MAILMBOX_ERROR_FILE_NOT_FOUND; 212 return MAILMBOX_ERROR_FILE_NOT_FOUND;
210 } 213 }
211 214
212 folder->mb_fd = fd; 215 folder->mb_fd = fd;
213 folder->mb_read_only = read_only; 216 folder->mb_read_only = read_only;
214 217
215 return MAILMBOX_NO_ERROR; 218 return MAILMBOX_NO_ERROR;
216} 219}
217 220
218/* 221/*
219 close the file 222 close the file
220*/ 223*/
221 224
222void mailmbox_close(struct mailmbox_folder * folder) 225void mailmbox_close(struct mailmbox_folder * folder)
223{ 226{
224 close(folder->mb_fd); 227 close(folder->mb_fd);
225 folder->mb_fd = -1; 228 folder->mb_fd = -1;
226} 229}
227 230
228 231
229static int mailmbox_validate_lock(struct mailmbox_folder * folder, 232static int mailmbox_validate_lock(struct mailmbox_folder * folder,
230 int (* custom_lock)(struct mailmbox_folder *), 233 int (* custom_lock)(struct mailmbox_folder *),
231 int (* custom_unlock)(struct mailmbox_folder *)) 234 int (* custom_unlock)(struct mailmbox_folder *))
232{ 235{
233 struct stat buf; 236 struct stat buf;
234 int res; 237 int res;
235 int r; 238 int r;
236 239
237 r = stat(folder->mb_filename, &buf); 240 r = stat(folder->mb_filename, &buf);
238 if (r < 0) { 241 if (r < 0) {
239 buf.st_mtime = (time_t) -1; 242 buf.st_mtime = (time_t) -1;
240 } 243 }
241 244
242 if ((buf.st_mtime != folder->mb_mtime) || 245 if ((buf.st_mtime != folder->mb_mtime) ||
243 ((size_t) buf.st_size != folder->mb_mapping_size)) { 246 ((size_t) buf.st_size != folder->mb_mapping_size)) {
244 int r; 247 int r;
245 248
246 mailmbox_unmap(folder); 249 mailmbox_unmap(folder);
247 mailmbox_close(folder); 250 mailmbox_close(folder);
248 251
249 r = mailmbox_open(folder); 252 r = mailmbox_open(folder);
250 if (r != MAILMBOX_NO_ERROR) { 253 if (r != MAILMBOX_NO_ERROR) {
251 res = r; 254 res = r;
252 goto err; 255 goto err;
253 } 256 }
254 257
255 r = custom_lock(folder); 258 r = custom_lock(folder);
256 if (r != MAILMBOX_NO_ERROR) { 259 if (r != MAILMBOX_NO_ERROR) {
257 res = r; 260 res = r;
258 goto err; 261 goto err;
259 } 262 }
260 263
261 r = mailmbox_map(folder); 264 r = mailmbox_map(folder);
262 if (r != MAILMBOX_NO_ERROR) { 265 if (r != MAILMBOX_NO_ERROR) {
263 res = r; 266 res = r;
264 goto err_unlock; 267 goto err_unlock;
265 } 268 }
266 269
267 r = mailmbox_parse(folder); 270 r = mailmbox_parse(folder);
268 if (r != MAILMBOX_NO_ERROR) { 271 if (r != MAILMBOX_NO_ERROR) {
269 res = r; 272 res = r;
270 goto err_unlock; 273 goto err_unlock;
271 } 274 }
272 275
273 folder->mb_mtime = buf.st_mtime; 276 folder->mb_mtime = buf.st_mtime;
274 277
275 return MAILMBOX_NO_ERROR; 278 return MAILMBOX_NO_ERROR;
276 } 279 }
277 else { 280 else {
278 r = custom_lock(folder); 281 r = custom_lock(folder);
279 if (r != MAILMBOX_NO_ERROR) { 282 if (r != MAILMBOX_NO_ERROR) {
280 res = r; 283 res = r;
281 goto err; 284 goto err;
282 } 285 }
283 } 286 }
284 287
285 return MAILMBOX_NO_ERROR; 288 return MAILMBOX_NO_ERROR;
286 289
287 err_unlock: 290 err_unlock:
288 custom_unlock(folder); 291 custom_unlock(folder);
289 err: 292 err:
290 return res; 293 return res;
291} 294}
292 295
293 296
294int mailmbox_validate_write_lock(struct mailmbox_folder * folder) 297int mailmbox_validate_write_lock(struct mailmbox_folder * folder)
295{ 298{
296 return mailmbox_validate_lock(folder, 299 return mailmbox_validate_lock(folder,
297 mailmbox_write_lock, 300 mailmbox_write_lock,
298 mailmbox_write_unlock); 301 mailmbox_write_unlock);
299} 302}
300 303
301 304
302int mailmbox_validate_read_lock(struct mailmbox_folder * folder) 305int mailmbox_validate_read_lock(struct mailmbox_folder * folder)
303{ 306{
304 return mailmbox_validate_lock(folder, 307 return mailmbox_validate_lock(folder,
305 mailmbox_read_lock, 308 mailmbox_read_lock,
306 mailmbox_read_unlock); 309 mailmbox_read_unlock);
307} 310}
308 311
309 312
310/* ********************************************************************** */ 313/* ********************************************************************** */
311/* append messages */ 314/* append messages */
312 315
313#define MAX_FROM_LINE_SIZE 256 316#define MAX_FROM_LINE_SIZE 256
314 317
315static inline size_t get_line(const char * line, size_t length, 318static inline size_t get_line(const char * line, size_t length,
316 const char ** pnext_line, size_t * pcount) 319 const char ** pnext_line, size_t * pcount)
317{ 320{
318 size_t count; 321 size_t count;
319 322
320 count = 0; 323 count = 0;
321 324
322 while (1) { 325 while (1) {
323 if (length == 0) 326 if (length == 0)
324 break; 327 break;
325 328
326 if (* line == '\r') { 329 if (* line == '\r') {
327 line ++; 330 line ++;
@@ -492,424 +495,436 @@ static inline char * write_fixed_line(char * str,
492 } 495 }
493 496
494 memcpy(str, line, count); 497 memcpy(str, line, count);
495 498
496 * pnext_line = next_line; 499 * pnext_line = next_line;
497 * pcount = count; 500 * pcount = count;
498 str += count; 501 str += count;
499 502
500 return str; 503 return str;
501} 504}
502 505
503static char * write_fixed_message(char * str, 506static char * write_fixed_message(char * str,
504 const char * message, size_t size, 507 const char * message, size_t size,
505 uint32_t uid, int force_no_uid) 508 uint32_t uid, int force_no_uid)
506{ 509{
507 size_t fixed_size; 510 size_t fixed_size;
508 size_t cur_token; 511 size_t cur_token;
509 size_t left; 512 size_t left;
510 int end; 513 int end;
511 int r; 514 int r;
512 const char * cur_src; 515 const char * cur_src;
513 size_t numlen; 516 size_t numlen;
514 517
515 cur_token = 0; 518 cur_token = 0;
516 519
517 fixed_size = 0; 520 fixed_size = 0;
518 521
519 /* headers */ 522 /* headers */
520 523
521 end = FALSE; 524 end = FALSE;
522 while (!end) { 525 while (!end) {
523 size_t begin; 526 size_t begin;
524 int ignore; 527 int ignore;
525 528
526 ignore = FALSE; 529 ignore = FALSE;
527 begin = cur_token; 530 begin = cur_token;
528 if (cur_token + strlen(UID_HEADER) <= size) { 531 if (cur_token + strlen(UID_HEADER) <= size) {
529 if (message[cur_token] == 'X') { 532 if (message[cur_token] == 'X') {
530 if (strncasecmp(message + cur_token, UID_HEADER, 533 if (strncasecmp(message + cur_token, UID_HEADER,
531 strlen(UID_HEADER)) == 0) { 534 strlen(UID_HEADER)) == 0) {
532 ignore = TRUE; 535 ignore = TRUE;
533 } 536 }
534 } 537 }
535 } 538 }
536 539
537 r = mailimf_ignore_field_parse(message, size, &cur_token); 540 r = mailimf_ignore_field_parse(message, size, &cur_token);
538 switch (r) { 541 switch (r) {
539 case MAILIMF_NO_ERROR: 542 case MAILIMF_NO_ERROR:
540 if (!ignore) { 543 if (!ignore) {
541 memcpy(str, message + begin, cur_token - begin); 544 memcpy(str, message + begin, cur_token - begin);
542 str += cur_token - begin; 545 str += cur_token - begin;
543 } 546 }
544 break; 547 break;
545 case MAILIMF_ERROR_PARSE: 548 case MAILIMF_ERROR_PARSE:
546 default: 549 default:
547 end = TRUE; 550 end = TRUE;
548 break; 551 break;
549 } 552 }
550 } 553 }
551 554
552 if (!force_no_uid) { 555 if (!force_no_uid) {
553 /* UID header */ 556 /* UID header */
554 557
555 memcpy(str, UID_HEADER " ", strlen(UID_HEADER " ")); 558 memcpy(str, UID_HEADER " ", strlen(UID_HEADER " "));
556 str += strlen(UID_HEADER " "); 559 str += strlen(UID_HEADER " ");
557 numlen = snprintf(str, 20, "%i\r\n", uid); 560 numlen = snprintf(str, 20, "%i\r\n", uid);
558 str += numlen; 561 str += numlen;
559 } 562 }
560 563
561 /* body */ 564 /* body */
562 565
563 cur_src = message + cur_token; 566 cur_src = message + cur_token;
564 left = size - cur_token; 567 left = size - cur_token;
565 while (left > 0) { 568 while (left > 0) {
566 size_t count; 569 size_t count;
567 const char * next; 570 const char * next;
568 571
569 str = write_fixed_line(str, cur_src, left, &next, &count); 572 str = write_fixed_line(str, cur_src, left, &next, &count);
570 573
571 cur_src = next; 574 cur_src = next;
572 left -= count; 575 left -= count;
573 } 576 }
574 577
575 return str; 578 return str;
576} 579}
577 580
578#define DEFAULT_FROM_LINE "From - Wed Jun 30 21:49:08 1993\n" 581#define DEFAULT_FROM_LINE "From - Wed Jun 30 21:49:08 1993\n"
579 582
580int 583int
581mailmbox_append_message_list_no_lock(struct mailmbox_folder * folder, 584mailmbox_append_message_list_no_lock(struct mailmbox_folder * folder,
582 carray * append_tab) 585 carray * append_tab)
583{ 586{
584 size_t extra_size; 587 size_t extra_size;
585 int r; 588 int r;
586 char from_line[MAX_FROM_LINE_SIZE] = DEFAULT_FROM_LINE; 589 char from_line[MAX_FROM_LINE_SIZE] = DEFAULT_FROM_LINE;
587 struct tm time_info; 590 struct tm time_info;
588 time_t date; 591 time_t date;
589 int res; 592 int res;
590 size_t old_size; 593 size_t old_size;
591 char * str; 594 char * str;
592 unsigned int i; 595 unsigned int i;
593 size_t from_size; 596 size_t from_size;
594 size_t maxuid; 597 size_t maxuid;
595 size_t left; 598 size_t left;
596 size_t crlf_count; 599 size_t crlf_count;
597 600
598 if (folder->mb_read_only) { 601 if (folder->mb_read_only) {
599 res = MAILMBOX_ERROR_READONLY; 602 res = MAILMBOX_ERROR_READONLY;
600 goto err; 603 goto err;
601 } 604 }
602 605
603 date = time(NULL); 606 date = time(NULL);
604 from_size = strlen(DEFAULT_FROM_LINE); 607 from_size = strlen(DEFAULT_FROM_LINE);
605 if (localtime_r(&date, &time_info) != NULL) 608 if (localtime_r(&date, &time_info) != NULL)
606 from_size = strftime(from_line, MAX_FROM_LINE_SIZE, "From - %c\n", &time_info); 609 from_size = strftime(from_line, MAX_FROM_LINE_SIZE, "From - %c\n", &time_info);
607 610
608 maxuid = /* */ folder->mb_max_uid; 611 maxuid = /* */ folder->mb_max_uid;
609 612
610 extra_size = 0; 613 extra_size = 0;
611 for(i = 0 ; i < carray_count(append_tab) ; i ++) { 614 for(i = 0 ; i < carray_count(append_tab) ; i ++) {
612 struct mailmbox_append_info * info; 615 struct mailmbox_append_info * info;
613 616
614 info = carray_get(append_tab, i); 617 info = carray_get(append_tab, i);
615 extra_size += from_size; 618 extra_size += from_size;
616 extra_size += get_fixed_message_size(info->ai_message, info->ai_size, 619 extra_size += get_fixed_message_size(info->ai_message, info->ai_size,
617 folder->mb_max_uid + i + 1, 620 folder->mb_max_uid + i + 1,
618 folder->mb_no_uid); 621 folder->mb_no_uid);
619 extra_size += 2; /* CR LF */ 622 extra_size += 2; /* CR LF */
623
624 info->ai_uid = folder->mb_max_uid + i + 1;
620 } 625 }
621 626
622 left = folder->mb_mapping_size; 627 left = folder->mb_mapping_size;
623 crlf_count = 0; 628 crlf_count = 0;
624 while (left >= 1) { 629 while (left >= 1) {
625 if (folder->mb_mapping[left - 1] == '\n') { 630 if (folder->mb_mapping[left - 1] == '\n') {
626 crlf_count ++; 631 crlf_count ++;
627 left --; 632 left --;
628 } 633 }
629 else if (folder->mb_mapping[left - 1] == '\r') { 634 else if (folder->mb_mapping[left - 1] == '\r') {
630 left --; 635 left --;
631 } 636 }
632 else 637 else
633 break; 638 break;
634 639
635 if (crlf_count == 2) 640 if (crlf_count == 2)
636 break; 641 break;
637 } 642 }
638 643
639 old_size = folder->mb_mapping_size; 644 old_size = folder->mb_mapping_size;
640 mailmbox_unmap(folder); 645 mailmbox_unmap(folder);
641 646
642 if (old_size != 0) { 647 if (old_size != 0) {
643 if (crlf_count != 2) 648 if (crlf_count != 2)
644 extra_size += (2 - crlf_count) * 2; 649 extra_size += (2 - crlf_count) * 2;
645 } 650 }
646 651
647 r = ftruncate(folder->mb_fd, extra_size + old_size); 652 r = ftruncate(folder->mb_fd, extra_size + old_size);
648 if (r < 0) { 653 if (r < 0) {
649 mailmbox_map(folder); 654 mailmbox_map(folder);
650 res = MAILMBOX_ERROR_FILE; 655 res = MAILMBOX_ERROR_FILE;
651 goto err; 656 goto err;
652 } 657 }
653 658
654 r = mailmbox_map(folder); 659 r = mailmbox_map(folder);
655 if (r < 0) { 660 if (r < 0) {
656 ftruncate(folder->mb_fd, old_size); 661 ftruncate(folder->mb_fd, old_size);
657 return MAILMBOX_ERROR_FILE; 662 return MAILMBOX_ERROR_FILE;
658 } 663 }
659 664
660 str = folder->mb_mapping + old_size; 665 str = folder->mb_mapping + old_size;
661 666
662 if (old_size != 0) { 667 if (old_size != 0) {
663 for(i = 0 ; i < 2 - crlf_count ; i ++) { 668 for(i = 0 ; i < 2 - crlf_count ; i ++) {
664 * str = '\r'; 669 * str = '\r';
665 str ++; 670 str ++;
666 * str = '\n'; 671 * str = '\n';
667 str ++; 672 str ++;
668 } 673 }
669 } 674 }
670 675
671 for(i = 0 ; i < carray_count(append_tab) ; i ++) { 676 for(i = 0 ; i < carray_count(append_tab) ; i ++) {
672 struct mailmbox_append_info * info; 677 struct mailmbox_append_info * info;
673 678
674 info = carray_get(append_tab, i); 679 info = carray_get(append_tab, i);
675 680
676 memcpy(str, from_line, from_size); 681 memcpy(str, from_line, from_size);
677 682
678 str += strlen(from_line); 683 str += strlen(from_line);
679 684
680 str = write_fixed_message(str, info->ai_message, info->ai_size, 685 str = write_fixed_message(str, info->ai_message, info->ai_size,
681 folder->mb_max_uid + i + 1, 686 folder->mb_max_uid + i + 1,
682 folder->mb_no_uid); 687 folder->mb_no_uid);
683 688
684 * str = '\r'; 689 * str = '\r';
685 str ++; 690 str ++;
686 * str = '\n'; 691 * str = '\n';
687 str ++; 692 str ++;
688 } 693 }
689 694
690 folder->mb_max_uid += carray_count(append_tab); 695 folder->mb_max_uid += carray_count(append_tab);
691 696
692 return MAILMBOX_NO_ERROR; 697 return MAILMBOX_NO_ERROR;
693 698
694 err: 699 err:
695 return res; 700 return res;
696} 701}
697 702
698int 703int
699mailmbox_append_message_list(struct mailmbox_folder * folder, 704mailmbox_append_message_list(struct mailmbox_folder * folder,
700 carray * append_tab) 705 carray * append_tab)
701{ 706{
702 int r; 707 int r;
703 int res; 708 int res;
704 size_t cur_token; 709 size_t cur_token;
705 710
706 r = mailmbox_validate_write_lock(folder); 711 r = mailmbox_validate_write_lock(folder);
707 if (r != MAILMBOX_NO_ERROR) { 712 if (r != MAILMBOX_NO_ERROR) {
708 res = r; 713 res = r;
709 goto err; 714 goto err;
710 } 715 }
711 716
712 r = mailmbox_expunge_no_lock(folder); 717 r = mailmbox_expunge_no_lock(folder);
713 if (r != MAILMBOX_NO_ERROR) { 718 if (r != MAILMBOX_NO_ERROR) {
714 res = r; 719 res = r;
715 goto unlock; 720 goto unlock;
716 } 721 }
717 722
718 cur_token = folder->mb_mapping_size; 723 cur_token = folder->mb_mapping_size;
719 724
720 r = mailmbox_append_message_list_no_lock(folder, append_tab); 725 r = mailmbox_append_message_list_no_lock(folder, append_tab);
721 if (r != MAILMBOX_NO_ERROR) { 726 if (r != MAILMBOX_NO_ERROR) {
722 res = r; 727 res = r;
723 goto unlock; 728 goto unlock;
724 } 729 }
725 730
726 mailmbox_sync(folder); 731 mailmbox_sync(folder);
727 732
728 r = mailmbox_parse_additionnal(folder, &cur_token); 733 r = mailmbox_parse_additionnal(folder, &cur_token);
729 if (r != MAILMBOX_NO_ERROR) { 734 if (r != MAILMBOX_NO_ERROR) {
730 res = r; 735 res = r;
731 goto unlock; 736 goto unlock;
732 } 737 }
733 738
734 mailmbox_timestamp(folder); 739 mailmbox_timestamp(folder);
735 740
736 mailmbox_write_unlock(folder); 741 mailmbox_write_unlock(folder);
737 742
738 return MAILMBOX_NO_ERROR; 743 return MAILMBOX_NO_ERROR;
739 744
740 unlock: 745 unlock:
741 mailmbox_write_unlock(folder); 746 mailmbox_write_unlock(folder);
742 err: 747 err:
743 return res; 748 return res;
744} 749}
745 750
746int 751int
747mailmbox_append_message(struct mailmbox_folder * folder, 752mailmbox_append_message_uid(struct mailmbox_folder * folder,
748 const char * data, size_t len) 753 const char * data, size_t len, unsigned int * puid)
749{ 754{
750 carray * tab; 755 carray * tab;
751 struct mailmbox_append_info * append_info; 756 struct mailmbox_append_info * append_info;
752 int res; 757 int res;
753 int r; 758 int r;
754 759
755 tab = carray_new(1); 760 tab = carray_new(1);
756 if (tab == NULL) { 761 if (tab == NULL) {
757 res = MAILMBOX_ERROR_MEMORY; 762 res = MAILMBOX_ERROR_MEMORY;
758 goto err; 763 goto err;
759 } 764 }
760 765
761 append_info = mailmbox_append_info_new(data, len); 766 append_info = mailmbox_append_info_new(data, len);
762 if (append_info == NULL) { 767 if (append_info == NULL) {
763 res = MAILMBOX_ERROR_MEMORY; 768 res = MAILMBOX_ERROR_MEMORY;
764 goto free_list; 769 goto free_list;
765 } 770 }
766 771
767 r = carray_add(tab, append_info, NULL); 772 r = carray_add(tab, append_info, NULL);
768 if (r < 0) { 773 if (r < 0) {
769 res = MAILMBOX_ERROR_MEMORY; 774 res = MAILMBOX_ERROR_MEMORY;
770 goto free_append_info; 775 goto free_append_info;
771 } 776 }
772 777
773 r = mailmbox_append_message_list(folder, tab); 778 r = mailmbox_append_message_list(folder, tab);
774 779
780 if (puid != NULL)
781 * puid = append_info->ai_uid;
782
775 mailmbox_append_info_free(append_info); 783 mailmbox_append_info_free(append_info);
776 carray_free(tab); 784 carray_free(tab);
777 785
778 return r; 786 return r;
779 787
780 free_append_info: 788 free_append_info:
781 mailmbox_append_info_free(append_info); 789 mailmbox_append_info_free(append_info);
782 free_list: 790 free_list:
783 carray_free(tab); 791 carray_free(tab);
784 err: 792 err:
785 return res; 793 return res;
786} 794}
787 795
796int
797mailmbox_append_message(struct mailmbox_folder * folder,
798 const char * data, size_t len)
799{
800 return mailmbox_append_message_uid(folder, data, len, NULL);
801}
802
788/* ********************************************************************** */ 803/* ********************************************************************** */
789 804
790int mailmbox_fetch_msg_no_lock(struct mailmbox_folder * folder, 805int mailmbox_fetch_msg_no_lock(struct mailmbox_folder * folder,
791 uint32_t num, char ** result, 806 uint32_t num, char ** result,
792 size_t * result_len) 807 size_t * result_len)
793{ 808{
794 struct mailmbox_msg_info * info; 809 struct mailmbox_msg_info * info;
795 int res; 810 int res;
796 chashdatum key; 811 chashdatum key;
797 chashdatum data; 812 chashdatum data;
798 int r; 813 int r;
799 814
800 key.data = &num; 815 key.data = &num;
801 key.len = sizeof(num); 816 key.len = sizeof(num);
802 817
803 r = chash_get(folder->mb_hash, &key, &data); 818 r = chash_get(folder->mb_hash, &key, &data);
804 if (r < 0) { 819 if (r < 0) {
805 res = MAILMBOX_ERROR_MSG_NOT_FOUND; 820 res = MAILMBOX_ERROR_MSG_NOT_FOUND;
806 goto err; 821 goto err;
807 } 822 }
808 823
809 info = data.data; 824 info = data.data;
810 825
811 if (info->msg_deleted) { 826 if (info->msg_deleted) {
812 res = MAILMBOX_ERROR_MSG_NOT_FOUND; 827 res = MAILMBOX_ERROR_MSG_NOT_FOUND;
813 goto err; 828 goto err;
814 } 829 }
815 830
816 * result = folder->mb_mapping + info->msg_headers; 831 * result = folder->mb_mapping + info->msg_headers;
817 * result_len = info->msg_size - info->msg_start_len; 832 * result_len = info->msg_size - info->msg_start_len;
818 833
819 return MAILMBOX_NO_ERROR; 834 return MAILMBOX_NO_ERROR;
820 835
821 err: 836 err:
822 return res; 837 return res;
823} 838}
824 839
825int mailmbox_fetch_msg_headers_no_lock(struct mailmbox_folder * folder, 840int mailmbox_fetch_msg_headers_no_lock(struct mailmbox_folder * folder,
826 uint32_t num, char ** result, 841 uint32_t num, char ** result,
827 size_t * result_len) 842 size_t * result_len)
828{ 843{
829 struct mailmbox_msg_info * info; 844 struct mailmbox_msg_info * info;
830 int res; 845 int res;
831 chashdatum key; 846 chashdatum key;
832 chashdatum data; 847 chashdatum data;
833 int r; 848 int r;
834 849
835 key.data = &num; 850 key.data = &num;
836 key.len = sizeof(num); 851 key.len = sizeof(num);
837 852
838 r = chash_get(folder->mb_hash, &key, &data); 853 r = chash_get(folder->mb_hash, &key, &data);
839 if (r < 0) { 854 if (r < 0) {
840 res = MAILMBOX_ERROR_MSG_NOT_FOUND; 855 res = MAILMBOX_ERROR_MSG_NOT_FOUND;
841 goto err; 856 goto err;
842 } 857 }
843 858
844 info = data.data; 859 info = data.data;
845 860
846 if (info->msg_deleted) { 861 if (info->msg_deleted) {
847 res = MAILMBOX_ERROR_MSG_NOT_FOUND; 862 res = MAILMBOX_ERROR_MSG_NOT_FOUND;
848 goto err; 863 goto err;
849 } 864 }
850 865
851 * result = folder->mb_mapping + info->msg_headers; 866 * result = folder->mb_mapping + info->msg_headers;
852 * result_len = info->msg_headers_len; 867 * result_len = info->msg_headers_len;
853 868
854 return MAILMBOX_NO_ERROR; 869 return MAILMBOX_NO_ERROR;
855 870
856 err: 871 err:
857 return res; 872 return res;
858} 873}
859 874
860int mailmbox_fetch_msg(struct mailmbox_folder * folder, 875int mailmbox_fetch_msg(struct mailmbox_folder * folder,
861 uint32_t num, char ** result, 876 uint32_t num, char ** result,
862 size_t * result_len) 877 size_t * result_len)
863{ 878{
864 MMAPString * mmapstr; 879 MMAPString * mmapstr;
865 int res; 880 int res;
866 char * data; 881 char * data;
867 size_t len; 882 size_t len;
868 int r; 883 int r;
869 size_t fixed_size; 884 size_t fixed_size;
870 char * end; 885 char * end;
871 886
872 r = mailmbox_validate_read_lock(folder); 887 r = mailmbox_validate_read_lock(folder);
873 if (r != MAILMBOX_NO_ERROR) { 888 if (r != MAILMBOX_NO_ERROR) {
874 res = r; 889 res = r;
875 goto err; 890 goto err;
876 } 891 }
877 892
878 r = mailmbox_fetch_msg_no_lock(folder, num, &data, &len); 893 r = mailmbox_fetch_msg_no_lock(folder, num, &data, &len);
879 if (r != MAILMBOX_NO_ERROR) { 894 if (r != MAILMBOX_NO_ERROR) {
880 res = r; 895 res = r;
881 goto unlock; 896 goto unlock;
882 } 897 }
883 898
884 /* size with no uid */ 899 /* size with no uid */
885 fixed_size = get_fixed_message_size(data, len, 0, 1 /* force no uid */); 900 fixed_size = get_fixed_message_size(data, len, 0, 1 /* force no uid */);
886 901
887#if 0 902#if 0
888 mmapstr = mmap_string_new_len(data, fixed_size); 903 mmapstr = mmap_string_new_len(data, fixed_size);
889 if (mmapstr == NULL) { 904 if (mmapstr == NULL) {
890 res = MAILMBOX_ERROR_MEMORY; 905 res = MAILMBOX_ERROR_MEMORY;
891 goto unlock; 906 goto unlock;
892 } 907 }
893#endif 908#endif
894 mmapstr = mmap_string_sized_new(fixed_size); 909 mmapstr = mmap_string_sized_new(fixed_size);
895 if (mmapstr == NULL) { 910 if (mmapstr == NULL) {
896 res = MAILMBOX_ERROR_MEMORY; 911 res = MAILMBOX_ERROR_MEMORY;
897 goto unlock; 912 goto unlock;
898 } 913 }
899 914
900 end = write_fixed_message(mmapstr->str, data, len, 0, 1 /* force no uid */); 915 end = write_fixed_message(mmapstr->str, data, len, 0, 1 /* force no uid */);
901 * end = '\0'; 916 * end = '\0';
902 mmapstr->len = fixed_size; 917 mmapstr->len = fixed_size;
903 918
904 r = mmap_string_ref(mmapstr); 919 r = mmap_string_ref(mmapstr);
905 if (r < 0) { 920 if (r < 0) {
906 mmap_string_free(mmapstr); 921 mmap_string_free(mmapstr);
907 res = MAILMBOX_ERROR_MEMORY; 922 res = MAILMBOX_ERROR_MEMORY;
908 goto unlock; 923 goto unlock;
909 } 924 }
910 925
911 * result = mmapstr->str; 926 * result = mmapstr->str;
912 * result_len = mmapstr->len; 927 * result_len = mmapstr->len;
913 928
914 mailmbox_read_unlock(folder); 929 mailmbox_read_unlock(folder);
915 930
diff --git a/kmicromail/libetpan/mbox/mailmbox.h b/kmicromail/libetpan/mbox/mailmbox.h
index 8be086c..0427f1f 100644
--- a/kmicromail/libetpan/mbox/mailmbox.h
+++ b/kmicromail/libetpan/mbox/mailmbox.h
@@ -1,140 +1,144 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAILMBOX_H 36#ifndef MAILMBOX_H
37 37
38#define MAILMBOX_H 38#define MAILMBOX_H
39 39
40#ifdef __cplusplus 40#ifdef __cplusplus
41extern "C" { 41extern "C" {
42#endif 42#endif
43 43
44#include <libetpan/mailmbox_types.h> 44#include <libetpan/mailmbox_types.h>
45 45
46int 46int
47mailmbox_append_message_list(struct mailmbox_folder * folder, 47mailmbox_append_message_list(struct mailmbox_folder * folder,
48 carray * append_tab); 48 carray * append_tab);
49 49
50int 50int
51mailmbox_append_message(struct mailmbox_folder * folder, 51mailmbox_append_message(struct mailmbox_folder * folder,
52 const char * data, size_t len); 52 const char * data, size_t len);
53 53
54int
55mailmbox_append_message_uid(struct mailmbox_folder * folder,
56 const char * data, size_t len, unsigned int * puid);
57
54int mailmbox_fetch_msg(struct mailmbox_folder * folder, 58int mailmbox_fetch_msg(struct mailmbox_folder * folder,
55 uint32_t num, char ** result, 59 uint32_t num, char ** result,
56 size_t * result_len); 60 size_t * result_len);
57 61
58int mailmbox_fetch_msg_headers(struct mailmbox_folder * folder, 62int mailmbox_fetch_msg_headers(struct mailmbox_folder * folder,
59 uint32_t num, char ** result, 63 uint32_t num, char ** result,
60 size_t * result_len); 64 size_t * result_len);
61 65
62void mailmbox_fetch_result_free(char * msg); 66void mailmbox_fetch_result_free(char * msg);
63 67
64int mailmbox_copy_msg_list(struct mailmbox_folder * dest_folder, 68int mailmbox_copy_msg_list(struct mailmbox_folder * dest_folder,
65 struct mailmbox_folder * src_folder, 69 struct mailmbox_folder * src_folder,
66 carray * tab); 70 carray * tab);
67 71
68int mailmbox_copy_msg(struct mailmbox_folder * dest_folder, 72int mailmbox_copy_msg(struct mailmbox_folder * dest_folder,
69 struct mailmbox_folder * src_folder, 73 struct mailmbox_folder * src_folder,
70 uint32_t uid); 74 uint32_t uid);
71 75
72int mailmbox_expunge(struct mailmbox_folder * folder); 76int mailmbox_expunge(struct mailmbox_folder * folder);
73 77
74int mailmbox_delete_msg(struct mailmbox_folder * folder, uint32_t uid); 78int mailmbox_delete_msg(struct mailmbox_folder * folder, uint32_t uid);
75 79
76int mailmbox_init(const char * filename, 80int mailmbox_init(const char * filename,
77 int force_readonly, 81 int force_readonly,
78 int force_no_uid, 82 int force_no_uid,
79 uint32_t default_written_uid, 83 uint32_t default_written_uid,
80 struct mailmbox_folder ** result_folder); 84 struct mailmbox_folder ** result_folder);
81 85
82void mailmbox_done(struct mailmbox_folder * folder); 86void mailmbox_done(struct mailmbox_folder * folder);
83 87
84/* low-level access primitives */ 88/* low-level access primitives */
85 89
86int mailmbox_write_lock(struct mailmbox_folder * folder); 90int mailmbox_write_lock(struct mailmbox_folder * folder);
87 91
88int mailmbox_write_unlock(struct mailmbox_folder * folder); 92int mailmbox_write_unlock(struct mailmbox_folder * folder);
89 93
90int mailmbox_read_lock(struct mailmbox_folder * folder); 94int mailmbox_read_lock(struct mailmbox_folder * folder);
91 95
92int mailmbox_read_unlock(struct mailmbox_folder * folder); 96int mailmbox_read_unlock(struct mailmbox_folder * folder);
93 97
94 98
95/* memory map */ 99/* memory map */
96 100
97int mailmbox_map(struct mailmbox_folder * folder); 101int mailmbox_map(struct mailmbox_folder * folder);
98 102
99void mailmbox_unmap(struct mailmbox_folder * folder); 103void mailmbox_unmap(struct mailmbox_folder * folder);
100 104
101void mailmbox_sync(struct mailmbox_folder * folder); 105void mailmbox_sync(struct mailmbox_folder * folder);
102 106
103 107
104/* open & close file */ 108/* open & close file */
105 109
106int mailmbox_open(struct mailmbox_folder * folder); 110int mailmbox_open(struct mailmbox_folder * folder);
107 111
108void mailmbox_close(struct mailmbox_folder * folder); 112void mailmbox_close(struct mailmbox_folder * folder);
109 113
110 114
111/* validate cache */ 115/* validate cache */
112 116
113int mailmbox_validate_write_lock(struct mailmbox_folder * folder); 117int mailmbox_validate_write_lock(struct mailmbox_folder * folder);
114 118
115int mailmbox_validate_read_lock(struct mailmbox_folder * folder); 119int mailmbox_validate_read_lock(struct mailmbox_folder * folder);
116 120
117 121
118/* fetch message */ 122/* fetch message */
119 123
120int mailmbox_fetch_msg_no_lock(struct mailmbox_folder * folder, 124int mailmbox_fetch_msg_no_lock(struct mailmbox_folder * folder,
121 uint32_t num, char ** result, 125 uint32_t num, char ** result,
122 size_t * result_len); 126 size_t * result_len);
123 127
124int mailmbox_fetch_msg_headers_no_lock(struct mailmbox_folder * folder, 128int mailmbox_fetch_msg_headers_no_lock(struct mailmbox_folder * folder,
125 uint32_t num, char ** result, 129 uint32_t num, char ** result,
126 size_t * result_len); 130 size_t * result_len);
127 131
128/* append message */ 132/* append message */
129 133
130int 134int
131mailmbox_append_message_list_no_lock(struct mailmbox_folder * folder, 135mailmbox_append_message_list_no_lock(struct mailmbox_folder * folder,
132 carray * append_tab); 136 carray * append_tab);
133 137
134int mailmbox_expunge_no_lock(struct mailmbox_folder * folder); 138int mailmbox_expunge_no_lock(struct mailmbox_folder * folder);
135 139
136#ifdef __cplusplus 140#ifdef __cplusplus
137} 141}
138#endif 142#endif
139 143
140#endif 144#endif
diff --git a/kmicromail/libetpan/mbox/mailmbox_types.c b/kmicromail/libetpan/mbox/mailmbox_types.c
index 1986182..4e3e521 100644
--- a/kmicromail/libetpan/mbox/mailmbox_types.c
+++ b/kmicromail/libetpan/mbox/mailmbox_types.c
@@ -53,198 +53,199 @@ int mailmbox_msg_info_update(struct mailmbox_folder * folder,
53 size_t msg_headers, size_t msg_headers_len, 53 size_t msg_headers, size_t msg_headers_len,
54 size_t msg_body, size_t msg_body_len, 54 size_t msg_body, size_t msg_body_len,
55 size_t msg_size, size_t msg_padding, 55 size_t msg_size, size_t msg_padding,
56 uint32_t msg_uid) 56 uint32_t msg_uid)
57{ 57{
58 struct mailmbox_msg_info * info; 58 struct mailmbox_msg_info * info;
59 int res; 59 int res;
60 chashdatum key; 60 chashdatum key;
61 chashdatum data; 61 chashdatum data;
62 int r; 62 int r;
63 63
64 key.data = &msg_uid; 64 key.data = &msg_uid;
65 key.len = sizeof(msg_uid); 65 key.len = sizeof(msg_uid);
66 r = chash_get(folder->mb_hash, &key, &data); 66 r = chash_get(folder->mb_hash, &key, &data);
67 if (r < 0) { 67 if (r < 0) {
68 unsigned int index; 68 unsigned int index;
69 69
70 info = mailmbox_msg_info_new(msg_start, msg_start_len, 70 info = mailmbox_msg_info_new(msg_start, msg_start_len,
71 msg_headers, msg_headers_len, 71 msg_headers, msg_headers_len,
72 msg_body, msg_body_len, msg_size, msg_padding, msg_uid); 72 msg_body, msg_body_len, msg_size, msg_padding, msg_uid);
73 if (info == NULL) { 73 if (info == NULL) {
74 res = MAILMBOX_ERROR_MEMORY; 74 res = MAILMBOX_ERROR_MEMORY;
75 goto err; 75 goto err;
76 } 76 }
77 77
78 r = carray_add(folder->mb_tab, info, &index); 78 r = carray_add(folder->mb_tab, info, &index);
79 if (r < 0) { 79 if (r < 0) {
80 mailmbox_msg_info_free(info); 80 mailmbox_msg_info_free(info);
81 res = MAILMBOX_ERROR_MEMORY; 81 res = MAILMBOX_ERROR_MEMORY;
82 goto err; 82 goto err;
83 } 83 }
84 84
85 if (msg_uid != 0) { 85 if (msg_uid != 0) {
86 chashdatum key; 86 chashdatum key;
87 chashdatum data; 87 chashdatum data;
88 88
89 key.data = &msg_uid; 89 key.data = &msg_uid;
90 key.len = sizeof(msg_uid); 90 key.len = sizeof(msg_uid);
91 data.data = info; 91 data.data = info;
92 data.len = 0; 92 data.len = 0;
93 93
94 r = chash_set(folder->mb_hash, &key, &data, NULL); 94 r = chash_set(folder->mb_hash, &key, &data, NULL);
95 if (r < 0) { 95 if (r < 0) {
96 mailmbox_msg_info_free(info); 96 mailmbox_msg_info_free(info);
97 carray_delete(folder->mb_tab, index); 97 carray_delete(folder->mb_tab, index);
98 res = MAILMBOX_ERROR_MEMORY; 98 res = MAILMBOX_ERROR_MEMORY;
99 goto err; 99 goto err;
100 } 100 }
101 } 101 }
102 102
103 info->msg_index = index; 103 info->msg_index = index;
104 } 104 }
105 else { 105 else {
106 info = data.data; 106 info = data.data;
107 107
108 info->msg_start = msg_start; 108 info->msg_start = msg_start;
109 info->msg_start_len = msg_start_len; 109 info->msg_start_len = msg_start_len;
110 info->msg_headers = msg_headers; 110 info->msg_headers = msg_headers;
111 info->msg_headers_len = msg_headers_len; 111 info->msg_headers_len = msg_headers_len;
112 info->msg_body = msg_body; 112 info->msg_body = msg_body;
113 info->msg_body_len = msg_body_len; 113 info->msg_body_len = msg_body_len;
114 info->msg_size = msg_size; 114 info->msg_size = msg_size;
115 info->msg_padding = msg_padding; 115 info->msg_padding = msg_padding;
116 } 116 }
117 117
118 return MAILMBOX_NO_ERROR; 118 return MAILMBOX_NO_ERROR;
119 119
120 err: 120 err:
121 return res; 121 return res;
122} 122}
123 123
124 124
125struct mailmbox_msg_info * 125struct mailmbox_msg_info *
126mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len, 126mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len,
127 size_t msg_headers, size_t msg_headers_len, 127 size_t msg_headers, size_t msg_headers_len,
128 size_t msg_body, size_t msg_body_len, 128 size_t msg_body, size_t msg_body_len,
129 size_t msg_size, size_t msg_padding, 129 size_t msg_size, size_t msg_padding,
130 uint32_t msg_uid) 130 uint32_t msg_uid)
131{ 131{
132 struct mailmbox_msg_info * info; 132 struct mailmbox_msg_info * info;
133 133
134 info = malloc(sizeof(* info)); 134 info = malloc(sizeof(* info));
135 if (info == NULL) 135 if (info == NULL)
136 return NULL; 136 return NULL;
137 137
138 info->msg_index = 0; 138 info->msg_index = 0;
139 info->msg_uid = msg_uid; 139 info->msg_uid = msg_uid;
140 if (msg_uid != 0) 140 if (msg_uid != 0)
141 info->msg_written_uid = TRUE; 141 info->msg_written_uid = TRUE;
142 else 142 else
143 info->msg_written_uid = FALSE; 143 info->msg_written_uid = FALSE;
144 info->msg_deleted = FALSE; 144 info->msg_deleted = FALSE;
145 145
146 info->msg_start = msg_start; 146 info->msg_start = msg_start;
147 info->msg_start_len = msg_start_len; 147 info->msg_start_len = msg_start_len;
148 148
149 info->msg_headers = msg_headers; 149 info->msg_headers = msg_headers;
150 info->msg_headers_len = msg_headers_len; 150 info->msg_headers_len = msg_headers_len;
151 151
152 info->msg_body = msg_body; 152 info->msg_body = msg_body;
153 info->msg_body_len = msg_body_len; 153 info->msg_body_len = msg_body_len;
154 154
155 info->msg_size = msg_size; 155 info->msg_size = msg_size;
156 156
157 info->msg_padding = msg_padding; 157 info->msg_padding = msg_padding;
158 158
159 return info; 159 return info;
160} 160}
161 161
162void mailmbox_msg_info_free(struct mailmbox_msg_info * info) 162void mailmbox_msg_info_free(struct mailmbox_msg_info * info)
163{ 163{
164 free(info); 164 free(info);
165} 165}
166 166
167 167
168/* append info */ 168/* append info */
169 169
170struct mailmbox_append_info * 170struct mailmbox_append_info *
171mailmbox_append_info_new(const char * ai_message, size_t ai_size) 171mailmbox_append_info_new(const char * ai_message, size_t ai_size)
172{ 172{
173 struct mailmbox_append_info * info; 173 struct mailmbox_append_info * info;
174 174
175 info = malloc(sizeof(* info)); 175 info = malloc(sizeof(* info));
176 if (info == NULL) 176 if (info == NULL)
177 return NULL; 177 return NULL;
178 178
179 info->ai_message = ai_message; 179 info->ai_message = ai_message;
180 info->ai_size = ai_size; 180 info->ai_size = ai_size;
181 181 info->ai_uid = 0;
182
182 return info; 183 return info;
183} 184}
184 185
185void mailmbox_append_info_free(struct mailmbox_append_info * info) 186void mailmbox_append_info_free(struct mailmbox_append_info * info)
186{ 187{
187 free(info); 188 free(info);
188} 189}
189 190
190struct mailmbox_folder * mailmbox_folder_new(const char * mb_filename) 191struct mailmbox_folder * mailmbox_folder_new(const char * mb_filename)
191{ 192{
192 struct mailmbox_folder * folder; 193 struct mailmbox_folder * folder;
193 194
194 folder = malloc(sizeof(* folder)); 195 folder = malloc(sizeof(* folder));
195 if (folder == NULL) 196 if (folder == NULL)
196 goto err; 197 goto err;
197 198
198 strncpy(folder->mb_filename, mb_filename, PATH_MAX); 199 strncpy(folder->mb_filename, mb_filename, PATH_MAX);
199 200
200 folder->mb_mtime = (time_t) -1; 201 folder->mb_mtime = (time_t) -1;
201 202
202 folder->mb_fd = -1; 203 folder->mb_fd = -1;
203 folder->mb_read_only = TRUE; 204 folder->mb_read_only = TRUE;
204 folder->mb_no_uid = TRUE; 205 folder->mb_no_uid = TRUE;
205 206
206 folder->mb_changed = FALSE; 207 folder->mb_changed = FALSE;
207 folder->mb_deleted_count = 0; 208 folder->mb_deleted_count = 0;
208 209
209 folder->mb_mapping = NULL; 210 folder->mb_mapping = NULL;
210 folder->mb_mapping_size = 0; 211 folder->mb_mapping_size = 0;
211 212
212 folder->mb_written_uid = 0; 213 folder->mb_written_uid = 0;
213 folder->mb_max_uid = 0; 214 folder->mb_max_uid = 0;
214 215
215 folder->mb_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYKEY); 216 folder->mb_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYKEY);
216 if (folder->mb_hash == NULL) 217 if (folder->mb_hash == NULL)
217 goto free; 218 goto free;
218 219
219 folder->mb_tab = carray_new(128); 220 folder->mb_tab = carray_new(128);
220 if (folder->mb_tab == NULL) 221 if (folder->mb_tab == NULL)
221 goto free_hash; 222 goto free_hash;
222 223
223 return folder; 224 return folder;
224 225
225 free_hash: 226 free_hash:
226 chash_free(folder->mb_hash); 227 chash_free(folder->mb_hash);
227 free: 228 free:
228 free(folder); 229 free(folder);
229 err: 230 err:
230 return NULL; 231 return NULL;
231} 232}
232 233
233void mailmbox_folder_free(struct mailmbox_folder * folder) 234void mailmbox_folder_free(struct mailmbox_folder * folder)
234{ 235{
235 unsigned int i; 236 unsigned int i;
236 237
237 for(i = 0 ; i < carray_count(folder->mb_tab) ; i++) { 238 for(i = 0 ; i < carray_count(folder->mb_tab) ; i++) {
238 struct mailmbox_msg_info * info; 239 struct mailmbox_msg_info * info;
239 240
240 info = carray_get(folder->mb_tab, i); 241 info = carray_get(folder->mb_tab, i);
241 if (info != NULL) 242 if (info != NULL)
242 mailmbox_msg_info_free(info); 243 mailmbox_msg_info_free(info);
243 } 244 }
244 245
245 carray_free(folder->mb_tab); 246 carray_free(folder->mb_tab);
246 247
247 chash_free(folder->mb_hash); 248 chash_free(folder->mb_hash);
248 249
249 free(folder); 250 free(folder);
250} 251}
diff --git a/kmicromail/libetpan/mbox/mailmbox_types.h b/kmicromail/libetpan/mbox/mailmbox_types.h
index dd6758c..bd6ee30 100644
--- a/kmicromail/libetpan/mbox/mailmbox_types.h
+++ b/kmicromail/libetpan/mbox/mailmbox_types.h
@@ -3,140 +3,141 @@
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAILMBOX_TYPES_H 36#ifndef MAILMBOX_TYPES_H
37 37
38#define MAILMBOX_TYPES_H 38#define MAILMBOX_TYPES_H
39 39
40#ifdef __cplusplus 40#ifdef __cplusplus
41extern "C" { 41extern "C" {
42#endif 42#endif
43 43
44#include <sys/types.h> 44#include <sys/types.h>
45 45
46#include <libetpan/libetpan-config.h> 46#include <libetpan/libetpan-config.h>
47 47
48#include <libetpan/mailimf.h> 48#include <libetpan/mailimf.h>
49#include <libetpan/carray.h> 49#include <libetpan/carray.h>
50#include <libetpan/chash.h> 50#include <libetpan/chash.h>
51 51
52enum { 52enum {
53 MAILMBOX_NO_ERROR = 0, 53 MAILMBOX_NO_ERROR = 0,
54 MAILMBOX_ERROR_PARSE, 54 MAILMBOX_ERROR_PARSE,
55 MAILMBOX_ERROR_INVAL, 55 MAILMBOX_ERROR_INVAL,
56 MAILMBOX_ERROR_FILE_NOT_FOUND, 56 MAILMBOX_ERROR_FILE_NOT_FOUND,
57 MAILMBOX_ERROR_MEMORY, 57 MAILMBOX_ERROR_MEMORY,
58 MAILMBOX_ERROR_TEMPORARY_FILE, 58 MAILMBOX_ERROR_TEMPORARY_FILE,
59 MAILMBOX_ERROR_FILE, 59 MAILMBOX_ERROR_FILE,
60 MAILMBOX_ERROR_MSG_NOT_FOUND, 60 MAILMBOX_ERROR_MSG_NOT_FOUND,
61 MAILMBOX_ERROR_READONLY, 61 MAILMBOX_ERROR_READONLY,
62}; 62};
63 63
64 64
65struct mailmbox_folder { 65struct mailmbox_folder {
66 char mb_filename[PATH_MAX]; 66 char mb_filename[PATH_MAX];
67 67
68 time_t mb_mtime; 68 time_t mb_mtime;
69 69
70 int mb_fd; 70 int mb_fd;
71 int mb_read_only; 71 int mb_read_only;
72 int mb_no_uid; 72 int mb_no_uid;
73 73
74 int mb_changed; 74 int mb_changed;
75 unsigned int mb_deleted_count; 75 unsigned int mb_deleted_count;
76 76
77 char * mb_mapping; 77 char * mb_mapping;
78 size_t mb_mapping_size; 78 size_t mb_mapping_size;
79 79
80 uint32_t mb_written_uid; 80 uint32_t mb_written_uid;
81 uint32_t mb_max_uid; 81 uint32_t mb_max_uid;
82 82
83 chash * mb_hash; 83 chash * mb_hash;
84 carray * mb_tab; 84 carray * mb_tab;
85}; 85};
86 86
87struct mailmbox_folder * mailmbox_folder_new(const char * mb_filename); 87struct mailmbox_folder * mailmbox_folder_new(const char * mb_filename);
88void mailmbox_folder_free(struct mailmbox_folder * folder); 88void mailmbox_folder_free(struct mailmbox_folder * folder);
89 89
90 90
91struct mailmbox_msg_info { 91struct mailmbox_msg_info {
92 unsigned int msg_index; 92 unsigned int msg_index;
93 uint32_t msg_uid; 93 uint32_t msg_uid;
94 int msg_written_uid; 94 int msg_written_uid;
95 int msg_deleted; 95 int msg_deleted;
96 96
97 size_t msg_start; 97 size_t msg_start;
98 size_t msg_start_len; 98 size_t msg_start_len;
99 99
100 size_t msg_headers; 100 size_t msg_headers;
101 size_t msg_headers_len; 101 size_t msg_headers_len;
102 102
103 size_t msg_body; 103 size_t msg_body;
104 size_t msg_body_len; 104 size_t msg_body_len;
105 105
106 size_t msg_size; 106 size_t msg_size;
107 107
108 size_t msg_padding; 108 size_t msg_padding;
109}; 109};
110 110
111 111
112int mailmbox_msg_info_update(struct mailmbox_folder * folder, 112int mailmbox_msg_info_update(struct mailmbox_folder * folder,
113 size_t msg_start, size_t msg_start_len, 113 size_t msg_start, size_t msg_start_len,
114 size_t msg_headers, size_t msg_headers_len, 114 size_t msg_headers, size_t msg_headers_len,
115 size_t msg_body, size_t msg_body_len, 115 size_t msg_body, size_t msg_body_len,
116 size_t msg_size, size_t msg_padding, 116 size_t msg_size, size_t msg_padding,
117 uint32_t msg_uid); 117 uint32_t msg_uid);
118 118
119struct mailmbox_msg_info * 119struct mailmbox_msg_info *
120mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len, 120mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len,
121 size_t msg_headers, size_t msg_headers_len, 121 size_t msg_headers, size_t msg_headers_len,
122 size_t msg_body, size_t msg_body_len, 122 size_t msg_body, size_t msg_body_len,
123 size_t msg_size, size_t msg_padding, 123 size_t msg_size, size_t msg_padding,
124 uint32_t msg_uid); 124 uint32_t msg_uid);
125 125
126void mailmbox_msg_info_free(struct mailmbox_msg_info * info); 126void mailmbox_msg_info_free(struct mailmbox_msg_info * info);
127 127
128struct mailmbox_append_info { 128struct mailmbox_append_info {
129 const char * ai_message; 129 const char * ai_message;
130 size_t ai_size; 130 size_t ai_size;
131 unsigned int ai_uid;
131}; 132};
132 133
133struct mailmbox_append_info * 134struct mailmbox_append_info *
134mailmbox_append_info_new(const char * ai_message, size_t ai_size); 135mailmbox_append_info_new(const char * ai_message, size_t ai_size);
135 136
136void mailmbox_append_info_free(struct mailmbox_append_info * info); 137void mailmbox_append_info_free(struct mailmbox_append_info * info);
137 138
138#ifdef __cplusplus 139#ifdef __cplusplus
139} 140}
140#endif 141#endif
141 142
142#endif 143#endif
diff --git a/kmicromail/libetpan/mh/mailmh.c b/kmicromail/libetpan/mh/mailmh.c
index d6ff950..119f217 100644
--- a/kmicromail/libetpan/mh/mailmh.c
+++ b/kmicromail/libetpan/mh/mailmh.c
@@ -598,368 +598,384 @@ int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder,
598 598
599#define MAX_TRY_ALLOC 32 599#define MAX_TRY_ALLOC 32
600 600
601/* initial file MUST be in the same directory */ 601/* initial file MUST be in the same directory */
602 602
603static int mailmh_folder_alloc_msg(struct mailmh_folder * folder, 603static int mailmh_folder_alloc_msg(struct mailmh_folder * folder,
604 char * filename, uint32_t * result) 604 char * filename, uint32_t * result)
605{ 605{
606 uint32_t max; 606 uint32_t max;
607 uint32_t k; 607 uint32_t k;
608 char * new_filename; 608 char * new_filename;
609 size_t len; 609 size_t len;
610 610
611 len = strlen(folder->fl_filename) + 20; 611 len = strlen(folder->fl_filename) + 20;
612 new_filename = malloc(len); 612 new_filename = malloc(len);
613 if (new_filename == NULL) 613 if (new_filename == NULL)
614 return MAILMH_ERROR_MEMORY; 614 return MAILMH_ERROR_MEMORY;
615 615
616 max = folder->fl_max_index + 1; 616 max = folder->fl_max_index + 1;
617 617
618 k = 0; 618 k = 0;
619 while (k < MAX_TRY_ALLOC) { 619 while (k < MAX_TRY_ALLOC) {
620 snprintf(new_filename, len, "%s%c%lu", folder->fl_filename, 620 snprintf(new_filename, len, "%s%c%lu", folder->fl_filename,
621 MAIL_DIR_SEPARATOR, (unsigned long) (max + k)); 621 MAIL_DIR_SEPARATOR, (unsigned long) (max + k));
622 622
623 if (link(filename, new_filename) == 0) { 623 if (link(filename, new_filename) == 0) {
624 int r; 624 int r;
625 625
626 free(new_filename); 626 free(new_filename);
627 unlink(filename); 627 unlink(filename);
628 628
629 if (k > MAX_TRY_ALLOC / 2) { 629 if (k > MAX_TRY_ALLOC / 2) {
630 r = mailmh_folder_update(folder); 630 r = mailmh_folder_update(folder);
631 /* ignore errors */ 631 /* ignore errors */
632 } 632 }
633 633
634 * result = max + k; 634 * result = max + k;
635 635
636 folder->fl_max_index = max + k; 636 folder->fl_max_index = max + k;
637 637
638 return MAILMH_NO_ERROR; 638 return MAILMH_NO_ERROR;
639 } 639 }
640 else if (errno == EXDEV) { 640 else if (errno == EXDEV) {
641 free(filename); 641 free(filename);
642 return MAILMH_ERROR_FOLDER; 642 return MAILMH_ERROR_FOLDER;
643 } 643 }
644 k ++; 644 k ++;
645 } 645 }
646 646
647 free(new_filename); 647 free(new_filename);
648 648
649 return MAILMH_ERROR_FOLDER; 649 return MAILMH_ERROR_FOLDER;
650} 650}
651 651
652int mailmh_folder_get_message_filename(struct mailmh_folder * folder, 652int mailmh_folder_get_message_filename(struct mailmh_folder * folder,
653 uint32_t index, char ** result) 653 uint32_t index, char ** result)
654{ 654{
655 char * filename; 655 char * filename;
656 int len; 656 int len;
657 657
658#if 0 658#if 0
659 r = mailmh_folder_update(folder); 659 r = mailmh_folder_update(folder);
660 if (r != MAILMH_NO_ERROR) 660 if (r != MAILMH_NO_ERROR)
661 return r; 661 return r;
662#endif 662#endif
663 663
664 len = strlen(folder->fl_filename) + 20; 664 len = strlen(folder->fl_filename) + 20;
665 filename = malloc(len); 665 filename = malloc(len);
666 if (filename == NULL) 666 if (filename == NULL)
667 return MAILMH_ERROR_MEMORY; 667 return MAILMH_ERROR_MEMORY;
668 668
669 snprintf(filename, len, "%s%c%lu", folder->fl_filename, MAIL_DIR_SEPARATOR, 669 snprintf(filename, len, "%s%c%lu", folder->fl_filename, MAIL_DIR_SEPARATOR,
670 (unsigned long) index); 670 (unsigned long) index);
671 671
672 * result = filename; 672 * result = filename;
673 673
674 return MAILMH_NO_ERROR;; 674 return MAILMH_NO_ERROR;;
675} 675}
676 676
677 677
678int mailmh_folder_get_message_fd(struct mailmh_folder * folder, 678int mailmh_folder_get_message_fd(struct mailmh_folder * folder,
679 uint32_t index, int flags, int * result) 679 uint32_t index, int flags, int * result)
680{ 680{
681 char * filename; 681 char * filename;
682 int fd; 682 int fd;
683 int r; 683 int r;
684 684
685#if 0 685#if 0
686 r = mailmh_folder_update(folder); 686 r = mailmh_folder_update(folder);
687 if (r != MAILMH_NO_ERROR) 687 if (r != MAILMH_NO_ERROR)
688 return r; 688 return r;
689#endif 689#endif
690 690
691 r = mailmh_folder_get_message_filename(folder, index, &filename); 691 r = mailmh_folder_get_message_filename(folder, index, &filename);
692 if (r != MAILMH_NO_ERROR) 692 if (r != MAILMH_NO_ERROR)
693 return r; 693 return r;
694 694
695 fd = open(filename, flags); 695 fd = open(filename, flags);
696 free(filename); 696 free(filename);
697 if (fd == -1) 697 if (fd == -1)
698 return MAILMH_ERROR_MSG_NOT_FOUND; 698 return MAILMH_ERROR_MSG_NOT_FOUND;
699 699
700 * result = fd; 700 * result = fd;
701 701
702 return MAILMH_NO_ERROR; 702 return MAILMH_NO_ERROR;
703} 703}
704 704
705int mailmh_folder_get_message_size(struct mailmh_folder * folder, 705int mailmh_folder_get_message_size(struct mailmh_folder * folder,
706 uint32_t index, size_t * result) 706 uint32_t index, size_t * result)
707{ 707{
708 int r; 708 int r;
709 char * filename; 709 char * filename;
710 struct stat buf; 710 struct stat buf;
711 711
712 r = mailmh_folder_get_message_filename(folder, index, &filename); 712 r = mailmh_folder_get_message_filename(folder, index, &filename);
713 if (r != MAILMH_NO_ERROR) 713 if (r != MAILMH_NO_ERROR)
714 return r; 714 return r;
715 715
716 r = stat(filename, &buf); 716 r = stat(filename, &buf);
717 free(filename); 717 free(filename);
718 if (r < 0) 718 if (r < 0)
719 return MAILMH_ERROR_FILE; 719 return MAILMH_ERROR_FILE;
720 720
721 * result = buf.st_size; 721 * result = buf.st_size;
722 722
723 return MAILMH_NO_ERROR; 723 return MAILMH_NO_ERROR;
724} 724}
725 725
726int mailmh_folder_add_message(struct mailmh_folder * folder, 726int mailmh_folder_add_message_uid(struct mailmh_folder * folder,
727 const char * message, size_t size) 727 const char * message, size_t size,
728 uint32_t * pindex)
728{ 729{
729 char * tmpname; 730 char * tmpname;
730 int fd; 731 int fd;
731 size_t namesize; 732 size_t namesize;
732 size_t left; 733 size_t left;
733 ssize_t res; 734 ssize_t res;
734 struct mailmh_msg_info * msg_info; 735 struct mailmh_msg_info * msg_info;
735 uint32_t index; 736 uint32_t index;
736 int error; 737 int error;
737 int r; 738 int r;
738 unsigned int array_index; 739 unsigned int array_index;
739 struct stat buf; 740 struct stat buf;
740 chashdatum key; 741 chashdatum key;
741 chashdatum data; 742 chashdatum data;
742 743
743#if 0 744#if 0
744 r = mailmh_folder_update(folder); 745 r = mailmh_folder_update(folder);
745 if (r != MAILMH_NO_ERROR) { 746 if (r != MAILMH_NO_ERROR) {
746 error = r; 747 error = r;
747 goto err; 748 goto err;
748 } 749 }
749#endif 750#endif
750 751
751 namesize = strlen(folder->fl_filename) + 20; 752 namesize = strlen(folder->fl_filename) + 20;
752 tmpname = malloc(namesize); 753 tmpname = malloc(namesize);
753 snprintf(tmpname, namesize, "%s%ctmpXXXXXX", 754 snprintf(tmpname, namesize, "%s%ctmpXXXXXX",
754 folder->fl_filename, MAIL_DIR_SEPARATOR); 755 folder->fl_filename, MAIL_DIR_SEPARATOR);
755 fd = mkstemp(tmpname); 756 fd = mkstemp(tmpname);
756 if (fd < 0) { 757 if (fd < 0) {
757 error = MAILMH_ERROR_FILE; 758 error = MAILMH_ERROR_FILE;
758 goto free; 759 goto free;
759 } 760 }
760 761
761 left = size; 762 left = size;
762 while (left > 0) { 763 while (left > 0) {
763 res = write(fd, message, left); 764 res = write(fd, message, left);
764 if (res == -1) { 765 if (res == -1) {
765 close(fd); 766 close(fd);
766 error = MAILMH_ERROR_FILE; 767 error = MAILMH_ERROR_FILE;
767 goto free; 768 goto free;
768 } 769 }
769 770
770 left -= res; 771 left -= res;
771 } 772 }
772 close(fd); 773 close(fd);
773 774
774 r = stat(tmpname, &buf); 775 r = stat(tmpname, &buf);
775 if (r < 0) { 776 if (r < 0) {
776 error = MAILMH_ERROR_FILE; 777 error = MAILMH_ERROR_FILE;
777 goto free; 778 goto free;
778 } 779 }
779 780
780 r = mailmh_folder_alloc_msg(folder, tmpname, &index); 781 r = mailmh_folder_alloc_msg(folder, tmpname, &index);
781 if (r != MAILMH_NO_ERROR) { 782 if (r != MAILMH_NO_ERROR) {
782 unlink(tmpname); 783 unlink(tmpname);
783 error = MAILMH_ERROR_COULD_NOT_ALLOC_MSG; 784 error = MAILMH_ERROR_COULD_NOT_ALLOC_MSG;
784 goto free; 785 goto free;
785 } 786 }
786 free(tmpname); 787 free(tmpname);
787 788
788 msg_info = mailmh_msg_info_new(index, size, buf.st_mtime); 789 msg_info = mailmh_msg_info_new(index, size, buf.st_mtime);
789 if (msg_info == NULL) { 790 if (msg_info == NULL) {
790 mailmh_folder_remove_message(folder, index); 791 mailmh_folder_remove_message(folder, index);
791 error = MAILMH_ERROR_MEMORY; 792 error = MAILMH_ERROR_MEMORY;
792 goto err; 793 goto err;
793 } 794 }
794 795
795 r = carray_add(folder->fl_msgs_tab, msg_info, &array_index); 796 r = carray_add(folder->fl_msgs_tab, msg_info, &array_index);
796 if (r < 0) { 797 if (r < 0) {
797 mailmh_folder_remove_message(folder, index); 798 mailmh_folder_remove_message(folder, index);
798 mailmh_msg_info_free(msg_info); 799 mailmh_msg_info_free(msg_info);
799 error = MAILMH_ERROR_MEMORY; 800 error = MAILMH_ERROR_MEMORY;
800 goto err; 801 goto err;
801 } 802 }
802 msg_info->msg_array_index = array_index; 803 msg_info->msg_array_index = array_index;
803 804
804#if 0 805#if 0
805 r = cinthash_add(folder->fl_msgs_hash, index, msg_info); 806 r = cinthash_add(folder->fl_msgs_hash, index, msg_info);
806#endif 807#endif
807 key.data = &index; 808 key.data = &index;
808 key.len = sizeof(index); 809 key.len = sizeof(index);
809 data.data = msg_info; 810 data.data = msg_info;
810 data.len = 0; 811 data.len = 0;
811 812
813 if (pindex != NULL)
814 * pindex = index;
815
812 r = chash_set(folder->fl_msgs_hash, &key, &data, NULL); 816 r = chash_set(folder->fl_msgs_hash, &key, &data, NULL);
813 if (r < 0) { 817 if (r < 0) {
814 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); 818 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index);
815 mailmh_msg_info_free(msg_info); 819 mailmh_msg_info_free(msg_info);
816 error = MAILMH_ERROR_MEMORY; 820 error = MAILMH_ERROR_MEMORY;
817 goto err; 821 goto err;
818 } 822 }
819 823
820 return MAILMH_NO_ERROR; 824 return MAILMH_NO_ERROR;
821 825
822 free: 826 free:
823 free(tmpname); 827 free(tmpname);
824 err: 828 err:
825 return error; 829 return error;
826} 830}
827 831
828int mailmh_folder_add_message_file(struct mailmh_folder * folder, 832int mailmh_folder_add_message(struct mailmh_folder * folder,
829 int fd) 833 const char * message, size_t size)
834{
835 return mailmh_folder_add_message_uid(folder, message, size, NULL);
836}
837
838int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder,
839 int fd, uint32_t * pindex)
830{ 840{
831 char * message; 841 char * message;
832 struct stat buf; 842 struct stat buf;
833 int r; 843 int r;
834 844
835#if 0 845#if 0
836 r = mailmh_folder_update(folder); 846 r = mailmh_folder_update(folder);
837 if (r != MAILMH_NO_ERROR) 847 if (r != MAILMH_NO_ERROR)
838 return r; 848 return r;
839#endif 849#endif
840 850
841 if (fstat(fd, &buf) == -1) 851 if (fstat(fd, &buf) == -1)
842 return MAILMH_ERROR_FILE; 852 return MAILMH_ERROR_FILE;
843 853
844 message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 854 message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
845 if (message == MAP_FAILED) 855 if (message == MAP_FAILED)
846 return MAILMH_ERROR_FILE; 856 return MAILMH_ERROR_FILE;
847 857
848 r = mailmh_folder_add_message(folder, message, buf.st_size); 858 r = mailmh_folder_add_message_uid(folder, message, buf.st_size, pindex);
849 859
850 munmap(message, buf.st_size); 860 munmap(message, buf.st_size);
851 861
852 return r; 862 return r;
853} 863}
854 864
865int mailmh_folder_add_message_file(struct mailmh_folder * folder,
866 int fd)
867{
868 return mailmh_folder_add_message_file_uid(folder, fd, NULL);
869}
870
855int mailmh_folder_remove_message(struct mailmh_folder * folder, 871int mailmh_folder_remove_message(struct mailmh_folder * folder,
856 uint32_t index) 872 uint32_t index)
857{ 873{
858 char * filename; 874 char * filename;
859 struct mailmh_msg_info * msg_info; 875 struct mailmh_msg_info * msg_info;
860 int res; 876 int res;
861 int r; 877 int r;
862 chashdatum key; 878 chashdatum key;
863 chashdatum data; 879 chashdatum data;
864 880
865#if 0 881#if 0
866 r = mailmh_folder_update(folder); 882 r = mailmh_folder_update(folder);
867 if (r != MAILMH_NO_ERROR) { 883 if (r != MAILMH_NO_ERROR) {
868 res = r; 884 res = r;
869 goto err; 885 goto err;
870 } 886 }
871#endif 887#endif
872 888
873 r = mailmh_folder_get_message_filename(folder, index, &filename); 889 r = mailmh_folder_get_message_filename(folder, index, &filename);
874 if (filename == NULL) { 890 if (filename == NULL) {
875 res = r; 891 res = r;
876 goto err; 892 goto err;
877 } 893 }
878 894
879 if (unlink(filename) == -1) { 895 if (unlink(filename) == -1) {
880 res = MAILMH_ERROR_FILE; 896 res = MAILMH_ERROR_FILE;
881 goto free; 897 goto free;
882 } 898 }
883 899
884 key.data = &index; 900 key.data = &index;
885 key.len = sizeof(index); 901 key.len = sizeof(index);
886 r = chash_get(folder->fl_msgs_hash, &key, &data); 902 r = chash_get(folder->fl_msgs_hash, &key, &data);
887#if 0 903#if 0
888 msg_info = cinthash_find(folder->fl_msgs_hash, index); 904 msg_info = cinthash_find(folder->fl_msgs_hash, index);
889#endif 905#endif
890 if (r == 0) { 906 if (r == 0) {
891 msg_info = data.data; 907 msg_info = data.data;
892 908
893 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); 909 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index);
894#if 0 910#if 0
895 cinthash_remove(folder->fl_msgs_hash, index); 911 cinthash_remove(folder->fl_msgs_hash, index);
896#endif 912#endif
897 chash_delete(folder->fl_msgs_hash, &key, NULL); 913 chash_delete(folder->fl_msgs_hash, &key, NULL);
898 } 914 }
899 915
900 return MAILMH_NO_ERROR; 916 return MAILMH_NO_ERROR;
901 917
902 free: 918 free:
903 free(filename); 919 free(filename);
904 err: 920 err:
905 return res; 921 return res;
906} 922}
907 923
908 924
909int mailmh_folder_move_message(struct mailmh_folder * dest_folder, 925int mailmh_folder_move_message(struct mailmh_folder * dest_folder,
910 struct mailmh_folder * src_folder, 926 struct mailmh_folder * src_folder,
911 uint32_t index) 927 uint32_t index)
912{ 928{
913 int fd; 929 int fd;
914 char * filename; 930 char * filename;
915 int r; 931 int r;
916 932
917#if 0 933#if 0
918 r = mailmh_folder_update(dest_folder); 934 r = mailmh_folder_update(dest_folder);
919 if (r != MAILMH_NO_ERROR) 935 if (r != MAILMH_NO_ERROR)
920 return r; 936 return r;
921 r = mailmh_folder_update(src_folder); 937 r = mailmh_folder_update(src_folder);
922 if (r != MAILMH_NO_ERROR) 938 if (r != MAILMH_NO_ERROR)
923 return r; 939 return r;
924#endif 940#endif
925 941
926 /* move on the same filesystem */ 942 /* move on the same filesystem */
927 r = mailmh_folder_get_message_filename(src_folder, index, &filename); 943 r = mailmh_folder_get_message_filename(src_folder, index, &filename);
928 if (r != MAILMH_NO_ERROR) 944 if (r != MAILMH_NO_ERROR)
929 return r; 945 return r;
930 946
931 r = mailmh_folder_alloc_msg(dest_folder, filename, &index); 947 r = mailmh_folder_alloc_msg(dest_folder, filename, &index);
932 free(filename); 948 free(filename);
933 if (r == MAILMH_NO_ERROR) 949 if (r == MAILMH_NO_ERROR)
934 return MAILMH_NO_ERROR; 950 return MAILMH_NO_ERROR;
935 951
936 /* move on the different filesystems */ 952 /* move on the different filesystems */
937 r = mailmh_folder_get_message_fd(src_folder, index, O_RDONLY, &fd); 953 r = mailmh_folder_get_message_fd(src_folder, index, O_RDONLY, &fd);
938 if (r != MAILMH_NO_ERROR) 954 if (r != MAILMH_NO_ERROR)
939 return r; 955 return r;
940 956
941 r = mailmh_folder_add_message_file(dest_folder, fd); 957 r = mailmh_folder_add_message_file(dest_folder, fd);
942 if (r != MAILMH_NO_ERROR) { 958 if (r != MAILMH_NO_ERROR) {
943 close(fd); 959 close(fd);
944 return r; 960 return r;
945 } 961 }
946 962
947 close(fd); 963 close(fd);
948 964
949 r = mailmh_folder_remove_message(src_folder, index); 965 r = mailmh_folder_remove_message(src_folder, index);
950 966
951 return MAILMH_NO_ERROR; 967 return MAILMH_NO_ERROR;
952} 968}
953 969
954unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder) 970unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder)
955{ 971{
956 unsigned int i; 972 unsigned int i;
957 unsigned int count; 973 unsigned int count;
958 974
959 count = 0; 975 count = 0;
960 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++) 976 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++)
961 if (carray_get(folder->fl_msgs_tab, i) != NULL) 977 if (carray_get(folder->fl_msgs_tab, i) != NULL)
962 count ++; 978 count ++;
963 979
964 return count; 980 return count;
965} 981}
diff --git a/kmicromail/libetpan/mh/mailmh.h b/kmicromail/libetpan/mh/mailmh.h
index 40432cb..00199b8 100644
--- a/kmicromail/libetpan/mh/mailmh.h
+++ b/kmicromail/libetpan/mh/mailmh.h
@@ -1,143 +1,150 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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#ifndef MAILMH_H 36#ifndef MAILMH_H
37 37
38#define MAILMH_H 38#define MAILMH_H
39 39
40#ifdef __cplusplus 40#ifdef __cplusplus
41extern "C" { 41extern "C" {
42#endif 42#endif
43 43
44#include <sys/types.h> 44#include <sys/types.h>
45#include <inttypes.h> 45#include <inttypes.h>
46#include <libetpan/carray.h> 46#include <libetpan/carray.h>
47#include <libetpan/cinthash.h> 47#include <libetpan/cinthash.h>
48#include <libetpan/chash.h> 48#include <libetpan/chash.h>
49 49
50enum { 50enum {
51 MAILMH_NO_ERROR = 0, 51 MAILMH_NO_ERROR = 0,
52 MAILMH_ERROR_FOLDER, 52 MAILMH_ERROR_FOLDER,
53 MAILMH_ERROR_MEMORY, 53 MAILMH_ERROR_MEMORY,
54 MAILMH_ERROR_FILE, 54 MAILMH_ERROR_FILE,
55 MAILMH_ERROR_COULD_NOT_ALLOC_MSG, 55 MAILMH_ERROR_COULD_NOT_ALLOC_MSG,
56 MAILMH_ERROR_RENAME, 56 MAILMH_ERROR_RENAME,
57 MAILMH_ERROR_MSG_NOT_FOUND, 57 MAILMH_ERROR_MSG_NOT_FOUND,
58}; 58};
59 59
60struct mailmh { 60struct mailmh {
61 struct mailmh_folder * mh_main; 61 struct mailmh_folder * mh_main;
62}; 62};
63 63
64struct mailmh_msg_info { 64struct mailmh_msg_info {
65 unsigned int msg_array_index; 65 unsigned int msg_array_index;
66 uint32_t msg_index; 66 uint32_t msg_index;
67 size_t msg_size; 67 size_t msg_size;
68 time_t msg_mtime; 68 time_t msg_mtime;
69}; 69};
70 70
71struct mailmh_folder { 71struct mailmh_folder {
72 char * fl_filename; 72 char * fl_filename;
73 unsigned int fl_array_index; 73 unsigned int fl_array_index;
74 74
75 char * fl_name; 75 char * fl_name;
76 time_t fl_mtime; 76 time_t fl_mtime;
77 struct mailmh_folder * fl_parent; 77 struct mailmh_folder * fl_parent;
78 uint32_t fl_max_index; 78 uint32_t fl_max_index;
79 79
80 carray * fl_msgs_tab; 80 carray * fl_msgs_tab;
81#if 0 81#if 0
82 cinthash_t * fl_msgs_hash; 82 cinthash_t * fl_msgs_hash;
83#endif 83#endif
84 chash * fl_msgs_hash; 84 chash * fl_msgs_hash;
85 85
86 carray * fl_subfolders_tab; 86 carray * fl_subfolders_tab;
87 chash * fl_subfolders_hash; 87 chash * fl_subfolders_hash;
88}; 88};
89 89
90struct mailmh * mailmh_new(const char * foldername); 90struct mailmh * mailmh_new(const char * foldername);
91void mailmh_free(struct mailmh * f); 91void mailmh_free(struct mailmh * f);
92 92
93struct mailmh_msg_info * 93struct mailmh_msg_info *
94mailmh_msg_info_new(uint32_t index, size_t size, time_t mtime); 94mailmh_msg_info_new(uint32_t index, size_t size, time_t mtime);
95void mailmh_msg_info_free(struct mailmh_msg_info * msg_info); 95void mailmh_msg_info_free(struct mailmh_msg_info * msg_info);
96 96
97struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent, 97struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent,
98 const char * name); 98 const char * name);
99void mailmh_folder_free(struct mailmh_folder * folder); 99void mailmh_folder_free(struct mailmh_folder * folder);
100 100
101int mailmh_folder_add_subfolder(struct mailmh_folder * parent, 101int mailmh_folder_add_subfolder(struct mailmh_folder * parent,
102 const char * name); 102 const char * name);
103 103
104struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root, 104struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root,
105 const char * filename); 105 const char * filename);
106 106
107int mailmh_folder_remove_subfolder(struct mailmh_folder * folder); 107int mailmh_folder_remove_subfolder(struct mailmh_folder * folder);
108 108
109int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder, 109int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder,
110 struct mailmh_folder * dst_folder, 110 struct mailmh_folder * dst_folder,
111 const char * new_name); 111 const char * new_name);
112 112
113int mailmh_folder_get_message_filename(struct mailmh_folder * folder, 113int mailmh_folder_get_message_filename(struct mailmh_folder * folder,
114 uint32_t index, char ** result); 114 uint32_t index, char ** result);
115 115
116int mailmh_folder_get_message_fd(struct mailmh_folder * folder, 116int mailmh_folder_get_message_fd(struct mailmh_folder * folder,
117 uint32_t index, int flags, int * result); 117 uint32_t index, int flags, int * result);
118 118
119int mailmh_folder_get_message_size(struct mailmh_folder * folder, 119int mailmh_folder_get_message_size(struct mailmh_folder * folder,
120 uint32_t index, size_t * result); 120 uint32_t index, size_t * result);
121 121
122int mailmh_folder_add_message_uid(struct mailmh_folder * folder,
123 const char * message, size_t size,
124 uint32_t * pindex);
125
122int mailmh_folder_add_message(struct mailmh_folder * folder, 126int mailmh_folder_add_message(struct mailmh_folder * folder,
123 const char * message, size_t size); 127 const char * message, size_t size);
124 128
129int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder,
130 int fd, uint32_t * pindex);
131
125int mailmh_folder_add_message_file(struct mailmh_folder * folder, 132int mailmh_folder_add_message_file(struct mailmh_folder * folder,
126 int fd); 133 int fd);
127 134
128int mailmh_folder_remove_message(struct mailmh_folder * folder, 135int mailmh_folder_remove_message(struct mailmh_folder * folder,
129 uint32_t index); 136 uint32_t index);
130 137
131int mailmh_folder_move_message(struct mailmh_folder * dest_folder, 138int mailmh_folder_move_message(struct mailmh_folder * dest_folder,
132 struct mailmh_folder * src_folder, 139 struct mailmh_folder * src_folder,
133 uint32_t index); 140 uint32_t index);
134 141
135int mailmh_folder_update(struct mailmh_folder * folder); 142int mailmh_folder_update(struct mailmh_folder * folder);
136 143
137unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder); 144unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder);
138 145
139#ifdef __cplusplus 146#ifdef __cplusplus
140} 147}
141#endif 148#endif
142 149
143#endif 150#endif
diff --git a/kmicromail/libetpan/mime/mailmime_decode.c b/kmicromail/libetpan/mime/mailmime_decode.c
index 3025dcb..e48ec19 100644
--- a/kmicromail/libetpan/mime/mailmime_decode.c
+++ b/kmicromail/libetpan/mime/mailmime_decode.c
@@ -62,266 +62,276 @@
62 62
63static int mailmime_charset_parse(const char * message, size_t length, 63static int mailmime_charset_parse(const char * message, size_t length,
64 size_t * index, char ** charset); 64 size_t * index, char ** charset);
65 65
66enum { 66enum {
67 MAILMIME_ENCODING_B, 67 MAILMIME_ENCODING_B,
68 MAILMIME_ENCODING_Q 68 MAILMIME_ENCODING_Q
69}; 69};
70 70
71static int mailmime_encoding_parse(const char * message, size_t length, 71static int mailmime_encoding_parse(const char * message, size_t length,
72 size_t * index, int * result); 72 size_t * index, int * result);
73 73
74static int mailmime_etoken_parse(const char * message, size_t length, 74static int mailmime_etoken_parse(const char * message, size_t length,
75 size_t * index, char ** result); 75 size_t * index, char ** result);
76 76
77static int 77static int
78mailmime_non_encoded_word_parse(const char * message, size_t length, 78mailmime_non_encoded_word_parse(const char * message, size_t length,
79 size_t * index, 79 size_t * index,
80 char ** result); 80 char ** result);
81 81
82static int 82static int
83mailmime_encoded_word_parse(const char * message, size_t length, 83mailmime_encoded_word_parse(const char * message, size_t length,
84 size_t * index, 84 size_t * index,
85 struct mailmime_encoded_word ** result); 85 struct mailmime_encoded_word ** result);
86 86
87 87
88enum { 88enum {
89 TYPE_ERROR, 89 TYPE_ERROR,
90 TYPE_WORD, 90 TYPE_WORD,
91 TYPE_ENCODED_WORD, 91 TYPE_ENCODED_WORD,
92}; 92};
93 93
94int mailmime_encoded_phrase_parse(const char * default_fromcode, 94int mailmime_encoded_phrase_parse(const char * default_fromcode,
95 const char * message, size_t length, 95 const char * message, size_t length,
96 size_t * index, const char * tocode, 96 size_t * index, const char * tocode,
97 char ** result) 97 char ** result)
98{ 98{
99 MMAPString * gphrase; 99 MMAPString * gphrase;
100 struct mailmime_encoded_word * word; 100 struct mailmime_encoded_word * word;
101 int first; 101 int first;
102 size_t cur_token; 102 size_t cur_token;
103 int r; 103 int r;
104 int res; 104 int res;
105 char * str; 105 char * str;
106 char * wordutf8; 106 char * wordutf8;
107 int type; 107 int type;
108 108
109 cur_token = * index; 109 cur_token = * index;
110 110
111 gphrase = mmap_string_new(""); 111 gphrase = mmap_string_new("");
112 if (gphrase == NULL) { 112 if (gphrase == NULL) {
113 res = MAILIMF_ERROR_MEMORY; 113 res = MAILIMF_ERROR_MEMORY;
114 goto err; 114 goto err;
115 } 115 }
116 116
117 first = TRUE; 117 first = TRUE;
118 118
119 type = TYPE_ERROR; /* XXX - removes a gcc warning */ 119 type = TYPE_ERROR; /* XXX - removes a gcc warning */
120 120
121 while (1) { 121 while (1) {
122 122
123 r = mailmime_encoded_word_parse(message, length, &cur_token, &word); 123 r = mailmime_encoded_word_parse(message, length, &cur_token, &word);
124 if (r == MAILIMF_NO_ERROR) { 124 if (r == MAILIMF_NO_ERROR) {
125 if (!first) { 125 if (!first) {
126 if (type != TYPE_ENCODED_WORD) { 126 if (type != TYPE_ENCODED_WORD) {
127 if (mmap_string_append_c(gphrase, ' ') == NULL) { 127 if (mmap_string_append_c(gphrase, ' ') == NULL) {
128 mailmime_encoded_word_free(word); 128 mailmime_encoded_word_free(word);
129 res = MAILIMF_ERROR_MEMORY; 129 res = MAILIMF_ERROR_MEMORY;
130 goto free; 130 goto free;
131 } 131 }
132 } 132 }
133 } 133 }
134 type = TYPE_ENCODED_WORD; 134 type = TYPE_ENCODED_WORD;
135 wordutf8 = NULL; 135 wordutf8 = NULL;
136 r = charconv(tocode, word->wd_charset, word->wd_text, 136 r = charconv(tocode, word->wd_charset, word->wd_text,
137 strlen(word->wd_text), &wordutf8); 137 strlen(word->wd_text), &wordutf8);
138 switch (r) { 138 switch (r) {
139 case MAIL_CHARCONV_ERROR_MEMORY: 139 case MAIL_CHARCONV_ERROR_MEMORY:
140 mailmime_encoded_word_free(word); 140 mailmime_encoded_word_free(word);
141 res = MAILIMF_ERROR_MEMORY; 141 res = MAILIMF_ERROR_MEMORY;
142 goto free; 142 goto free;
143 143
144 case MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET: 144 case MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET:
145 case MAIL_CHARCONV_ERROR_CONV: 145 case MAIL_CHARCONV_ERROR_CONV:
146 mailmime_encoded_word_free(word); 146 mailmime_encoded_word_free(word);
147 res = MAILIMF_ERROR_PARSE; 147 res = MAILIMF_ERROR_PARSE;
148 goto free; 148 goto free;
149 } 149 }
150 150
151 if (wordutf8 != NULL) { 151 if (wordutf8 != NULL) {
152 if (mmap_string_append(gphrase, wordutf8) == NULL) { 152 if (mmap_string_append(gphrase, wordutf8) == NULL) {
153 mailmime_encoded_word_free(word); 153 mailmime_encoded_word_free(word);
154 free(wordutf8); 154 free(wordutf8);
155 res = MAILIMF_ERROR_MEMORY; 155 res = MAILIMF_ERROR_MEMORY;
156 goto free; 156 goto free;
157 } 157 }
158 free(wordutf8); 158 free(wordutf8);
159 } 159 }
160 mailmime_encoded_word_free(word); 160 mailmime_encoded_word_free(word);
161 first = FALSE; 161 first = FALSE;
162 } 162 }
163 else if (r == MAILIMF_ERROR_PARSE) { 163 else if (r == MAILIMF_ERROR_PARSE) {
164 /* do nothing */ 164 /* do nothing */
165 } 165 }
166 else { 166 else {
167 res = r; 167 res = r;
168 goto free; 168 goto free;
169 } 169 }
170 170
171 if (r == MAILIMF_ERROR_PARSE) { 171 if (r == MAILIMF_ERROR_PARSE) {
172 char * raw_word; 172 char * raw_word;
173 173
174 r = mailmime_non_encoded_word_parse(message, length, 174 r = mailmime_non_encoded_word_parse(message, length,
175 &cur_token, &raw_word); 175 &cur_token, &raw_word);
176 if (r == MAILIMF_NO_ERROR) { 176 if (r == MAILIMF_NO_ERROR) {
177 if (!first) { 177 if (!first) {
178 if (mmap_string_append_c(gphrase, ' ') == NULL) { 178 if (mmap_string_append_c(gphrase, ' ') == NULL) {
179 free(raw_word); 179 free(raw_word);
180 res = MAILIMF_ERROR_MEMORY; 180 res = MAILIMF_ERROR_MEMORY;
181 goto free; 181 goto free;
182 } 182 }
183 } 183 }
184 type = TYPE_WORD; 184 type = TYPE_WORD;
185 185
186 wordutf8 = NULL; 186 wordutf8 = NULL;
187 r = charconv(tocode, default_fromcode, raw_word, 187 r = charconv(tocode, default_fromcode, raw_word,
188 strlen(raw_word), &wordutf8); 188 strlen(raw_word), &wordutf8);
189 189
190 if (wordutf8 != NULL) { 190 switch (r) {
191 if (mmap_string_append(gphrase, wordutf8) == NULL) { 191 case MAIL_CHARCONV_ERROR_MEMORY:
192 free(wordutf8); 192 free(raw_word);
193 free(raw_word); 193 res = MAILIMF_ERROR_MEMORY;
194 res = MAILIMF_ERROR_MEMORY; 194 goto free;
195 goto free;
196 }
197 195
196 case MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET:
197 case MAIL_CHARCONV_ERROR_CONV:
198 free(raw_word);
199 res = MAILIMF_ERROR_PARSE;
200 goto free;
201 }
202
203 if (mmap_string_append(gphrase, wordutf8) == NULL) {
198 free(wordutf8); 204 free(wordutf8);
205 free(raw_word);
206 res = MAILIMF_ERROR_MEMORY;
207 goto free;
199 } 208 }
209
200 free(raw_word); 210 free(raw_word);
201 first = FALSE; 211 first = FALSE;
202 } 212 }
203 else if (r == MAILIMF_ERROR_PARSE) { 213 else if (r == MAILIMF_ERROR_PARSE) {
204 break; 214 break;
205 } 215 }
206 else { 216 else {
207 res = r; 217 res = r;
208 goto free; 218 goto free;
209 } 219 }
210 } 220 }
211 } 221 }
212 222
213 if (first) { 223 if (first) {
214 res = MAILIMF_ERROR_PARSE; 224 res = MAILIMF_ERROR_PARSE;
215 goto free; 225 goto free;
216 } 226 }
217 227
218 str = strdup(gphrase->str); 228 str = strdup(gphrase->str);
219 if (str == NULL) { 229 if (str == NULL) {
220 res = MAILIMF_ERROR_MEMORY; 230 res = MAILIMF_ERROR_MEMORY;
221 goto free; 231 goto free;
222 } 232 }
223 mmap_string_free(gphrase); 233 mmap_string_free(gphrase);
224 234
225 * result = str; 235 * result = str;
226 * index = cur_token; 236 * index = cur_token;
227 237
228 return MAILIMF_NO_ERROR; 238 return MAILIMF_NO_ERROR;
229 239
230 free: 240 free:
231 mmap_string_free(gphrase); 241 mmap_string_free(gphrase);
232 err: 242 err:
233 return res; 243 return res;
234} 244}
235 245
236static int 246static int
237mailmime_non_encoded_word_parse(const char * message, size_t length, 247mailmime_non_encoded_word_parse(const char * message, size_t length,
238 size_t * index, 248 size_t * index,
239 char ** result) 249 char ** result)
240{ 250{
241 int end; 251 int end;
242 size_t cur_token; 252 size_t cur_token;
243 int res; 253 int res;
244 char * text; 254 char * text;
245 int r; 255 int r;
246 size_t begin; 256 size_t begin;
247 257
248 cur_token = * index; 258 cur_token = * index;
249 259
250 r = mailimf_fws_parse(message, length, &cur_token); 260 r = mailimf_fws_parse(message, length, &cur_token);
251 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) { 261 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
252 res = r; 262 res = r;
253 goto err; 263 goto err;
254 } 264 }
255 265
256 begin = cur_token; 266 begin = cur_token;
257 267
258 end = FALSE; 268 end = FALSE;
259 while (1) { 269 while (1) {
260 if (cur_token >= length) 270 if (cur_token >= length)
261 break; 271 break;
262 272
263 switch (message[cur_token]) { 273 switch (message[cur_token]) {
264 case ' ': 274 case ' ':
265 case '\t': 275 case '\t':
266 case '\r': 276 case '\r':
267 case '\n': 277 case '\n':
268 end = TRUE; 278 end = TRUE;
269 break; 279 break;
270 } 280 }
271 281
272 if (end) 282 if (end)
273 break; 283 break;
274 284
275 cur_token ++; 285 cur_token ++;
276 } 286 }
277 287
278 if (cur_token - begin == 0) { 288 if (cur_token - begin == 0) {
279 res = MAILIMF_ERROR_PARSE; 289 res = MAILIMF_ERROR_PARSE;
280 goto err; 290 goto err;
281 } 291 }
282 292
283 text = malloc(cur_token - begin + 1); 293 text = malloc(cur_token - begin + 1);
284 if (text == NULL) { 294 if (text == NULL) {
285 res = MAILIMF_ERROR_MEMORY; 295 res = MAILIMF_ERROR_MEMORY;
286 goto err; 296 goto err;
287 } 297 }
288 298
289 memcpy(text, message + begin, cur_token - begin); 299 memcpy(text, message + begin, cur_token - begin);
290 text[cur_token - begin] = '\0'; 300 text[cur_token - begin] = '\0';
291 301
292 * index = cur_token; 302 * index = cur_token;
293 * result = text; 303 * result = text;
294 304
295 return MAILIMF_NO_ERROR; 305 return MAILIMF_NO_ERROR;
296 306
297 err: 307 err:
298 return res; 308 return res;
299} 309}
300 310
301static int mailmime_encoded_word_parse(const char * message, size_t length, 311static int mailmime_encoded_word_parse(const char * message, size_t length,
302 size_t * index, 312 size_t * index,
303 struct mailmime_encoded_word ** result) 313 struct mailmime_encoded_word ** result)
304{ 314{
305 size_t cur_token; 315 size_t cur_token;
306 char * charset; 316 char * charset;
307 int encoding; 317 int encoding;
308 char * text; 318 char * text;
309 size_t end_encoding; 319 size_t end_encoding;
310 char * decoded; 320 char * decoded;
311 size_t decoded_len; 321 size_t decoded_len;
312 struct mailmime_encoded_word * ew; 322 struct mailmime_encoded_word * ew;
313 int r; 323 int r;
314 int res; 324 int res;
315 int opening_quote; 325 int opening_quote;
316 int end; 326 int end;
317 327
318 cur_token = * index; 328 cur_token = * index;
319 329
320 r = mailimf_fws_parse(message, length, &cur_token); 330 r = mailimf_fws_parse(message, length, &cur_token);
321 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) { 331 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
322 res = r; 332 res = r;
323 goto err; 333 goto err;
324 } 334 }
325 335
326 opening_quote = FALSE; 336 opening_quote = FALSE;
327 r = mailimf_char_parse(message, length, &cur_token, '\"'); 337 r = mailimf_char_parse(message, length, &cur_token, '\"');
diff --git a/kmicromail/libetpan/mime/mailmime_write.c b/kmicromail/libetpan/mime/mailmime_write.c
index 5c3b1f7..208e3ba 100644
--- a/kmicromail/libetpan/mime/mailmime_write.c
+++ b/kmicromail/libetpan/mime/mailmime_write.c
@@ -316,257 +316,257 @@ static int mailmime_language_write(FILE * f, int * col,
316 cur = clist_next(cur)) { 316 cur = clist_next(cur)) {
317 char * lang; 317 char * lang;
318 size_t len; 318 size_t len;
319 319
320 lang = clist_content(cur); 320 lang = clist_content(cur);
321 len = strlen(lang); 321 len = strlen(lang);
322 322
323 if (!first) { 323 if (!first) {
324 r = mailimf_string_write(f, col, ", ", 2); 324 r = mailimf_string_write(f, col, ", ", 2);
325 if (r != MAILIMF_NO_ERROR) 325 if (r != MAILIMF_NO_ERROR)
326 return r; 326 return r;
327 } 327 }
328 else { 328 else {
329 first = FALSE; 329 first = FALSE;
330 } 330 }
331 331
332 if (* col > 1) { 332 if (* col > 1) {
333 333
334 if (* col + len > MAX_MAIL_COL) { 334 if (* col + len > MAX_MAIL_COL) {
335 r = mailimf_string_write(f, col, "\r\n ", 3); 335 r = mailimf_string_write(f, col, "\r\n ", 3);
336 if (r != MAILIMF_NO_ERROR) 336 if (r != MAILIMF_NO_ERROR)
337 return r; 337 return r;
338#if 0 338#if 0
339 * col = 1; 339 * col = 1;
340#endif 340#endif
341 } 341 }
342 } 342 }
343 343
344 r = mailimf_string_write(f, col, lang, len); 344 r = mailimf_string_write(f, col, lang, len);
345 if (r != MAILIMF_NO_ERROR) 345 if (r != MAILIMF_NO_ERROR)
346 return r; 346 return r;
347 } 347 }
348 348
349 r = mailimf_string_write(f, col, "\r\n", 2); 349 r = mailimf_string_write(f, col, "\r\n", 2);
350 if (r != MAILIMF_NO_ERROR) 350 if (r != MAILIMF_NO_ERROR)
351 return r; 351 return r;
352#if 0 352#if 0
353 * col = 0; 353 * col = 0;
354#endif 354#endif
355 355
356 return MAILIMF_NO_ERROR; 356 return MAILIMF_NO_ERROR;
357} 357}
358 358
359static int mailmime_disposition_write(FILE * f, int * col, 359static int mailmime_disposition_write(FILE * f, int * col,
360 struct mailmime_disposition * 360 struct mailmime_disposition *
361 disposition) 361 disposition)
362{ 362{
363 struct mailmime_disposition_type * dsp_type; 363 struct mailmime_disposition_type * dsp_type;
364 int r; 364 int r;
365 clistiter * cur; 365 clistiter * cur;
366 366
367 dsp_type = disposition->dsp_type; 367 dsp_type = disposition->dsp_type;
368 368
369 r = mailimf_string_write(f, col, "Content-Disposition: ", 21); 369 r = mailimf_string_write(f, col, "Content-Disposition: ", 21);
370 if (r != MAILIMF_NO_ERROR) 370 if (r != MAILIMF_NO_ERROR)
371 return r; 371 return r;
372 372
373 switch (dsp_type->dsp_type) { 373 switch (dsp_type->dsp_type) {
374 case MAILMIME_DISPOSITION_TYPE_INLINE: 374 case MAILMIME_DISPOSITION_TYPE_INLINE:
375 r = mailimf_string_write(f, col, "inline", 6); 375 r = mailimf_string_write(f, col, "inline", 6);
376 break; 376 break;
377 377
378 case MAILMIME_DISPOSITION_TYPE_ATTACHMENT: 378 case MAILMIME_DISPOSITION_TYPE_ATTACHMENT:
379 r = mailimf_string_write(f, col, "attachment", 10); 379 r = mailimf_string_write(f, col, "attachment", 10);
380 break; 380 break;
381 381
382 case MAILMIME_DISPOSITION_TYPE_EXTENSION: 382 case MAILMIME_DISPOSITION_TYPE_EXTENSION:
383 r = mailimf_string_write(f, col, dsp_type->dsp_extension, 383 r = mailimf_string_write(f, col, dsp_type->dsp_extension,
384 strlen(dsp_type->dsp_extension)); 384 strlen(dsp_type->dsp_extension));
385 break; 385 break;
386 386
387 default: 387 default:
388 r = MAILIMF_ERROR_INVAL; 388 r = MAILIMF_ERROR_INVAL;
389 break; 389 break;
390 } 390 }
391 391
392 if (r != MAILIMF_NO_ERROR) 392 if (r != MAILIMF_NO_ERROR)
393 return r; 393 return r;
394 394
395 for(cur = clist_begin(disposition->dsp_parms) ; 395 for(cur = clist_begin(disposition->dsp_parms) ;
396 cur != NULL ; cur = clist_next(cur)) { 396 cur != NULL ; cur = clist_next(cur)) {
397 struct mailmime_disposition_parm * param; 397 struct mailmime_disposition_parm * param;
398 398
399 param = cur->data; 399 param = cur->data;
400 400
401 r = mailimf_string_write(f, col, "; ", 2); 401 r = mailimf_string_write(f, col, "; ", 2);
402 if (r != MAILIMF_NO_ERROR) 402 if (r != MAILIMF_NO_ERROR)
403 return r; 403 return r;
404 404
405 r = mailmime_disposition_param_write(f, col, param); 405 r = mailmime_disposition_param_write(f, col, param);
406 if (r != MAILIMF_NO_ERROR) 406 if (r != MAILIMF_NO_ERROR)
407 return r; 407 return r;
408 } 408 }
409 409
410 r = mailimf_string_write(f, col, "\r\n", 2); 410 r = mailimf_string_write(f, col, "\r\n", 2);
411 if (r != MAILIMF_NO_ERROR) 411 if (r != MAILIMF_NO_ERROR)
412 return r; 412 return r;
413 413
414 return MAILIMF_NO_ERROR; 414 return MAILIMF_NO_ERROR;
415} 415}
416 416
417static int 417static int
418mailmime_disposition_param_write(FILE * f, int * col, 418mailmime_disposition_param_write(FILE * f, int * col,
419 struct mailmime_disposition_parm * param) 419 struct mailmime_disposition_parm * param)
420{ 420{
421 size_t len; 421 size_t len;
422 char sizestr[20]; 422 char sizestr[20];
423 int r; 423 int r;
424 424
425 switch (param->pa_type) { 425 switch (param->pa_type) {
426 case MAILMIME_DISPOSITION_PARM_FILENAME: 426 case MAILMIME_DISPOSITION_PARM_FILENAME:
427 len = strlen("filename=") + strlen(param->pa_data.pa_filename); 427 len = strlen("filename=") + strlen(param->pa_data.pa_filename);
428 break; 428 break;
429 429
430 case MAILMIME_DISPOSITION_PARM_CREATION_DATE: 430 case MAILMIME_DISPOSITION_PARM_CREATION_DATE:
431 len = strlen("creation-date=") + strlen(param->pa_data.pa_creation_date); 431 len = strlen("creation-date=") + strlen(param->pa_data.pa_creation_date);
432 break; 432 break;
433 433
434 case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE: 434 case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE:
435 len = strlen("modification-date=") + 435 len = strlen("modification-date=") +
436 strlen(param->pa_data.pa_modification_date); 436 strlen(param->pa_data.pa_modification_date);
437 break; 437 break;
438 438
439 case MAILMIME_DISPOSITION_PARM_READ_DATE: 439 case MAILMIME_DISPOSITION_PARM_READ_DATE:
440 len = strlen("read-date=") + strlen(param->pa_data.pa_read_date); 440 len = strlen("read-date=") + strlen(param->pa_data.pa_read_date);
441 break; 441 break;
442 442
443 case MAILMIME_DISPOSITION_PARM_SIZE: 443 case MAILMIME_DISPOSITION_PARM_SIZE:
444 snprintf(sizestr, 20, "%u", param->pa_data.pa_size); 444 snprintf(sizestr, 20, "%lu", (unsigned long) param->pa_data.pa_size);
445 len = strlen("size=") + strlen(sizestr); 445 len = strlen("size=") + strlen(sizestr);
446 break; 446 break;
447 447
448 case MAILMIME_DISPOSITION_PARM_PARAMETER: 448 case MAILMIME_DISPOSITION_PARM_PARAMETER:
449 len = strlen(param->pa_data.pa_parameter->pa_name) + 1 + 449 len = strlen(param->pa_data.pa_parameter->pa_name) + 1 +
450 strlen(param->pa_data.pa_parameter->pa_value); 450 strlen(param->pa_data.pa_parameter->pa_value);
451 break; 451 break;
452 452
453 default: 453 default:
454 return MAILIMF_ERROR_INVAL; 454 return MAILIMF_ERROR_INVAL;
455 } 455 }
456 456
457 if (* col > 1) { 457 if (* col > 1) {
458 458
459 if (* col + len > MAX_MAIL_COL) { 459 if (* col + len > MAX_MAIL_COL) {
460 r = mailimf_string_write(f, col, "\r\n ", 3); 460 r = mailimf_string_write(f, col, "\r\n ", 3);
461 if (r != MAILIMF_NO_ERROR) 461 if (r != MAILIMF_NO_ERROR)
462 return r; 462 return r;
463#if 0 463#if 0
464 * col = 1; 464 * col = 1;
465#endif 465#endif
466 } 466 }
467 } 467 }
468 468
469 switch (param->pa_type) { 469 switch (param->pa_type) {
470 case MAILMIME_DISPOSITION_PARM_FILENAME: 470 case MAILMIME_DISPOSITION_PARM_FILENAME:
471 r = mailimf_string_write(f, col, "filename=", 9); 471 r = mailimf_string_write(f, col, "filename=", 9);
472 if (r != MAILIMF_NO_ERROR) 472 if (r != MAILIMF_NO_ERROR)
473 return r; 473 return r;
474 474
475 r = mailimf_quoted_string_write(f, col, 475 r = mailimf_quoted_string_write(f, col,
476 param->pa_data.pa_filename, strlen(param->pa_data.pa_filename)); 476 param->pa_data.pa_filename, strlen(param->pa_data.pa_filename));
477 if (r != MAILIMF_NO_ERROR) 477 if (r != MAILIMF_NO_ERROR)
478 return r; 478 return r;
479 break; 479 break;
480 480
481 case MAILMIME_DISPOSITION_PARM_CREATION_DATE: 481 case MAILMIME_DISPOSITION_PARM_CREATION_DATE:
482 r = mailimf_string_write(f, col, "creation-date=", 14); 482 r = mailimf_string_write(f, col, "creation-date=", 14);
483 if (r != MAILIMF_NO_ERROR) 483 if (r != MAILIMF_NO_ERROR)
484 return r; 484 return r;
485 485
486 r = mailimf_quoted_string_write(f, col, param->pa_data.pa_creation_date, 486 r = mailimf_quoted_string_write(f, col, param->pa_data.pa_creation_date,
487 strlen(param->pa_data.pa_creation_date)); 487 strlen(param->pa_data.pa_creation_date));
488 if (r != MAILIMF_NO_ERROR) 488 if (r != MAILIMF_NO_ERROR)
489 return r; 489 return r;
490 break; 490 break;
491 491
492 case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE: 492 case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE:
493 r = mailimf_string_write(f, col, "modification-date=", 18); 493 r = mailimf_string_write(f, col, "modification-date=", 18);
494 if (r != MAILIMF_NO_ERROR) 494 if (r != MAILIMF_NO_ERROR)
495 return r; 495 return r;
496 496
497 r = mailimf_quoted_string_write(f, col, 497 r = mailimf_quoted_string_write(f, col,
498 param->pa_data.pa_modification_date, 498 param->pa_data.pa_modification_date,
499 strlen(param->pa_data.pa_modification_date)); 499 strlen(param->pa_data.pa_modification_date));
500 if (r != MAILIMF_NO_ERROR) 500 if (r != MAILIMF_NO_ERROR)
501 return r; 501 return r;
502 break; 502 break;
503 503
504 case MAILMIME_DISPOSITION_PARM_READ_DATE: 504 case MAILMIME_DISPOSITION_PARM_READ_DATE:
505 r = mailimf_string_write(f, col, "read-date=", 10); 505 r = mailimf_string_write(f, col, "read-date=", 10);
506 if (r != MAILIMF_NO_ERROR) 506 if (r != MAILIMF_NO_ERROR)
507 return r; 507 return r;
508 508
509 r = mailimf_quoted_string_write(f, col, param->pa_data.pa_read_date, 509 r = mailimf_quoted_string_write(f, col, param->pa_data.pa_read_date,
510 strlen(param->pa_data.pa_read_date)); 510 strlen(param->pa_data.pa_read_date));
511 if (r != MAILIMF_NO_ERROR) 511 if (r != MAILIMF_NO_ERROR)
512 return r; 512 return r;
513 break; 513 break;
514 514
515 case MAILMIME_DISPOSITION_PARM_SIZE: 515 case MAILMIME_DISPOSITION_PARM_SIZE:
516 r = mailimf_string_write(f, col, "size=", 5); 516 r = mailimf_string_write(f, col, "size=", 5);
517 if (r != MAILIMF_NO_ERROR) 517 if (r != MAILIMF_NO_ERROR)
518 return r; 518 return r;
519 519
520 r = mailimf_string_write(f, col, sizestr, strlen(sizestr)); 520 r = mailimf_string_write(f, col, sizestr, strlen(sizestr));
521 if (r != MAILIMF_NO_ERROR) 521 if (r != MAILIMF_NO_ERROR)
522 return r; 522 return r;
523 break; 523 break;
524 524
525 case MAILMIME_DISPOSITION_PARM_PARAMETER: 525 case MAILMIME_DISPOSITION_PARM_PARAMETER:
526 r = mailmime_parameter_write(f, col, param->pa_data.pa_parameter); 526 r = mailmime_parameter_write(f, col, param->pa_data.pa_parameter);
527 if (r != MAILIMF_NO_ERROR) 527 if (r != MAILIMF_NO_ERROR)
528 return r; 528 return r;
529 break; 529 break;
530 } 530 }
531 531
532 return MAILIMF_NO_ERROR; 532 return MAILIMF_NO_ERROR;
533} 533}
534 534
535static int mailmime_parameter_write(FILE * f, int * col, 535static int mailmime_parameter_write(FILE * f, int * col,
536 struct mailmime_parameter * param) 536 struct mailmime_parameter * param)
537{ 537{
538 int r; 538 int r;
539 539
540 r = mailimf_string_write(f, col, param->pa_name, 540 r = mailimf_string_write(f, col, param->pa_name,
541 strlen(param->pa_name)); 541 strlen(param->pa_name));
542 if (r != MAILIMF_NO_ERROR) 542 if (r != MAILIMF_NO_ERROR)
543 return r; 543 return r;
544 544
545 r = mailimf_string_write(f, col, "=", 1); 545 r = mailimf_string_write(f, col, "=", 1);
546 if (r != MAILIMF_NO_ERROR) 546 if (r != MAILIMF_NO_ERROR)
547 return r; 547 return r;
548 548
549 r = mailimf_quoted_string_write(f, col, param->pa_value, 549 r = mailimf_quoted_string_write(f, col, param->pa_value,
550 strlen(param->pa_value)); 550 strlen(param->pa_value));
551 if (r != MAILIMF_NO_ERROR) 551 if (r != MAILIMF_NO_ERROR)
552 return r; 552 return r;
553 553
554 return MAILIMF_NO_ERROR; 554 return MAILIMF_NO_ERROR;
555} 555}
556 556
557int mailmime_content_type_write(FILE * f, int * col, 557int mailmime_content_type_write(FILE * f, int * col,
558 struct mailmime_content * content) 558 struct mailmime_content * content)
559{ 559{
560 clistiter * cur; 560 clistiter * cur;
561 size_t len; 561 size_t len;
562 int r; 562 int r;
563 563
564 r = mailmime_type_write(f, col, content->ct_type); 564 r = mailmime_type_write(f, col, content->ct_type);
565 if (r != MAILIMF_NO_ERROR) 565 if (r != MAILIMF_NO_ERROR)
566 return r; 566 return r;
567 567
568 r = mailimf_string_write(f, col, "/", 1); 568 r = mailimf_string_write(f, col, "/", 1);
569 if (r != MAILIMF_NO_ERROR) 569 if (r != MAILIMF_NO_ERROR)
570 return r; 570 return r;
571 571
572 r = mailimf_string_write(f, col, content->ct_subtype, 572 r = mailimf_string_write(f, col, content->ct_subtype,
diff --git a/kmicromail/libetpan/smtp/mailsmtp.c b/kmicromail/libetpan/smtp/mailsmtp.c
index b3be432..3ab1d11 100644
--- a/kmicromail/libetpan/smtp/mailsmtp.c
+++ b/kmicromail/libetpan/smtp/mailsmtp.c
@@ -67,256 +67,258 @@
67 RFC 2852 : Deliver By SMTP Service Extension 67 RFC 2852 : Deliver By SMTP Service Extension
68 RFC 2920 : SMTP Service Extension for Command Pipelining 68 RFC 2920 : SMTP Service Extension for Command Pipelining
69 RFC 3030 : SMTP Service Extensions for Transmission of Large and Binary MIME 69 RFC 3030 : SMTP Service Extensions for Transmission of Large and Binary MIME
70 Messages 70 Messages
71*/ 71*/
72 72
73#define SMTP_STATUS_CONTINUE 0x1000 73#define SMTP_STATUS_CONTINUE 0x1000
74 74
75mailsmtp * mailsmtp_new(size_t progr_rate, 75mailsmtp * mailsmtp_new(size_t progr_rate,
76 progress_function * progr_fun) 76 progress_function * progr_fun)
77{ 77{
78 mailsmtp * session; 78 mailsmtp * session;
79 79
80 session = malloc(sizeof(* session)); 80 session = malloc(sizeof(* session));
81 if (session == NULL) 81 if (session == NULL)
82 goto err; 82 goto err;
83 83
84 session->stream = NULL; 84 session->stream = NULL;
85 85
86 session->progr_rate = progr_rate; 86 session->progr_rate = progr_rate;
87 session->progr_fun = progr_fun; 87 session->progr_fun = progr_fun;
88 88
89 session->response = NULL; 89 session->response = NULL;
90 90
91 session->line_buffer = mmap_string_new(""); 91 session->line_buffer = mmap_string_new("");
92 if (session->line_buffer == NULL) 92 if (session->line_buffer == NULL)
93 goto free_session; 93 goto free_session;
94 94
95 session->response_buffer = mmap_string_new(""); 95 session->response_buffer = mmap_string_new("");
96 if (session->response_buffer == NULL) 96 if (session->response_buffer == NULL)
97 goto free_line_buffer; 97 goto free_line_buffer;
98 98
99 session->esmtp = 0; 99 session->esmtp = 0;
100 session->auth = MAILSMTP_AUTH_NOT_CHECKED; 100 session->auth = MAILSMTP_AUTH_NOT_CHECKED;
101 101
102 return session; 102 return session;
103 103
104 free_line_buffer: 104 free_line_buffer:
105 mmap_string_free(session->line_buffer); 105 mmap_string_free(session->line_buffer);
106 free_session: 106 free_session:
107 free(session); 107 free(session);
108 err: 108 err:
109 return NULL; 109 return NULL;
110} 110}
111 111
112void mailsmtp_free(mailsmtp * session) 112void mailsmtp_free(mailsmtp * session)
113{ 113{
114 if (session->stream) 114 if (session->stream)
115 mailsmtp_quit(session); 115 mailsmtp_quit(session);
116 116
117 mmap_string_free(session->line_buffer); 117 mmap_string_free(session->line_buffer);
118 mmap_string_free(session->response_buffer); 118 mmap_string_free(session->response_buffer);
119 free(session); 119 free(session);
120} 120}
121 121
122static int send_command(mailsmtp * f, char * command); 122static int send_command(mailsmtp * f, char * command);
123 123
124static int read_response(mailsmtp * session); 124static int read_response(mailsmtp * session);
125 125
126/* smtp operations */ 126/* smtp operations */
127 127
128int mailsmtp_connect(mailsmtp * session, mailstream * s) 128int mailsmtp_connect(mailsmtp * session, mailstream * s)
129{ 129{
130 int code; 130 int code;
131 131
132 session->stream = s; 132 session->stream = s;
133 133
134 code = read_response(session); 134 code = read_response(session);
135 135
136 switch (code) { 136 switch (code) {
137 case 220: 137 case 220:
138 return MAILSMTP_NO_ERROR; 138 return MAILSMTP_NO_ERROR;
139 139
140 case 554: 140 case 554:
141 session->stream = NULL; 141 session->stream = NULL;
142 mailstream_close(s); 142 mailstream_close(s);
143 return MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE; 143 return MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE;
144 144
145 default: 145 default:
146 session->stream = NULL; 146 session->stream = NULL;
147 mailstream_close(s); 147 mailstream_close(s);
148 return MAILSMTP_ERROR_UNEXPECTED_CODE; 148 return MAILSMTP_ERROR_UNEXPECTED_CODE;
149 } 149 }
150} 150}
151 151
152 152
153#define SMTP_STRING_SIZE 513 153#define SMTP_STRING_SIZE 513
154 154
155int mailsmtp_quit(mailsmtp * session) 155int mailsmtp_quit(mailsmtp * session)
156{ 156{
157 char command[SMTP_STRING_SIZE]; 157 char command[SMTP_STRING_SIZE];
158 int r; 158 int r;
159 159
160 snprintf(command, SMTP_STRING_SIZE, "QUIT\r\n"); 160 snprintf(command, SMTP_STRING_SIZE, "QUIT\r\n");
161 r = send_command(session, command); 161 r = send_command(session, command);
162 if (r == -1) 162 if (r == -1)
163 return MAILSMTP_ERROR_STREAM; 163 return MAILSMTP_ERROR_STREAM;
164 r = read_response(session); 164 r = read_response(session);
165 if (r == 0) 165 if (r == 0)
166 return MAILSMTP_ERROR_STREAM; 166 return MAILSMTP_ERROR_STREAM;
167 mailstream_close(session->stream); 167 mailstream_close(session->stream);
168 session->stream = NULL; 168 session->stream = NULL;
169 169
170 return MAILSMTP_NO_ERROR; 170 return MAILSMTP_NO_ERROR;
171} 171}
172 172
173 173
174 174
175#define HOSTNAME_SIZE 256 175#define HOSTNAME_SIZE 256
176 176
177int mailsmtp_helo(mailsmtp * session) 177int mailsmtp_helo(mailsmtp * session)
178{ 178{
179 int r; 179 int r;
180 char hostname[HOSTNAME_SIZE]; 180 char hostname[HOSTNAME_SIZE];
181 char command[SMTP_STRING_SIZE]; 181 char command[SMTP_STRING_SIZE];
182 182
183 r = gethostname(hostname, HOSTNAME_SIZE); 183 r = gethostname(hostname, HOSTNAME_SIZE);
184 if (r < 0) 184 if (r < 0)
185 return MAILSMTP_ERROR_HOSTNAME; 185 return MAILSMTP_ERROR_HOSTNAME;
186 186
187 snprintf(command, SMTP_STRING_SIZE, "HELO %s\r\n", hostname); 187 snprintf(command, SMTP_STRING_SIZE, "HELO %s\r\n", hostname);
188 r = send_command(session, command); 188 r = send_command(session, command);
189 if (r == -1) 189 if (r == -1)
190 return MAILSMTP_ERROR_STREAM; 190 return MAILSMTP_ERROR_STREAM;
191 r = read_response(session); 191 r = read_response(session);
192 192
193 switch (r) { 193 switch (r) {
194 case 250: 194 case 250:
195 session->esmtp = 0;
196 session->auth = MAILSMTP_AUTH_NOT_CHECKED;
195 return MAILSMTP_NO_ERROR; 197 return MAILSMTP_NO_ERROR;
196 198
197 case 504: 199 case 504:
198 return MAILSMTP_ERROR_NOT_IMPLEMENTED; 200 return MAILSMTP_ERROR_NOT_IMPLEMENTED;
199 201
200 case 550: 202 case 550:
201 return MAILSMTP_ERROR_ACTION_NOT_TAKEN; 203 return MAILSMTP_ERROR_ACTION_NOT_TAKEN;
202 204
203 case 0: 205 case 0:
204 return MAILSMTP_ERROR_STREAM; 206 return MAILSMTP_ERROR_STREAM;
205 207
206 default: 208 default:
207 return MAILSMTP_ERROR_UNEXPECTED_CODE; 209 return MAILSMTP_ERROR_UNEXPECTED_CODE;
208 } 210 }
209} 211}
210 212
211int mailsmtp_mail(mailsmtp * session, const char * from) 213int mailsmtp_mail(mailsmtp * session, const char * from)
212{ 214{
213 int r; 215 int r;
214 char command[SMTP_STRING_SIZE]; 216 char command[SMTP_STRING_SIZE];
215 217
216 snprintf(command, SMTP_STRING_SIZE, "MAIL FROM:<%s>\r\n", from); 218 snprintf(command, SMTP_STRING_SIZE, "MAIL FROM:<%s>\r\n", from);
217 r = send_command(session, command); 219 r = send_command(session, command);
218 if (r == -1) 220 if (r == -1)
219 return MAILSMTP_ERROR_STREAM; 221 return MAILSMTP_ERROR_STREAM;
220 r = read_response(session); 222 r = read_response(session);
221 223
222 switch (r) { 224 switch (r) {
223 case 250: 225 case 250:
224 return MAILSMTP_NO_ERROR; 226 return MAILSMTP_NO_ERROR;
225 227
226 case 552: 228 case 552:
227 return MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION; 229 return MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION;
228 230
229 case 451: 231 case 451:
230 return MAILSMTP_ERROR_IN_PROCESSING; 232 return MAILSMTP_ERROR_IN_PROCESSING;
231 233
232 case 452: 234 case 452:
233 return MAILSMTP_ERROR_INSUFFICIENT_SYSTEM_STORAGE; 235 return MAILSMTP_ERROR_INSUFFICIENT_SYSTEM_STORAGE;
234 236
235 case 550: 237 case 550:
236 return MAILSMTP_ERROR_MAILBOX_UNAVAILABLE; 238 return MAILSMTP_ERROR_MAILBOX_UNAVAILABLE;
237 239
238 case 553: 240 case 553:
239 return MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED; 241 return MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED;
240 242
241 case 503: 243 case 503:
242 return MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND; 244 return MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND;
243 245
244 case 0: 246 case 0:
245 return MAILSMTP_ERROR_STREAM; 247 return MAILSMTP_ERROR_STREAM;
246 248
247 default: 249 default:
248 return MAILSMTP_ERROR_UNEXPECTED_CODE; 250 return MAILSMTP_ERROR_UNEXPECTED_CODE;
249 } 251 }
250} 252}
251 253
252int mailsmtp_rcpt(mailsmtp * session, const char * to) 254int mailsmtp_rcpt(mailsmtp * session, const char * to)
253{ 255{
254 return mailesmtp_rcpt(session, to, 0, NULL); 256 return mailesmtp_rcpt(session, to, 0, NULL);
255} 257}
256 258
257int mailsmtp_data(mailsmtp * session) 259int mailsmtp_data(mailsmtp * session)
258{ 260{
259 int r; 261 int r;
260 char command[SMTP_STRING_SIZE]; 262 char command[SMTP_STRING_SIZE];
261 263
262 snprintf(command, SMTP_STRING_SIZE, "DATA\r\n"); 264 snprintf(command, SMTP_STRING_SIZE, "DATA\r\n");
263 r = send_command(session, command); 265 r = send_command(session, command);
264 if (r == -1) 266 if (r == -1)
265 return MAILSMTP_ERROR_STREAM; 267 return MAILSMTP_ERROR_STREAM;
266 r = read_response(session); 268 r = read_response(session);
267 269
268 switch (r) { 270 switch (r) {
269 case 354: 271 case 354:
270 return MAILSMTP_NO_ERROR; 272 return MAILSMTP_NO_ERROR;
271 273
272 case 451: 274 case 451:
273 return MAILSMTP_ERROR_IN_PROCESSING; 275 return MAILSMTP_ERROR_IN_PROCESSING;
274 276
275 case 554: 277 case 554:
276 return MAILSMTP_ERROR_TRANSACTION_FAILED; 278 return MAILSMTP_ERROR_TRANSACTION_FAILED;
277 279
278 case 503: 280 case 503:
279 return MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND; 281 return MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND;
280 282
281 default: 283 default:
282 return MAILSMTP_ERROR_UNEXPECTED_CODE; 284 return MAILSMTP_ERROR_UNEXPECTED_CODE;
283 } 285 }
284} 286}
285 287
286static int send_data(mailsmtp * session, const char * message, size_t size); 288static int send_data(mailsmtp * session, const char * message, size_t size);
287 289
288int mailsmtp_data_message(mailsmtp * session, 290int mailsmtp_data_message(mailsmtp * session,
289 const char * message, 291 const char * message,
290 size_t size) 292 size_t size)
291{ 293{
292 int r; 294 int r;
293 295
294 r = send_data(session, message, size); 296 r = send_data(session, message, size);
295 if (r == -1) 297 if (r == -1)
296 return MAILSMTP_ERROR_STREAM; 298 return MAILSMTP_ERROR_STREAM;
297 299
298 r = read_response(session); 300 r = read_response(session);
299 301
300 switch(r) { 302 switch(r) {
301 case 250: 303 case 250:
302 return MAILSMTP_NO_ERROR; 304 return MAILSMTP_NO_ERROR;
303 305
304 case 552: 306 case 552:
305 return MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION; 307 return MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION;
306 308
307 case 554: 309 case 554:
308 return MAILSMTP_ERROR_TRANSACTION_FAILED; 310 return MAILSMTP_ERROR_TRANSACTION_FAILED;
309 311
310 case 451: 312 case 451:
311 return MAILSMTP_ERROR_IN_PROCESSING; 313 return MAILSMTP_ERROR_IN_PROCESSING;
312 314
313 case 452: 315 case 452:
314 return MAILSMTP_ERROR_INSUFFICIENT_SYSTEM_STORAGE; 316 return MAILSMTP_ERROR_INSUFFICIENT_SYSTEM_STORAGE;
315 317
316 case 0: 318 case 0:
317 return MAILSMTP_ERROR_STREAM; 319 return MAILSMTP_ERROR_STREAM;
318 320
319 default: 321 default:
320 return MAILSMTP_ERROR_UNEXPECTED_CODE; 322 return MAILSMTP_ERROR_UNEXPECTED_CODE;
321 } 323 }
322} 324}
diff --git a/kmicromail/libetpan/smtp/mailsmtp_helper.c b/kmicromail/libetpan/smtp/mailsmtp_helper.c
index 32d6564..7995377 100644
--- a/kmicromail/libetpan/smtp/mailsmtp_helper.c
+++ b/kmicromail/libetpan/smtp/mailsmtp_helper.c
@@ -1,184 +1,180 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
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 "mailsmtp.h" 36#include "mailsmtp.h"
37#include <string.h> 37#include <string.h>
38#include <stdlib.h> 38#include <stdlib.h>
39#include "mail.h" 39#include "mail.h"
40 40
41int mailsmtp_init(mailsmtp * session) 41int mailsmtp_init(mailsmtp * session)
42{ 42{
43 int r; 43 int r;
44 session->esmtp = 0; 44
45 r = mailesmtp_ehlo(session); 45 r = mailesmtp_ehlo(session);
46 46
47 if (r == MAILSMTP_NO_ERROR) { 47 if (r == MAILSMTP_NO_ERROR)
48 // session->esmtp = TRUE;
49 return MAILSMTP_NO_ERROR; 48 return MAILSMTP_NO_ERROR;
50 }
51 49
52 r = mailsmtp_helo(session); 50 r = mailsmtp_helo(session);
53 /* if (r == MAILSMTP_NO_ERROR) { */ 51 if (r == MAILSMTP_NO_ERROR)
54/* session->esmtp = FALSE; */ 52 return MAILSMTP_NO_ERROR;
55/* return MAILSMTP_NO_ERROR; */
56/* } */
57 53
58 return r; 54 return r;
59} 55}
60 56
61 57
62 58
63int mailesmtp_send(mailsmtp * session, 59int mailesmtp_send(mailsmtp * session,
64 const char * from, 60 const char * from,
65 int return_full, 61 int return_full,
66 const char * envid, 62 const char * envid,
67 clist * addresses, 63 clist * addresses,
68 const char * message, size_t size) 64 const char * message, size_t size)
69{ 65{
70 int r; 66 int r;
71 clistiter * l; 67 clistiter * l;
72 68
73 if (!session->esmtp) 69 if (!session->esmtp)
74 return mailsmtp_send(session, from, addresses, message, size); 70 return mailsmtp_send(session, from, addresses, message, size);
75 71
76 r = mailesmtp_mail(session, from, return_full, envid); 72 r = mailesmtp_mail(session, from, return_full, envid);
77 if (r != MAILSMTP_NO_ERROR) 73 if (r != MAILSMTP_NO_ERROR)
78 return r; 74 return r;
79 75
80 for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) { 76 for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) {
81 struct esmtp_address * addr; 77 struct esmtp_address * addr;
82 78
83 addr = clist_content(l); 79 addr = clist_content(l);
84 80
85 r = mailesmtp_rcpt(session, addr->address, addr->notify, addr->orcpt); 81 r = mailesmtp_rcpt(session, addr->address, addr->notify, addr->orcpt);
86 if (r != MAILSMTP_NO_ERROR) 82 if (r != MAILSMTP_NO_ERROR)
87 return r; 83 return r;
88 } 84 }
89 85
90 r = mailsmtp_data(session); 86 r = mailsmtp_data(session);
91 if (r != MAILSMTP_NO_ERROR) 87 if (r != MAILSMTP_NO_ERROR)
92 return r; 88 return r;
93 89
94 r = mailsmtp_data_message(session, message, size); 90 r = mailsmtp_data_message(session, message, size);
95 if (r != MAILSMTP_NO_ERROR) 91 if (r != MAILSMTP_NO_ERROR)
96 return r; 92 return r;
97 93
98 return MAILSMTP_NO_ERROR; 94 return MAILSMTP_NO_ERROR;
99} 95}
100 96
101int mailsmtp_send(mailsmtp * session, 97int mailsmtp_send(mailsmtp * session,
102 const char * from, 98 const char * from,
103 clist * addresses, 99 clist * addresses,
104 const char * message, size_t size) 100 const char * message, size_t size)
105{ 101{
106 int r; 102 int r;
107 clistiter * l; 103 clistiter * l;
108 104
109 r = mailsmtp_mail(session, from); 105 r = mailsmtp_mail(session, from);
110 if (r != MAILSMTP_NO_ERROR) 106 if (r != MAILSMTP_NO_ERROR)
111 return r; 107 return r;
112 108
113 for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) { 109 for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) {
114 struct esmtp_address * addr; 110 struct esmtp_address * addr;
115 111
116 addr = clist_content(l); 112 addr = clist_content(l);
117 113
118 r = mailsmtp_rcpt(session, addr->address); 114 r = mailsmtp_rcpt(session, addr->address);
119 if (r != MAILSMTP_NO_ERROR) 115 if (r != MAILSMTP_NO_ERROR)
120 return r; 116 return r;
121 } 117 }
122 118
123 r = mailsmtp_data(session); 119 r = mailsmtp_data(session);
124 if (r != MAILSMTP_NO_ERROR) 120 if (r != MAILSMTP_NO_ERROR)
125 return r; 121 return r;
126 122
127 r = mailsmtp_data_message(session, message, size); 123 r = mailsmtp_data_message(session, message, size);
128 if (r != MAILSMTP_NO_ERROR) 124 if (r != MAILSMTP_NO_ERROR)
129 return r; 125 return r;
130 126
131 return MAILSMTP_NO_ERROR; 127 return MAILSMTP_NO_ERROR;
132} 128}
133 129
134 130
135 131
136 132
137 133
138 134
139 135
140 136
141 137
142 138
143 139
144 140
145 141
146/* esmtp addresses and smtp addresses */ 142/* esmtp addresses and smtp addresses */
147 143
148static struct esmtp_address * esmtp_address_new(char * addr, 144static struct esmtp_address * esmtp_address_new(char * addr,
149 int notify, char * orcpt) 145 int notify, char * orcpt)
150{ 146{
151 struct esmtp_address * esmtpa; 147 struct esmtp_address * esmtpa;
152 148
153 esmtpa = malloc(sizeof(* esmtpa)); 149 esmtpa = malloc(sizeof(* esmtpa));
154 if (esmtpa == NULL) 150 if (esmtpa == NULL)
155 return NULL; 151 return NULL;
156 152
157 esmtpa->address = strdup(addr); 153 esmtpa->address = strdup(addr);
158 if (esmtpa->address == NULL) { 154 if (esmtpa->address == NULL) {
159 free(esmtpa); 155 free(esmtpa);
160 return NULL; 156 return NULL;
161 } 157 }
162 158
163 if (orcpt != NULL) { 159 if (orcpt != NULL) {
164 esmtpa->orcpt = strdup(orcpt); 160 esmtpa->orcpt = strdup(orcpt);
165 if (esmtpa->orcpt == NULL) { 161 if (esmtpa->orcpt == NULL) {
166 free(esmtpa->address); 162 free(esmtpa->address);
167 free(esmtpa); 163 free(esmtpa);
168 return NULL; 164 return NULL;
169 } 165 }
170 } 166 }
171 else 167 else
172 esmtpa->orcpt = NULL; 168 esmtpa->orcpt = NULL;
173 169
174 esmtpa->notify = notify; 170 esmtpa->notify = notify;
175 171
176 return esmtpa; 172 return esmtpa;
177} 173}
178 174
179static void esmtp_address_free(struct esmtp_address * addr) 175static void esmtp_address_free(struct esmtp_address * addr)
180{ 176{
181 if (addr->orcpt) 177 if (addr->orcpt)
182 free(addr->orcpt); 178 free(addr->orcpt);
183 if (addr->address) 179 if (addr->address)
184 free(addr->address); 180 free(addr->address);
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 3998abd..3b0ca1f 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,187 +1,237 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "abstractmail.h" 2#include "abstractmail.h"
3#include "imapwrapper.h" 3#include "imapwrapper.h"
4#include "pop3wrapper.h" 4#include "pop3wrapper.h"
5#include "nntpwrapper.h" 5#include "nntpwrapper.h"
6#include "mhwrapper.h" 6#include "mhwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8 8
9 9
10#include <qprogressbar.h>
11#include <qapplication.h>
10 12
11#include <kdecore/kstandarddirs.h> 13#include <kdecore/kstandarddirs.h>
12#include <qfile.h> 14#include <qfile.h>
13#include <qtextstream.h> 15#include <qtextstream.h>
14#include <stdlib.h> 16#include <stdlib.h>
15#include <libetpan/mailmime_content.h> 17#include <libetpan/mailmime_content.h>
16#include <libetpan/mailmime.h> 18#include <libetpan/mailmime.h>
17 19
18using namespace Opie::Core; 20using namespace Opie::Core;
19AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 21AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
20{ 22{
21 return new IMAPwrapper(a); 23 return new IMAPwrapper(a);
22} 24}
23 25
24AbstractMail* AbstractMail::getWrapper(POP3account *a) 26AbstractMail* AbstractMail::getWrapper(POP3account *a)
25{ 27{
26 return new POP3wrapper(a); 28 return new POP3wrapper(a);
27} 29}
28 30
29AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 31AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
30{ 32{
31 return new NNTPwrapper(a); 33 return new NNTPwrapper(a);
32} 34}
33 35
34AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 36AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
35{ 37{
36 return new MHwrapper(a,name); 38 return new MHwrapper(a,name);
37} 39}
38 40
39AbstractMail* AbstractMail::getWrapper(Account*a) 41AbstractMail* AbstractMail::getWrapper(Account*a)
40{ 42{
41 if (!a) return 0; 43 if (!a) return 0;
42 switch (a->getType()) { 44 switch (a->getType()) {
43 case MAILLIB::A_IMAP: 45 case MAILLIB::A_IMAP:
44 return new IMAPwrapper((IMAPaccount*)a); 46 return new IMAPwrapper((IMAPaccount*)a);
45 break; 47 break;
46 case MAILLIB::A_POP3: 48 case MAILLIB::A_POP3:
47 return new POP3wrapper((POP3account*)a); 49 return new POP3wrapper((POP3account*)a);
48 break; 50 break;
49 case MAILLIB::A_NNTP: 51 case MAILLIB::A_NNTP:
50 return new NNTPwrapper((NNTPaccount*)a); 52 return new NNTPwrapper((NNTPaccount*)a);
51 break; 53 break;
52 default: 54 default:
53 return 0; 55 return 0;
54 } 56 }
55} 57}
56 58
57encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 59encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
58{ 60{
59 // odebug << "Decode string start" << oendl; 61 // odebug << "Decode string start" << oendl;
60 char*result_text; 62 char*result_text;
61 size_t index = 0; 63 size_t index = 0;
62 /* reset for recursive use! */ 64 /* reset for recursive use! */
63 size_t target_length = 0; 65 size_t target_length = 0;
64 result_text = 0; 66 result_text = 0;
65 int mimetype = MAILMIME_MECHANISM_7BIT; 67 int mimetype = MAILMIME_MECHANISM_7BIT;
66 if (enc.lower()=="quoted-printable") { 68 if (enc.lower()=="quoted-printable") {
67 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 69 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
68 } else if (enc.lower()=="base64") { 70 } else if (enc.lower()=="base64") {
69 mimetype = MAILMIME_MECHANISM_BASE64; 71 mimetype = MAILMIME_MECHANISM_BASE64;
70 } else if (enc.lower()=="8bit") { 72 } else if (enc.lower()=="8bit") {
71 mimetype = MAILMIME_MECHANISM_8BIT; 73 mimetype = MAILMIME_MECHANISM_8BIT;
72 } else if (enc.lower()=="binary") { 74 } else if (enc.lower()=="binary") {
73 mimetype = MAILMIME_MECHANISM_BINARY; 75 mimetype = MAILMIME_MECHANISM_BINARY;
74 } 76 }
75 77
76 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 78 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
77 &result_text,&target_length); 79 &result_text,&target_length);
78 80
79 encodedString* result = new encodedString(); 81 encodedString* result = new encodedString();
80 if (err == MAILIMF_NO_ERROR) { 82 if (err == MAILIMF_NO_ERROR) {
81 result->setContent(result_text,target_length); 83 result->setContent(result_text,target_length);
82 } 84 }
83 //odebug << "Decode string finished" << oendl; 85 //odebug << "Decode string finished" << oendl;
84 return result; 86 return result;
85} 87}
86 88
87QString AbstractMail::convert_String(const char*text) 89QString AbstractMail::convert_String(const char*text)
88{ 90{
89 //size_t index = 0; 91 //size_t index = 0;
90 char*res = 0; 92 char*res = 0;
91 int err = MAILIMF_NO_ERROR; 93 int err = MAILIMF_NO_ERROR;
92 94
93 QString result(text); 95 QString result(text);
94 96
95 /* due a bug in libetpan it isn't usable this moment */ 97 /* due a bug in libetpan it isn't usable this moment */
96/* int err = mailmime_encoded_phrase_parse("iso-8859-1", 98/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
97 text, strlen(text),&index, "iso-8859-1",&res);*/ 99 text, strlen(text),&index, "iso-8859-1",&res);*/
98 //odebug << "Input: " << text << "" << oendl; 100 //odebug << "Input: " << text << "" << oendl;
99 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 101 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
100// result = QString(res); 102// result = QString(res);
101// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; 103// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl;
102 } 104 }
103 if (res) free(res); 105 if (res) free(res);
104 return result; 106 return result;
105} 107}
106 108
107/* cp & paste from launcher */ 109/* cp & paste from launcher */
108QString AbstractMail::gen_attachment_id() 110QString AbstractMail::gen_attachment_id()
109{ 111{
110 QFile file( "/proc/sys/kernel/random/uuid" ); 112 QFile file( "/proc/sys/kernel/random/uuid" );
111 if (!file.open(IO_ReadOnly ) ) 113 if (!file.open(IO_ReadOnly ) )
112 return QString::null; 114 return QString::null;
113 115
114 QTextStream stream(&file); 116 QTextStream stream(&file);
115 117
116 return "{" + stream.read().stripWhiteSpace() + "}"; 118 return "{" + stream.read().stripWhiteSpace() + "}";
117} 119}
118 120
119int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 121int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
120{ 122{
121 return 0; 123 return 0;
122} 124}
123 125
124QString AbstractMail::defaultLocalfolder() 126QString AbstractMail::defaultLocalfolder()
125{ 127{
126 // QString f = getenv( "HOME" ); 128 // QString f = getenv( "HOME" );
127 QString f = locateLocal( "data", "kmicromail/localmail"); 129 QString f = locateLocal( "data", "kmicromail/localmail");
128 // f += "/Applications/opiemail/localmail"; 130 // f += "/Applications/opiemail/localmail";
129 return f; 131 return f;
130} 132}
131 133
132QString AbstractMail::draftFolder() 134QString AbstractMail::draftFolder()
133{ 135{
134 return QString("Drafts"); 136 return QString("Drafts");
135} 137}
136 138
137/* temporary - will be removed when implemented in all classes */ 139/* temporary - will be removed when implemented in all classes */
138void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 140void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
139{ 141{
140} 142}
141void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 143void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
142{ 144{
143 qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 145 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
144 146 // this is currently re-implemented in pop3wrapper and imapwrapper
147 int iii = 0;
148 int count = target.count();
149 QProgressBar bar( count,0 );
150 bar.setCaption (("Removing mails - close to abort!") );
151 int w = 300;
152 if ( QApplication::desktop()->width() < 320 )
153 w = 220;
154 int h = bar.sizeHint().height() ;
155 int dw = QApplication::desktop()->width();
156 int dh = QApplication::desktop()->height();
157 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
158 bar.show();
159 int modulo = (count/10)+1;
160 int incCounter = 0;
161 while (iii < count ) {
162 if ( ! bar.isVisible() )
163 return ;
164 if ( incCounter % modulo == 0 )
165 bar.setProgress( incCounter );
166 ++incCounter;
167 qApp->processEvents();
168 RecMailP mail = (*target.at( iii ));
169 deleteMail(mail);
170 ++iii;
171 }
145} 172}
146void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 173void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
147 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 174 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
148{ 175{
149 QValueList<RecMailP> t; 176 QValueList<RecMailP> t;
150 listMessages(fromFolder->getName(),t, maxSizeInKb); 177 listMessages(fromFolder->getName(),t, maxSizeInKb);
151 mvcpMailList( t,targetFolder,targetWrapper,moveit); 178 mvcpMailList( t,targetFolder,targetWrapper,moveit);
152 179
153} 180}
154void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 181void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
155 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 182 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
156{ 183{
157
158 encodedString*st = 0; 184 encodedString*st = 0;
159 int iii = 0; 185 int iii = 0;
160 int count = t.count(); 186 int count = t.count();
187 if ( count == 0 )
188 return;
189
190 QProgressBar bar( count,0 );
191 bar.setCaption (("Copying mails - close to abort!") );
192 int w = 300;
193 if ( QApplication::desktop()->width() < 320 )
194 w = 220;
195 int h = bar.sizeHint().height() ;
196 int dw = QApplication::desktop()->width();
197 int dh = QApplication::desktop()->height();
198 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
199 bar.show();
200 int modulo = (count/10)+1;
201 int incCounter = 0;
161 while (iii < count ) { 202 while (iii < count ) {
203 if ( ! bar.isVisible() )
204 return ;
205 if ( incCounter % modulo == 0 )
206 bar.setProgress( incCounter );
207 ++incCounter;
208 bar.raise();
209 qApp->processEvents();
210 //qDebug("copy ");
162 RecMailP r = (*t.at( iii )); 211 RecMailP r = (*t.at( iii ));
163 st = fetchRawBody(r); 212 st = fetchRawBody(r);
164 if (st) { 213 if (st) {
165 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 214 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
166 delete st; 215 delete st;
167 } 216 }
168 ++iii; 217 ++iii;
169 } 218 }
219 bar.hide();
170 if (moveit) { 220 if (moveit) {
171 deleteMailList( t ); 221 deleteMailList( t );
172 //deleteAllMail(fromFolder); 222 //deleteAllMail(fromFolder);
173 } 223 }
174} 224}
175 225
176void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 226void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
177{ 227{
178 encodedString*st = 0; 228 encodedString*st = 0;
179 st = fetchRawBody(mail); 229 st = fetchRawBody(mail);
180 if (st) { 230 if (st) {
181 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 231 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
182 delete st; 232 delete st;
183 } 233 }
184 if (moveit) { 234 if (moveit) {
185 deleteMail(mail); 235 deleteMail(mail);
186 } 236 }
187} 237}
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index bb8bbfc..11d3343 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,136 +1,137 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include <stdlib.h> 2#include <stdlib.h>
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include <qpe/global.h> 4#include <qpe/global.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include "imapwrapper.h" 6#include "imapwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include "logindialog.h" 8#include "logindialog.h"
9#include <qprogressbar.h>
9 10
10using namespace Opie::Core; 11using namespace Opie::Core;
11IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 12IMAPwrapper::IMAPwrapper( IMAPaccount *a )
12 : AbstractMail() 13 : AbstractMail()
13{ 14{
14 account = a; 15 account = a;
15 m_imap = 0; 16 m_imap = 0;
16 m_Lastmbox = ""; 17 m_Lastmbox = "";
17} 18}
18 19
19IMAPwrapper::~IMAPwrapper() 20IMAPwrapper::~IMAPwrapper()
20{ 21{
21 logout(); 22 logout();
22} 23}
23 24
24/* to avoid to often select statements in loops etc. 25/* to avoid to often select statements in loops etc.
25 we trust that we are logged in and connection is established!*/ 26 we trust that we are logged in and connection is established!*/
26int IMAPwrapper::selectMbox(const QString&mbox) 27int IMAPwrapper::selectMbox(const QString&mbox)
27{ 28{
28 if (mbox == m_Lastmbox) { 29 if (mbox == m_Lastmbox) {
29 return MAILIMAP_NO_ERROR; 30 return MAILIMAP_NO_ERROR;
30 } 31 }
31 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 32 int err = mailimap_select( m_imap, (char*)mbox.latin1());
32 if ( err != MAILIMAP_NO_ERROR ) { 33 if ( err != MAILIMAP_NO_ERROR ) {
33 m_Lastmbox = ""; 34 m_Lastmbox = "";
34 return err; 35 return err;
35 } 36 }
36 m_Lastmbox = mbox; 37 m_Lastmbox = mbox;
37 return err; 38 return err;
38} 39}
39 40
40void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 41void IMAPwrapper::imap_progress( size_t current, size_t maximum )
41{ 42{
42 qApp->processEvents(); 43 qApp->processEvents();
43 qDebug("imap progress %d of %d ",current,maximum ); 44 qDebug("imap progress %d of %d ",current,maximum );
44} 45}
45 46
46bool IMAPwrapper::start_tls(bool force_tls) 47bool IMAPwrapper::start_tls(bool force_tls)
47{ 48{
48 int err; 49 int err;
49 bool try_tls; 50 bool try_tls;
50 mailimap_capability_data * cap_data = 0; 51 mailimap_capability_data * cap_data = 0;
51 52
52 err = mailimap_capability(m_imap,&cap_data); 53 err = mailimap_capability(m_imap,&cap_data);
53 if (err != MAILIMAP_NO_ERROR) { 54 if (err != MAILIMAP_NO_ERROR) {
54 Global::statusMessage("error getting capabilities!"); 55 Global::statusMessage("error getting capabilities!");
55 return false; 56 return false;
56 } 57 }
57 clistiter * cur; 58 clistiter * cur;
58 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 59 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
59 struct mailimap_capability * cap; 60 struct mailimap_capability * cap;
60 cap = (struct mailimap_capability *)clist_content(cur); 61 cap = (struct mailimap_capability *)clist_content(cur);
61 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 62 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
62 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 63 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
63 try_tls = true; 64 try_tls = true;
64 break; 65 break;
65 } 66 }
66 } 67 }
67 } 68 }
68 if (cap_data) { 69 if (cap_data) {
69 mailimap_capability_data_free(cap_data); 70 mailimap_capability_data_free(cap_data);
70 } 71 }
71 if (try_tls) { 72 if (try_tls) {
72 err = mailimap_starttls(m_imap); 73 err = mailimap_starttls(m_imap);
73 if (err != MAILIMAP_NO_ERROR && force_tls) { 74 if (err != MAILIMAP_NO_ERROR && force_tls) {
74 Global::statusMessage(tr("Server has no TLS support!")); 75 Global::statusMessage(tr("Server has no TLS support!"));
75 try_tls = false; 76 try_tls = false;
76 } else { 77 } else {
77 mailstream_low * low; 78 mailstream_low * low;
78 mailstream_low * new_low; 79 mailstream_low * new_low;
79 low = mailstream_get_low(m_imap->imap_stream); 80 low = mailstream_get_low(m_imap->imap_stream);
80 if (!low) { 81 if (!low) {
81 try_tls = false; 82 try_tls = false;
82 } else { 83 } else {
83 int fd = mailstream_low_get_fd(low); 84 int fd = mailstream_low_get_fd(low);
84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 85 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
85 mailstream_low_free(low); 86 mailstream_low_free(low);
86 mailstream_set_low(m_imap->imap_stream, new_low); 87 mailstream_set_low(m_imap->imap_stream, new_low);
87 } else { 88 } else {
88 try_tls = false; 89 try_tls = false;
89 } 90 }
90 } 91 }
91 } 92 }
92 } 93 }
93 return try_tls; 94 return try_tls;
94} 95}
95 96
96void IMAPwrapper::login() 97void IMAPwrapper::login()
97{ 98{
98 const char *server, *user, *pass; 99 const char *server, *user, *pass;
99 uint16_t port; 100 uint16_t port;
100 int err = MAILIMAP_NO_ERROR; 101 int err = MAILIMAP_NO_ERROR;
101 102
102 if (account->getOffline()) return; 103 if (account->getOffline()) return;
103 /* we are connected this moment */ 104 /* we are connected this moment */
104 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 105 /* TODO: setup a timer holding the line or if connection closed - delete the value */
105 if (m_imap) { 106 if (m_imap) {
106 err = mailimap_noop(m_imap); 107 err = mailimap_noop(m_imap);
107 if (err!=MAILIMAP_NO_ERROR) { 108 if (err!=MAILIMAP_NO_ERROR) {
108 logout(); 109 logout();
109 } else { 110 } else {
110 mailstream_flush(m_imap->imap_stream); 111 mailstream_flush(m_imap->imap_stream);
111 return; 112 return;
112 } 113 }
113 } 114 }
114 server = account->getServer().latin1(); 115 server = account->getServer().latin1();
115 port = account->getPort().toUInt(); 116 port = account->getPort().toUInt();
116 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 117 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
117 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 118 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
118 login.show(); 119 login.show();
119 if ( QDialog::Accepted == login.exec() ) { 120 if ( QDialog::Accepted == login.exec() ) {
120 // ok 121 // ok
121 user = login.getUser().latin1(); 122 user = login.getUser().latin1();
122 pass = login.getPassword().latin1(); 123 pass = login.getPassword().latin1();
123 } else { 124 } else {
124 // cancel 125 // cancel
125 return; 126 return;
126 } 127 }
127 } else { 128 } else {
128 user = account->getUser().latin1(); 129 user = account->getUser().latin1();
129 pass = account->getPassword().latin1(); 130 pass = account->getPassword().latin1();
130 } 131 }
131 132
132 m_imap = mailimap_new( 20, &imap_progress ); 133 m_imap = mailimap_new( 20, &imap_progress );
133 134
134 /* connect */ 135 /* connect */
135 bool ssl = false; 136 bool ssl = false;
136 bool try_tls = false; 137 bool try_tls = false;
@@ -746,485 +747,514 @@ void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_tex
746 } 747 }
747 QString sub; 748 QString sub;
748 sub = which->bd_media_text; 749 sub = which->bd_media_text;
749 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 750 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
750 target_part->setSubtype(sub.lower()); 751 target_part->setSubtype(sub.lower());
751 target_part->setLines(which->bd_lines); 752 target_part->setLines(which->bd_lines);
752 fillBodyFields(target_part,which->bd_fields); 753 fillBodyFields(target_part,which->bd_fields);
753} 754}
754 755
755void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 756void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
756{ 757{
757 if (!which) { 758 if (!which) {
758 return; 759 return;
759 } 760 }
760 target_part->setSubtype("rfc822"); 761 target_part->setSubtype("rfc822");
761 //odebug << "Message part" << oendl; 762 //odebug << "Message part" << oendl;
762 /* we set this type to text/plain */ 763 /* we set this type to text/plain */
763 target_part->setLines(which->bd_lines); 764 target_part->setLines(which->bd_lines);
764 fillBodyFields(target_part,which->bd_fields); 765 fillBodyFields(target_part,which->bd_fields);
765} 766}
766 767
767void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 768void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
768{ 769{
769 if (!which) return; 770 if (!which) return;
770 QString sub = which->bd_media_subtype; 771 QString sub = which->bd_media_subtype;
771 target_part->setSubtype(sub.lower()); 772 target_part->setSubtype(sub.lower());
772 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 773 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
773 clistcell*cur = 0; 774 clistcell*cur = 0;
774 mailimap_single_body_fld_param*param=0; 775 mailimap_single_body_fld_param*param=0;
775 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 776 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
776 param = (mailimap_single_body_fld_param*)cur->data; 777 param = (mailimap_single_body_fld_param*)cur->data;
777 if (param) { 778 if (param) {
778 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 779 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
779 } 780 }
780 } 781 }
781 } 782 }
782} 783}
783 784
784void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 785void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
785{ 786{
786 if (!which) { 787 if (!which) {
787 return; 788 return;
788 } 789 }
789 QString type,sub; 790 QString type,sub;
790 switch (which->bd_media_basic->med_type) { 791 switch (which->bd_media_basic->med_type) {
791 case MAILIMAP_MEDIA_BASIC_APPLICATION: 792 case MAILIMAP_MEDIA_BASIC_APPLICATION:
792 type = "application"; 793 type = "application";
793 break; 794 break;
794 case MAILIMAP_MEDIA_BASIC_AUDIO: 795 case MAILIMAP_MEDIA_BASIC_AUDIO:
795 type = "audio"; 796 type = "audio";
796 break; 797 break;
797 case MAILIMAP_MEDIA_BASIC_IMAGE: 798 case MAILIMAP_MEDIA_BASIC_IMAGE:
798 type = "image"; 799 type = "image";
799 break; 800 break;
800 case MAILIMAP_MEDIA_BASIC_MESSAGE: 801 case MAILIMAP_MEDIA_BASIC_MESSAGE:
801 type = "message"; 802 type = "message";
802 break; 803 break;
803 case MAILIMAP_MEDIA_BASIC_VIDEO: 804 case MAILIMAP_MEDIA_BASIC_VIDEO:
804 type = "video"; 805 type = "video";
805 break; 806 break;
806 case MAILIMAP_MEDIA_BASIC_OTHER: 807 case MAILIMAP_MEDIA_BASIC_OTHER:
807 default: 808 default:
808 if (which->bd_media_basic->med_basic_type) { 809 if (which->bd_media_basic->med_basic_type) {
809 type = which->bd_media_basic->med_basic_type; 810 type = which->bd_media_basic->med_basic_type;
810 } else { 811 } else {
811 type = ""; 812 type = "";
812 } 813 }
813 break; 814 break;
814 } 815 }
815 if (which->bd_media_basic->med_subtype) { 816 if (which->bd_media_basic->med_subtype) {
816 sub = which->bd_media_basic->med_subtype; 817 sub = which->bd_media_basic->med_subtype;
817 } else { 818 } else {
818 sub = ""; 819 sub = "";
819 } 820 }
820 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 821 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
821 target_part->setType(type.lower()); 822 target_part->setType(type.lower());
822 target_part->setSubtype(sub.lower()); 823 target_part->setSubtype(sub.lower());
823 fillBodyFields(target_part,which->bd_fields); 824 fillBodyFields(target_part,which->bd_fields);
824} 825}
825 826
826void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 827void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
827{ 828{
828 if (!which) return; 829 if (!which) return;
829 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 830 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
830 clistcell*cur; 831 clistcell*cur;
831 mailimap_single_body_fld_param*param=0; 832 mailimap_single_body_fld_param*param=0;
832 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 833 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
833 param = (mailimap_single_body_fld_param*)cur->data; 834 param = (mailimap_single_body_fld_param*)cur->data;
834 if (param) { 835 if (param) {
835 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 836 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
836 } 837 }
837 } 838 }
838 } 839 }
839 mailimap_body_fld_enc*enc = which->bd_encoding; 840 mailimap_body_fld_enc*enc = which->bd_encoding;
840 QString encoding(""); 841 QString encoding("");
841 switch (enc->enc_type) { 842 switch (enc->enc_type) {
842 case MAILIMAP_BODY_FLD_ENC_7BIT: 843 case MAILIMAP_BODY_FLD_ENC_7BIT:
843 encoding = "7bit"; 844 encoding = "7bit";
844 break; 845 break;
845 case MAILIMAP_BODY_FLD_ENC_8BIT: 846 case MAILIMAP_BODY_FLD_ENC_8BIT:
846 encoding = "8bit"; 847 encoding = "8bit";
847 break; 848 break;
848 case MAILIMAP_BODY_FLD_ENC_BINARY: 849 case MAILIMAP_BODY_FLD_ENC_BINARY:
849 encoding="binary"; 850 encoding="binary";
850 break; 851 break;
851 case MAILIMAP_BODY_FLD_ENC_BASE64: 852 case MAILIMAP_BODY_FLD_ENC_BASE64:
852 encoding="base64"; 853 encoding="base64";
853 break; 854 break;
854 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 855 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
855 encoding="quoted-printable"; 856 encoding="quoted-printable";
856 break; 857 break;
857 case MAILIMAP_BODY_FLD_ENC_OTHER: 858 case MAILIMAP_BODY_FLD_ENC_OTHER:
858 default: 859 default:
859 if (enc->enc_value) { 860 if (enc->enc_value) {
860 char*t=enc->enc_value; 861 char*t=enc->enc_value;
861 encoding=QString(enc->enc_value); 862 encoding=QString(enc->enc_value);
862 enc->enc_value=0L; 863 enc->enc_value=0L;
863 free(t); 864 free(t);
864 } 865 }
865 } 866 }
866 if (which->bd_description) { 867 if (which->bd_description) {
867 target_part->setDescription(QString(which->bd_description)); 868 target_part->setDescription(QString(which->bd_description));
868 } 869 }
869 target_part->setEncoding(encoding); 870 target_part->setEncoding(encoding);
870 target_part->setSize(which->bd_size); 871 target_part->setSize(which->bd_size);
871} 872}
872void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 873void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
873{ 874{
875 //#if 0
874 mailimap_flag_list*flist; 876 mailimap_flag_list*flist;
875 mailimap_set *set; 877 mailimap_set *set;
876 mailimap_store_att_flags * store_flags; 878 mailimap_store_att_flags * store_flags;
877 int err; 879 int err;
878 login(); 880 login();
881 //#endif
879 if (!m_imap) { 882 if (!m_imap) {
880 return; 883 return;
881 } 884 }
882 int iii = 0; 885 int iii = 0;
883 int count = target.count(); 886 int count = target.count();
884 qDebug("imap remove count %d ", count); 887 // qDebug("imap remove count %d ", count);
888
889 QProgressBar bar( count,0 );
890 bar.setCaption (("Removing mails - close to abort!") );
891 int w = 300;
892 if ( QApplication::desktop()->width() < 320 )
893 w = 220;
894 int h = bar.sizeHint().height() ;
895 int dw = QApplication::desktop()->width();
896 int dh = QApplication::desktop()->height();
897 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
898 bar.show();
899 int modulo = (count/10)+1;
900 int incCounter = 0;
901
885 while (iii < count ) { 902 while (iii < count ) {
886 qDebug("IMAP remove %d ", iii); 903 if ( ! bar.isVisible() )
904 return ;
905 if ( incCounter % modulo == 0 )
906 bar.setProgress( incCounter );
907 ++incCounter;
908 qApp->processEvents();
887 RecMailP mail = (*target.at( iii )); 909 RecMailP mail = (*target.at( iii ));
888 910 //#if 0
911 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
889 err = selectMbox(mail->getMbox()); 912 err = selectMbox(mail->getMbox());
890 if ( err != MAILIMAP_NO_ERROR ) { 913 if ( err != MAILIMAP_NO_ERROR ) {
891 return; 914 return;
892 } 915 }
893 flist = mailimap_flag_list_new_empty(); 916 flist = mailimap_flag_list_new_empty();
894 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 917 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
895 store_flags = mailimap_store_att_flags_new_set_flags(flist); 918 store_flags = mailimap_store_att_flags_new_set_flags(flist);
896 set = mailimap_set_new_single(mail->getNumber()); 919 set = mailimap_set_new_single(mail->getNumber());
897 err = mailimap_store(m_imap,set,store_flags); 920 err = mailimap_store(m_imap,set,store_flags);
898 mailimap_set_free( set ); 921 mailimap_set_free( set );
899 mailimap_store_att_flags_free(store_flags); 922 mailimap_store_att_flags_free(store_flags);
900 923
901 if (err != MAILIMAP_NO_ERROR) { 924 if (err != MAILIMAP_NO_ERROR) {
902 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 925 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
903 return; 926 return;
904 } 927 }
905 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 928 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
906 /* should we realy do that at this moment? */ 929 /* should we realy do that at this moment? */
907 930
931 // err = mailimap_expunge(m_imap);
932 //if (err != MAILIMAP_NO_ERROR) {
933 // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
934 // }
935 //#endif
936 //deleteMail( mail);
937 ++iii;
938 }
939 //qDebug("Deleting imap mails... ");
908 err = mailimap_expunge(m_imap); 940 err = mailimap_expunge(m_imap);
909 if (err != MAILIMAP_NO_ERROR) { 941 if (err != MAILIMAP_NO_ERROR) {
910 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 942 Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
911 } 943 }
912 ++iii;
913 }
914} 944}
915void IMAPwrapper::deleteMail(const RecMailP&mail) 945void IMAPwrapper::deleteMail(const RecMailP&mail)
916{ 946{
917 mailimap_flag_list*flist; 947 mailimap_flag_list*flist;
918 mailimap_set *set; 948 mailimap_set *set;
919 mailimap_store_att_flags * store_flags; 949 mailimap_store_att_flags * store_flags;
920 int err; 950 int err;
921 login(); 951 login();
922 if (!m_imap) { 952 if (!m_imap) {
923 return; 953 return;
924 } 954 }
925 err = selectMbox(mail->getMbox()); 955 err = selectMbox(mail->getMbox());
926 if ( err != MAILIMAP_NO_ERROR ) { 956 if ( err != MAILIMAP_NO_ERROR ) {
927 return; 957 return;
928 } 958 }
929 flist = mailimap_flag_list_new_empty(); 959 flist = mailimap_flag_list_new_empty();
930 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 960 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
931 store_flags = mailimap_store_att_flags_new_set_flags(flist); 961 store_flags = mailimap_store_att_flags_new_set_flags(flist);
932 set = mailimap_set_new_single(mail->getNumber()); 962 set = mailimap_set_new_single(mail->getNumber());
933 err = mailimap_store(m_imap,set,store_flags); 963 err = mailimap_store(m_imap,set,store_flags);
934 mailimap_set_free( set ); 964 mailimap_set_free( set );
935 mailimap_store_att_flags_free(store_flags); 965 mailimap_store_att_flags_free(store_flags);
936 966
937 if (err != MAILIMAP_NO_ERROR) { 967 if (err != MAILIMAP_NO_ERROR) {
938 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 968 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
939 return; 969 return;
940 } 970 }
941 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 971 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
942 /* should we realy do that at this moment? */ 972 /* should we realy do that at this moment? */
943 973
944 err = mailimap_expunge(m_imap); 974 err = mailimap_expunge(m_imap);
945 if (err != MAILIMAP_NO_ERROR) { 975 if (err != MAILIMAP_NO_ERROR) {
946 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 976 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
947 } 977 }
948 qDebug("IMAPwrapper::deleteMail "); 978 //qDebug("IMAPwrapper::deleteMail 2");
949 979
950} 980}
951 981
952void IMAPwrapper::answeredMail(const RecMailP&mail) 982void IMAPwrapper::answeredMail(const RecMailP&mail)
953{ 983{
954 mailimap_flag_list*flist; 984 mailimap_flag_list*flist;
955 mailimap_set *set; 985 mailimap_set *set;
956 mailimap_store_att_flags * store_flags; 986 mailimap_store_att_flags * store_flags;
957 int err; 987 int err;
958 login(); 988 login();
959 if (!m_imap) { 989 if (!m_imap) {
960 return; 990 return;
961 } 991 }
962 err = selectMbox(mail->getMbox()); 992 err = selectMbox(mail->getMbox());
963 if ( err != MAILIMAP_NO_ERROR ) { 993 if ( err != MAILIMAP_NO_ERROR ) {
964 return; 994 return;
965 } 995 }
966 flist = mailimap_flag_list_new_empty(); 996 flist = mailimap_flag_list_new_empty();
967 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 997 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
968 store_flags = mailimap_store_att_flags_new_add_flags(flist); 998 store_flags = mailimap_store_att_flags_new_add_flags(flist);
969 set = mailimap_set_new_single(mail->getNumber()); 999 set = mailimap_set_new_single(mail->getNumber());
970 err = mailimap_store(m_imap,set,store_flags); 1000 err = mailimap_store(m_imap,set,store_flags);
971 mailimap_set_free( set ); 1001 mailimap_set_free( set );
972 mailimap_store_att_flags_free(store_flags); 1002 mailimap_store_att_flags_free(store_flags);
973 1003
974 if (err != MAILIMAP_NO_ERROR) { 1004 if (err != MAILIMAP_NO_ERROR) {
975 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1005 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
976 return; 1006 return;
977 } 1007 }
978} 1008}
979 1009
980QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 1010QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
981{ 1011{
982 QString body(""); 1012 QString body("");
983 encodedString*res = fetchRawPart(mail,path,internal_call); 1013 encodedString*res = fetchRawPart(mail,path,internal_call);
984 encodedString*r = decode_String(res,enc); 1014 encodedString*r = decode_String(res,enc);
985 delete res; 1015 delete res;
986 if (r) { 1016 if (r) {
987 if (r->Length()>0) { 1017 if (r->Length()>0) {
988 body = r->Content(); 1018 body = r->Content();
989 } 1019 }
990 delete r; 1020 delete r;
991 } 1021 }
992 return body; 1022 return body;
993} 1023}
994 1024
995QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1025QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
996{ 1026{
997 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1027 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
998} 1028}
999 1029
1000encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1030encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1001{ 1031{
1002 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1032 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1003 encodedString*r = decode_String(res,part->Encoding()); 1033 encodedString*r = decode_String(res,part->Encoding());
1004 delete res; 1034 delete res;
1005 return r; 1035 return r;
1006} 1036}
1007 1037
1008encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1038encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1009{ 1039{
1010 return fetchRawPart(mail,part->Positionlist(),false); 1040 return fetchRawPart(mail,part->Positionlist(),false);
1011} 1041}
1012 1042
1013int IMAPwrapper::deleteAllMail(const FolderP&folder) 1043int IMAPwrapper::deleteAllMail(const FolderP&folder)
1014{ 1044{
1015 login(); 1045 login();
1016 if (!m_imap) { 1046 if (!m_imap) {
1017 return 0; 1047 return 0;
1018 } 1048 }
1019 mailimap_flag_list*flist; 1049 mailimap_flag_list*flist;
1020 mailimap_set *set; 1050 mailimap_set *set;
1021 mailimap_store_att_flags * store_flags; 1051 mailimap_store_att_flags * store_flags;
1022 int err = selectMbox(folder->getName()); 1052 int err = selectMbox(folder->getName());
1023 if ( err != MAILIMAP_NO_ERROR ) { 1053 if ( err != MAILIMAP_NO_ERROR ) {
1024 return 0; 1054 return 0;
1025 } 1055 }
1026 1056
1027 int last = m_imap->imap_selection_info->sel_exists; 1057 int last = m_imap->imap_selection_info->sel_exists;
1028 if (last == 0) { 1058 if (last == 0) {
1029 Global::statusMessage(tr("Mailbox has no mails!")); 1059 Global::statusMessage(tr("Mailbox has no mails!"));
1030 return 0; 1060 return 0;
1031 } 1061 }
1032 flist = mailimap_flag_list_new_empty(); 1062 flist = mailimap_flag_list_new_empty();
1033 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1063 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1034 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1064 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1035 set = mailimap_set_new_interval( 1, last ); 1065 set = mailimap_set_new_interval( 1, last );
1036 err = mailimap_store(m_imap,set,store_flags); 1066 err = mailimap_store(m_imap,set,store_flags);
1037 mailimap_set_free( set ); 1067 mailimap_set_free( set );
1038 mailimap_store_att_flags_free(store_flags); 1068 mailimap_store_att_flags_free(store_flags);
1039 if (err != MAILIMAP_NO_ERROR) { 1069 if (err != MAILIMAP_NO_ERROR) {
1040 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1070 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1041 return 0; 1071 return 0;
1042 } 1072 }
1043 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1073 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1044 /* should we realy do that at this moment? */ 1074 /* should we realy do that at this moment? */
1045 err = mailimap_expunge(m_imap); 1075 err = mailimap_expunge(m_imap);
1046 if (err != MAILIMAP_NO_ERROR) { 1076 if (err != MAILIMAP_NO_ERROR) {
1047 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1077 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1048 return 0; 1078 return 0;
1049 } 1079 }
1050 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1080 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1051 return 1; 1081 return 1;
1052} 1082}
1053 1083
1054int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1084int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1055{ 1085{
1056 if (folder.length()==0) return 0; 1086 if (folder.length()==0) return 0;
1057 login(); 1087 login();
1058 if (!m_imap) {return 0;} 1088 if (!m_imap) {return 0;}
1059 QString pre = account->getPrefix(); 1089 QString pre = account->getPrefix();
1060 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1090 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1061 pre+=delemiter; 1091 pre+=delemiter;
1062 } 1092 }
1063 if (parentfolder) { 1093 if (parentfolder) {
1064 pre += parentfolder->getDisplayName()+delemiter; 1094 pre += parentfolder->getDisplayName()+delemiter;
1065 } 1095 }
1066 pre+=folder; 1096 pre+=folder;
1067 if (getsubfolder) { 1097 if (getsubfolder) {
1068 if (delemiter.length()>0) { 1098 if (delemiter.length()>0) {
1069 pre+=delemiter; 1099 pre+=delemiter;
1070 } else { 1100 } else {
1071 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 1101 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
1072 return 0; 1102 return 0;
1073 } 1103 }
1074 } 1104 }
1075 // odebug << "Creating " << pre.latin1() << "" << oendl; 1105 // odebug << "Creating " << pre.latin1() << "" << oendl;
1076 int res = mailimap_create(m_imap,pre.latin1()); 1106 int res = mailimap_create(m_imap,pre.latin1());
1077 if (res != MAILIMAP_NO_ERROR) { 1107 if (res != MAILIMAP_NO_ERROR) {
1078 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1108 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1079 return 0; 1109 return 0;
1080 } 1110 }
1081 return 1; 1111 return 1;
1082} 1112}
1083 1113
1084int IMAPwrapper::deleteMbox(const FolderP&folder) 1114int IMAPwrapper::deleteMbox(const FolderP&folder)
1085{ 1115{
1086 if (!folder) return 0; 1116 if (!folder) return 0;
1087 login(); 1117 login();
1088 if (!m_imap) {return 0;} 1118 if (!m_imap) {return 0;}
1089 int res = mailimap_delete(m_imap,folder->getName()); 1119 int res = mailimap_delete(m_imap,folder->getName());
1090 if (res != MAILIMAP_NO_ERROR) { 1120 if (res != MAILIMAP_NO_ERROR) {
1091 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1121 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1092 return 0; 1122 return 0;
1093 } 1123 }
1094 return 1; 1124 return 1;
1095} 1125}
1096 1126
1097void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1127void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1098{ 1128{
1099 mailimap_status_att_list * att_list =0; 1129 mailimap_status_att_list * att_list =0;
1100 mailimap_mailbox_data_status * status=0; 1130 mailimap_mailbox_data_status * status=0;
1101 clistiter * cur = 0; 1131 clistiter * cur = 0;
1102 int r = 0; 1132 int r = 0;
1103 target_stat.message_count = 0; 1133 target_stat.message_count = 0;
1104 target_stat.message_unseen = 0; 1134 target_stat.message_unseen = 0;
1105 target_stat.message_recent = 0; 1135 target_stat.message_recent = 0;
1106 login(); 1136 login();
1107 if (!m_imap) { 1137 if (!m_imap) {
1108 return; 1138 return;
1109 } 1139 }
1110 att_list = mailimap_status_att_list_new_empty(); 1140 att_list = mailimap_status_att_list_new_empty();
1111 if (!att_list) return; 1141 if (!att_list) return;
1112 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1142 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1113 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1143 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1114 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1144 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1115 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1145 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1116 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1146 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1117 for (cur = clist_begin(status->st_info_list); 1147 for (cur = clist_begin(status->st_info_list);
1118 cur != NULL ; cur = clist_next(cur)) { 1148 cur != NULL ; cur = clist_next(cur)) {
1119 mailimap_status_info * status_info; 1149 mailimap_status_info * status_info;
1120 status_info = (mailimap_status_info *)clist_content(cur); 1150 status_info = (mailimap_status_info *)clist_content(cur);
1121 switch (status_info->st_att) { 1151 switch (status_info->st_att) {
1122 case MAILIMAP_STATUS_ATT_MESSAGES: 1152 case MAILIMAP_STATUS_ATT_MESSAGES:
1123 target_stat.message_count = status_info->st_value; 1153 target_stat.message_count = status_info->st_value;
1124 break; 1154 break;
1125 case MAILIMAP_STATUS_ATT_RECENT: 1155 case MAILIMAP_STATUS_ATT_RECENT:
1126 target_stat.message_recent = status_info->st_value; 1156 target_stat.message_recent = status_info->st_value;
1127 break; 1157 break;
1128 case MAILIMAP_STATUS_ATT_UNSEEN: 1158 case MAILIMAP_STATUS_ATT_UNSEEN:
1129 target_stat.message_unseen = status_info->st_value; 1159 target_stat.message_unseen = status_info->st_value;
1130 break; 1160 break;
1131 } 1161 }
1132 } 1162 }
1133 } else { 1163 } else {
1134 // odebug << "Error retrieving status" << oendl; 1164 // odebug << "Error retrieving status" << oendl;
1135 } 1165 }
1136 if (status) mailimap_mailbox_data_status_free(status); 1166 if (status) mailimap_mailbox_data_status_free(status);
1137 if (att_list) mailimap_status_att_list_free(att_list); 1167 if (att_list) mailimap_status_att_list_free(att_list);
1138} 1168}
1139 1169
1140void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1170void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1141{ 1171{
1142 login(); 1172 login();
1143 if (!m_imap) return; 1173 if (!m_imap) return;
1144 if (!msg) return; 1174 if (!msg) return;
1145 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1175 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1146 if (r != MAILIMAP_NO_ERROR) { 1176 if (r != MAILIMAP_NO_ERROR) {
1147 Global::statusMessage("Error storing mail!"); 1177 Global::statusMessage("Error storing mail!");
1148 } 1178 }
1149} 1179}
1150 1180
1151MAILLIB::ATYPE IMAPwrapper::getType()const 1181MAILLIB::ATYPE IMAPwrapper::getType()const
1152{ 1182{
1153 return account->getType(); 1183 return account->getType();
1154} 1184}
1155 1185
1156const QString&IMAPwrapper::getName()const 1186const QString&IMAPwrapper::getName()const
1157{ 1187{
1158 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1188 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1159 return account->getAccountName(); 1189 return account->getAccountName();
1160} 1190}
1161 1191
1162encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1192encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1163{ 1193{
1164 // dummy 1194 // dummy
1165 QValueList<int> path; 1195 QValueList<int> path;
1166 return fetchRawPart(mail,path,false); 1196 return fetchRawPart(mail,path,false);
1167} 1197}
1168 1198
1169void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1199void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1170 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1200 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1171{ 1201{
1172 if (targetWrapper != this || maxSizeInKb > 0 ) { 1202 if (targetWrapper != this || maxSizeInKb > 0 ) {
1173 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); 1203 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1174 qDebug("IMAPwrapper::mvcpAllMails::Using generic"); 1204 qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1175 // odebug << "Using generic" << oendl; 1205 // odebug << "Using generic" << oendl;
1176 return; 1206 return;
1177 } 1207 }
1178 mailimap_set *set = 0; 1208 mailimap_set *set = 0;
1179 login(); 1209 login();
1180 if (!m_imap) { 1210 if (!m_imap) {
1181 return; 1211 return;
1182 } 1212 }
1183 int err = selectMbox(fromFolder->getName()); 1213 int err = selectMbox(fromFolder->getName());
1184 if ( err != MAILIMAP_NO_ERROR ) { 1214 if ( err != MAILIMAP_NO_ERROR ) {
1185 return; 1215 return;
1186 } 1216 }
1187 int last = m_imap->imap_selection_info->sel_exists; 1217 int last = m_imap->imap_selection_info->sel_exists;
1188 set = mailimap_set_new_interval( 1, last ); 1218 set = mailimap_set_new_interval( 1, last );
1189 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1219 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1190 mailimap_set_free( set ); 1220 mailimap_set_free( set );
1191 if ( err != MAILIMAP_NO_ERROR ) { 1221 if ( err != MAILIMAP_NO_ERROR ) {
1192 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); 1222 QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response);
1193 Global::statusMessage(error_msg); 1223 Global::statusMessage(error_msg);
1194 // odebug << error_msg << oendl; 1224 // odebug << error_msg << oendl;
1195 return; 1225 return;
1196 } 1226 }
1197 if (moveit) { 1227 if (moveit) {
1198 deleteAllMail(fromFolder); 1228 deleteAllMail(fromFolder);
1199 } 1229 }
1200} 1230}
1201 1231
1202void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1232void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1203{ 1233{
1204 if (targetWrapper != this) { 1234 if (targetWrapper != this) {
1205 // odebug << "Using generic" << oendl; 1235 // odebug << "Using generic" << oendl;
1206 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1236 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1207 return; 1237 return;
1208 } 1238 }
1209 mailimap_set *set = 0; 1239 mailimap_set *set = 0;
1210 login(); 1240 login();
1211 if (!m_imap) { 1241 if (!m_imap) {
1212 return; 1242 return;
1213 } 1243 }
1214 int err = selectMbox(mail->getMbox()); 1244 int err = selectMbox(mail->getMbox());
1215 if ( err != MAILIMAP_NO_ERROR ) { 1245 if ( err != MAILIMAP_NO_ERROR ) {
1216 return; 1246 return;
1217 } 1247 }
1218 set = mailimap_set_new_single(mail->getNumber()); 1248 set = mailimap_set_new_single(mail->getNumber());
1219 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1249 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1220 mailimap_set_free( set ); 1250 mailimap_set_free( set );
1221 if ( err != MAILIMAP_NO_ERROR ) { 1251 if ( err != MAILIMAP_NO_ERROR ) {
1222 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); 1252 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response);
1223 Global::statusMessage(error_msg); 1253 Global::statusMessage(error_msg);
1224 // odebug << error_msg << oendl; 1254 // odebug << error_msg << oendl;
1225 return; 1255 return;
1226 } 1256 }
1227 if (moveit) { 1257 if (moveit) {
1228 deleteMail(mail); 1258 deleteMail(mail);
1229 } 1259 }
1230} 1260}
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp
index 7a84b30..0e6612c 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.cpp
+++ b/kmicromail/libmailwrapper/pop3wrapper.cpp
@@ -1,282 +1,321 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include <stdlib.h> 2#include <stdlib.h>
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mailtypes.h" 4#include "mailtypes.h"
5#include "logindialog.h" 5#include "logindialog.h"
6#include <libetpan/libetpan.h> 6#include <libetpan/libetpan.h>
7 7
8 8
9#include <qpe/global.h> 9#include <qpe/global.h>
10#include <qfile.h> 10#include <qfile.h>
11#include <qprogressbar.h>
12#include <qapplication.h>
11 13
12/* we don't fetch messages larger than 5 MB */ 14/* we don't fetch messages larger than 5 MB */
13#define HARD_MSG_SIZE_LIMIT 5242880 15#define HARD_MSG_SIZE_LIMIT 5242880
14 16
15using namespace Opie::Core; 17using namespace Opie::Core;
16POP3wrapper::POP3wrapper( POP3account *a ) 18POP3wrapper::POP3wrapper( POP3account *a )
17: Genericwrapper() { 19: Genericwrapper() {
18 account = a; 20 account = a;
19 m_pop3 = NULL; 21 m_pop3 = NULL;
20 msgTempName = a->getFileName()+"_msg_cache"; 22 msgTempName = a->getFileName()+"_msg_cache";
21 last_msg_id = 0; 23 last_msg_id = 0;
22} 24}
23 25
24POP3wrapper::~POP3wrapper() { 26POP3wrapper::~POP3wrapper() {
25 logout(); 27 logout();
26 QFile msg_cache(msgTempName); 28 QFile msg_cache(msgTempName);
27 if (msg_cache.exists()) { 29 if (msg_cache.exists()) {
28 msg_cache.remove(); 30 msg_cache.remove();
29 } 31 }
30} 32}
31 33
32void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
33 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; 35 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl;
34} 36}
35 37
36RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
37 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
38 char *message = 0; 40 char *message = 0;
39 size_t length = 0; 41 size_t length = 0;
40 42
41 RecBodyP body = new RecBody(); 43 RecBodyP body = new RecBody();
42 44
43 login(); 45 login();
44 if ( !m_pop3 ) { 46 if ( !m_pop3 ) {
45 return body; 47 return body;
46 } 48 }
47 49
48 mailmessage * mailmsg; 50 mailmessage * mailmsg;
49 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 51 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 52 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
51 return body; 53 return body;
52 } 54 }
53 55
54 QFile msg_cache(msgTempName); 56 QFile msg_cache(msgTempName);
55 57
56 cleanMimeCache(); 58 cleanMimeCache();
57 59
58 if (mail->getNumber()!=last_msg_id) { 60 if (mail->getNumber()!=last_msg_id) {
59 if (msg_cache.exists()) { 61 if (msg_cache.exists()) {
60 msg_cache.remove(); 62 msg_cache.remove();
61 } 63 }
62 msg_cache.open(IO_ReadWrite|IO_Truncate); 64 msg_cache.open(IO_ReadWrite|IO_Truncate);
63 last_msg_id = mail->getNumber(); 65 last_msg_id = mail->getNumber();
64 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 66 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
65 err = mailmessage_fetch(mailmsg,&message,&length); 67 err = mailmessage_fetch(mailmsg,&message,&length);
66 msg_cache.writeBlock(message,length); 68 msg_cache.writeBlock(message,length);
67 } else { 69 } else {
68 QString msg=""; 70 QString msg="";
69 msg_cache.open(IO_ReadOnly); 71 msg_cache.open(IO_ReadOnly);
70 message = new char[4096]; 72 message = new char[4096];
71 memset(message,0,4096); 73 memset(message,0,4096);
72 while (msg_cache.readBlock(message,4095)>0) { 74 while (msg_cache.readBlock(message,4095)>0) {
73 msg+=message; 75 msg+=message;
74 memset(message,0,4096); 76 memset(message,0,4096);
75 } 77 }
76 delete message; 78 delete message;
77 message = (char*)malloc(msg.length()+1*sizeof(char)); 79 message = (char*)malloc(msg.length()+1*sizeof(char));
78 memset(message,0,msg.length()+1); 80 memset(message,0,msg.length()+1);
79 memcpy(message,msg.latin1(),msg.length()); 81 memcpy(message,msg.latin1(),msg.length());
80 /* transform to libetpan stuff */ 82 /* transform to libetpan stuff */
81 mailmsg = mailmessage_new(); 83 mailmsg = mailmessage_new();
82 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 84 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
83 generic_message_t * msg_data; 85 generic_message_t * msg_data;
84 msg_data = (generic_message_t *)mailmsg->msg_data; 86 msg_data = (generic_message_t *)mailmsg->msg_data;
85 msg_data->msg_fetched = 1; 87 msg_data->msg_fetched = 1;
86 msg_data->msg_message = message; 88 msg_data->msg_message = message;
87 msg_data->msg_length = strlen(message); 89 msg_data->msg_length = strlen(message);
88 } 90 }
89 body = parseMail(mailmsg); 91 body = parseMail(mailmsg);
90 92
91 /* clean up */ 93 /* clean up */
92 if (mailmsg) 94 if (mailmsg)
93 mailmessage_free(mailmsg); 95 mailmessage_free(mailmsg);
94 if (message) 96 if (message)
95 free(message); 97 free(message);
96 98
97 return body; 99 return body;
98} 100}
99 101
100void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 102void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
101{ 103{
102 login(); 104 login();
103 if (!m_pop3) 105 if (!m_pop3)
104 return; 106 return;
105 uint32_t res_messages,res_recent,res_unseen; 107 uint32_t res_messages,res_recent,res_unseen;
106 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 108 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
107 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); 109 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb);
108 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 110 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
109} 111}
110 112
111void POP3wrapper::login() 113void POP3wrapper::login()
112{ 114{
113 if (account->getOffline()) 115 if (account->getOffline())
114 return; 116 return;
115 /* we'll hold the line */ 117 /* we'll hold the line */
116 if ( m_pop3 != NULL ) 118 if ( m_pop3 != NULL )
117 return; 119 return;
118 120
119 const char *server, *user, *pass; 121 const char *server, *user, *pass;
120 uint16_t port; 122 uint16_t port;
121 int err = MAILPOP3_NO_ERROR; 123 int err = MAILPOP3_NO_ERROR;
122 124
123 server = account->getServer().latin1(); 125 server = account->getServer().latin1();
124 port = account->getPort().toUInt(); 126 port = account->getPort().toUInt();
125 127
126 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 128 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
127 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 129 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
128 login.show(); 130 login.show();
129 if ( QDialog::Accepted == login.exec() ) { 131 if ( QDialog::Accepted == login.exec() ) {
130 // ok 132 // ok
131 user = login.getUser().latin1(); 133 user = login.getUser().latin1();
132 pass = login.getPassword().latin1(); 134 pass = login.getPassword().latin1();
133 } else { 135 } else {
134 // cancel 136 // cancel
135 ; // odebug << "POP3: Login canceled" << oendl; 137 ; // odebug << "POP3: Login canceled" << oendl;
136 return; 138 return;
137 } 139 }
138 } else { 140 } else {
139 user = account->getUser().latin1(); 141 user = account->getUser().latin1();
140 pass = account->getPassword().latin1(); 142 pass = account->getPassword().latin1();
141 } 143 }
142 144
143 // bool ssl = account->getSSL(); 145 // bool ssl = account->getSSL();
144 146
145 m_pop3=mailstorage_new(NULL); 147 m_pop3=mailstorage_new(NULL);
146 148
147 int conntypeset = account->ConnectionType(); 149 int conntypeset = account->ConnectionType();
148 int conntype = 0; 150 int conntype = 0;
149 if ( conntypeset == 3 ) { 151 if ( conntypeset == 3 ) {
150 conntype = CONNECTION_TYPE_COMMAND; 152 conntype = CONNECTION_TYPE_COMMAND;
151 } else if ( conntypeset == 2 ) { 153 } else if ( conntypeset == 2 ) {
152 conntype = CONNECTION_TYPE_TLS; 154 conntype = CONNECTION_TYPE_TLS;
153 } else if ( conntypeset == 1 ) { 155 } else if ( conntypeset == 1 ) {
154 conntype = CONNECTION_TYPE_STARTTLS; 156 conntype = CONNECTION_TYPE_STARTTLS;
155 } else if ( conntypeset == 0 ) { 157 } else if ( conntypeset == 0 ) {
156 conntype = CONNECTION_TYPE_TRY_STARTTLS; 158 conntype = CONNECTION_TYPE_TRY_STARTTLS;
157 } 159 }
158 160
159 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 161 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
160 162
161 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 163 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
162 (char*)user,(char*)pass,0,0,0); 164 (char*)user,(char*)pass,0,0,0);
163 165
164 166
165 err = mailstorage_connect(m_pop3); 167 err = mailstorage_connect(m_pop3);
166 if (err != MAIL_NO_ERROR) { 168 if (err != MAIL_NO_ERROR) {
167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 169 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
168 Global::statusMessage(tr("Error initializing folder")); 170 Global::statusMessage(tr("Error initializing folder"));
169 mailstorage_free(m_pop3); 171 mailstorage_free(m_pop3);
170 m_pop3 = 0; 172 m_pop3 = 0;
171 } else { 173 } else {
172 mailsession * session = m_pop3->sto_session; 174 mailsession * session = m_pop3->sto_session;
173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 175 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
174 if (mail) { 176 if (mail) {
175 mail->pop3_progr_fun = &pop3_progress; 177 mail->pop3_progr_fun = &pop3_progress;
176 } 178 }
177 } 179 }
178} 180}
179 181
180void POP3wrapper::logout() 182void POP3wrapper::logout()
181{ 183{
182 if ( m_pop3 == NULL ) 184 if ( m_pop3 == NULL )
183 return; 185 return;
184 mailstorage_free(m_pop3); 186 mailstorage_free(m_pop3);
185 m_pop3 = 0; 187 m_pop3 = 0;
186} 188}
187 189
188 190
189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { 191QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); 192 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>();
191 FolderP inb=new Folder("INBOX","/"); 193 FolderP inb=new Folder("INBOX","/");
192 folders->append(inb); 194 folders->append(inb);
193 return folders; 195 return folders;
194} 196}
195 197
196void POP3wrapper::deleteMailList(QValueList<RecMailP>&target) 198void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target)
197{ 199{
198 login(); 200 login();
199 if (!m_pop3) 201 if (!m_pop3)
200 return; 202 return;
201 int iii = 0; 203 int iii = 0;
202 int count = target.count(); 204 int count = target.count();
203 while (iii < count ) { 205 QProgressBar bar( count,0 );
206 bar.setCaption (("Removing mails - close to abort!") );
207 int w = 300;
208 if ( QApplication::desktop()->width() < 320 )
209 w = 220;
210 int h = bar.sizeHint().height() ;
211 int dw = QApplication::desktop()->width();
212 int dh = QApplication::desktop()->height();
213 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
214 bar.show();
215 int modulo = (count/10)+1;
216 int incCounter = 0;
217 while (iii < count ) {
218 if ( ! bar.isVisible() )
219 return ;
220 if ( incCounter % modulo == 0 )
221 bar.setProgress( incCounter );
222 ++incCounter;
223 qApp->processEvents();
224 //qDebug("delete ");
204 RecMailP mail = (*target.at( iii )); 225 RecMailP mail = (*target.at( iii ));
205 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 226 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
206 if (err != MAIL_NO_ERROR) { 227 if (err != MAIL_NO_ERROR) {
207 Global::statusMessage(tr("error deleting mail")); 228 Global::statusMessage(tr("Error deleting mail"));
208 } 229 }
209 ++iii; 230 ++iii;
210 } 231 }
211} 232}
212void POP3wrapper::deleteMail(const RecMailP&mail) { 233void POP3wrapper::deleteMail(const RecMailP&mail) {
213 login(); 234 login();
214 if (!m_pop3) 235 if (!m_pop3)
215 return; 236 return;
216 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 237 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
217 if (err != MAIL_NO_ERROR) { 238 if (err != MAIL_NO_ERROR) {
218 Global::statusMessage(tr("error deleting mail")); 239 Global::statusMessage(tr("error deleting mail"));
219 } 240 }
220} 241}
221 242
222void POP3wrapper::answeredMail(const RecMailP&) {} 243void POP3wrapper::answeredMail(const RecMailP&) {}
223 244
224int POP3wrapper::deleteAllMail(const FolderP&) { 245int POP3wrapper::deleteAllMail(const FolderP&) {
225 login(); 246 login();
226 if (!m_pop3) 247 if (!m_pop3)
227 return 0; 248 return 0;
228 int res = 1; 249 int res = 1;
229 250
230 uint32_t result = 0; 251 uint32_t result = 0;
231 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); 252 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
232 if (err != MAIL_NO_ERROR) { 253 if (err != MAIL_NO_ERROR) {
233 Global::statusMessage(tr("Error getting folder info")); 254 Global::statusMessage(tr("Error getting folder info"));
234 return 0; 255 return 0;
235 } 256 }
257 QProgressBar bar( result,0 );
258 bar.setCaption (("Deleting mails - close to abort!") );
259 int w = 300;
260 if ( QApplication::desktop()->width() < 320 )
261 w = 220;
262 int h = bar.sizeHint().height() ;
263 int dw = QApplication::desktop()->width();
264 int dh = QApplication::desktop()->height();
265 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
266 bar.show();
267 int modulo = (result/10)+1;
268 int incCounter = 0;
236 for (unsigned int i = 0; i < result; ++i) { 269 for (unsigned int i = 0; i < result; ++i) {
270 if ( ! bar.isVisible() )
271 return 0;
272 if ( incCounter % modulo == 0 )
273 bar.setProgress( incCounter );
274 ++incCounter;
275 qApp->processEvents();
237 err = mailsession_remove_message(m_pop3->sto_session,i+1); 276 err = mailsession_remove_message(m_pop3->sto_session,i+1);
238 if (err != MAIL_NO_ERROR) { 277 if (err != MAIL_NO_ERROR) {
239 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 278 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
240 res=0; 279 res=0;
241 } 280 }
242 break; 281 break;
243 } 282 }
244 return res; 283 return res;
245} 284}
246 285
247void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 286void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
248 login(); 287 login();
249 target_stat.message_count = 0; 288 target_stat.message_count = 0;
250 target_stat.message_unseen = 0; 289 target_stat.message_unseen = 0;
251 target_stat.message_recent = 0; 290 target_stat.message_recent = 0;
252 if (!m_pop3) 291 if (!m_pop3)
253 return; 292 return;
254 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 293 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
255 &target_stat.message_recent,&target_stat.message_unseen); 294 &target_stat.message_recent,&target_stat.message_unseen);
256 if (r != MAIL_NO_ERROR) { 295 if (r != MAIL_NO_ERROR) {
257 ; // odebug << "error getting folter status." << oendl; 296 ; // odebug << "error getting folter status." << oendl;
258 } 297 }
259} 298}
260 299
261encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { 300encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
262 char*target=0; 301 char*target=0;
263 size_t length=0; 302 size_t length=0;
264 encodedString*res = 0; 303 encodedString*res = 0;
265 mailmessage * mailmsg = 0; 304 mailmessage * mailmsg = 0;
266 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 305 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
267 err = mailmessage_fetch(mailmsg,&target,&length); 306 err = mailmessage_fetch(mailmsg,&target,&length);
268 if (mailmsg) 307 if (mailmsg)
269 mailmessage_free(mailmsg); 308 mailmessage_free(mailmsg);
270 if (target) { 309 if (target) {
271 res = new encodedString(target,length); 310 res = new encodedString(target,length);
272 } 311 }
273 return res; 312 return res;
274} 313}
275 314
276MAILLIB::ATYPE POP3wrapper::getType()const { 315MAILLIB::ATYPE POP3wrapper::getType()const {
277 return account->getType(); 316 return account->getType();
278} 317}
279 318
280const QString&POP3wrapper::getName()const{ 319const QString&POP3wrapper::getName()const{
281 return account->getAccountName(); 320 return account->getAccountName();
282} 321}
diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h
index ee754a4..7c70942 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.h
+++ b/kmicromail/libmailwrapper/pop3wrapper.h
@@ -1,44 +1,44 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __POP3WRAPPER 2#ifndef __POP3WRAPPER
3#define __POP3WRAPPER 3#define __POP3WRAPPER
4 4
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "genericwrapper.h" 6#include "genericwrapper.h"
7#include <qstring.h> 7#include <qstring.h>
8 8
9class encodedString; 9class encodedString;
10struct mailstorage; 10struct mailstorage;
11struct mailfolder; 11struct mailfolder;
12 12
13class POP3wrapper : public Genericwrapper 13class POP3wrapper : public Genericwrapper
14{ 14{
15 Q_OBJECT 15 Q_OBJECT
16 16
17public: 17public:
18 POP3wrapper( POP3account *a ); 18 POP3wrapper( POP3account *a );
19 virtual ~POP3wrapper(); 19 virtual ~POP3wrapper();
20 /* mailbox will be ignored */ 20 /* mailbox will be ignored */
21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
23 /* mailbox will be ignored */ 23 /* mailbox will be ignored */
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
25 25
26 virtual void deleteMail(const RecMailP&mail); 26 virtual void deleteMail(const RecMailP&mail);
27 virtual void deleteMailList(const QValueList<RecMailP>&target);
27 virtual void answeredMail(const RecMailP&mail); 28 virtual void answeredMail(const RecMailP&mail);
28 virtual void deleteMailList(QValueList<RecMailP>&target);
29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
30 30
31 virtual RecBodyP fetchBody( const RecMailP &mail ); 31 virtual RecBodyP fetchBody( const RecMailP &mail );
32 virtual encodedString* fetchRawBody(const RecMailP&mail); 32 virtual encodedString* fetchRawBody(const RecMailP&mail);
33 virtual void logout(); 33 virtual void logout();
34 virtual MAILLIB::ATYPE getType()const; 34 virtual MAILLIB::ATYPE getType()const;
35 virtual const QString&getName()const; 35 virtual const QString&getName()const;
36 static void pop3_progress( size_t current, size_t maximum ); 36 static void pop3_progress( size_t current, size_t maximum );
37 37
38protected: 38protected:
39 void login(); 39 void login();
40 POP3account *account; 40 POP3account *account;
41 mailstorage*m_pop3; 41 mailstorage*m_pop3;
42}; 42};
43 43
44#endif 44#endif
diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp
index 3fbdcec..251f15a 100644
--- a/kmicromail/opiemail.cpp
+++ b/kmicromail/opiemail.cpp
@@ -1,408 +1,421 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2// CHANGED 2004-08-06 Lutz Rogowski 2// CHANGED 2004-08-06 Lutz Rogowski
3 3
4#include "settingsdialog.h" 4#include "settingsdialog.h"
5#include "opiemail.h" 5#include "opiemail.h"
6#include "editaccounts.h" 6#include "editaccounts.h"
7#include "composemail.h" 7#include "composemail.h"
8#include "mailistviewitem.h" 8#include "mailistviewitem.h"
9#include "viewmail.h" 9#include "viewmail.h"
10#include "selectstore.h" 10#include "selectstore.h"
11#include "selectsmtp.h" 11#include "selectsmtp.h"
12 12
13#include <qmessagebox.h> 13#include <qmessagebox.h>
14 14
15#include <qpe/qpeapplication.h> 15#include <qpe/qpeapplication.h>
16#include <libmailwrapper/smtpwrapper.h> 16#include <libmailwrapper/smtpwrapper.h>
17#include <libmailwrapper/mailtypes.h> 17#include <libmailwrapper/mailtypes.h>
18#include <libmailwrapper/abstractmail.h> 18#include <libmailwrapper/abstractmail.h>
19/* OPIE */ 19/* OPIE */
20//#include <qpe/resource.h> 20//#include <qpe/resource.h>
21#include <qpe/qpeapplication.h> 21//#include <qpe/qpeapplication.h>
22 22
23/* QT */ 23/* QT */
24 24
25using namespace Opie::Core; 25using namespace Opie::Core;
26 26
27OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) 27OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags )
28 : MainWindow( parent, name) //, WStyle_ContextHelp ) 28 : MainWindow( parent, name) //, WStyle_ContextHelp )
29{ 29{
30 settings = new Settings(); 30 settings = new Settings();
31 31
32 folderView->populate( settings->getAccounts() ); 32 folderView->populate( settings->getAccounts() );
33 33
34} 34}
35 35
36OpieMail::~OpieMail() 36OpieMail::~OpieMail()
37{ 37{
38 if (settings) delete settings; 38 if (settings) delete settings;
39} 39}
40 40
41void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 41void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
42{ 42{
43 43
44} 44}
45#include <stdlib.h> 45#include <stdlib.h>
46void OpieMail::message(const QCString &msg, const QByteArray &data) 46void OpieMail::message(const QCString &msg, const QByteArray &data)
47{ 47{
48 // copied from old mail2 48 // copied from old mail2
49 static int ii = 0; 49 static int ii = 0;
50 50
51 // block second call 51 // block second call
52 if ( ii < 2 ) { 52 if ( ii < 2 ) {
53 ++ii; 53 ++ii;
54 if ( ii > 1 ) { 54 if ( ii > 1 ) {
55 qDebug("qcop call blocked "); 55 qDebug("qcop call blocked ");
56 return; 56 return;
57 } 57 }
58 } 58 }
59 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); 59 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this);
60 if (msg == "writeMail(QString,QString)") 60 if (msg == "writeMail(QString,QString)")
61 { 61 {
62 QDataStream stream(data,IO_ReadOnly); 62 QDataStream stream(data,IO_ReadOnly);
63 QString name, email; 63 QString name, email;
64 stream >> name >> email; 64 stream >> name >> email;
65 // removing the whitespaces at beginning and end is needed! 65 // removing the whitespaces at beginning and end is needed!
66 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); 66 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace());
67 } 67 }
68 else if (msg == "newMail()") 68 else if (msg == "newMail()")
69 { 69 {
70 slotComposeMail(); 70 slotComposeMail();
71 } 71 }
72 else if (msg == "newMail(QString)") 72 else if (msg == "newMail(QString)")
73 { 73 {
74 QDataStream stream(data,IO_ReadOnly); 74 QDataStream stream(data,IO_ReadOnly);
75 QString nameemail; 75 QString nameemail;
76 stream >> nameemail; 76 stream >> nameemail;
77 // the format is 77 // the format is
78 // NAME <EMAIL>:SUBJECT 78 // NAME <EMAIL>:SUBJECT
79 //qDebug("message %s ", nameemail.latin1()); 79 //qDebug("message %s ", nameemail.latin1());
80 80
81 slotwriteMail2( nameemail ); 81 slotwriteMail2( nameemail );
82 } 82 }
83} 83}
84void OpieMail::slotwriteMail2(const QString& namemail ) 84void OpieMail::slotwriteMail2(const QString& namemail )
85{ 85{
86 // qDebug("OpieMail::slotwriteMail2 "); 86 // qDebug("OpieMail::slotwriteMail2 ");
87 qApp->processEvents(); 87 qApp->processEvents();
88 ComposeMail compose( settings, this, 0, true ); 88 ComposeMail compose( settings, this, 0, true );
89 if ( !namemail.isEmpty() ) { 89 if ( !namemail.isEmpty() ) {
90 QString to = namemail; 90 QString to = namemail;
91 if ( namemail.find( " <") > 1 ) { 91 if ( namemail.find( " <") > 1 ) {
92 to = "\"" +to.replace( QRegExp( " <"), "\" <") ; 92 to = "\"" +to.replace( QRegExp( " <"), "\" <") ;
93 } else 93 } else
94 if ( namemail.find( "<") > 1 ) { 94 if ( namemail.find( "<") > 1 ) {
95 to = "\"" +to.replace( QRegExp( "<"), "\" <") ; 95 to = "\"" +to.replace( QRegExp( "<"), "\" <") ;
96 } 96 }
97 int sub = to.find( ">:"); 97 int sub = to.find( ">:");
98 if ( sub > 0 ) { 98 if ( sub > 0 ) {
99 compose.setTo( to.left(sub+1) ); 99 compose.setTo( to.left(sub+1) );
100 compose.setSubject( to.mid(sub+2) ); 100 compose.setSubject( to.mid(sub+2) );
101 } else 101 } else
102 compose.setTo( to ); 102 compose.setTo( to );
103 } 103 }
104 compose.slotAdjustColumns(); 104 compose.slotAdjustColumns();
105 compose.showMaximized(); 105 compose.showMaximized();
106 compose.exec(); 106 compose.exec();
107 //qDebug("retttich "); 107 //qDebug("retttich ");
108} 108}
109void OpieMail::slotwriteMail(const QString&name,const QString&email) 109void OpieMail::slotwriteMail(const QString&name,const QString&email)
110{ 110{
111 // qDebug("OpieMail::slotwriteMail "); 111 // qDebug("OpieMail::slotwriteMail ");
112 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); 112 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp );
113 if (!email.isEmpty()) 113 if (!email.isEmpty())
114 { 114 {
115 if (!name.isEmpty()) 115 if (!name.isEmpty())
116 { 116 {
117 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); 117 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
118 } 118 }
119 else 119 else
120 { 120 {
121 compose.setTo(email); 121 compose.setTo(email);
122 } 122 }
123 } 123 }
124 compose.slotAdjustColumns(); 124 compose.slotAdjustColumns();
125 compose.showMaximized(); 125 compose.showMaximized();
126 compose.exec(); 126 compose.exec();
127} 127}
128 128
129void OpieMail::slotComposeMail() 129void OpieMail::slotComposeMail()
130{ 130{
131 slotwriteMail2( QString () ); 131 slotwriteMail2( QString () );
132 //slotwriteMail(0l,0l); 132 //slotwriteMail(0l,0l);
133} 133}
134 134
135void OpieMail::slotSendQueued() 135void OpieMail::slotSendQueued()
136{ 136{
137 SMTPaccount *smtp = 0; 137 SMTPaccount *smtp = 0;
138 138
139 QList<Account> list = settings->getAccounts(); 139 QList<Account> list = settings->getAccounts();
140 QList<SMTPaccount> smtpList; 140 QList<SMTPaccount> smtpList;
141 smtpList.setAutoDelete(false); 141 smtpList.setAutoDelete(false);
142 Account *it; 142 Account *it;
143 for ( it = list.first(); it; it = list.next() ) 143 for ( it = list.first(); it; it = list.next() )
144 { 144 {
145 if ( it->getType() == MAILLIB::A_SMTP ) 145 if ( it->getType() == MAILLIB::A_SMTP )
146 { 146 {
147 smtp = static_cast<SMTPaccount *>(it); 147 smtp = static_cast<SMTPaccount *>(it);
148 smtpList.append(smtp); 148 smtpList.append(smtp);
149 } 149 }
150 } 150 }
151 if (smtpList.count()==0) 151 if (smtpList.count()==0)
152 { 152 {
153 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first!\n")); 153 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first!\n"));
154 return; 154 return;
155 } 155 }
156 if (smtpList.count()==1) 156 if (smtpList.count()==1)
157 { 157 {
158 smtp = smtpList.at(0); 158 smtp = smtpList.at(0);
159 } 159 }
160 else 160 else
161 { 161 {
162 smtp = 0; 162 smtp = 0;
163 selectsmtp selsmtp; 163 selectsmtp selsmtp;
164 selsmtp.setSelectionlist(&smtpList); 164 selsmtp.setSelectionlist(&smtpList);
165 selsmtp.showMaximized(); 165 selsmtp.showMaximized();
166 if ( selsmtp.exec() == QDialog::Accepted ) 166 if ( selsmtp.exec() == QDialog::Accepted )
167 { 167 {
168 smtp = selsmtp.selected_smtp(); 168 smtp = selsmtp.selected_smtp();
169 } 169 }
170 } 170 }
171 if (smtp) 171 if (smtp)
172 { 172 {
173 SMTPwrapper * wrap = new SMTPwrapper(smtp); 173 SMTPwrapper * wrap = new SMTPwrapper(smtp);
174 if ( wrap->flushOutbox() ) 174 if ( wrap->flushOutbox() )
175 { 175 {
176 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); 176 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed"));
177 } 177 }
178 delete wrap; 178 delete wrap;
179 } 179 }
180} 180}
181 181
182void OpieMail::slotSearchMails() 182void OpieMail::slotSearchMails()
183{ 183{
184 qDebug("OpieMail::slotSearchMails():not implemented "); 184 qDebug("OpieMail::slotSearchMails():not implemented ");
185} 185}
186 186
187void OpieMail::slotEditSettings() 187void OpieMail::slotEditSettings()
188{ 188{
189 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); 189 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp );
190 settingsDialog.showMaximized(); 190 settingsDialog.showMaximized();
191 settingsDialog.exec(); 191 settingsDialog.exec();
192} 192}
193 193
194void OpieMail::slotEditAccounts() 194void OpieMail::slotEditAccounts()
195{ 195{
196 EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp ); 196 EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp );
197 eaDialog.slotAdjustColumns(); 197 eaDialog.slotAdjustColumns();
198 eaDialog.showMaximized(); 198 eaDialog.showMaximized();
199 eaDialog.exec(); 199 eaDialog.exec();
200 if ( settings ) delete settings; 200 if ( settings ) delete settings;
201 settings = new Settings(); 201 settings = new Settings();
202 202
203 folderView->populate( settings->getAccounts() ); 203 folderView->populate( settings->getAccounts() );
204} 204}
205 205
206void OpieMail::displayMail() 206void OpieMail::displayMail()
207{ 207{
208 QListViewItem*item = mailView->currentItem(); 208 QListViewItem*item = mailView->currentItem();
209 if (!item) return; 209 if (!item) return;
210 RecMailP mail = ((MailListViewItem*)item)->data(); 210 RecMailP mail = ((MailListViewItem*)item)->data();
211 RecBodyP body = folderView->fetchBody(mail); 211 RecBodyP body = folderView->fetchBody(mail);
212 ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); 212 ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp );
213 readMail.setBody( body ); 213 readMail.setBody( body );
214 readMail.setMail( mail ); 214 readMail.setMail( mail );
215 readMail.showMaximized(); 215 readMail.showMaximized();
216 readMail.exec(); 216 readMail.exec();
217 217
218 if ( readMail.deleted ) 218 if ( readMail.deleted )
219 { 219 {
220 folderView->refreshCurrent(); 220 folderView->refreshCurrent();
221 } 221 }
222 else 222 else
223 { 223 {
224 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); 224 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() );
225 } 225 }
226} 226}
227 227
228void OpieMail::slotDeleteMail() 228void OpieMail::slotDeleteMail()
229{ 229{
230 if (!mailView->currentItem()) return; 230 if (!mailView->currentItem()) return;
231 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 231 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
232 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 232 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
233 { 233 {
234 mail->Wrapper()->deleteMail( mail ); 234 mail->Wrapper()->deleteMail( mail );
235 folderView->refreshCurrent(); 235 folderView->refreshCurrent();
236 } 236 }
237} 237}
238void OpieMail::slotDeleteAllMail() 238void OpieMail::slotDeleteAllMail()
239{ 239{
240 if (!mailView->currentItem()) return; 240
241 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 241 QValueList<RecMailP> t;
242 if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 242 if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
243 { 243 {
244 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 244 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
245 while ( item ) { 245 while ( item ) {
246 if ( item->isSelected() ) { 246 if ( item->isSelected() ) {
247 RecMailP mail = item->data(); 247 t.append( item->data() );
248 mail->Wrapper()->deleteMail( mail ); 248 }
249 item = (MailListViewItem*)item->nextSibling();
249 } 250 }
250 item = (MailListViewItem*)item->nextSibling();
251 } 251 }
252 folderView->refreshCurrent(); 252 else
253 } 253 return;
254 if ( t.count() == 0 )
255 return;
256 RecMailP mail = t.first();
257 mail->Wrapper()->deleteMailList(t);
258 folderView->refreshCurrent();
259
260
254} 261}
255void OpieMail::clearSelection() 262void OpieMail::clearSelection()
256{ 263{
257 mailView->clearSelection(); 264 mailView->clearSelection();
258 265
259} 266}
260 267
261void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) 268void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int )
262{ 269{
263 if (!mailView->currentItem()) return; 270 if (!mailView->currentItem()) return;
264 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); 271 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType();
265 /* just the RIGHT button - or hold on pda */ 272 /* just the RIGHT button - or hold on pda */
266 if (button!=2) {return;} 273 if (button!=2) {return;}
267 if (!item) return; 274 if (!item) return;
268 QPopupMenu *m = new QPopupMenu(0); 275 QPopupMenu *m = new QPopupMenu(0);
269 if (m) 276 if (m)
270 { 277 {
271 if (mailtype==MAILLIB::A_NNTP) { 278 if (mailtype==MAILLIB::A_NNTP) {
272 m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); 279 m->insertItem(tr("Read this posting"),this,SLOT(displayMail()));
273// m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); 280// m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail()));
274 } else { 281 } else {
275 if (folderView->currentisDraft()) { 282 if (folderView->currentisDraft()) {
276 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); 283 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail()));
277 } 284 }
278 m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); 285 m->insertItem(tr("Read this mail"),this,SLOT(displayMail()));
279 m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail())); 286 m->insertItem(tr("Move/Copy this mail"),this,SLOT(slotMoveCopyMail()));
280 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); 287 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail()));
281 m->insertSeparator(); 288 m->insertSeparator();
282 m->insertItem(tr("Copy/Move all selected mail"),this,SLOT(slotMoveCopyAllMail())); 289 m->insertItem(tr("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail()));
283 m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail())); 290 m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail()));
284 m->insertItem(tr("Clear selection"),this,SLOT(clearSelection())); 291 m->insertItem(tr("Clear selection"),this,SLOT(clearSelection()));
285 } 292 }
286 m->setFocus(); 293 m->setFocus();
287 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 294 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
288 delete m; 295 delete m;
289 } 296 }
290} 297}
291 298
292void OpieMail::slotShowFolders( bool show ) 299void OpieMail::slotShowFolders( bool show )
293{ 300{
294 if ( show && folderView->isHidden() ) 301 if ( show && folderView->isHidden() )
295 { 302 {
296 folderView->show(); 303 folderView->show();
297 } 304 }
298 else if ( !show && !folderView->isHidden() ) 305 else if ( !show && !folderView->isHidden() )
299 { 306 {
300 folderView->hide(); 307 folderView->hide();
301 } 308 }
302} 309}
303 310
304void OpieMail::refreshMailView(const QValueList<RecMailP>&list) 311void OpieMail::refreshMailView(const QValueList<RecMailP>&list)
305{ 312{
306 MailListViewItem*item = 0; 313 MailListViewItem*item = 0;
307 mailView->clear(); 314 mailView->clear();
308 315
309 QValueList<RecMailP>::ConstIterator it; 316 QValueList<RecMailP>::ConstIterator it;
310 for (it = list.begin(); it != list.end();++it) 317 for (it = list.begin(); it != list.end();++it)
311 { 318 {
312 item = new MailListViewItem(mailView,item); 319 item = new MailListViewItem(mailView,item);
313 item->storeData((*it)); 320 item->storeData((*it));
314 item->showEntry(); 321 item->showEntry();
315 } 322 }
316} 323}
317 324
318void OpieMail::mailLeftClicked( QListViewItem *item ) 325void OpieMail::mailLeftClicked( QListViewItem *item )
319{ 326{
320 mailView->clearSelection(); 327 mailView->clearSelection();
321 /* just LEFT button - or tap with stylus on pda */ 328 /* just LEFT button - or tap with stylus on pda */
322 //if (button!=1) return; 329 //if (button!=1) return;
323 if (!item) return; 330 if (!item) return;
324 if (folderView->currentisDraft()) { 331 if (folderView->currentisDraft()) {
325 reEditMail(); 332 reEditMail();
326 } else { 333 } else {
327 displayMail(); 334 displayMail();
328 } 335 }
329} 336}
330 337
331void OpieMail::slotMoveCopyMail() 338void OpieMail::slotMoveCopyMail()
332{ 339{
333 if (!mailView->currentItem()) return; 340 if (!mailView->currentItem()) return;
334 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 341 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
335 AbstractMail*targetMail = 0; 342 AbstractMail*targetMail = 0;
336 QString targetFolder = ""; 343 QString targetFolder = "";
337 Selectstore sels; 344 Selectstore sels;
338 folderView->setupFolderselect(&sels); 345 folderView->setupFolderselect(&sels);
339 if (!sels.exec()) return; 346 if (!sels.exec()) return;
340 targetMail = sels.currentMail(); 347 targetMail = sels.currentMail();
341 targetFolder = sels.currentFolder(); 348 targetFolder = sels.currentFolder();
342 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 349 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
343 targetFolder.isEmpty()) 350 targetFolder.isEmpty())
344 { 351 {
345 return; 352 return;
346 } 353 }
347 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 354 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
348 { 355 {
349 QMessageBox::critical(0,tr("Error creating new Folder"), 356 QMessageBox::critical(0,tr("Error creating new Folder"),
350 tr("<center>Error while creating<br>new folder - breaking.</center>")); 357 tr("<center>Error while creating<br>new folder - breaking.</center>"));
351 return; 358 return;
352 } 359 }
360 sels.hide();
361 qApp->processEvents();
362 // qDebug("hiding sels ");
353 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); 363 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails());
354 folderView->refreshCurrent(); 364 folderView->refreshCurrent();
355} 365}
356 366
357void OpieMail::slotMoveCopyAllMail() 367void OpieMail::slotMoveCopyAllMail()
358{ 368{
359 369
360 if (!mailView->currentItem()) return; 370 if (!mailView->currentItem()) return;
361 QValueList<RecMailP> t; 371 QValueList<RecMailP> t;
362 if ( QMessageBox::warning(this, tr("Copy/Move all selected mails"), tr("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 372 // if ( QMessageBox::warning(this, tr("Move/Copy all selected mails"), tr("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
363 { 373 {
364 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 374 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
365 while ( item ) { 375 while ( item ) {
366 if ( item->isSelected() ) { 376 if ( item->isSelected() ) {
367 t.append( item->data() ); 377 t.append( item->data() );
368 } 378 }
369 item = (MailListViewItem*)item->nextSibling(); 379 item = (MailListViewItem*)item->nextSibling();
370 } 380 }
371 } 381 }
372 else 382 // else
373 return; 383 // return;
374 if ( t.count() == 0 ) 384 if ( t.count() == 0 )
375 return; 385 return;
376 RecMailP mail = t.first(); 386 RecMailP mail = t.first();
377 AbstractMail*targetMail = 0; 387 AbstractMail*targetMail = 0;
378 QString targetFolder = ""; 388 QString targetFolder = "";
379 Selectstore sels; 389 Selectstore sels;
380 folderView->setupFolderselect(&sels); 390 folderView->setupFolderselect(&sels);
381 if (!sels.exec()) return; 391 if (!sels.exec()) return;
382 targetMail = sels.currentMail(); 392 targetMail = sels.currentMail();
383 targetFolder = sels.currentFolder(); 393 targetFolder = sels.currentFolder();
384 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 394 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
385 targetFolder.isEmpty()) 395 targetFolder.isEmpty())
386 { 396 {
387 return; 397 return;
388 } 398 }
389 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 399 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
390 { 400 {
391 QMessageBox::critical(0,tr("Error creating new Folder"), 401 QMessageBox::critical(0,tr("Error creating new Folder"),
392 tr("<center>Error while creating<br>new folder - breaking.</center>")); 402 tr("<center>Error while creating<br>new folder - breaking.</center>"));
393 return; 403 return;
394 } 404 }
405 sels.hide();
406 qApp->processEvents();
407 //qDebug("hiding sels ");
395 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails()); 408 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails());
396 folderView->refreshCurrent(); 409 folderView->refreshCurrent();
397} 410}
398 411
399void OpieMail::reEditMail() 412void OpieMail::reEditMail()
400{ 413{
401 if (!mailView->currentItem()) return; 414 if (!mailView->currentItem()) return;
402 415
403 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); 416 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp );
404 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); 417 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data());
405 compose.slotAdjustColumns(); 418 compose.slotAdjustColumns();
406 compose.showMaximized(); 419 compose.showMaximized();
407 compose.exec(); 420 compose.exec();
408} 421}