~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to camel/providers/imap/camel-imap-store-summary.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#define _PRIVATE(o) (((CamelImapStoreSummary *)(o))->priv)
47
47
 
48
 
static void namespace_clear(CamelStoreSummary *s);
49
 
 
50
48
static gint summary_header_load(CamelStoreSummary *, FILE *);
51
49
static gint summary_header_save(CamelStoreSummary *, FILE *);
52
50
 
126
124
 *
127
125
 * Create a new CamelImapStoreSummary object.
128
126
 *
129
 
 * Return value: A new CamelImapStoreSummary widget.
 
127
 * Returns: A new CamelImapStoreSummary widget.
130
128
 **/
131
129
CamelImapStoreSummary *
132
130
camel_imap_store_summary_new (void)
146
144
 * A referenced to the summary item is returned, which may be
147
145
 * ref'd or free'd as appropriate.
148
146
 *
149
 
 * Return value: The summary item, or NULL if the @full_name name
 
147
 * Returns: The summary item, or NULL if the @full_name name
150
148
 * is not available.
151
149
 * It must be freed using camel_store_summary_info_free().
152
150
 **/
179
177
        if (dir_sep != '/') {
180
178
                p = path = alloca(strlen(full_name)*3+1);
181
179
                f = full_name;
182
 
                while ( (c = *f++ & 0xff) ) {
 
180
                while ((c = *f++ & 0xff)) {
183
181
                        if (c == dir_sep)
184
182
                                *p++ = '/';
185
183
                        else if (c == '/' || c == '%')
363
361
        return name;
364
362
}
365
363
 
366
 
/* TODO: this api needs some more work */
367
 
CamelImapStoreNamespace *camel_imap_store_summary_namespace_new(CamelImapStoreSummary *s, const gchar *full_name, gchar dir_sep)
 
364
static CamelImapStoreNamespace *
 
365
namespace_new (CamelImapStoreSummary *s, const gchar *full_name, gchar dir_sep)
368
366
{
369
367
        CamelImapStoreNamespace *ns;
370
368
        gchar *p, *o, c;
390
388
        return ns;
391
389
}
392
390
 
393
 
void camel_imap_store_summary_namespace_set(CamelImapStoreSummary *s, CamelImapStoreNamespace *ns)
394
 
{
395
 
        d(printf("Setting namesapce to '%s' '%c' -> '%s'\n", ns->full_name, ns->sep, ns->path));
396
 
        namespace_clear((CamelStoreSummary *)s);
397
 
        s->namespace = ns;
398
 
        camel_store_summary_touch((CamelStoreSummary *)s);
 
391
static CamelImapStoreNamespace *
 
392
namespace_find (CamelImapStoreNamespace *ns, const gchar *full_name, gchar dir_sep)
 
393
{
 
394
        if (!ns || !full_name)
 
395
                return NULL;
 
396
 
 
397
        while (ns) {
 
398
                gint len = strlen (ns->full_name);
 
399
 
 
400
                if ((g_ascii_strcasecmp (ns->full_name, full_name) == 0 ||
 
401
                    (g_ascii_strncasecmp (ns->full_name, full_name, len) == 0
 
402
                    && len + 1 == strlen (full_name) && full_name [len] == ns->sep))&& (!dir_sep || ns->sep == dir_sep)) {
 
403
                        break;
 
404
                }
 
405
                ns = ns->next;
 
406
        }
 
407
 
 
408
        return ns;
 
409
}
 
410
 
 
411
void
 
412
camel_imap_store_summary_namespace_set_main (CamelImapStoreSummary *s, const gchar *full_name, gchar dir_sep)
 
413
{
 
414
        CamelImapStoreNamespace *ns;
 
415
 
 
416
        g_return_if_fail (s != NULL);
 
417
        g_return_if_fail (full_name != NULL);
 
418
 
 
419
        ns = namespace_find (s->namespace, full_name, dir_sep);
 
420
 
 
421
        if (ns) {
 
422
                /* is in the list of known namespaces already */
 
423
                if (ns != s->namespace) {
 
424
                        CamelImapStoreNamespace *prev = s->namespace;
 
425
 
 
426
                        while (prev && prev->next != ns)
 
427
                                prev = prev->next;
 
428
 
 
429
                        g_return_if_fail (prev != NULL);
 
430
 
 
431
                        /* move it to the first */
 
432
                        prev->next = ns->next;
 
433
                        ns->next = s->namespace;
 
434
                        s->namespace = ns;
 
435
 
 
436
                        /* fix a dir separator, for the inherit/guess option */
 
437
                        if (dir_sep != 0)
 
438
                                s->namespace->sep = dir_sep;
 
439
                } else
 
440
                        return;
 
441
        } else {
 
442
                if (!dir_sep && s->namespace)
 
443
                        dir_sep = s->namespace->sep; /* inherit */
 
444
                else if (!dir_sep)
 
445
                        dir_sep = '/'; /* guess */
 
446
 
 
447
                ns = namespace_new (s, full_name, dir_sep);
 
448
                if (ns) {
 
449
                        ns->next = s->namespace;
 
450
                        s->namespace = ns;
 
451
                }
 
452
        }
 
453
 
 
454
        camel_store_summary_touch ((CamelStoreSummary *)s);
 
455
}
 
456
 
 
457
void
 
458
camel_imap_store_summary_namespace_add_secondary (CamelImapStoreSummary *s, const gchar *full_name, gchar dir_sep)
 
459
{
 
460
        CamelImapStoreNamespace **tail;
 
461
 
 
462
        g_return_if_fail (s != NULL);
 
463
        g_return_if_fail (full_name != NULL);
 
464
 
 
465
        if (namespace_find (s->namespace, full_name, dir_sep))
 
466
                return;
 
467
 
 
468
        for (tail = &s->namespace; *tail; tail = &((*tail)->next)) {
 
469
                /* do nothing, just keep moving to the last */
 
470
        }
 
471
 
 
472
        *tail = namespace_new (s, full_name, dir_sep);
 
473
}
 
474
 
 
475
CamelImapStoreNamespace *
 
476
camel_imap_store_summary_get_main_namespace (CamelImapStoreSummary *s)
 
477
{
 
478
        g_return_val_if_fail (s != NULL, NULL);
 
479
 
 
480
        return s->namespace;
399
481
}
400
482
 
401
483
CamelImapStoreNamespace *
404
486
        gint len;
405
487
        CamelImapStoreNamespace *ns;
406
488
 
407
 
        /* NB: this currently only compares against 1 namespace, in future compare against others */
408
489
        ns = s->namespace;
409
490
        while (ns) {
410
491
                len = strlen(ns->path);
412
493
                    || (strncmp(ns->path, path, len) == 0
413
494
                        && (path[len] == '/' || path[len] == 0)))
414
495
                        break;
415
 
                ns = NULL;
 
496
                ns = ns->next;
416
497
        }
417
498
 
418
 
        /* have a default? */
 
499
        /* NULL indicates not found */
419
500
        return ns;
420
501
}
421
502
 
425
506
        gint len;
426
507
        CamelImapStoreNamespace *ns;
427
508
 
428
 
        /* NB: this currently only compares against 1 namespace, in future compare against others */
429
509
        ns = s->namespace;
430
510
        while (ns) {
431
511
                len = strlen(ns->full_name);
434
514
                    || (strncmp(ns->full_name, full, len) == 0
435
515
                        && (full[len] == ns->sep || full[len] == 0)))
436
516
                        break;
437
 
                ns = NULL;
 
517
                ns = ns->next;
438
518
        }
