2009-03-30 [colin] 3.7.1cvs30
[claws.git] / src / imap.c
index 2d20e9c5259505429d42aca7e660d0e1d888b45e..712d0fdb150a54d405f15fb5b230b44cb47a4f23 100644 (file)
@@ -229,6 +229,8 @@ static gint         imap_remove_msgs        (Folder         *folder,
                                         FolderItem     *dest, 
                                         MsgInfoList    *msglist, 
                                         GRelation      *relation);
+static gint    imap_expunge            (Folder         *folder, 
+                                        FolderItem     *dest);
 static gint    imap_remove_all_msg     (Folder         *folder, 
                                         FolderItem     *item);
 
@@ -382,7 +384,7 @@ static gint imap_cmd_store  (IMAPSession    *session,
                                 IMAPFlags flags,
                                 GSList *tags,
                                 int do_add);
-static gint imap_cmd_expunge   (IMAPSession    *session);
+static gint imap_cmd_expunge   (IMAPSession    *session, gboolean force);
 
 static void imap_path_separator_subst          (gchar          *str,
                                                 gchar           separator);
@@ -476,6 +478,7 @@ FolderClass *imap_get_class(void)
                imap_class.copy_msgs = imap_copy_msgs;
                imap_class.remove_msg = imap_remove_msg;
                imap_class.remove_msgs = imap_remove_msgs;
+               imap_class.expunge = imap_expunge;
                imap_class.remove_all_msg = imap_remove_all_msg;
                imap_class.is_msg_changed = imap_is_msg_changed;
                imap_class.change_flags = imap_change_flags;
