static int get_flags(mailmessage * msg_info, struct mail_flags ** result) { chashdatum key; chashdatum value; struct maildir * md; struct mail_flags * flags; struct maildir_session_state_data * data; struct maildir_msg * md_msg; int r; uint32_t driver_flags; clist * ext; if (msg_info->msg_flags != NULL) { * result = msg_info->msg_flags; return MAIL_NO_ERROR; } data = get_session_data(msg_info); flags = mail_flags_store_get(data->md_flags_store, msg_info->msg_index); if (flags != NULL) { msg_info->msg_flags = flags; * result = msg_info->msg_flags; return MAIL_NO_ERROR; } md = get_maildir_session(msg_info); if (md == NULL) return MAIL_ERROR_BAD_STATE; key.data = msg_info->msg_uid; key.len = strlen(msg_info->msg_uid); r = chash_get(md->mdir_msg_hash, &key, &value); if (r < 0) return MAIL_ERROR_MSG_NOT_FOUND; md_msg = value.data; driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags); ext = clist_new(); if (ext == NULL) return MAIL_ERROR_MEMORY; msg_info->msg_flags = mail_flags_new(driver_flags, ext); * result = msg_info->msg_flags; return MAIL_NO_ERROR; }
static int get_envelopes_list(mailsession * session, struct mailmessage_list * env_list) { int r; struct maildir * md; unsigned int i; int res; check_folder(session); md = get_maildir_session(session); if (md == NULL) { res = MAIL_ERROR_BAD_STATE; goto err; } r = maildir_update(md); if (r != MAILDIR_NO_ERROR) { res = maildirdriver_maildir_error_to_mail_error(r); goto err; } r = maildriver_generic_get_envelopes_list(session, env_list); if (r != MAIL_NO_ERROR) { res = r; goto err; } for(i = 0 ; i < carray_count(env_list->msg_tab) ; i++) { struct maildir_msg * md_msg; mailmessage * msg; uint32_t driver_flags; clist * ext; chashdatum key; chashdatum value; msg = carray_get(env_list->msg_tab, i); key.data = msg->msg_uid; key.len = strlen(msg->msg_uid); r = chash_get(md->mdir_msg_hash, &key, &value); if (r < 0) continue; md_msg = value.data; driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags); if (msg->msg_flags == NULL) { ext = clist_new(); if (ext == NULL) { res = MAIL_ERROR_MEMORY; continue; } msg->msg_flags = mail_flags_new(driver_flags, ext); if (msg->msg_flags == NULL) { clist_free(ext); res = MAIL_ERROR_MEMORY; continue; } if ((md_msg->msg_flags & MAILDIR_FLAG_NEW) != 0) { mail_flags_store_set(get_data(session)->md_flags_store, msg); } } else { msg->msg_flags->fl_flags &= MAIL_FLAG_FORWARDED; msg->msg_flags->fl_flags |= driver_flags; } } return MAIL_NO_ERROR; err: return res; }
static int get_flags(mailmessage * msg_info, struct mail_flags ** result) { struct mail_cache_db * cache_db_flags; chashdatum key; chashdatum value; struct maildir * md; struct mail_flags * flags; struct maildir_cached_session_state_data * data; struct maildir_msg * md_msg; int r; uint32_t driver_flags; char filename_flags[PATH_MAX]; char keyname[PATH_MAX]; MMAPString * mmapstr; if (msg_info->msg_flags != NULL) { * result = msg_info->msg_flags; return MAIL_NO_ERROR; } data = get_cached_session_data(msg_info); flags = mail_flags_store_get(data->md_flags_store, msg_info->msg_index); if (flags != NULL) { msg_info->msg_flags = flags; * result = msg_info->msg_flags; return MAIL_NO_ERROR; } snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", data->md_flags_directory, MAIL_DIR_SEPARATOR, data->md_quoted_mb, MAIL_DIR_SEPARATOR, FLAGS_NAME); r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); if (r < 0) return MAIL_ERROR_FILE; snprintf(keyname, PATH_MAX, "%s-flags", msg_info->msg_uid); mmapstr = mmap_string_new(""); if (mmapstr == NULL) { mail_cache_db_close_unlock(filename_flags, cache_db_flags); return MAIL_ERROR_MEMORY; } r = generic_cache_flags_read(cache_db_flags, mmapstr, keyname, &flags); mmap_string_free(mmapstr); mail_cache_db_close_unlock(filename_flags, cache_db_flags); if (r != MAIL_NO_ERROR) { flags = mail_flags_new_empty(); if (flags == NULL) return MAIL_ERROR_MEMORY; } md = get_maildir_session(msg_info); if (md == NULL) return MAIL_ERROR_BAD_STATE; key.data = msg_info->msg_uid; key.len = (unsigned int) strlen(msg_info->msg_uid); r = chash_get(md->mdir_msg_hash, &key, &value); if (r < 0) return MAIL_ERROR_MSG_NOT_FOUND; md_msg = value.data; driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags); flags->fl_flags = driver_flags; msg_info->msg_flags = flags; * result = msg_info->msg_flags; return MAIL_NO_ERROR; }