+GSList *mbox_get_num_list(Folder *folder, FolderItem *item)
+{
+ GSList *mlist;
+ GList * l;
+ FILE * fp;
+ gchar * mbox_path;
+
+ mlist = NULL;
+
+ mbox_path = mbox_folder_get_path(item);
+
+ if (mbox_path == NULL)
+ return NULL;
+
+ mbox_purge_deleted(mbox_path);
+
+ fp = fopen(mbox_path, "rb");
+
+ if (fp == NULL) {
+ g_free(mbox_path);
+ return NULL;
+ }
+
+ mbox_lockread_file(fp, mbox_path);
+
+ mbox_cache_synchronize_from_file(fp, mbox_path, TRUE);
+
+ item->last_num = mbox_cache_get_count(mbox_path);
+
+ for(l = mbox_cache_get_msg_list(mbox_path) ; l != NULL ;
+ l = g_list_next(l)) {
+ struct _message * msg;
+
+ msg = (struct _message *) l->data;
+
+ if (MSG_IS_INVALID(msg->flags) || !MSG_IS_REALLY_DELETED(msg->flags)) {
+ mlist = g_slist_append(mlist, GINT_TO_POINTER(msg->msgnum));
+ } else {
+ MSG_SET_PERM_FLAGS(msg->flags, MSG_REALLY_DELETED);
+ }
+ }
+
+ mbox_unlock_file(fp, mbox_path);
+
+ g_free(mbox_path);
+
+ fclose(fp);
+
+ return mlist;
+}
+
+MsgInfo *mbox_fetch_msginfo(Folder *folder, FolderItem *item, gint num)
+{
+ gchar *mbox_path;
+ struct _message *msg;
+ FILE *src;
+ MsgInfo *msginfo;
+
+ g_return_val_if_fail(folder != NULL, NULL);
+ g_return_val_if_fail(item != NULL, NULL);
+
+ mbox_path = mbox_folder_get_path(item);
+
+ g_return_val_if_fail(mbox_path != NULL, NULL);
+
+ src = fopen(mbox_path, "rb");
+ if (src == NULL) {
+ g_free(mbox_path);
+ return NULL;
+ }
+ mbox_lockread_file(src, mbox_path);
+ mbox_cache_synchronize_from_file(src, mbox_path, TRUE);
+
+ msg = mbox_cache_get_msg(mbox_path, num);
+ if (msg == NULL) {
+ mbox_unlock_file(src, mbox_path);
+ fclose(src);
+ g_free(mbox_path);
+ return NULL;
+ }
+
+ fseek(src, msg->header, SEEK_SET);
+ msginfo = mbox_parse_msg(src, msg, item);
+
+ mbox_unlock_file(src, mbox_path);
+ fclose(src);
+ g_free(mbox_path);
+
+ return msginfo;
+}
+
+gboolean mbox_check_msgnum_validity(Folder *folder, FolderItem *item)
+{
+ mboxcache * old_cache;
+ gboolean scan_new = TRUE;
+ struct stat s;
+ gchar *filename;
+
+ filename = mbox_folder_get_path(item);
+
+ old_cache = mbox_cache_get_mbox(filename);
+
+ if (old_cache != NULL) {
+ if (stat(filename, &s) < 0) {
+ FILE_OP_ERROR(filename, "stat");
+ } else if (old_cache->mtime == s.st_mtime) {
+ debug_print("Folder is not modified.\n");
+ scan_new = FALSE;
+ }
+ }
+
+ g_free(filename);
+
+ return !scan_new;
+}
+