2006-02-05 [colin] 2.0.0cvs17
[claws.git] / src / imap.c
index e02a2fad77e61928ae9f9b6dfda2b769daa15831..c428a0b9d3ca8e755fe3d28251e74320fc35bd20 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
@@ -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)
@@ -1099,6 +1104,9 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                        g_relation_insert(relation, fileinfo->msginfo != NULL ? 
                                          (gpointer) fileinfo->msginfo : (gpointer) fileinfo,
                                          GINT_TO_POINTER(dest->last_num + 1));
+               if (new_uid == 0) {
+                       new_uid = dest->last_num+1;
+               }
                if (last_uid < new_uid)
                        last_uid = new_uid;
                if (file_is_tmp)
@@ -1109,6 +1117,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);
@@ -1239,18 +1248,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;
@@ -3094,6 +3113,8 @@ gint imap_get_num_list(Folder *folder, FolderItem *_item, GSList **msgnum_list,
                        ok = imap_status(session, IMAP_FOLDER(folder), item->item.path, item,
                                 &exists, &uid_next, &uid_val, NULL, FALSE);
                }
+               item->item.last_num = uid_next - 1;
+               
                item->use_cache = (time_t)0;
                if (ok != IMAP_SUCCESS) {
                        statusbar_pop_all();
@@ -3118,8 +3139,9 @@ gint imap_get_num_list(Folder *folder, FolderItem *_item, GSList **msgnum_list,
 
        /* If old uid_next matches new uid_next we can be sure no message
           was added to the folder */
-       if (( selected_folder && !session->folder_content_changed) ||
-           (!selected_folder && uid_next == item->uid_next)) {
+       debug_print("uid_next is %d and item->uid_next %d \n", 
+               uid_next, item->uid_next);
+       if (uid_next == item->uid_next) {
                nummsgs = g_slist_length(item->uid_list);
 
                /* If number of messages is still the same we
@@ -3351,6 +3373,7 @@ gboolean imap_scan_required(Folder *folder, FolderItem *_item)
                item->c_uid_next = uid_next;
                item->c_uid_validity = uid_val;
                item->c_unseen = unseen;
+               item->item.last_num = uid_next - 1;
                debug_print("uidnext %d, item->uid_next %d, exists %d, item->item.total_msgs %d\n", 
                        uid_next, item->uid_next, exists, item->item.total_msgs);
                if ((uid_next != item->uid_next) || (exists != item->item.total_msgs)) {