author | zautrix <zautrix> | 2004-07-03 16:33:12 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-07-03 16:33:12 (UTC) |
commit | e3b89230f065c48c84b48c88edb6eb088374c487 (patch) (unidiff) | |
tree | 162ea2ef909a6f82ccfcedf45d80d6c821174912 /kmicromail/libetpan/generic/maildirdriver_tools.c | |
parent | 2dd6ac0b2d24c91d35ce674a6c26351352df2b15 (diff) | |
download | kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.zip kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.gz kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.bz2 |
Initial revision
Diffstat (limited to 'kmicromail/libetpan/generic/maildirdriver_tools.c') (more/less context) (show whitespace changes)
-rw-r--r-- | kmicromail/libetpan/generic/maildirdriver_tools.c | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/kmicromail/libetpan/generic/maildirdriver_tools.c b/kmicromail/libetpan/generic/maildirdriver_tools.c new file mode 100644 index 0000000..f3e21e4 --- a/dev/null +++ b/kmicromail/libetpan/generic/maildirdriver_tools.c | |||
@@ -0,0 +1,195 @@ | |||
1 | /* | ||
2 | * libEtPan! -- a mail stuff library | ||
3 | * | ||
4 | * Copyright (C) 2001, 2002 - DINH Viet Hoa | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
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 | ||
17 | * from this software without specific prior written permission. | ||
18 | * | ||
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 | ||
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
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 | ||
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 | ||
29 | * SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * $Id$ | ||
34 | */ | ||
35 | |||
36 | #include "mailmessage.h" | ||
37 | #include "maildirdriver_tools.h" | ||
38 | #include "maildir.h" | ||
39 | #include "generic_cache.h" | ||
40 | #include <sys/types.h> | ||
41 | #include <sys/stat.h> | ||
42 | #include <stdlib.h> | ||
43 | #include <string.h> | ||
44 | |||
45 | int maildirdriver_maildir_error_to_mail_error(int error) | ||
46 | { | ||
47 | switch (error) { | ||
48 | case MAILDIR_NO_ERROR: | ||
49 | return MAIL_NO_ERROR; | ||
50 | |||
51 | case MAILDIR_ERROR_CREATE: | ||
52 | return MAIL_ERROR_FILE; | ||
53 | |||
54 | case MAILDIR_ERROR_DIRECTORY: | ||
55 | return MAIL_ERROR_FILE; | ||
56 | |||
57 | case MAILDIR_ERROR_MEMORY: | ||
58 | return MAIL_ERROR_MEMORY; | ||
59 | |||
60 | case MAILDIR_ERROR_FILE: | ||
61 | return MAIL_ERROR_FILE; | ||
62 | |||
63 | case MAILDIR_ERROR_NOT_FOUND: | ||
64 | return MAIL_ERROR_MSG_NOT_FOUND; | ||
65 | |||
66 | default: | ||
67 | return MAIL_ERROR_INVAL; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | |||
72 | |||
73 | uint32_t maildirdriver_maildir_flags_to_flags(uint32_t md_flags) | ||
74 | { | ||
75 | uint32_t flags; | ||
76 | |||
77 | flags = 0; | ||
78 | if ((md_flags & MAILDIR_FLAG_NEW) != 0) | ||
79 | flags |= MAIL_FLAG_NEW; | ||
80 | |||
81 | if ((md_flags & MAILDIR_FLAG_SEEN) != 0) | ||
82 | flags |= MAIL_FLAG_SEEN; | ||
83 | |||
84 | if ((md_flags & MAILDIR_FLAG_REPLIED) != 0) | ||
85 | flags |= MAIL_FLAG_ANSWERED; | ||
86 | |||
87 | if ((md_flags & MAILDIR_FLAG_FLAGGED) != 0) | ||
88 | flags |= MAIL_FLAG_FLAGGED; | ||
89 | |||
90 | if ((md_flags & MAILDIR_FLAG_TRASHED) != 0) | ||
91 | flags |= MAIL_FLAG_DELETED; | ||
92 | |||
93 | return flags; | ||
94 | } | ||
95 | |||
96 | uint32_t maildirdriver_flags_to_maildir_flags(uint32_t flags) | ||
97 | { | ||
98 | uint32_t md_flags; | ||
99 | |||
100 | md_flags = 0; | ||
101 | if ((flags & MAIL_FLAG_NEW) != 0) | ||
102 | md_flags |= MAILDIR_FLAG_NEW; | ||
103 | |||
104 | if ((flags & MAIL_FLAG_SEEN) != 0) | ||
105 | md_flags |= MAILDIR_FLAG_SEEN; | ||
106 | |||
107 | if ((flags & MAIL_FLAG_ANSWERED) != 0) | ||
108 | md_flags |= MAILDIR_FLAG_REPLIED; | ||
109 | |||
110 | if ((flags & MAIL_FLAG_FLAGGED) != 0) | ||
111 | md_flags |= MAILDIR_FLAG_FLAGGED; | ||
112 | |||
113 | if ((flags & MAIL_FLAG_DELETED) != 0) | ||
114 | md_flags |= MAILDIR_FLAG_TRASHED; | ||
115 | |||
116 | return md_flags; | ||
117 | } | ||
118 | |||
119 | |||
120 | int maildir_get_messages_list(mailsession * session, struct maildir * md, | ||
121 | mailmessage_driver * message_driver, | ||
122 | struct mailmessage_list ** result) | ||
123 | { | ||
124 | unsigned int i; | ||
125 | struct mailmessage_list * env_list; | ||
126 | int r; | ||
127 | carray * tab; | ||
128 | int res; | ||
129 | |||
130 | tab = carray_new(128); | ||
131 | if (tab == NULL) { | ||
132 | res = MAIL_ERROR_MEMORY; | ||
133 | goto err; | ||
134 | } | ||
135 | |||
136 | for(i = 0 ; i < carray_count(md->mdir_msg_list) ; i++) { | ||
137 | struct maildir_msg * md_msg; | ||
138 | mailmessage * msg; | ||
139 | char * filename; | ||
140 | struct stat stat_info; | ||
141 | |||
142 | md_msg = carray_get(md->mdir_msg_list, i); | ||
143 | |||
144 | filename = maildir_message_get(md, md_msg->msg_uid); | ||
145 | r = stat(filename, &stat_info); | ||
146 | free(filename); | ||
147 | if (r < 0) | ||
148 | continue; | ||
149 | |||
150 | msg = mailmessage_new(); | ||
151 | if (msg == NULL) { | ||
152 | res = MAIL_ERROR_MEMORY; | ||
153 | goto free_list; | ||
154 | } | ||
155 | |||
156 | r = mailmessage_init(msg, session, message_driver, | ||
157 | i + 1, stat_info.st_size); | ||
158 | if (r != MAIL_NO_ERROR) { | ||
159 | mailmessage_free(msg); | ||
160 | res = r; | ||
161 | goto free_list; | ||
162 | } | ||
163 | |||
164 | msg->msg_uid = strdup(md_msg->msg_uid); | ||
165 | if (msg->msg_uid == NULL) { | ||
166 | mailmessage_free(msg); | ||
167 | res = MAIL_ERROR_MEMORY; | ||
168 | goto free_list; | ||
169 | } | ||
170 | |||
171 | r = carray_add(tab, msg, NULL); | ||
172 | if (r < 0) { | ||
173 | mailmessage_free(msg); | ||
174 | res = MAIL_ERROR_MEMORY; | ||
175 | goto free_list; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | env_list = mailmessage_list_new(tab); | ||
180 | if (env_list == NULL) { | ||
181 | res = MAIL_ERROR_MEMORY; | ||
182 | goto free_list; | ||
183 | } | ||
184 | |||
185 | * result = env_list; | ||
186 | |||
187 | return MAIL_NO_ERROR; | ||
188 | |||
189 | free_list: | ||
190 | for(i = 0 ; i < carray_count(tab) ; i ++) | ||
191 | mailmessage_free(carray_get(tab, i)); | ||
192 | carray_free(tab); | ||
193 | err: | ||
194 | return res; | ||
195 | } | ||