Changeset 3012

Show
Ignore:
Timestamp:
11/27/07 21:33:18
Author:
pvanhoof
Message:

Several fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/pvanhoof/bs/libtinymail-camel/bs

    • Property svn:ignore set to Makefile.in libbodystruct.a .deps Makefile
  • devel/pvanhoof/bs/libtinymail-camel/bs/.svnignore

    r3011 r3012  
     1Makefile.in 
     2libbodystruct.a 
    13.deps 
    24Makefile 
    3 Makefile.in 
    4 libbodystruct.a 
  • devel/pvanhoof/bs/libtinymail-camel/bs/bodystruct.c

    r3011 r3012  
    113113 
    114114        if (strncmp ((const char *) inptr, "NIL", 3) != 0) { 
    115                 if (*inptr != '"') { 
    116                         *in = inptr; 
    117                        set_error (err, in); 
    118                         return NULL
    119                 } 
    120                 inptr++; 
     115                gboolean quoted = FALSE; 
     116 
     117                if (*inptr == '"') { 
     118                        inptr++
     119                       quoted = TRUE; 
     120                } 
    121121                start = inptr; 
    122122                while (inptr < inend) { 
    123                         if (*inptr == '"' && inptr[-1] != '\\') 
    124                                 break; 
     123                        if (quoted) { 
     124                                if (*inptr == '"' && inptr[-1] != '\\') 
     125                                        break; 
     126                        } else { 
     127                                if (*inptr == ')' && inptr[-1] != '\\') 
     128                                        break; 
     129                        } 
    125130                        inptr++; 
    126131                } 
     
    128133                qstring = g_strndup ((const char *) start, inptr - start); 
    129134                unescape_qstring (qstring); 
    130                 if (*inptr != '"') { 
     135 
     136                if (quoted && *inptr != '"') { 
    131137                        g_free (qstring); 
    132138                        *in = inptr; 
     
    134140                        return NULL; 
    135141                } 
    136                 inptr++; 
     142                if (quoted) 
     143                        inptr++; 
    137144        } else 
    138145                inptr += 3; 
     
    316323        if (!val) { 
    317324                *in = inptr; 
    318                 set_error (err, in); 
    319325                g_free (name); 
    320326        } else { 
  • devel/pvanhoof/bs/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c

    r3011 r3012  
    43604360        gboolean amcon = FALSE; 
    43614361 
    4362         g_static_mutex_lock (&gmsgstore_lock); 
     4362        g_static_mutex_lock (&gmsgstore_lock); /* A */ 
     4363 
    43634364        if (imap_folder->gmsgstore) { 
    43644365                imap_debug ("Get-Message service reused\n"); 
     
    44184419 
    44194420static void  
    4420 stop_gmsgstore (CamelImapFolder *imap_folder, gboolean ctchecker) 
    4421 
    4422         if (ctchecker) { 
    4423                 camel_object_ref (imap_folder); 
    4424                 imap_folder->gmsgstore_signal = g_timeout_add (1000, 
    4425                         check_gmsgstore_die, imap_folder); 
    4426         } 
    4427         g_static_mutex_unlock (&gmsgstore_lock); 
     4421stop_gmsgstore (CamelImapFolder *imap_folder, gboolean ctchecker, gboolean quick) 
     4422
     4423        if (quick) { 
     4424                if (ctchecker) { 
     4425                        camel_object_ref (imap_folder); 
     4426                        imap_folder->gmsgstore_signal = g_timeout_add (1000, 
     4427                                check_gmsgstore_die, imap_folder); 
     4428                } 
     4429        } else { 
     4430                imap_folder->gmsgstore->clean_exit = FALSE; 
     4431                imap_folder->gmsgstore_ticks = 0; 
     4432                if (ctchecker) { 
     4433                        camel_object_ref (imap_folder); 
     4434                        imap_folder->gmsgstore_signal = g_timeout_add (1, 
     4435                                check_gmsgstore_die, imap_folder); 
     4436                } 
     4437        } 
     4438 
     4439        g_static_mutex_unlock (&gmsgstore_lock); /* A */ 
    44284440} 
    44294441 
     
    44334445  CamelImapFolder *imap_folder = (CamelImapFolder *) folder; 
    44344446  gchar *path = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec); 
     4447 
     4448  gboolean retry = TRUE; 
     4449  gint ex_id; 
     4450  gboolean err = FALSE; 
     4451  gchar *err_message; 
     4452  CamelImapStore *store = NULL; 
     4453  ssize_t nread = 0; 
     4454  FILE *f = NULL; 
     4455  gboolean ctchecker = FALSE; 
     4456 
    44354457  if (!g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) 
    44364458  { 
     
    44454467        } else { 
    44464468 
    4447                 gboolean ctchecker = FALSE; 
    4448                 CamelImapStore *store; 
    44494469                char *tag, line[MAX_LINE_LEN]; 
    44504470                int taglen; 
    44514471                CamelStreamBuffer *server_stream; 
    4452                 ssize_t nread = 0; 
    4453                 FILE *f = fopen (path, "w"); 
    4454                 int fd = fileno (f); 
     4472                int fd; 
     4473 
     4474                f = fopen (path, "w"); 
     4475                fd = fileno (f); 
    44554476 
    44564477                if (!f || fd == -1) { 
     
    44624483                        return NULL; 
    44634484 
    4464                 if (store->capabilities & IMAP_CAPABILITY_BINARY
     4485                while (retry
    44654486                { 
    4466                         gchar line[MAX_LINE_LEN]; 
    4467                         gboolean err = FALSE; 
    4468                         char two_bytes[2]; 
    4469                         char t_str [1024]; 
    4470                         int f = 0; 
    4471                         ssize_t hread = 1; 
    4472                         gint length=0, rec=0; 
    4473                         char *pos, *ppos; 
    4474                         gboolean unsolicited = TRUE; 
    4475  
    4476                         /* Stops idle */ 
    4477                         camel_imap_command_start (store, folder, ex, 
    4478                                 "UID FETCH %s BINARY.PEEK[%s]", uid, spec); 
    4479  
    4480                         while (unsolicited) 
     4487                        retry = FALSE; 
     4488 
     4489                        if (store->capabilities & IMAP_CAPABILITY_BINARY) 
    44814490                        { 
    4482                                 two_bytes [0] = ' '; 
    4483                                 f = 0; 
    4484                                 nread = 1; 
    4485  
    4486                                 /* a01 uid fetch 1 BINARY.PEEK[] 
    4487                                  * * Bla bla 
    4488                                  * * 1 FETCH (UID 1 BINARY[] {24693}\r\n 
    4489                                  * Subject: Testing.... 
    4490                                  * )\r\n 
    4491                                  * a01 OK .... \r\n */ 
    4492  
    4493                                 /* Read the length in the "\*.*[~|]{<LENGTH>}" */ 
    4494                                 while (two_bytes[0] != '\n' && f < 1023 && nread > 0) 
     4491                                gchar line[MAX_LINE_LEN]; 
     4492                                gboolean err = FALSE; 
     4493                                char two_bytes[2]; 
     4494                                char t_str [1024]; 
     4495                                int f = 0; 
     4496                                ssize_t hread = 1; 
     4497                                gint length=0, rec=0; 
     4498                                char *pos, *ppos; 
     4499                                gboolean unsolicited = TRUE; 
     4500 
     4501                                nread = 0; 
     4502 
     4503                                /* Stops idle */ 
     4504                                camel_imap_command_start (store, folder, ex, 
     4505                                        "UID FETCH %s BINARY.PEEK[%s]", uid, spec); 
     4506 
     4507                                while (unsolicited) 
    44954508                                { 
    4496                                         nread = camel_stream_read (store->ostream, two_bytes, 1); 
    4497                                         line [f] = two_bytes [0]; 
    4498                                         f++; 
    4499                                 } 
    4500                                 line[f] = '\0'; 
    4501  
    4502                                 /* The first line is very unlikely going to consume 1023 bytes */ 
    4503                                 if (f > 1023 || nread <= 0) { 
    4504                                         //err = TRUE; 
    4505                                         //ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
    4506                                         //errmessage = g_strdup_printf ("Read from service failed: Long " 
    4507                                         //      " first line during binary fetch for uid=%s", uid); 
    4508                                         //goto berrorhander; 
    4509                                 } 
    4510  
    4511                                 /* If the line doesn't start with "* " */ 
    4512  
    4513                                 if (camel_strstrcase (line, "BAD")) { 
    4514                                         g_warning ("Read from service failed: Server does not like how " 
    4515                                                 " we use BINARY (%s)\n", line); 
    4516                                         store->capabilities &= ~IMAP_CAPABILITY_BINARY; 
    4517                                         //retry = TRUE; 
    4518                                         CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); 
    4519                                         //goto myretry; 
    4520                                 } 
    4521  
    4522                                 if (*line != '*' || *(line + 1) != ' ') 
    4523                                 { 
    4524                                         //err = TRUE; 
    4525                                         //ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
    4526                                         //errmessage = g_strdup_printf ("Read from service failed: Line doesn't start " 
    4527                                         //      " with \"* \" for uid=%s (in stead it started with %s)", uid, line); 
    4528                                         //goto berrorhander; 
    4529                                 } 
    4530  
    4531                                 pos = strchr (line, '{'); 
    4532  
    4533                                 /* If we don't find a '{' character */ 
    4534                                 if (!pos) { 
    4535                                         imap_debug ("unsolicited in BINARY: %s\n", line); 
    4536                                         continue; 
    4537                                 } 
    4538  
    4539                                 /* Set the '}' character to \0 */ 
    4540                                 ppos = strchr (pos, '}'); 
    4541                                 if (ppos) { 
    4542                                         *ppos = '\0'; 
    4543                                         unsolicited = FALSE; 
    4544                                 } 
    4545                         } 
    4546  
    4547                         length = strtol (pos + 1, NULL, 10); 
    4548  
    4549                         /* If strtol failed (it's important enough to check this) */ 
    4550                         if (errno == ERANGE) 
    4551                         { 
    4552                                 //err = TRUE; 
    4553                                 //ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
    4554                                 //errmessage = g_strdup_printf ("Read from service failed: " 
    4555                                 //      "strtol failed for uid=%s (the line was: %s)", uid, line); 
    4556                                 //goto berrorhander; 
    4557                         } 
    4558  
    4559                         /* Until we have reached the length, read 1024 at the time */ 
    4560                         while (hread > 0 && rec < length) 
    4561                         { 
    4562                                 int wread = (length - rec); 
    4563                                 if (wread < 1 || wread > 1024) 
    4564                                         wread = 1024; 
    4565                                 hread = camel_stream_read (store->ostream, t_str, wread); 
    4566                                 if (hread > 0) 
    4567                                 { 
    4568 int hu = write (fd, t_str, hread); 
    4569                                         /* And write them too */ 
    4570                                         if (hu != hread) 
     4509                                        two_bytes [0] = ' '; 
     4510                                        f = 0; 
     4511                                        nread = 1; 
     4512 
     4513                                        /* a01 uid fetch 1 BINARY.PEEK[] 
     4514                                         * * Bla bla 
     4515                                         * * 1 FETCH (UID 1 BINARY[] {24693}\r\n 
     4516                                         * Subject: Testing.... 
     4517                                         * )\r\n 
     4518                                         * a01 OK .... \r\n */ 
     4519 
     4520                                        /* Read the length in the "\*.*[~|]{<LENGTH>}" */ 
     4521                                        while (two_bytes[0] != '\n' && f < 1023 && nread > 0) { 
     4522                                                nread = camel_stream_read (store->ostream, two_bytes, 1); 
     4523                                                line [f] = two_bytes [0]; 
     4524                                                f++; 
     4525                                        } 
     4526 
     4527                                        line[f] = '\0'; 
     4528 
     4529                                        /* The first line is very unlikely going to consume 1023 bytes */ 
     4530                                        if (f > 1023 || nread <= 0) { 
     4531                                                err = TRUE; 
     4532                                                ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
     4533                                                err_message = g_strdup_printf ("Read from service failed: Long " 
     4534                                                        " first line during binary fetch for uid=%s", uid); 
     4535                                                goto fetch_berrorhander; 
     4536                                        } 
     4537 
     4538                                        /* If the line doesn't start with "* " */ 
     4539                                        if (camel_strstrcase (line, "BAD")) { 
     4540                                                g_warning ("Read from service failed: Server does not like how " 
     4541                                                        " we use BINARY (%s)\n", line); 
     4542                                                store->capabilities &= ~IMAP_CAPABILITY_BINARY; 
     4543                                                retry = TRUE; 
     4544                                                CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); 
     4545                                                goto fetch_retry; 
     4546                                        } 
     4547 
     4548                                        if (*line != '*' || *(line + 1) != ' ') 
    45714549                                        { 
    4572  
    4573                                                 printf("N wrote: %s (%d, %d, %d)\n", t_str, errno, hu, hread); 
    4574 perror("write"); 
    4575                                                 //err = TRUE; 
    4576                                                 //errmessage = g_strdup_printf ("Write to cache failed: %s", g_strerror (errno)); 
    4577                                                 //goto berrorhander; 
     4550                                                err = TRUE; 
     4551                                                ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
     4552                                                err_message = g_strdup_printf ("Read from service failed: Line doesn't start " 
     4553                                                        " with \"* \" for uid=%s (in stead it started with %s)", uid, line); 
     4554                                                goto fetch_berrorhander; 
    45784555                                        } 
    4579 printf("wrote: %s (%d)\n", t_str, errno); 
    4580                                         rec += hread; 
    4581                                         camel_operation_progress (NULL, rec, length); 
    4582                                 } else { 
    4583                                         if (hread != 0) { 
    4584                                                 //ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
    4585                                                 //errmessage = g_strdup_printf ("Read from service failed, UID=%s", uid); 
    4586                                                 //err = TRUE; 
    4587                                                 //goto berrorhander; 
     4556 
     4557                                        pos = strchr (line, '{'); 
     4558 
     4559                                        /* If we don't find a '{' character */ 
     4560                                        if (!pos) { 
     4561                                                imap_debug ("unsolicited in BINARY: %s\n", line); 
     4562                                                continue; 
     4563                                        } 
     4564 
     4565                                        /* Set the '}' character to \0 */ 
     4566                                        ppos = strchr (pos, '}'); 
     4567                                        if (ppos) { 
     4568                                                *ppos = '\0'; 
     4569                                                unsolicited = FALSE; 
    45884570                                        } 
    45894571                                } 
    4590                         } 
    4591  
    4592  
    4593                         /* Read away the last two lines */ 
    4594                         for (f = 0; f < 2; f++) { 
    4595                                 nread = 1; two_bytes[0] = 'x'; 
    4596                                 while (two_bytes[0] != '\n' && nread > 0) { 
    4597                                         nread = camel_stream_read (store->ostream, two_bytes, 1); 
    4598                                         printf ("%c", two_bytes[0]); 
     4572 
     4573                                length = strtol (pos + 1, NULL, 10); 
     4574 
     4575                                /* If strtol failed (it's important enough to check this) */ 
     4576                                if (errno == ERANGE) 
     4577                                { 
     4578                                        err = TRUE; 
     4579                                        ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
     4580                                        err_message = g_strdup_printf ("Read from service failed: " 
     4581                                                "strtol failed for uid=%s (the line was: %s)", uid, line); 
     4582                                        goto fetch_berrorhander; 
    45994583                                } 
    4600                                 printf("\n"); 
    4601                         } 
    4602 //berrorhander: 
    4603                         CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); 
    4604  
    4605                         //if (err) 
    4606                                 //goto errorhander; 
    4607                 } else 
    4608                 { 
    4609                         gboolean err=FALSE; 
    4610                         gchar line [MAX_LINE_LEN]; 
    4611                         guint linenum = 0; 
    4612                         CamelStreamBuffer *server_stream; 
    4613                         gchar *tag; 
    4614                         guint taglen; 
    4615                         gboolean isnextdone = FALSE, hadr = FALSE; 
    4616                         guint tread = 0, exread = 0; 
    4617  
    4618                         nread = 0; 
    4619  
    4620                         /* 
    4621                         a01 UID FETCH 1:10 BODY.PEEK[0] 
    4622                         * Bla bla 
    4623                         * 1 FETCH (UID 6 BODY[0] {908} 
    4624                         Received: from nic.funet.fi 
    4625                         */ 
    4626  
    4627                         /* Stops idle */ 
    4628                         camel_imap_command_start (store, folder, ex, 
    4629                                 "UID FETCH %s BODY.PEEK[%s]", uid, spec); 
    4630  
    4631                         tag = g_strdup_printf ("%c%.5u", store->tag_prefix, store->command-1); 
    4632                         taglen = strlen (tag); 
    4633  
    4634                         server_stream = (CamelStreamBuffer*) store->istream; 
    4635  
    4636                         if (!server_stream) { 
    4637                                 //err = TRUE; 
    4638                                 //ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
    4639                                 //errmessage = g_strdup ("Read from service failed: Service unavailable"); 
    4640                         } else 
    4641                                 store->command++; 
    4642  
    4643                         if (server_stream) 
    4644                           while ((nread = camel_stream_buffer_gets (server_stream, line, MAX_LINE_LEN) > 0)) 
    4645                           { 
    4646                                 gint llen = 0; 
    4647  
    4648                                 /* It might be the line before the last line 
    4649                                  * TNY TODO: why no check for (linenum != 0) then ? */ 
    4650  
    4651                                 if (line[0] == ')' && (line[1] == '\n' || (line[1] == '\r' && line[2] == '\n'))) 
     4584 
     4585                                /* Until we have reached the length, read 1024 at the time */ 
     4586                                while (hread > 0 && rec < length) 
    46524587                                { 
    4653                                         if (line[1] == '\r') 
    4654                                                 hadr = TRUE; 
    4655                                         isnextdone = TRUE; 
    4656                                         continue; 
    4657                                 } 
    4658  
    4659                                 /* It's the first line (or an unsolicited one) */ 
    4660                                 if (linenum == 0 && (line [0] != '*' || line[1] != ' ')) 
    4661                                 { 
    4662                                         //ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
    4663                                         //errmessage = g_strdup ("Read from service failed: Unexpected result from service"); 
    4664                                         //err=TRUE; 
    4665                                         break; 
    4666                                 } else if (linenum == 0) 
    4667                                 { 
    4668                                         char *pos, *ppos; 
    4669                                         pos = strchr (line, '{'); 
    4670                                         if (pos) { 
    4671                                                 ppos = strchr (pos, '}'); 
    4672                                                 if (ppos) { 
    4673                                                         *ppos = '\0'; 
    4674                                                         exread = strtol (pos + 1, NULL, 10); 
     4588                                        int wread = (length - rec); 
     4589                                        if (wread < 1 || wread > 1024) 
     4590                                                wread = 1024; 
     4591                                        hread = camel_stream_read (store->ostream, t_str, wread); 
     4592                                        if (hread > 0) 
     4593                                        { 
     4594                                                /* And write them too */ 
     4595                                                if (write (fd, t_str, hread) != hread) 
     4596                                                { 
     4597                                                        err = TRUE; 
     4598                                                        err_message = g_strdup_printf ("Write to cache failed: %s", g_strerror (errno)); 
     4599                                                        goto fetch_berrorhander; 
    46754600                                                } 
    4676                                                 linenum++; 
     4601                                                rec += hread; 
     4602                                                camel_operation_progress (NULL, rec, length); 
    46774603                                        } else { 
    4678                                                 imap_debug ("Unsolicited in FETCH: %s\n", line); 
    4679                                         } 
    4680                                         continue; 
    4681                                 } 
    4682  
    4683                                 /* It's the last line (isnextdone will be ignored if that is the case) */ 
    4684                                 if (!strncmp (line, tag, taglen)) 
    4685                                         break; 
    4686  
    4687                                 if (isnextdone) 
    4688                                 { 
    4689                                         if (hadr) { 
    4690                                                 if (write (fd, ")\n", 2) != 2) 
    4691                                                 { 
    4692                                                         //err = TRUE; 
    4693                                                         //errmessage = g_strdup_printf ("Write to cache failed: %s", g_strerror (errno)); 
    4694                                                         break; 
    4695                                                 } 
    4696                                         } else { 
    4697                                                 if (write (fd, ")\r\n", 3) != 3) 
    4698                                                 { 
    4699                                                         //err = TRUE; 
    4700                                                         //errmessage = g_strdup_printf ("Write to cache failed: %s", g_strerror (errno)); 
    4701                                                         break; 
     4604                                                if (hread != 0) { 
     4605                                                        err = TRUE; 
     4606                                                        ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
     4607                                                        err_message = g_strdup_printf ("Read from service failed, UID=%s", uid); 
     4608                                                        goto fetch_berrorhander; 
    47024609                                                } 
    47034610                                        } 
    4704  
    4705                                         hadr = FALSE; 
    4706                                         isnextdone = FALSE; 
    47074611                                } 
    47084612 
    4709                                 llen = strlen (line); 
    4710                                 if (write (fd, line, llen) != llen) 
     4613                                /* Read away the last two lines */ 
     4614                                for (f = 0; f < 2; f++) { 
     4615                                        nread = 1; two_bytes[0] = 'x'; 
     4616                                        while (two_bytes[0] != '\n' && nread > 0) { 
     4617                                                nread = camel_stream_read (store->ostream, two_bytes, 1); 
     4618                                                printf ("%c", two_bytes[0]); 
     4619                                        } 
     4620                                } 
     4621fetch_berrorhander: 
     4622                                CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); 
     4623 
     4624                                if (err) 
     4625                                        goto fetch_errorhandler; 
     4626                        } else 
     4627                        { 
     4628                                gboolean err=FALSE; 
     4629                                gchar line [MAX_LINE_LEN]; 
     4630                                guint linenum = 0; 
     4631                                CamelStreamBuffer *server_stream; 
     4632                                gchar *tag; 
     4633                                guint taglen; 
     4634                                gboolean isnextdone = FALSE, hadr = FALSE; 
     4635                                guint tread = 0, exread = 0; 
     4636 
     4637                                nread = 0; 
     4638 
     4639                                /* 
     4640                                a01 UID FETCH 1:10 BODY.PEEK[0] 
     4641                                * Bla bla 
     4642                                * 1 FETCH (UID 6 BODY[0] {908} 
     4643                                Received: from nic.funet.fi 
     4644                                */ 
     4645 
     4646                                /* Stops idle */ 
     4647                                camel_imap_command_start (store, folder, ex, 
     4648                                        "UID FETCH %s BODY.PEEK[%s]", uid, spec); 
     4649 
     4650                                tag = g_strdup_printf ("%c%.5u", store->tag_prefix, store->command-1); 
     4651                                taglen = strlen (tag); 
     4652 
     4653                                server_stream = (CamelStreamBuffer*) store->istream; 
     4654 
     4655                                if (!server_stream) { 
     4656                                        err = TRUE; 
     4657                                        ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
     4658                                        err_message = g_strdup ("Read from service failed: Service unavailable"); 
     4659                                } else 
     4660                                        store->command++; 
     4661 
     4662                                if (server_stream) 
    47114663                                { 
    4712                                         //err = TRUE; 
    4713                                         //errmessage = g_strdup_printf ("Write to cache failed: %s", g_strerror (errno)); 
    4714                                         break; 
     4664                                  while ((nread = camel_stream_buffer_gets (server_stream, line, MAX_LINE_LEN) > 0)) 
     4665                                  { 
     4666                                        gint llen = 0; 
     4667 
     4668                                        /* It might be the line before the last line 
     4669                                         * TNY TODO: why no check for (linenum != 0) then ? */ 
     4670 
     4671                                        if (line[0] == ')' && (line[1] == '\n' || (line[1] == '\r' && line[2] == '\n'))) 
     4672                                        { 
     4673                                                if (line[1] == '\r') 
     4674                                                        hadr = TRUE; 
     4675                                                isnextdone = TRUE; 
     4676                                                continue; 
     4677                                        } 
     4678 
     4679                                        /* It's the first line (or an unsolicited one) */ 
     4680                                        if (linenum == 0 && (line [0] != '*' || line[1] != ' ')) 
     4681                                        { 
     4682                                                ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
     4683                                                err_message = g_strdup ("Read from service failed: Unexpected result from service"); 
     4684                                                err=TRUE; 
     4685                                                break; 
     4686                                        } else if (linenum == 0) 
     4687                                        { 
     4688                                                char *pos, *ppos; 
     4689                                                pos = strchr (line, '{'); 
     4690                                                if (pos) { 
     4691                                                        ppos = strchr (pos, '}'); 
     4692                                                        if (ppos) { 
     4693                                                                *ppos = '\0'; 
     4694                                                                exread = strtol (pos + 1, NULL, 10); 
     4695                                                        } 
     4696                                                        linenum++; 
     4697                                                } else { 
     4698                                                        imap_debug ("Unsolicited in FETCH: %s\n", line); 
     4699                                                } 
     4700                                                continue; 
     4701                                        } 
     4702 
     4703                                        /* It's the last line (isnextdone will be ignored if that is the case) */ 
     4704                                        if (!strncmp (line, tag, taglen)) 
     4705                                                break; 
     4706 
     4707                                        if (isnextdone) 
     4708                                        { 
     4709                                                if (hadr) { 
     4710                                                        if (write (fd, ")\n", 2) != 2) 
     4711                                                        { 
     4712                                                                err = TRUE; 
     4713                                                                err_message = g_strdup_printf ("Write to cache failed: %s", g_strerror (errno)); 
     4714                                                                break; 
     4715                                                        } 
     4716                                                } else { 
     4717                                                        if (write (fd, ")\r\n", 3) != 3) 
     4718                                                        { 
     4719                                                                err = TRUE; 
     4720                                                                err_message = g_strdup_printf ("Write to cache failed: %s", g_strerror (errno)); 
     4721                                                                break; 
     4722                                                        } 
     4723                                                } 
     4724 
     4725                                                hadr = FALSE; 
     4726                                                isnextdone = FALSE; 
     4727                                        } 
     4728 
     4729                                        llen = strlen (line); 
     4730                                        if (write (fd, line, llen) != llen) { 
     4731                                                err = TRUE; 
     4732                                                err_message = g_strdup_printf ("Write to cache failed: %s", g_strerror (errno)); 
     4733                                                break; 
     4734                                        } 
     4735 
     4736                                        linenum++; 
     4737                                        tread += llen; 
     4738 
     4739                                        camel_operation_progress (NULL, tread, exread); 
     4740 
     4741                                        memset (line, 0, MAX_LINE_LEN); 
     4742                                  } 
    47154743                                } 
    4716 prinf ("Wrote: %s\n", line); 
    4717                                 linenum++; 
    4718                                 tread += llen; 
    4719  
    4720                                 camel_operation_progress (NULL, tread, exread); 
    4721  
    4722                                 memset (line, 0, MAX_LINE_LEN); 
    4723                           } 
    4724  
    4725                         CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); 
    4726  
    4727                         if (nread <= 0) { 
    4728                                 //err = TRUE; 
    4729                                 //ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
    4730                                 //errmessage = g_strdup_printf ("Read from service failed: %s", g_strerror (errno)); 
     4744 
     4745                                CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); 
     4746 
     4747                                if (nread <= 0) { 
     4748                                        err = TRUE; 
     4749                                        ex_id = CAMEL_EXCEPTION_SERVICE_UNAVAILABLE; 
     4750          &nb