gchar *mh_fetch_msg (Folder *folder,
FolderItem *item,
gint num);
-MsgInfo *mh_fetch_msginfo (Folder *folder,
+MsgInfo *mh_get_msginfo (Folder *folder,
FolderItem *item,
gint num);
gint mh_add_msg (Folder *folder,
gchar *mh_get_new_msg_filename (FolderItem *dest);
-static GSList *mh_get_uncached_msgs (GHashTable *msg_table,
- FolderItem *item);
static MsgInfo *mh_parse_msg (const gchar *file,
FolderItem *item);
static void mh_scan_tree_recursive (FolderItem *item);
gpointer data);
+FolderClass mh_class =
+{
+ F_MH,
+ "mh",
+
+ /* Folder functions */
+ mh_folder_new,
+ mh_folder_destroy,
+ mh_scan_tree,
+ mh_create_tree,
+
+ /* FolderItem functions */
+ NULL,
+ NULL,
+ mh_create_folder,
+ mh_rename_folder,
+ mh_remove_folder,
+ mh_get_num_list,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+
+ /* Message functions */
+ mh_get_msginfo,
+ NULL,
+ mh_fetch_msg,
+ mh_add_msg,
+ mh_move_msg,
+ mh_move_msgs_with_dest,
+ mh_copy_msg,
+ mh_copy_msgs_with_dest,
+ mh_remove_msg,
+ NULL,
+ mh_remove_all_msg,
+ mh_is_msg_changed,
+ NULL,
+};
+
+FolderClass *mh_get_class()
+{
+ return &mh_class;
+}
+
Folder *mh_folder_new(const gchar *name, const gchar *path)
{
Folder *folder;
folder = (Folder *)g_new0(MHFolder, 1);
+ folder->class = &mh_class;
mh_folder_init(folder, name, path);
return folder;
static void mh_folder_init(Folder *folder, const gchar *name, const gchar *path)
{
- folder->type = F_MH;
-
folder_local_folder_init(folder, name, path);
-/* folder->get_msg_list = mh_get_msg_list; */
- folder->fetch_msg = mh_fetch_msg;
- folder->fetch_msginfo = mh_fetch_msginfo;
- folder->add_msg = mh_add_msg;
- folder->move_msg = mh_move_msg;
- folder->move_msgs_with_dest = mh_move_msgs_with_dest;
- folder->copy_msg = mh_copy_msg;
- folder->copy_msgs_with_dest = mh_copy_msgs_with_dest;
- folder->remove_msg = mh_remove_msg;
- folder->remove_all_msg = mh_remove_all_msg;
- folder->is_msg_changed = mh_is_msg_changed;
-/* folder->scan = mh_scan_folder; */
- folder->get_num_list = mh_get_num_list;
- folder->scan_tree = mh_scan_tree;
- folder->create_tree = mh_create_tree;
- folder->create_folder = mh_create_folder;
- folder->rename_folder = mh_rename_folder;
- folder->remove_folder = mh_remove_folder;
- folder->destroy = mh_folder_destroy;
}
void mh_get_last_num(Folder *folder, FolderItem *item)
return nummsgs;
}
-GSList *mh_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache)
-{
- GSList *mlist;
- GHashTable *msg_table;
- gchar *path;
- struct stat s;
- gboolean scan_new = TRUE;
-#ifdef MEASURE_TIME
- struct timeval tv_before, tv_after, tv_result;
-
- gettimeofday(&tv_before, NULL);
-#endif
-
- g_return_val_if_fail(item != NULL, NULL);
-
- path = folder_item_get_path(item);
- if (stat(path, &s) < 0) {
- FILE_OP_ERROR(path, "stat");
- } else {
- time_t mtime;
-
- mtime = MAX(s.st_mtime, s.st_ctime);
- if (item->mtime == mtime) {
- debug_print("Folder is not modified.\n");
- scan_new = FALSE;
- } else
- item->mtime = mtime;
- }
- g_free(path);
-
- if (use_cache && !scan_new) {
- mlist = procmsg_read_cache(item, FALSE);
- if (!mlist)
- mlist = mh_get_uncached_msgs(NULL, item);
- } else if (use_cache) {
- GSList *newlist;
-
- mlist = procmsg_read_cache(item, TRUE);
- msg_table = procmsg_msg_hash_table_create(mlist);
-
- newlist = mh_get_uncached_msgs(msg_table, item);
- if (msg_table)
- g_hash_table_destroy(msg_table);
-
- mlist = g_slist_concat(mlist, newlist);
- } else
- mlist = mh_get_uncached_msgs(NULL, item);
-
- procmsg_set_flags(mlist, item);
-
-#ifdef MEASURE_TIME
- gettimeofday(&tv_after, NULL);
-
- timersub(&tv_after, &tv_before, &tv_result);
- g_print("mh_get_msg_list: %s: elapsed time: %ld.%06ld sec\n",
- item->path, tv_result.tv_sec, tv_result.tv_usec);
-#endif
-
- return mlist;
-}
-
gchar *mh_fetch_msg(Folder *folder, FolderItem *item, gint num)
{
gchar *path;
return file;
}
-MsgInfo *mh_fetch_msginfo(Folder *folder, FolderItem *item, gint num)
+MsgInfo *mh_get_msginfo(Folder *folder, FolderItem *item, gint num)
{
- gchar *path;
- gchar *file;
- MsgFlags flags;
MsgInfo *msginfo;
- struct stat s;
+ gchar *file;
g_return_val_if_fail(item != NULL, NULL);
g_return_val_if_fail(num > 0, NULL);
- path = folder_item_get_path(item);
- file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
- g_free(path);
- if (!is_file_exist(file)) {
- g_free(file);
- return NULL;
- }
-
- folder_item_set_default_flags(item, &flags);
- msginfo = procheader_parse_file(file, flags, TRUE, FALSE);
- if(!msginfo) {
- g_free(file);
- return NULL;
- }
+ file = mh_fetch_msg(folder, item, num);
+ if (!file) return NULL;
- msginfo->msgnum = num;
- msginfo->folder = item;
-
- if (stat(file, &s) < 0) {
- FILE_OP_ERROR(file, "stat");
- msginfo->size = 0;
- msginfo->mtime = 0;
- } else {
- msginfo->size = s.st_size;
- msginfo->mtime = s.st_mtime;
- }
+ msginfo = mh_parse_msg(file, item);
+ if (msginfo)
+ msginfo->msgnum = num;
g_free(file);
if (link(file, destfile) < 0) {
if (copy_file(file, destfile, TRUE) < 0) {
- g_warning(_("can't copy message %s to %s\n"),
+ g_warning("can't copy message %s to %s\n",
file, destfile);
g_free(destfile);
return -1;
g_return_val_if_fail(msginfo != NULL, -1);
if (msginfo->folder == dest) {
- g_warning(_("the src folder is identical to the dest.\n"));
+ g_warning("the src folder is identical to the dest.\n");
return -1;
}
ret = mh_add_msg(folder, dest, srcfile, FALSE);
g_free(srcfile);
- if (ret != -1) {
- gchar *destdir;
- FILE *fp;
-
- destdir = folder_item_get_path(dest);
- if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
- g_warning(_("Can't open mark file.\n"));
- else {
- SET_DEST_MSG_FLAGS(fp, dest, msginfo);
- fclose(fp);
- }
- g_free(destdir);
-
+ if (ret != -1)
ret = folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
- }
return ret;
}
msginfo = (MsgInfo *)cur->data;
if (msginfo->folder == dest) {
- g_warning(_("the src folder is identical to the dest.\n"));
+ g_warning("the src folder is identical to the dest.\n");
continue;
}
debug_print("Moving message %s%c%d to %s ...\n",
g_return_val_if_fail(msginfo != NULL, -1);
if (msginfo->folder == dest) {
- g_warning(_("the src folder is identical to the dest.\n"));
+ g_warning("the src folder is identical to the dest.\n");
return -1;
}
msginfo->msgnum, dest->path);
- if (copy_file(srcfile, destfile, TRUE) < 0) {
+ if ((MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags))
+ && dest->stype != F_QUEUE && dest->stype != F_DRAFT) {
+ if (procmsg_remove_special_headers(srcfile, destfile) !=0) {
+ g_free(srcfile);
+ g_free(destfile);
+ return -1;
+ }
+ } else if (copy_file(srcfile, destfile, TRUE) < 0) {
FILE_OP_ERROR(srcfile, "copy");
g_free(srcfile);
g_free(destfile);
return -1;
}
+
if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
if (chmod(destfile, prefs->folder_chmod) < 0)
FILE_OP_ERROR(destfile, "chmod");
msginfo = (MsgInfo *)cur->data;
if (msginfo->folder == dest) {
- g_warning(_("the src folder is identical to the dest.\n"));
+ g_warning("the src folder is identical to the dest.\n");
continue;
}
debug_print("Copying message %s%c%d to %s ...\n",
{ \
if (!is_dir_exist(dir)) { \
if (is_file_exist(dir)) { \
- g_warning(_("File `%s' already exists.\n" \
- "Can't create folder."), dir); \
+ g_warning("File `%s' already exists.\n" \
+ "Can't create folder.", dir); \
return -1; \
} \
if (make_dir(dir) < 0) \
gchar *path;
gchar *fullpath;
FolderItem *new_item;
+ gchar *mh_sequences_filename;
+ FILE *mh_sequences_file;
g_return_val_if_fail(folder != NULL, NULL);
g_return_val_if_fail(parent != NULL, NULL);
g_return_val_if_fail(name != NULL, NULL);
path = folder_item_get_path(parent);
- if (!is_dir_exist(path))
- make_dir_hier(path);
-
+ if (!is_dir_exist(path))
+ if (make_dir_hier(path) != 0)
+ return NULL;
+
fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, name, NULL);
g_free(path);
path = g_strdup(name);
new_item = folder_item_new(folder, name, path);
folder_item_append(parent, new_item);
+
+ g_free(path);
+
+ path = folder_item_get_path(new_item);
+ mh_sequences_filename = g_strconcat(path, G_DIR_SEPARATOR_S,
+ ".mh_sequences", NULL);
+ if ((mh_sequences_file = fopen(mh_sequences_filename, "a+b")) != NULL) {
+ fclose(mh_sequences_file);
+ }
+ g_free(mh_sequences_filename);
g_free(path);
return new_item;
return 0;
}
-
-static GSList *mh_get_uncached_msgs(GHashTable *msg_table, FolderItem *item)
-{
- gchar *path;
- DIR *dp;
- struct dirent *d;
- struct stat s;
- GSList *newlist = NULL;
- GSList *last = NULL;
- MsgInfo *msginfo;
- gint n_newmsg = 0;
- gint num;
-
- g_return_val_if_fail(item != NULL, NULL);
-
- path = folder_item_get_path(item);
- g_return_val_if_fail(path != NULL, NULL);
- if (change_dir(path) < 0) {
- g_free(path);
- return NULL;
- }
- g_free(path);
-
- if ((dp = opendir(".")) == NULL) {
- FILE_OP_ERROR(item->path, "opendir");
- return NULL;
- }
-
- debug_print("\tSearching uncached messages... ");
-
- if (msg_table) {
- while ((d = readdir(dp)) != NULL) {
- if ((num = to_number(d->d_name)) < 0) continue;
- if (stat(d->d_name, &s) < 0) {
- FILE_OP_ERROR(d->d_name, "stat");
- continue;
- }
- if (!S_ISREG(s.st_mode)) continue;
-
- msginfo = g_hash_table_lookup
- (msg_table, GUINT_TO_POINTER(num));
-
- if (!msginfo) {
- /* not found in the cache (uncached message) */
- msginfo = mh_parse_msg(d->d_name, item);
- if (!msginfo) continue;
-
- if (!newlist)
- last = newlist =
- g_slist_append(NULL, msginfo);
- else {
- last = g_slist_append(last, msginfo);
- last = last->next;
- }
- n_newmsg++;
- }
- }
- } else {
- /* discard all previous cache */
- while ((d = readdir(dp)) != NULL) {
- if (to_number(d->d_name) < 0) continue;
- if (stat(d->d_name, &s) < 0) {
- FILE_OP_ERROR(d->d_name, "stat");
- continue;
- }
- if (!S_ISREG(s.st_mode)) continue;
-
- msginfo = mh_parse_msg(d->d_name, item);
- if (!msginfo) continue;
-
- if (!newlist)
- last = newlist = g_slist_append(NULL, msginfo);
- else {
- last = g_slist_append(last, msginfo);
- last = last->next;
- }
- n_newmsg++;
- }
- }
-
- closedir(dp);
-
- if (n_newmsg)
- debug_print("%d uncached message(s) found.\n", n_newmsg);
- else
- debug_print("done.\n");
-
- /* sort new messages in numerical order */
- if (newlist) {
- debug_print("\tSorting uncached messages in numerical order... ");
- newlist = g_slist_sort
- (newlist, (GCompareFunc)procmsg_cmp_msgnum_for_sort);
- debug_print("done.\n");
- }
-
- return newlist;
-}
-
static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
{
struct stat s;