summaryrefslogtreecommitdiffabout
path: root/kmicromail/libetpan/generic/maildirdriver_message.c
Unidiff
Diffstat (limited to 'kmicromail/libetpan/generic/maildirdriver_message.c') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/generic/maildirdriver_message.c58
1 files changed, 57 insertions, 1 deletions
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
@@ -25,38 +25,42 @@
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,
@@ -69,25 +73,25 @@ static mailmessage_driver local_maildir_message_driver = {
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;
@@ -188,12 +192,64 @@ static int initialize(mailmessage * msg_info)
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}