Accept unsolicited CAPABILITY report as part of LOGIN/AUTHENTICATE response
authorDavid Woodhouse <David.Woodhouse@intel.com>
Thu, 17 Jun 2010 13:47:56 +0000 (14:47 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 23 Jun 2010 22:52:28 +0000 (23:52 +0100)
Also fix up freeing of cinfo status response.

camel/providers/imapx/camel-imapx-server.c
camel/providers/imapx/camel-imapx-utils.c

index 7eceb1e..6389d41 100644 (file)
@@ -1433,6 +1433,7 @@ imapx_untagged(CamelIMAPXServer *imap, CamelException *ex)
                                if (imap->cinfo)
                                        imapx_free_capability(imap->cinfo);
                                imap->cinfo = sinfo->u.cinfo;
+                               sinfo->u.cinfo = NULL;
                                c(printf("got capability flags %08x\n", imap->cinfo->capa));
                        }
                        break;
@@ -2533,9 +2534,21 @@ imapx_reconnect (CamelIMAPXServer *is, CamelException *ex)
 
                imapx_command_run (is, ic);
 
-               if (!(camel_exception_is_set (ic->ex) || ic->status->result != IMAPX_OK))
+               if (!(camel_exception_is_set (ic->ex) || ic->status->result != IMAPX_OK)) {
+                       /* Forget old capabilities after login */
+                       if (is->cinfo) {
+                               imapx_free_capability(is->cinfo);
+                               is->cinfo = NULL;
+                       }
+
+                       if (ic->status->condition == IMAPX_CAPABILITY) {
+                               is->cinfo = ic->status->u.cinfo;
+                               ic->status->u.cinfo = NULL;
+                               c(printf("got capability flags %08x\n", is->cinfo->capa));
+                       }
+
                        authenticated = TRUE;
-               else {
+               else {
                        /* If exception is set, it might be mostly due to cancellation and we would get an
                           io error, else re-prompt. If authentication fails for other reasons ic->status would be
                            set with the error message */
@@ -2558,20 +2571,16 @@ imapx_reconnect (CamelIMAPXServer *is, CamelException *ex)
        if (camel_exception_is_set (ex))
                goto exception;
 
-       /* After login we re-capa */
-       if (is->cinfo) {
-               imapx_free_capability(is->cinfo);
-               is->cinfo = NULL;
-       }
-       
-
-       ic = camel_imapx_command_new("CAPABILITY", NULL, "CAPABILITY");
-       imapx_command_run (is, ic);
-       camel_exception_xfer (ex, ic->ex);
-       camel_imapx_command_free(ic);
+       /* After login we re-capa unless the server already told us */
+       if (!is->cinfo) {
+               ic = camel_imapx_command_new("CAPABILITY", NULL, "CAPABILITY");
+               imapx_command_run (is, ic);
+               camel_exception_xfer (ex, ic->ex);
+               camel_imapx_command_free(ic);
 
-       if (camel_exception_is_set (ex))
-               goto exception;
+               if (camel_exception_is_set (ex))
+                       goto exception;
+       }
 
        is->state = IMAPX_AUTHENTICATED;
 
index ea0c983..6369d09 100644 (file)
@@ -1698,6 +1698,10 @@ imapx_free_status(struct _status_info *sinfo)
                g_ptr_array_free (sinfo->u.copyuid.uids, FALSE);
                g_ptr_array_free (sinfo->u.copyuid.copied_uids, FALSE);
                break;
+       case IMAPX_CAPABILITY:
+               if (sinfo->u.cinfo)
+                       imapx_free_capability(sinfo->u.cinfo);
+               break;
        default:
                break;
        }