@@ -1166,7 +1169,7 @@ static gint imap_session_authenticate(IMAPSession *session,
        acc_pass = account->passwd;
 try_again:
        pass = acc_pass;
-       if (!pass && account->imap_auth_type != IMAP_AUTH_ANON) {
+       if (!pass && account->imap_auth_type != IMAP_AUTH_ANON && account->imap_auth_type != IMAP_AUTH_GSSAPI) {
                gchar *tmp_pass;
                tmp_pass = input_dialog_query_password_keep(account->recv_server, 
                                                            account->userid,
@@ -1175,7 +1178,7 @@ try_again:
                        return MAILIMAP_NO_ERROR;
                Xstrdup_a(pass, tmp_pass, {g_free(tmp_pass); return MAILIMAP_NO_ERROR;});
                g_free(tmp_pass);
-       } else if (account->imap_auth_type == IMAP_AUTH_ANON) {
+       } else if (account->imap_auth_type == IMAP_AUTH_ANON || account->imap_auth_type == IMAP_AUTH_GSSAPI) {
                pass = "";
        }
        statuswindow_print_all(_("Connecting to IMAP4 server %s...\n"),
@@ -1995,7 +1998,7 @@ static gint imap_do_remove_msgs(Folder *folder, FolderItem *dest,
                        return ok;
                }
        } /* else we just need to expunge */
-       ok = imap_cmd_expunge(session);
+       ok = imap_cmd_expunge(session, folder->account->imap_use_trash);
        if (ok != MAILIMAP_NO_ERROR) {
                log_warning(LOG_PROTOCOL, _("can't expunge\n"));
                g_free(destdir);
@@ -2085,7 +2088,7 @@ static gint imap_scan_tree_real(Folder *folder, gboolean subs_only)
 
        if (folder->account->imap_dir && *folder->account->imap_dir) {
                gchar *real_path;
-               int r;
+               int r = MAILIMAP_NO_ERROR;
                clist * lep_list;
 
                Xstrdup_a(root_folder, folder->account->imap_dir, {return -1;});
@@ -2167,7 +2170,7 @@ static gint imap_scan_tree_recursive(IMAPSession *session, FolderItem *item, gbo
        gchar separator;
        gchar wildcard[3];
        clist * lep_list;
-       int r;
+       int r = MAILIMAP_NO_ERROR;
        
        g_return_val_if_fail(item != NULL, -1);
        g_return_val_if_fail(item->folder != NULL, -1);
@@ -2320,7 +2323,7 @@ GList *imap_scan_subtree(Folder *folder, FolderItem *item, gboolean unsubs_only,
        GSList *item_list = NULL, *cur;
        GList *child_list = NULL, *tmplist = NULL;
        GSList *sub_list = NULL;
-       int r;
+       int r = MAILIMAP_NO_ERROR;
 
        if (!session)
                return NULL;
@@ -2588,7 +2591,7 @@ static FolderItem *imap_create_folder(Folder *folder, FolderItem *parent,
        gchar separator;
        gchar *new_name;
        const gchar *p;
-       gint ok;
+       gint ok = MAILIMAP_NO_ERROR;
        gboolean no_select = FALSE, no_sub = FALSE;
        gboolean exist = FALSE;
        
@@ -2737,7 +2740,7 @@ static gint imap_rename_folder(Folder *folder, FolderItem *item,
        gchar *new_cache_dir;
        IMAPSession *session;
        gchar separator;
-       gint ok;
+       gint ok = MAILIMAP_NO_ERROR;
        gint exists, recent, unseen;
        guint32 uid_validity;
 
@@ -2827,7 +2830,7 @@ static gint imap_rename_folder(Folder *folder, FolderItem *item,
 gint imap_subscribe(Folder *folder, FolderItem *item, gchar *rpath, gboolean sub)
 {
        gchar *path;
-       gint r = -1;
+       gint r = MAILIMAP_NO_ERROR;
        IMAPSession *session;
        debug_print("getting session...\n");
 
@@ -2859,7 +2862,7 @@ gint imap_subscribe(Folder *folder, FolderItem *item, gchar *rpath, gboolean sub
 
 static gint imap_remove_folder_real(Folder *folder, FolderItem *item)
 {
-       gint ok;
+       gint ok = MAILIMAP_NO_ERROR;
        IMAPSession *session;
        gchar *path;
        gchar *cache_dir;
@@ -2891,7 +2894,10 @@ static gint imap_remove_folder_real(Folder *folder, FolderItem *item)
        }
        ok = imap_cmd_delete(session, path);
        if (ok != MAILIMAP_NO_ERROR && !is_fatal(ok)) {
-               gchar *tmp = g_strdup_printf("%s%c", path, 
+               gchar *tmp = NULL;
+               
+               ok = MAILIMAP_NO_ERROR;
+               tmp = g_strdup_printf("%s%c", path, 
                                imap_get_path_separator(session, IMAP_FOLDER(folder), path, &ok));
                g_free(path);
                path = tmp;
@@ -3005,10 +3011,9 @@ static void *imap_get_uncached_messages_thread(void *data)
                                g_slist_free(tags);
                                continue;
                        }
-                       if (tags != NULL) {
-                               g_slist_free(msginfo->tags);
-                               msginfo->tags = NULL;
-                       }
+                       g_slist_free(msginfo->tags);
+                       msginfo->tags = NULL;
+
                        for (cur = tags; cur; cur = cur->next) {
                                gchar *real_tag = imap_modified_utf7_to_utf8(cur->data, TRUE);
                                gint id = 0;
@@ -3018,12 +3023,14 @@ static void *imap_get_uncached_messages_thread(void *data)
                                        got_alien_tags = TRUE;
                                }
                                if (!g_slist_find(msginfo->tags, GINT_TO_POINTER(id))) {
-                                       msginfo->tags = g_slist_append(
+                                       msginfo->tags = g_slist_prepend(
                                                        msginfo->tags,
                                                        GINT_TO_POINTER(id));
                                }
                                g_free(real_tag);
                        }
+                       if (msginfo->tags)
+                               msginfo->tags = g_slist_reverse(msginfo->tags);
                        slist_free_strings(tags);
                        g_slist_free(tags);
                        msginfo->folder = item;
@@ -3160,7 +3167,7 @@ gchar imap_get_path_separator_for_item(FolderItem *item)
        IMAPFolder *imap_folder = NULL;
        IMAPSession *session = NULL;
        gchar result = '/';
-       gint ok;
+       gint ok = MAILIMAP_NO_ERROR;
        if (!item)
                return '/';
        folder = item->folder;
@@ -3211,7 +3218,7 @@ static gchar imap_refresh_path_separator(IMAPSession *session, IMAPFolder *folde
 static gchar imap_get_path_separator(IMAPSession *session, IMAPFolder *folder, const gchar *path, gint *ok)
 {
        gchar separator = '/';
-
+       *ok = MAILIMAP_NO_ERROR;
        if (folder->last_seen_separator == 0) {
                folder->last_seen_separator = imap_refresh_path_separator(session, folder, "", ok);
        }
@@ -3232,10 +3239,12 @@ static gchar *imap_get_real_path(IMAPSession *session, IMAPFolder *folder, const
 {
        gchar *real_path = NULL;
        gchar separator;
-
+       
        g_return_val_if_fail(folder != NULL, NULL);
        g_return_val_if_fail(path != NULL, NULL);
 
+       *ok = MAILIMAP_NO_ERROR;
+       
        real_path = imap_utf8_to_modified_utf7(path, FALSE);
        separator = imap_get_path_separator(session, folder, path, ok);
        if (*ok == MAILIMAP_NO_ERROR)
@@ -3328,7 +3337,7 @@ static gint imap_select(IMAPSession *session, IMAPFolder *folder,
                        gboolean block)
 {
        gchar *real_path;
-       gint ok;
+       gint ok = MAILIMAP_NO_ERROR;
        gint exists_, recent_, unseen_;
        guint32 uid_validity_;
        gint can_create_flags_;
@@ -3403,7 +3412,7 @@ static gint imap_status(IMAPSession *session, IMAPFolder *folder,
                        guint32 *uid_next, guint32 *uid_validity,
                        gint *unseen, gboolean block)
 {
-       int r;
+       int r = MAILIMAP_NO_ERROR;
        clistiter * iter;
        struct mailimap_mailbox_data_status * data_status;
        int got_values;
@@ -3789,7 +3798,7 @@ static gint imap_cmd_append(IMAPSession *session,
        struct mailimap_flag_list * flag_list;
        int r;
        
-       g_return_val_if_fail(file != NULL, MAILIMAP_ERROR_BAD_STATE);
+       cm_return_val_if_fail(file != NULL, MAILIMAP_ERROR_BAD_STATE);
 
        flag_list = imap_flag_to_lep(item, flags, NULL);
        lock_session(session);
@@ -3855,10 +3864,13 @@ static gint imap_cmd_store(IMAPSession *session,
        return MAILIMAP_NO_ERROR;
 }
 
-static gint imap_cmd_expunge(IMAPSession *session)
+static gint imap_cmd_expunge(IMAPSession *session, gboolean do_expunge)
 {
        int r;
        
+       if (!do_expunge)
+               return MAILIMAP_NO_ERROR;
+
        if (prefs_common.work_offline && 
            !inc_offline_should_override(FALSE,
                _("Claws Mail needs network access in order "
@@ -3875,6 +3887,15 @@ static gint imap_cmd_expunge(IMAPSession *session)
        return MAILIMAP_NO_ERROR;
 }
 
+gint imap_expunge(Folder *folder, FolderItem *item)
+{
+       IMAPSession *session = imap_session_get(folder);
+       if (session == NULL)
+               return -1;
+       
+       return imap_cmd_expunge(session, TRUE);
+}
+
 static void imap_path_separator_subst(gchar *str, gchar separator)
 {
        gchar *p;
@@ -3903,7 +3924,7 @@ static gboolean imap_rename_folder_func(GNode *node, gpointer data)
        gchar *new_itempath;
        gint oldpathlen;
        IMAPSession *session = imap_session_get(item->folder);
-       gint ok;
+       gint ok = MAILIMAP_NO_ERROR;
        oldpathlen = strlen(oldpath);
        if (strncmp(oldpath, item->path, oldpathlen) != 0) {
                g_warning("path doesn't match: %s, %s\n", oldpath, item->path);
@@ -4465,15 +4486,8 @@ static gint imap_remove_msg(Folder *folder, FolderItem *item, gint uid)
                return ok;
        }
 
-       if (!session->uidplus) {
-               ok = imap_cmd_expunge(session);
-       } else {
-               gchar *uidstr;
+       ok = imap_cmd_expunge(session, folder->account->imap_use_trash);
 
-               uidstr = g_strdup_printf("%u", uid);
-               ok = imap_cmd_expunge(session);
-               g_free(uidstr);
-       }
        if (ok != MAILIMAP_NO_ERROR) {
                log_warning(LOG_PROTOCOL, _("can't expunge\n"));
                return ok;
@@ -5772,7 +5786,11 @@ char* imap_utf8_to_modified_utf7(const char *src, gboolean change_spaces)
   unsigned long ucs4 = 0, bitbuf = 0;
 
   /* initialize hex lookup table */
-  char *dst, *res = malloc(2*strlen(src)+1);
+  char *dst, *res;
+
+  if (!src) return NULL;
+
+  res = malloc(2*strlen(src)+1);
   dst = res;
   if(!dst) return NULL;