author | zautrix <zautrix> | 2005-03-18 20:17:03 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-18 20:17:03 (UTC) |
commit | 9e549686b23b6dffdcbd09c9b10dc2cb795fbcdf (patch) (unidiff) | |
tree | 2528e6cc740225ca0f47d5ac8ff70f7d3bb10621 /libetpan/src/driver/implementation/maildir/maildirdriver_tools.c | |
parent | 9319998f20f03dcc217fbb39656755dc65226276 (diff) | |
download | kdepimpi-9e549686b23b6dffdcbd09c9b10dc2cb795fbcdf.zip kdepimpi-9e549686b23b6dffdcbd09c9b10dc2cb795fbcdf.tar.gz kdepimpi-9e549686b23b6dffdcbd09c9b10dc2cb795fbcdf.tar.bz2 |
Initial revision
Diffstat (limited to 'libetpan/src/driver/implementation/maildir/maildirdriver_tools.c') (more/less context) (show whitespace changes)
-rw-r--r-- | libetpan/src/driver/implementation/maildir/maildirdriver_tools.c | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/libetpan/src/driver/implementation/maildir/maildirdriver_tools.c b/libetpan/src/driver/implementation/maildir/maildirdriver_tools.c new file mode 100644 index 0000000..e3036e8 --- a/dev/null +++ b/libetpan/src/driver/implementation/maildir/maildirdriver_tools.c | |||
@@ -0,0 +1,198 @@ | |||
1 | /* | ||
2 | * libEtPan! -- a mail stuff library | ||
3 | * | ||
4 | * Copyright (C) 2001, 2005 - 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 AUTHORS 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 AUTHORS 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_FOLDER: | ||
64 | return MAIL_ERROR_FOLDER; | ||
65 | |||
66 | case MAILDIR_ERROR_NOT_FOUND: | ||
67 | return MAIL_ERROR_MSG_NOT_FOUND; | ||
68 | |||
69 | default: | ||
70 | return MAIL_ERROR_INVAL; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | |||
76 | uint32_t maildirdriver_maildir_flags_to_flags(uint32_t md_flags) | ||
77 | { | ||
78 | uint32_t flags; | ||
79 | |||
80 | flags = 0; | ||
81 | if ((md_flags & MAILDIR_FLAG_NEW) != 0) | ||
82 | flags |= MAIL_FLAG_NEW; | ||
83 | |||
84 | if ((md_flags & MAILDIR_FLAG_SEEN) != 0) | ||
85 | flags |= MAIL_FLAG_SEEN; | ||
86 | |||
87 | if ((md_flags & MAILDIR_FLAG_REPLIED) != 0) | ||
88 | flags |= MAIL_FLAG_ANSWERED; | ||
89 | |||
90 | if ((md_flags & MAILDIR_FLAG_FLAGGED) != 0) | ||
91 | flags |= MAIL_FLAG_FLAGGED; | ||
92 | |||
93 | if ((md_flags & MAILDIR_FLAG_TRASHED) != 0) | ||
94 | flags |= MAIL_FLAG_DELETED; | ||
95 | |||
96 | return flags; | ||
97 | } | ||
98 | |||
99 | uint32_t maildirdriver_flags_to_maildir_flags(uint32_t flags) | ||
100 | { | ||
101 | uint32_t md_flags; | ||
102 | |||
103 | md_flags = 0; | ||
104 | if ((flags & MAIL_FLAG_NEW) != 0) | ||
105 | md_flags |= MAILDIR_FLAG_NEW; | ||
106 | |||
107 | if ((flags & MAIL_FLAG_SEEN) != 0) | ||
108 | md_flags |= MAILDIR_FLAG_SEEN; | ||
109 | |||
110 | if ((flags & MAIL_FLAG_ANSWERED) != 0) | ||
111 | md_flags |= MAILDIR_FLAG_REPLIED; | ||
112 | |||
113 | if ((flags & MAIL_FLAG_FLAGGED) != 0) | ||
114 | md_flags |= MAILDIR_FLAG_FLAGGED; | ||
115 | |||
116 | if ((flags & MAIL_FLAG_DELETED) != 0) | ||
117 | md_flags |= MAILDIR_FLAG_TRASHED; | ||
118 | |||
119 | return md_flags; | ||
120 | } | ||
121 | |||
122 | |||
123 | int maildir_get_messages_list(mailsession * session, struct maildir * md, | ||
124 | mailmessage_driver * message_driver, | ||
125 | struct mailmessage_list ** result) | ||
126 | { | ||
127 | unsigned int i; | ||
128 | struct mailmessage_list * env_list; | ||
129 | int r; | ||
130 | carray * tab; | ||
131 | int res; | ||
132 | |||
133 | tab = carray_new(128); | ||
134 | if (tab == NULL) { | ||
135 | res = MAIL_ERROR_MEMORY; | ||
136 | goto err; | ||
137 | } | ||
138 | |||
139 | for(i = 0 ; i < carray_count(md->mdir_msg_list) ; i++) { | ||
140 | struct maildir_msg * md_msg; | ||
141 | mailmessage * msg; | ||
142 | char * filename; | ||
143 | struct stat stat_info; | ||
144 | |||
145 | md_msg = carray_get(md->mdir_msg_list, i); | ||
146 | |||
147 | filename = maildir_message_get(md, md_msg->msg_uid); | ||
148 | r = stat(filename, &stat_info); | ||
149 | free(filename); | ||
150 | if (r < 0) | ||
151 | continue; | ||
152 | |||
153 | msg = mailmessage_new(); | ||
154 | if (msg == NULL) { | ||
155 | res = MAIL_ERROR_MEMORY; | ||
156 | goto free_list; | ||
157 | } | ||
158 | |||
159 | r = mailmessage_init(msg, session, message_driver, | ||
160 | i + 1, stat_info.st_size); | ||
161 | if (r != MAIL_NO_ERROR) { | ||
162 | mailmessage_free(msg); | ||
163 | res = r; | ||
164 | goto free_list; | ||
165 | } | ||
166 | |||
167 | msg->msg_uid = strdup(md_msg->msg_uid); | ||
168 | if (msg->msg_uid == NULL) { | ||
169 | mailmessage_free(msg); | ||
170 | res = MAIL_ERROR_MEMORY; | ||
171 | goto free_list; | ||
172 | } | ||
173 | |||
174 | r = carray_add(tab, msg, NULL); | ||
175 | if (r < 0) { | ||
176 | mailmessage_free(msg); | ||
177 | res = MAIL_ERROR_MEMORY; | ||
178 | goto free_list; | ||
179 | } | ||
180 | } | ||
181 | |||
182 | env_list = mailmessage_list_new(tab); | ||
183 | if (env_list == NULL) { | ||
184 | res = MAIL_ERROR_MEMORY; | ||
185 | goto free_list; | ||
186 | } | ||
187 | |||
188 | * result = env_list; | ||
189 | |||
190 | return MAIL_NO_ERROR; | ||
191 | |||
192 | free_list: | ||
193 | for(i = 0 ; i < carray_count(tab) ; i ++) | ||
194 | mailmessage_free(carray_get(tab, i)); | ||
195 | carray_free(tab); | ||
196 | err: | ||
197 | return res; | ||
198 | } | ||