int mailmbox_init(const char * filename, int force_readonly, int force_no_uid, uint32_t default_written_uid, struct mailmbox_folder ** result_folder) { struct mailmbox_folder * folder; int r; int res; folder = mailmbox_folder_new(filename); if (folder == NULL) { res = MAILMBOX_ERROR_MEMORY; goto err; } folder->mb_no_uid = force_no_uid; folder->mb_read_only = force_readonly; folder->mb_written_uid = default_written_uid; folder->mb_changed = FALSE; folder->mb_deleted_count = 0; r = mailmbox_open(folder); if (r != MAILMBOX_NO_ERROR) { res = r; goto free; } r = mailmbox_map(folder); if (r != MAILMBOX_NO_ERROR) { res = r; goto close; } r = mailmbox_validate_read_lock(folder); if (r != MAILMBOX_NO_ERROR) { res = r; goto unmap; } mailmbox_read_unlock(folder); * result_folder = folder; return MAILMBOX_NO_ERROR; unmap: mailmbox_unmap(folder); close: mailmbox_close(folder); free: mailmbox_folder_free(folder); err: return res; }
static int mboxdriver_messages_number(mailsession * session, const char * mb, uint32_t * result) { struct mailmbox_folder * folder; int r; UNUSED(mb); folder = get_mbox_session(session); if (folder == NULL) return MAIL_ERROR_STATUS; r = mailmbox_validate_read_lock(folder); if (r != MAIL_NO_ERROR) return r; mailmbox_read_unlock(folder); * result = carray_count(folder->mb_tab) - folder->mb_deleted_count; return MAILMBOX_NO_ERROR; }
int mailmbox_fetch_msg_headers(struct mailmbox_folder * folder, uint32_t num, char ** result, size_t * result_len) { MMAPString * mmapstr; int res; char * data; size_t len; int r; size_t fixed_size; char * end; r = mailmbox_validate_read_lock(folder); if (r != MAILMBOX_NO_ERROR) { res = r; goto err; } r = mailmbox_fetch_msg_headers_no_lock(folder, num, &data, &len); if (r != MAILMBOX_NO_ERROR) { res = r; goto unlock; } #if 0 mmapstr = mmap_string_new_len(data, len); if (mmapstr == NULL) { res = MAILMBOX_ERROR_MEMORY; goto unlock; } #endif /* size with no uid */ fixed_size = get_fixed_message_size(data, len, 0, 1 /* force no uid */); mmapstr = mmap_string_sized_new(fixed_size); if (mmapstr == NULL) { res = MAILMBOX_ERROR_MEMORY; goto unlock; } end = write_fixed_message(mmapstr->str, data, len, 0, 1 /* force no uid */); * end = '\0'; mmapstr->len = fixed_size; r = mmap_string_ref(mmapstr); if (r < 0) { mmap_string_free(mmapstr); res = MAILMBOX_ERROR_MEMORY; goto unlock; } * result = mmapstr->str; * result_len = mmapstr->len; mailmbox_read_unlock(folder); return MAILMBOX_NO_ERROR; unlock: mailmbox_read_unlock(folder); err: return res; }
int mailmbox_copy_msg_list(struct mailmbox_folder * dest_folder, struct mailmbox_folder * src_folder, carray * tab) { int r; int res; carray * append_tab; unsigned int i; r = mailmbox_validate_read_lock(src_folder); if (r != MAILMBOX_NO_ERROR) { res = r; goto err; } append_tab = carray_new(carray_count(tab)); if (append_tab == NULL) { res = MAILMBOX_ERROR_MEMORY; goto src_unlock; } for(i = 0 ; i < carray_count(tab) ; i ++) { struct mailmbox_append_info * append_info; char * data; size_t len; uint32_t uid; uid = * ((uint32_t *) carray_get(tab, i)); r = mailmbox_fetch_msg_no_lock(src_folder, uid, &data, &len); if (r != MAILMBOX_NO_ERROR) { res = r; goto free_list; } append_info = mailmbox_append_info_new(data, len); if (append_info == NULL) { res = MAILMBOX_ERROR_MEMORY; goto free_list; } r = carray_add(append_tab, append_info, NULL); if (r < 0) { mailmbox_append_info_free(append_info); res = MAILMBOX_ERROR_MEMORY; goto free_list; } } r = mailmbox_append_message_list(dest_folder, append_tab); if (r != MAILMBOX_NO_ERROR) { res = r; goto src_unlock; } for(i = 0 ; i < carray_count(append_tab) ; i ++) { struct mailmbox_append_info * append_info; append_info = carray_get(append_tab, i); mailmbox_append_info_free(append_info); } carray_free(append_tab); mailmbox_read_unlock(src_folder); return MAILMBOX_NO_ERROR; free_list: for(i = 0 ; i < carray_count(append_tab) ; i ++) { struct mailmbox_append_info * append_info; append_info = carray_get(append_tab, i); mailmbox_append_info_free(append_info); } carray_free(append_tab); src_unlock: mailmbox_read_unlock(src_folder); err: return res; }
static int mboxdriver_get_envelopes_list(mailsession * session, struct mailmessage_list * env_list) { struct mailmbox_folder * folder; unsigned int i; int r; int res; folder = get_mbox_session(session); if (folder == NULL) { res = MAIL_ERROR_BAD_STATE; goto err; } r = mailmbox_validate_read_lock(folder); if (r != MAILMBOX_NO_ERROR) { res = mboxdriver_mbox_error_to_mail_error(r); goto err; } for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { mailmessage * msg; struct mailimf_fields * fields; char * headers; size_t headers_len; size_t cur_token; msg = carray_get(env_list->msg_tab, i); if (msg == NULL) continue; if (msg->msg_fields != NULL) continue; r = mailmbox_fetch_msg_headers_no_lock(folder, msg->msg_index, &headers, &headers_len); if (r != MAILMBOX_NO_ERROR) { res = mboxdriver_mbox_error_to_mail_error(r); goto unlock; } cur_token = 0; r = mailimf_envelope_fields_parse(headers, headers_len, &cur_token, &fields); if (r != MAILIMF_NO_ERROR) continue; msg->msg_fields = fields; } mailmbox_read_unlock(folder); return MAIL_NO_ERROR; unlock: mailmbox_read_unlock(folder); err: return res; }