2006-02-06 [colin] 2.0.0cvs21
[claws.git] / src / imap.c
index ac9d74063c68bb8196846bd30e6b71fef8e37164..f637763bcca145bee600dd315ccebe68803476e0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -932,7 +932,7 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                make_dir_hier(path);
        filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
        g_free(path);
-
+       debug_print("trying to fetch cached %s\n", filename);
        if (is_file_exist(filename)) {
                /* see whether the local file represents the whole message
                 * or not. As the IMAP server reports size with \r chars,
@@ -1069,6 +1069,11 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                                        unlock_session();
                                        return -1;
                                }
+                       }  else if (!(MSG_IS_QUEUED(*fileinfo->flags) 
+                                     || MSG_IS_DRAFT(*fileinfo->flags))
+                                   && (folder_has_parent_of_type(dest, F_QUEUE)
+                                   || folder_has_parent_of_type(dest, F_DRAFT))) {
+                               return -1;
                        } 
                }
                if (real_file == NULL)
@@ -1093,6 +1098,24 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                        statusbar_progress_all(0,0,0);
                        statusbar_pop_all();
                        return -1;
+               } else {
+                       debug_print("appended new message as %d\n", new_uid);
+                       /* put the local file in the imapcache, so that we don't
+                        * have to fetch it back later. */
+                       if (new_uid > 0) {
+                               gchar *cache_path = folder_item_get_path(dest);
+                               if (!is_dir_exist(cache_path))
+                                       make_dir_hier(cache_path);
+                               if (is_dir_exist(cache_path)) {
+                                       gchar *cache_file = g_strconcat(
+                                               cache_path, G_DIR_SEPARATOR_S, 
+                                               itos(new_uid), NULL);
+                                       copy_file(real_file, cache_file, TRUE);
+                                       debug_print("copied to cache: %s\n", cache_file);
+                                       g_free(cache_file);
+                               }
+                               g_free(cache_path);
+                       }
                }
 
                if (relation != NULL)
@@ -1112,6 +1135,7 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
        statusbar_progress_all(0,0,0);
        statusbar_pop_all();
        
+       imap_cmd_expunge(session);
        unlock_session();
        
        g_free(destdir);
@@ -1242,18 +1266,28 @@ static gint imap_copy_msgs(Folder *folder, FolderItem *dest,
        msginfo = (MsgInfo *)msglist->data;
        g_return_val_if_fail(msginfo->folder != NULL, -1);
 
+       /* if from/to are the same "type" (with or without extra headers),
+        * copy them via imap */
        if (folder == msginfo->folder->folder &&
            !folder_has_parent_of_type(msginfo->folder, F_DRAFT) &&
-           !folder_has_parent_of_type(msginfo->folder, F_QUEUE)) {
+           !folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
+           !folder_has_parent_of_type(dest, F_DRAFT) &&
+           !folder_has_parent_of_type(dest, F_QUEUE)) {
+               ret = imap_do_copy_msgs(folder, dest, msglist, relation);
+               return ret;
+       } else if (folder == msginfo->folder->folder &&
+           (folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
+            folder_has_parent_of_type(msginfo->folder, F_QUEUE)) && 
+           (folder_has_parent_of_type(dest, F_DRAFT) ||
+            folder_has_parent_of_type(dest, F_QUEUE))) {
                ret = imap_do_copy_msgs(folder, dest, msglist, relation);
                return ret;
        }
-
+       /* else reupload them */
        file_list = procmsg_get_message_file_list(msglist);
        g_return_val_if_fail(file_list != NULL, -1);
 
        ret = imap_add_msgs(folder, dest, file_list, relation);
-
        procmsg_message_file_list_free(file_list);
 
        return ret;