439
519
 
440
 
        /* have a default? */
 
520
        /* NULL indicates not found */
441
521
        return ns;
442
522
}
443
523
 
444
524
static void
445
 
namespace_free(CamelStoreSummary *s, CamelImapStoreNamespace *ns)
 
525
namespace_free (CamelImapStoreSummary *is, CamelImapStoreNamespace *ns)
446
526
{
447
527
        g_free(ns->path);
448
528
        g_free(ns->full_name);
450
530
}
451
531
 
452
532
static void
453
 
namespace_clear(CamelStoreSummary *s)
 
533
namespace_clear (CamelImapStoreSummary *is)
454
534
{
455
 
        CamelImapStoreSummary *is = (CamelImapStoreSummary *)s;
 
535
        while (is->namespace) {
 
536
                CamelImapStoreNamespace *next = is->namespace->next;
456
537
 
457
 
        if (is->namespace)
458
 
                namespace_free(s, is->namespace);
459
 
        is->namespace = NULL;
 
538
                namespace_free (is, is->namespace);
 
539
                is->namespace = next;
 
540
        }
460
541
}
461
542
 
462
 
static CamelImapStoreNamespace *
463
 
namespace_load(CamelStoreSummary *s, FILE *in)
 
543
static gboolean
 
544
namespaces_load (CamelImapStoreSummary *s, FILE *in, guint count)
464
545
{
465
 
        CamelImapStoreNamespace *ns;
 
546
        CamelImapStoreNamespace *ns, **tail;
466
547
        guint32 sep = '/';
467
548
 
468
 
        ns = g_malloc0(sizeof(*ns));
469
 
        if (camel_file_util_decode_string(in, &ns->path) == -1
470
 
            || camel_file_util_decode_string(in, &ns->full_name) == -1
471
 
            || camel_file_util_decode_uint32(in, &sep) == -1) {
472
 
                namespace_free(s, ns);
473
 
                ns = NULL;
474
 
        } else {
475
 
                ns->sep = sep;
 
549
        namespace_clear (s);
 
550
 
 
551
        tail = &s->namespace;
 
552
 
 
553
        while (count > 0) {
 
554
                ns = g_malloc0 (sizeof(*ns));
 
555
                if (camel_file_util_decode_string (in, &ns->path) == -1
 
556
                    || camel_file_util_decode_string (in, &ns->full_name) == -1
 
557
                    || camel_file_util_decode_uint32 (in, &sep) == -1) {
 
558
                        namespace_free (s, ns);
 
559
                        return FALSE;
 
560
                } else {
 
561
                        ns->sep = sep;
 
562
 
 
563
                        *tail = ns;
 
564
                        tail = &ns->next;
 
565
                }
 
566
 
 
567
                count --;
476
568
        }
477
569
 
478
 
        return ns;
 
570
        return count == 0;
479
571
}
480
572
 
481
 
static gint
482
 
namespace_save(CamelStoreSummary *s, FILE *in, CamelImapStoreNamespace *ns)
 
573
static gboolean
 
574
namespaces_save (CamelImapStoreSummary *s, FILE *in, CamelImapStoreNamespace *ns)
483
575
{
484
 
        if (camel_file_util_encode_string(in, ns->path) == -1
485
 
            || camel_file_util_encode_string(in, ns->full_name) == -1
486
 
            || camel_file_util_encode_uint32(in, (guint32)ns->sep) == -1)
487
 
                return -1;
488
 
 
489
 
        return 0;
 
576
        while (ns) {
 
577
                if (camel_file_util_encode_string(in, ns->path) == -1
 
578
                    || camel_file_util_encode_string(in, ns->full_name) == -1
 
579
                    || camel_file_util_encode_uint32(in, (guint32)ns->sep) == -1)
 
580
                        return FALSE;
 
581
 
 
582
                ns = ns->next;
 
583
        }
 
584
 
 
585
        return TRUE;
490
586
}
491
587
 
492
588
static gint
495
591
        CamelImapStoreSummary *is = (CamelImapStoreSummary *)s;
496
592
        gint32 version, capabilities, count;
497
593
 
498
 
        namespace_clear(s);
 
594
        namespace_clear (is);
499
595
 
500
596
        if (camel_imap_store_summary_parent->summary_header_load((CamelStoreSummary *)s, in) == -1
501
597
            || camel_file_util_decode_fixed_int32(in, &version) == -1)
508
604
                return -1;
509
605
        }
