Improve some sieve-related translations
[claws.git] / src / plugins / mailmbox / mailmbox_types.c
blob8da9685012798be8e00071c8d3cde9b687bf57d7
1 /*
2 * libEtPan! -- a mail stuff library
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved.
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.
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.
32 #include "config.h"
34 #include "mailmbox_types.h"
35 #include "utils.h"
37 #include <string.h>
38 #include <stdlib.h>
40 #ifndef TRUE
41 #define TRUE 1
42 #endif
44 #ifndef FALSE
45 #define FALSE 0
46 #endif
48 /* *********************************************************************** */
50 int claws_mailmbox_msg_info_update(struct claws_mailmbox_folder * folder,
51 size_t msg_start, size_t msg_start_len,
52 size_t msg_headers, size_t msg_headers_len,
53 size_t msg_body, size_t msg_body_len,
54 size_t msg_size, size_t msg_padding,
55 uint32_t msg_uid)
57 struct claws_mailmbox_msg_info * info;
58 int res;
59 chashdatum key;
60 chashdatum data;
61 int r;
63 key.data = &msg_uid;
64 key.len = sizeof(msg_uid);
65 r = chash_get(folder->mb_hash, &key, &data);
66 if (r < 0) {
67 unsigned int index;
69 info = claws_mailmbox_msg_info_new(msg_start, msg_start_len,
70 msg_headers, msg_headers_len,
71 msg_body, msg_body_len, msg_size, msg_padding, msg_uid);
72 if (info == NULL) {
73 res = MAILMBOX_ERROR_MEMORY;
74 goto err;
77 r = carray_add(folder->mb_tab, info, &index);
78 if (r < 0) {
79 claws_mailmbox_msg_info_free(info);
80 res = MAILMBOX_ERROR_MEMORY;
81 goto err;
84 if (msg_uid != 0) {
85 chashdatum key;
86 chashdatum data;
88 key.data = &msg_uid;
89 key.len = sizeof(msg_uid);
90 data.data = info;
91 data.len = 0;
93 r = chash_set(folder->mb_hash, &key, &data, NULL);
94 if (r < 0) {
95 claws_mailmbox_msg_info_free(info);
96 carray_delete(folder->mb_tab, index);
97 res = MAILMBOX_ERROR_MEMORY;
98 goto err;
102 info->msg_index = index;
104 else {
105 info = data.data;
107 info->msg_start = msg_start;
108 info->msg_start_len = msg_start_len;
109 info->msg_headers = msg_headers;
110 info->msg_headers_len = msg_headers_len;
111 info->msg_body = msg_body;
112 info->msg_body_len = msg_body_len;
113 info->msg_size = msg_size;
114 info->msg_padding = msg_padding;
117 return MAILMBOX_NO_ERROR;
119 err:
120 return res;
124 struct claws_mailmbox_msg_info *
125 claws_mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len,
126 size_t msg_headers, size_t msg_headers_len,
127 size_t msg_body, size_t msg_body_len,
128 size_t msg_size, size_t msg_padding,
129 uint32_t msg_uid)
131 struct claws_mailmbox_msg_info * info;
133 info = malloc(sizeof(* info));
134 if (info == NULL)
135 return NULL;
137 info->msg_index = 0;
138 info->msg_uid = msg_uid;
139 if (msg_uid != 0)
140 info->msg_written_uid = TRUE;
141 else
142 info->msg_written_uid = FALSE;
143 info->msg_deleted = FALSE;
145 info->msg_start = msg_start;
146 info->msg_start_len = msg_start_len;
148 info->msg_headers = msg_headers;
149 info->msg_headers_len = msg_headers_len;
151 info->msg_body = msg_body;
152 info->msg_body_len = msg_body_len;
154 info->msg_size = msg_size;
156 info->msg_padding = msg_padding;
158 return info;
161 void claws_mailmbox_msg_info_free(struct claws_mailmbox_msg_info * info)
163 free(info);
167 /* append info */
169 struct claws_mailmbox_append_info *
170 claws_mailmbox_append_info_new(const char * ai_message, size_t ai_size)
172 struct claws_mailmbox_append_info * info;
174 info = malloc(sizeof(* info));
175 if (info == NULL)
176 return NULL;
178 info->ai_message = ai_message;
179 info->ai_size = ai_size;
181 return info;
184 void claws_mailmbox_append_info_free(struct claws_mailmbox_append_info * info)
186 free(info);
189 struct claws_mailmbox_folder * claws_mailmbox_folder_new(const char * mb_filename)
191 struct claws_mailmbox_folder * folder;
193 folder = malloc(sizeof(* folder));
194 if (folder == NULL)
195 goto err;
197 strncpy(folder->mb_filename, mb_filename, PATH_MAX - 1);
198 folder->mb_filename[PATH_MAX - 1] = '\0';
199 folder->mb_mtime = (time_t) -1;
201 folder->mb_fd = -1;
202 folder->mb_read_only = TRUE;
203 folder->mb_no_uid = TRUE;
205 folder->mb_changed = FALSE;
206 folder->mb_deleted_count = 0;
208 folder->mb_mapping = NULL;
209 folder->mb_mapping_size = 0;
211 folder->mb_written_uid = 0;
212 folder->mb_max_uid = 0;
214 folder->mb_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYKEY);
215 if (folder->mb_hash == NULL)
216 goto free;
218 folder->mb_tab = carray_new(128);
219 if (folder->mb_tab == NULL)
220 goto free_hash;
222 return folder;
224 free_hash:
225 chash_free(folder->mb_hash);
226 free:
227 free(folder);
228 err:
229 return NULL;
232 void claws_mailmbox_folder_free(struct claws_mailmbox_folder * folder)
234 unsigned int i;
236 for(i = 0 ; i < carray_count(folder->mb_tab) ; i++) {
237 struct claws_mailmbox_msg_info * info;
239 info = carray_get(folder->mb_tab, i);
240 if (info != NULL)
241 claws_mailmbox_msg_info_free(info);
244 carray_free(folder->mb_tab);
246 chash_free(folder->mb_hash);
248 free(folder);