0.9.4claws5
authorChristoph Hohmann <reboot@gmx.ch>
Wed, 6 Aug 2003 14:35:14 +0000 (14:35 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Wed, 6 Aug 2003 14:35:14 +0000 (14:35 +0000)
* sync with 0.9.4cvs2
        see ChangeLog 2003-07-29

ChangeLog.claws
configure.ac
src/imap.c

index daa7b3f54f3e33cdcd2d76ee7ed0184918c7e347..7ece7c4caf3465b84622298c4cd2a91ba8c44fd8 100644 (file)
@@ -1,3 +1,8 @@
+2003-08-06 [christoph] 0.9.4claws5
+
+       * sync with 0.9.4cvs2
+               see ChangeLog 2003-07-29                
+
 2003-08-05 [paul]      0.9.4claws4
 
        * sync with 0.9.4cvs3
index 01a8bdf0346ad054988dee58abff364debed084b..677334caf4e8fa42bc2b98466422422445fba2cf 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=4
+EXTRA_VERSION=5
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index 10ea45dcd4560c4bd1e92e92c225242352677d02..45a6a75f29fe203df8799605c3d520b874d679d5 100644 (file)
@@ -79,11 +79,16 @@ struct _IMAPSession
 {
        Session session;
 
+       gboolean authenticated;
+
        gchar **capability;
+       gboolean uidplus;
+
        gchar *mbox;
-       time_t last_access_time;
-       gboolean authenticated;
        guint cmd_count;
+
+       /* CLAWS */
+       time_t last_access_time;
        gboolean folder_content_changed;
        guint exists;
 };
@@ -204,6 +209,7 @@ static void imap_folder_item_destroy        (Folder         *folder,
 
 static IMAPSession *imap_session_get   (Folder         *folder);
 
+static gint imap_greeting              (IMAPSession    *session);
 static gint imap_auth                  (IMAPSession    *session,
                                         const gchar    *user,
                                         const gchar    *pass,
@@ -294,10 +300,10 @@ static MsgFlags imap_parse_flags  (const gchar    *flag_str);
 static MsgInfo *imap_parse_envelope    (SockInfo       *sock,
                                         FolderItem     *item,
                                         GString        *line_str);
-static gint imap_greeting              (IMAPSession    *session);
+
 static gboolean imap_has_capability    (IMAPSession    *session,
                                         const gchar    *cap);
-void imap_free_capabilities            (IMAPSession    *session);
+static void imap_free_capabilities     (IMAPSession    *session);
 
 /* low-level IMAP4rev1 commands */
 static gint imap_cmd_authenticate
@@ -352,7 +358,7 @@ static gint imap_cmd_append (IMAPSession    *session,
                                 const gchar    *destfolder,
                                 const gchar    *file,
                                 IMAPFlags       flags,
-                                gint32         *newuid);
+                                guint32        *new_uid);
 static gint imap_cmd_copy       (IMAPSession    *session, 
                                  const gchar    *seq_set, 
                                  const gchar    *destfolder,
@@ -531,13 +537,53 @@ static void imap_reset_uid_lists(Folder *folder)
        g_node_traverse(folder->node, G_IN_ORDER, G_TRAVERSE_ALL, -1, imap_reset_uid_lists_func, NULL); 
 }
 
+/* Send CAPABILITY, and examine the server's response to see whether this
+ * connection is pre-authenticated or not and build a list of CAPABILITIES. */
+static gint imap_greeting(IMAPSession *session)
+{
+       gchar *capstr;
+       GPtrArray *argbuf;
+
+       imap_gen_send(session, "CAPABILITY");
+       
+       argbuf = g_ptr_array_new();
+
+       if (imap_cmd_ok(session, argbuf) != IMAP_SUCCESS ||
+           ((capstr = search_array_str(argbuf, "CAPABILITY ")) == NULL)) {
+               ptr_array_free_strings(argbuf);
+               g_ptr_array_free(argbuf, TRUE);
+               return -1;
+       }
+
+       session->authenticated = search_array_str(argbuf, "PREAUTH") != NULL;
+       
+       capstr += strlen("CAPABILITY ");
+
+       IMAP_SESSION(session)->capability = g_strsplit(capstr, " ", 0);
+       
+       ptr_array_free_strings(argbuf);
+       g_ptr_array_free(argbuf, TRUE);
+
+       if (imap_has_capability(session, "UIDPLUS")) 
+               session->uidplus = TRUE; 
+
+       return 0;
+}
+
 static gint imap_auth(IMAPSession *session, const gchar *user, const gchar *pass,
                      IMAPAuthType type)
 {
+       gint ok;
+
        if (type == 0 || type == IMAP_AUTH_LOGIN)
-               return imap_cmd_login(session, user, pass);
+               ok = imap_cmd_login(session, user, pass);
        else
-               return imap_cmd_authenticate(session, user, pass, type);
+               ok = imap_cmd_authenticate(session, user, pass, type);
+
+       if (ok == IMAP_SUCCESS)
+               session->authenticated = TRUE;
+
+       return ok;
 }
 
 static IMAPSession *imap_session_get(Folder *folder)
@@ -673,8 +719,8 @@ IMAPSession *imap_session_new(const PrefsAccount *account)
 
        session->capability = NULL;
 
-       session->mbox = NULL;
        session->authenticated = FALSE;
+       session->mbox = NULL;
        session->cmd_count = 0;
 
        /* Only need to log in if the connection was not PREAUTH */
@@ -684,7 +730,8 @@ IMAPSession *imap_session_new(const PrefsAccount *account)
        }
 
 #if USE_OPENSSL
-       if (account->ssl_imap == SSL_STARTTLS && imap_has_capability(session, "STARTTLS")) {
+       if (account->ssl_imap == SSL_STARTTLS && 
+           imap_has_capability(session, "STARTTLS")) {
                gint ok;
 
                ok = imap_cmd_starttls(session);
@@ -700,6 +747,7 @@ IMAPSession *imap_session_new(const PrefsAccount *account)
 
                imap_free_capabilities(session);
                session->authenticated = FALSE;
+               session->uidplus = FALSE;
                session->cmd_count = 1;
 
                if (imap_greeting(session) != IMAP_SUCCESS) {
@@ -740,11 +788,10 @@ void imap_session_authenticate(IMAPSession *session, const PrefsAccount *account
 
 void imap_session_destroy(Session *session)
 {
+       imap_free_capabilities(IMAP_SESSION(session));
+       g_free(IMAP_SESSION(session)->mbox);
        sock_close(session->sock);
        session->sock = NULL;
-
-       g_free(IMAP_SESSION(session)->mbox);
-       imap_free_capabilities(IMAP_SESSION(session));
 }
 
 gchar *imap_fetch_msg(Folder *folder, FolderItem *item, gint uid)
@@ -819,7 +866,7 @@ gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
        guint32 last_uid = 0;
        GSList *cur;
        MsgFileInfo *fileinfo;
-       gint ok, newnum;
+       gint ok;
 
        g_return_val_if_fail(folder != NULL, -1);
        g_return_val_if_fail(dest != NULL, -1);
@@ -832,6 +879,7 @@ gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
 
        for (cur = file_list; cur != NULL; cur = cur->next) {
                IMAPFlags iflags = 0;
+               guint32 new_uid = 0;
 
                fileinfo = (MsgFileInfo *)cur->data;
 
@@ -850,7 +898,8 @@ gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                    dest->stype == F_TRASH)
                        iflags |= IMAP_FLAG_SEEN;
 
-               ok = imap_cmd_append(session, destdir, fileinfo->file, iflags, &newnum);
+               ok = imap_cmd_append(session, destdir, fileinfo->file, iflags, 
+                                    &new_uid);
 
                if (ok != IMAP_SUCCESS) {
                        g_warning("can't append message %s\n", fileinfo->file);
@@ -860,10 +909,10 @@ gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
 
                if (relation != NULL)
                        g_relation_insert(relation, fileinfo->msginfo != NULL ? 
-                                         fileinfo->msginfo : fileinfo,
+                                         (gpointer) fileinfo->msginfo : (gpointer) fileinfo,
                                          GINT_TO_POINTER(dest->last_num + 1));
-               if (newnum > last_uid)
-                       last_uid = newnum;
+               if (last_uid < new_uid)
+                       last_uid = new_uid;
        }
 
        g_free(destdir);
@@ -2377,6 +2426,23 @@ catch:
 
 #undef THROW
 
+static gboolean imap_has_capability(IMAPSession *session, const gchar *cap)
+{
+       gchar **p;
+       
+       for (p = session->capability; *p != NULL; ++p) {
+               if (!g_strcasecmp(*p, cap))
+                       return TRUE;
+       }
+
+       return FALSE;
+}
+
+void imap_free_capabilities(IMAPSession *session)
+{
+       g_strfreev(session->capability);
+       session->capability = NULL;
+}
 
 /* low-level IMAP4rev1 commands */
 
@@ -2448,53 +2514,6 @@ static gint imap_cmd_logout(IMAPSession *session)
        return imap_cmd_ok(session, NULL);
 }
 
-/* Send CAPABILITY, and examine the server's response to see whether this
- * connection is pre-authenticated or not and build a list of CAPABILITIES. */
-static gint imap_greeting(IMAPSession *session)
-{
-       gchar *capstr;
-       GPtrArray *argbuf;
-
-       imap_gen_send(session, "CAPABILITY");
-       
-       argbuf = g_ptr_array_new();
-
-       if (imap_cmd_ok(session, argbuf) != IMAP_SUCCESS ||
-           ((capstr = search_array_str(argbuf, "CAPABILITY ")) == NULL)) {
-               ptr_array_free_strings(argbuf);
-               g_ptr_array_free(argbuf, TRUE);
-               return -1;
-       }
-
-       session->authenticated = search_array_str(argbuf, "PREAUTH") != NULL;
-       
-       capstr += strlen("CAPABILITY ");
-
-       IMAP_SESSION(session)->capability = g_strsplit(capstr, " ", 0);
-       
-       ptr_array_free_strings(argbuf);
-       g_ptr_array_free(argbuf, TRUE);
-
-       return 0;
-}
-
-static gboolean imap_has_capability(IMAPSession *session, const gchar *cap)
-{
-       gchar **p;
-       
-       for (p = session->capability; *p != NULL; ++p)
-               if (g_strcasecmp(*p, cap) == 0)
-                       return TRUE;
-
-       return FALSE;
-}
-
-void imap_free_capabilities(IMAPSession *session)
-{
-       g_strfreev(session->capability);
-       session->capability = NULL;
-}
-
 static gint imap_cmd_noop(IMAPSession *session)
 {
        imap_gen_send(session, "NOOP");
@@ -2768,17 +2787,18 @@ static gint imap_cmd_fetch(IMAPSession *session, guint32 uid, const gchar *filen
 }
 
 static gint imap_cmd_append(IMAPSession *session, const gchar *destfolder,
-                           const gchar *file, IMAPFlags flags, gint32 *new_uid)
+                           const gchar *file, IMAPFlags flags, guint32 *new_uid)
 {
        gint ok;
-       gint size, newuid;
+       gint size;
        gchar *destfolder_;
        gchar *flag_str;
+       guint32 new_uid_;
        gchar *ret = NULL;
        gchar buf[BUFFSIZE];
        FILE *fp;
-       GPtrArray *reply;
-       gchar *okmsginfo;
+       GPtrArray *argbuf;
+       gchar *resp_str;
 
        g_return_val_if_fail(file != NULL, IMAP_ERROR);
 
@@ -2822,22 +2842,30 @@ static gint imap_cmd_append(IMAPSession *session, const gchar *destfolder,
 
        fclose(fp);
 
-       reply = g_ptr_array_new();
+       if (new_uid != NULL)
+               *new_uid = 0;
 
-       *new_uid = 0;
-       ok = imap_cmd_ok(session, reply);
-       if (ok != IMAP_SUCCESS)
-               log_warning(_("can't append message to %s\n"), destfolder_);
-       else if (
-           (new_uid != NULL) && 
-           (imap_has_capability(session, "UIDPLUS") && reply->len > 0) &&
-           ((okmsginfo = g_ptr_array_index(reply, reply->len - 1)) != NULL) &&
-           (sscanf(okmsginfo, "%*u OK [APPENDUID %*u %u]", &newuid) == 1)) {
-               *new_uid = newuid;
-       }
+       if (new_uid != NULL && session->uidplus) {
+               argbuf = g_ptr_array_new();
+
+               ok = imap_cmd_ok(session, argbuf);
+               if (ok != IMAP_SUCCESS)
+                       log_warning(_("can't append message to %s\n"),
+                                   destfolder_);
+               else if (argbuf->len > 0) {
+                       resp_str = g_ptr_array_index(argbuf, argbuf->len - 1);
+                       if (resp_str &&
+                           sscanf(resp_str, "%*u OK [APPENDUID %*u %u]",
+                                  &new_uid_) == 1) {
+                               *new_uid = new_uid_;
+                       }
+               }
+
+               ptr_array_free_strings(argbuf);
+               g_ptr_array_free(argbuf, TRUE);
+       } else
+               ok = imap_cmd_ok(session, NULL);
 
-       ptr_array_free_strings(reply);
-       g_ptr_array_free(reply, TRUE);
        return ok;
 }