510
606
 
511
 
        /* note file format can be expanded to contain more namespaces, but only 1 at the moment */
512
607
        if (camel_file_util_decode_fixed_int32(in, &capabilities) == -1
513
 
            || camel_file_util_decode_fixed_int32(in, &count) == -1
514
 
            || count > 1)
 
608
            || camel_file_util_decode_fixed_int32(in, &count) == -1)
515
609
                return -1;
516
610
 
517
611
        is->capabilities = capabilities;
518
 
        if (count == 1) {
519
 
                if ((is->namespace = namespace_load(s, in)) == NULL)
 
612
        if (count >= 1) {
 
613
                if (!namespaces_load (is, in, count))
520
614
                        return -1;
521
615
        }
522
616
 
527
621
summary_header_save(CamelStoreSummary *s, FILE *out)
528
622
{
529
623
        CamelImapStoreSummary *is = (CamelImapStoreSummary *)s;
530
 
        guint32 count;
 
624
        guint32 count = 0;
 
625
        CamelImapStoreNamespace *ns;
531
626
 
532
 
        count = is->namespace?1:0;
 
627
        for (ns = is->namespace; ns; ns = ns->next) {
 
628
                count++;
 
629
        }
533
630
 
534
631
        /* always write as latest version */
535
632
        if (camel_imap_store_summary_parent->summary_header_save((CamelStoreSummary *)s, out) == -1
538
635
            || camel_file_util_encode_fixed_int32(out, count) == -1)
539
636
                return -1;
540
637
 
541
 
        if (is->namespace && namespace_save(s, out, is->namespace) == -1)
 
638
        if (!namespaces_save (is, out, is->namespace))
542
639
                return -1;
543
640
 
544
641
        return 0;