* src/mbox.c
[claws.git] / src / mbox.c
index a5de8eff89315284cfd4a3d2d8bd644f78c4af95..59cae3b1f81d30b059cadd90356834c8fc62d9f1 100644 (file)
                fclose(tmp_fp); \
                fclose(mbox_fp); \
                unlink(tmp_file); \
+               g_free(tmp_file); \
                return -1; \
        } \
 }
 
-gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table)
+gint proc_mbox(FolderItem *dest, const gchar *mbox)
 {
        FILE *mbox_fp;
        gchar buf[MSGBUFSIZE], from_line[MSGBUFSIZE];
@@ -66,9 +67,9 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table)
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(mbox != NULL, -1);
 
-       debug_print(_("Getting messages from %s into %s...\n"), mbox, dest->path);
+       debug_print("Getting messages from %s into %s...\n", mbox, dest->path);
 
-       if ((mbox_fp = fopen(mbox, "r")) == NULL) {
+       if ((mbox_fp = fopen(mbox, "rb")) == NULL) {
                FILE_OP_ERROR(mbox, "fopen");
                return -1;
        }
@@ -100,22 +101,23 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table)
        do {
                FILE *tmp_fp;
                FolderItem *dropfolder;
-               gchar *startp, *endp, *rpath;
                gint empty_line;
                gint val;
                gboolean is_next_msg = FALSE;
                gint msgnum;
 
-               if ((tmp_fp = fopen(tmp_file, "w")) == NULL) {
+               if ((tmp_fp = fopen(tmp_file, "wb")) == NULL) {
                        FILE_OP_ERROR(tmp_file, "fopen");
                        g_warning(_("can't open temporary file\n"));
                        fclose(mbox_fp);
+                       g_free(tmp_file);
                        return -1;
                }
                if (change_file_mode_rw(tmp_fp, tmp_file) < 0)
                        FILE_OP_ERROR(tmp_file, "chmod");
 
                /* convert unix From into Return-Path */
+               /*
                startp = from_line + 5;
                endp = strchr(startp, ' ');
                if (endp == NULL)
@@ -126,6 +128,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table)
                g_snprintf(from_line, sizeof(from_line),
                           "Return-Path: %s\n", rpath);
                g_free(rpath);
+               */
 
                FPUTS_TO_TMP_ABORT_IF_FAIL(from_line);
                FPUTS_TO_TMP_ABORT_IF_FAIL(buf);
@@ -196,51 +199,42 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table)
                        g_warning(_("can't write to temporary file\n"));
                        fclose(mbox_fp);
                        unlink(tmp_file);
+                       g_free(tmp_file);
                        return -1;
                }
 
-               if (folder_table) {
-                       if (prefs_filtering == NULL) {
-                               /* old filtering */
-                               dropfolder = filter_get_dest_folder
-                                       (prefs_common.fltlist, tmp_file);
-                               if (!dropfolder ||
-                                   !strcmp(dropfolder->path, FILTER_NOT_RECEIVE))
-                                       dropfolder = dest;
-                               val = GPOINTER_TO_INT(g_hash_table_lookup
-                                                     (folder_table, dropfolder));
-                               if (val == 0) {
-                                       folder_item_scan(dropfolder);
-                                       g_hash_table_insert(folder_table, dropfolder,
-                                                           GINT_TO_POINTER(1));
-                               }
-                       }
-                       else {
-                               /* new filtering */
+               if (global_processing == NULL) {
+                       /* old filtering */
+                       dropfolder = filter_get_dest_folder
+                               (prefs_common.fltlist, tmp_file);
+                       if (!dropfolder ||
+                           !strcmp(dropfolder->path, FILTER_NOT_RECEIVE))
                                dropfolder = dest;
-                       }
-               } else
-                       dropfolder = dest;
+               } else {
+                       /* CLAWS: new filtering */
+                       dropfolder = folder_get_default_processing();
+               }
 
-               if (msgnum =folder_item_add_msg(dropfolder, tmp_file) < 0) {
+                       
+               if ((msgnum = folder_item_add_msg(dropfolder, tmp_file, TRUE)) < 0) {
                        fclose(mbox_fp);
                        unlink(tmp_file);
+                       g_free(tmp_file);
                        return -1;
                }
-               
-               if (prefs_filtering != NULL) {
-                       /* new filtering */
-                       if (folder_table) {
-                               filter_message(prefs_filtering, dropfolder,
-                                              msgnum, folder_table);
-                       }
+
+               if (global_processing) {
+                       /* CLAWS: new filtering */
+                       filter_message(global_processing, dest,
+                                      msgnum);
                }
 
                msgs++;
        } while (from_line[0] != '\0');
 
+       g_free(tmp_file);
        fclose(mbox_fp);
-       debug_print(_("%d messages found.\n"), msgs);
+       debug_print("%d messages found.\n", msgs);
 
        return msgs;
 }
@@ -255,7 +249,7 @@ gint lock_mbox(const gchar *base, LockType type)
                FILE *lockfp;
 
                lockfile = g_strdup_printf("%s.%d", base, getpid());
-               if ((lockfp = fopen(lockfile, "w")) == NULL) {
+               if ((lockfp = fopen(lockfile, "wb")) == NULL) {
                        FILE_OP_ERROR(lockfile, "fopen");
                        g_warning(_("can't create lock file %s\n"), lockfile);
                        g_warning(_("use 'flock' instead of 'file' if possible.\n"));
@@ -365,7 +359,7 @@ gint unlock_mbox(const gchar *base, gint fd, LockType type)
 
 gint copy_mbox(const gchar *src, const gchar *dest)
 {
-       return copy_file(src, dest);
+       return copy_file(src, dest, TRUE);
 }
 
 void empty_mbox(const gchar *mbox)
@@ -374,7 +368,7 @@ void empty_mbox(const gchar *mbox)
                FILE *fp;
 
                FILE_OP_ERROR(mbox, "truncate");
-               if ((fp = fopen(mbox, "w")) == NULL) {
+               if ((fp = fopen(mbox, "wb")) == NULL) {
                        FILE_OP_ERROR(mbox, "fopen");
                        g_warning(_("can't truncate mailbox to zero.\n"));
                        return;
@@ -397,15 +391,15 @@ gint export_to_mbox(FolderItem *src, const gchar *mbox)
        g_return_val_if_fail(src->folder != NULL, -1);
        g_return_val_if_fail(mbox != NULL, -1);
 
-       debug_print(_("Exporting messages from %s into %s...\n"),
+       debug_print("Exporting messages from %s into %s...\n",
                    src->path, mbox);
 
-       if ((mbox_fp = fopen(mbox, "w")) == NULL) {
+       if ((mbox_fp = fopen(mbox, "wb")) == NULL) {
                FILE_OP_ERROR(mbox, "fopen");
                return -1;
        }
 
-       mlist = src->folder->get_msg_list(src->folder, src, TRUE);
+       mlist = folder_item_get_msg_list(src);
 
        for (cur = mlist; cur != NULL; cur = cur->next) {
                msginfo = (MsgInfo *)cur->data;