~ubuntu-branches/ubuntu/saucy/evolution-data-server/saucy

« back to all changes in this revision

Viewing changes to camel/camel-mime-utils.c

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-10-08 12:58:16 UTC
  • mfrom: (181.1.7 quantal)
  • Revision ID: package-import@ubuntu.com-20121008125816-i3n76e8c0m64e7xp
Tags: 3.6.0-0ubuntu2
* Fix LP: #1038047 part 1 - Don't abort in e_source_registry_new* when a
  problem occurs connecting to the Dbus service
  - add debian/patches/dont-abort-in-e_source_registry_new.patch
  - update debian/patches/series
* Fix LP: #1038047 part 2 - libedataserver depends on
  evolution-data-server-common to ensure that the GSettings schemas are
  present
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
633
633
        inend = in + len;
634
634
        outptr = out;
635
635
 
636
 
        d(printf("quoted-printable, decoding text '%.*s'\n", len, in));
 
636
        d (printf ("quoted-printable, decoding text '%.*s'\n", len, in));
637
637
 
638
638
        state = *savestate;
639
639
        save = *saveme;
729
729
        inend = in + len;
730
730
        outptr = out;
731
731
 
732
 
        d(printf("decoding text '%.*s'\n", len, in));
 
732
        d (printf ("decoding text '%.*s'\n", len, in));
733
733
 
734
734
        inptr = in;
735
735
        while (inptr < inend) {
786
786
                }
787
787
        }
788
788
 
789
 
        d(printf("encoding '%.*s' = '%.*s'\n", len, in, outptr-out, out));
 
789
        d (printf ("encoding '%.*s' = '%.*s'\n", len, in, outptr - out, out));
790
790
 
791
791
        return (outptr - out);
792
792
}
797
797
        const gchar *inptr = *in;
798
798
        gchar c;
799
799
 
800
 
        d2(printf("is ws: '%s'\n", *in));
 
800
        d2 (printf ("is ws: '%s'\n", *in));
801
801
 
802
802
        while ((camel_mime_is_lwsp (*inptr) || *inptr =='(') && *inptr != '\0') {
803
803
                while (camel_mime_is_lwsp (*inptr) && *inptr != '\0') {
804
 
                        d2(printf("(%c)", *inptr));
 
804
                        d2 (printf ("(%c)", *inptr));
805
805
                        inptr++;
806
806
                }
807
 
                d2(printf("\n"));
 
807
                d2 (printf ("\n"));
808
808
 
809
809
                /* check for comments */
810
810
                if (*inptr == '(') {
906
906
 
907
907
        errnosav = errno;
908
908
 
909
 
        w(g_warning ("camel_iconv_strndup: %s at byte %lu", g_strerror (errno), n - inleft));
 
909
        w (g_warning ("camel_iconv_strndup: %s at byte %lu", g_strerror (errno), n - inleft));
910
910
 
911
911
        g_free (out);
912
912
 
1115
1115
                declen = quoted_decode (inptr, inend - inptr, decoded);
1116
1116
 
1117
1117
                if (declen == -1) {
1118
 
                        d(fprintf (stderr, "encountered broken 'Q' encoding\n"));
 
1118
                        d (fprintf (stderr, "encountered broken 'Q' encoding\n"));
1119
1119
                        return NULL;
1120
1120
                }
1121
1121
                break;
1122
1122
        default:
1123
 
                d(fprintf (stderr, "unknown encoding\n"));
 
1123
                d (fprintf (stderr, "unknown encoding\n"));
1124
1124
                return NULL;
1125
1125
        }
1126
1126
 
1162
1162
                charset = camel_iconv_charset_name (charset);
1163
1163
 
1164
1164
        if (!charset[0] || (cd = camel_iconv_open ("UTF-8", charset)) == (iconv_t) -1) {
1165
 
                w(g_warning ("Cannot convert from %s to UTF-8, header display may "
1166
 
                             "be corrupt: %s", charset[0] ? charset : "unspecified charset",
1167
 
                             g_strerror (errno)));
 
1165
                w (g_warning (
 
1166
                        "Cannot convert from %s to UTF-8, "
 
1167
                        "header display may be corrupt: %s",
 
1168
                        charset[0] ? charset : "unspecified charset",
 
1169
                        g_strerror (errno)));
1168
1170
 
1169
1171
                return decode_8bit ((gchar *) decoded, declen, default_charset);
1170
1172
        }
1175
1177
        if (buf != NULL)
1176
1178
                return buf;
1177
1179
 
1178
 
        w(g_warning ("Failed to convert \"%.*s\" to UTF-8, display may be "
1179
 
                     "corrupt: %s", declen, decoded, g_strerror (errno)));
 
1180
        w (g_warning (
 
1181
                "Failed to convert \"%.*s\" to UTF-8, display may be "
 
1182
                "corrupt: %s", declen, decoded, g_strerror (errno)));
1180
1183
 
1181
1184
        return decode_8bit ((gchar *) decoded, declen, charset);
1182
1185
}
1223
1226
        outbuf = outbase = g_malloc (outlen);
1224
1227
 
1225
1228
        if (camel_iconv (ic, &inbuf, &inlen, &outbuf, &outlen) == (gsize) -1) {
1226
 
                w(g_warning("Conversion to '%s' failed: %s", charset, g_strerror (errno)));
 
1229
                w (g_warning ("Conversion to '%s' failed: %s", charset, g_strerror (errno)));
1227
1230
                g_free (outbase);
1228
1231
                camel_iconv_close (ic);
1229
1232
                return FALSE;
1436
1439
        const gchar *inptr, *p;
1437
1440
        gint first = 1;
1438
1441
 
1439
 
        d(printf("Converting [%d] '%.*s' to %s\n", len, len, in, type));
 
1442
        d (printf ("Converting [%d] '%.*s' to %s\n", len, len, in, type));
1440
1443
 
1441
1444
        /* convert utf8->encoding */
1442
1445
        bufflen = len * 6 + 16;
1468
1471
                        proclen = -1;
1469
1472
                        p = inptr;
1470
1473
                        i = 0;
1471
 
                        while (p < (in+len) && convlen < (75 - strlen("=?utf-8?q?\?="))) {
 
1474
                        while (p < (in + len) && convlen < (75 - strlen ("=?utf-8?q?\?="))) {
1472
1475
                                guchar c = *p++;
1473
1476
 
1474
1477
                                if (c >= 0xc0)
1482
1485
                                        convlen += 3;
1483
1486
                        }
1484
1487
 
1485
 
                        if (proclen >= 0 && proclen < i && convlen < (75 - strlen("=?utf-8?q?\?=")))
 
1488
                        if (proclen >= 0 && proclen < i && convlen < (75 - strlen ("=?utf-8?q?\?=")))
1486
1489
                                proclen = i;
1487
1490
 
1488
1491
                        /* well, we probably have broken utf8, just copy it anyway what the heck */
1489
1492
                        if (proclen == -1) {
1490
 
                                w(g_warning("Appear to have truncated utf8 sequence"));
 
1493
                                w (g_warning ("Appear to have truncated utf8 sequence"));
1491
1494
                                proclen = inlen;
1492
1495
                        }
1493
1496
 
1501
1504
                        convlen = MIN (inlen, CAMEL_FOLD_PREENCODED);
1502
1505
                        p = inptr;
1503
1506
                        if (camel_iconv (ic, &inptr, (gsize *) &convlen, &out, &outlen) == (gsize) -1 && errno != EINVAL) {
1504
 
                                w(g_warning("Conversion problem: conversion truncated: %s", g_strerror (errno)));
 
1507
                                w (g_warning ("Conversion problem: conversion truncated: %s", g_strerror (errno)));
1505
1508
                                /* blah, we include it anyway, better than infinite loop ... */
1506
1509
                                inptr += convlen;
1507
1510
                        } else {
1524
1527
                        out += quoted_encode ((guchar *) buffer, enclen, (guchar *) out, safemask);
1525
1528
                        sprintf (out, "?=");
1526
1529
 
1527
 
                        d(printf("converted part = %s\n", ascii));
 
1530
                        d (printf ("converted part = %s\n", ascii));
1528
1531
 
1529
1532
                        g_string_append (outstring, ascii);
1530
1533
                }
1575
1578
                newinptr = g_utf8_next_char (inptr);
1576
1579
                c = g_utf8_get_char ((gchar *) inptr);
1577
1580
                if (newinptr == NULL || !g_unichar_validate (c)) {
1578
 
                        w(g_warning ("Invalid UTF-8 sequence encountered (pos %d, gchar '%c'): %s",
1579
 
                                     (inptr - in), inptr[0], in));
 
1581
                        w (g_warning (
 
1582
                                "Invalid UTF-8 sequence encountered "
 
1583
                                "(pos %d, gchar '%c'): %s",
 
1584
                                (inptr - in), inptr[0], in));
1580
1585
                        inptr++;
1581
1586
                        continue;
1582
1587
                }
1755
1760
                c = g_utf8_get_char ((gchar *) inptr);
1756
1761
 
1757
1762
                if (!g_unichar_validate (c)) {
1758
 
                        w(g_warning ("Invalid UTF-8 sequence encountered (pos %d, gchar '%c'): %s",
1759
 
                                     (inptr - in), inptr[0], in));
 
1763
                        w (g_warning (
 
1764
                                "Invalid UTF-8 sequence encountered "
 
1765
                                "(pos %d, gchar '%c'): %s",
 
1766
                                (inptr - in), inptr[0], in));
1760
1767
                        inptr++;
1761
1768
                        continue;
1762
1769
                }
2065
2072
 
2066
2073
        header_decode_lwsp (&inptr);
2067
2074
        if (*inptr == '"') {
2068
 
                d(printf("decoding quoted string\n"));
 
2075
                d (printf ("decoding quoted string\n"));
2069
2076
                return header_decode_quoted_string (in);
2070
2077
        } else if (camel_mime_is_ttoken (*inptr)) {
2071
 
                d(printf("decoding token\n"));
 
2078
                d (printf ("decoding token\n"));
2072
2079
                /* this may not have the right specials for all params? */
2073
2080
                return decode_token (in);
2074
2081
        }
2191
2198
                return NULL;
2192
2199
 
2193
2200
        decword = hex_decode (inptr, inend - inptr);
2194
 
        decoded = header_convert("UTF-8", charset, decword, strlen(decword));
 
2201
        decoded = header_convert ("UTF-8", charset, decword, strlen (decword));
2195
2202
        g_free (decword);
2196
2203
 
2197
2204
        return decoded;
2322
2329
{
2323
2330
        /* no type == text/plain or text/"*" */
2324
2331
        if (ct == NULL || (ct->type == NULL && ct->subtype == NULL)) {
2325
 
                return (!g_ascii_strcasecmp(type, "text")
2326
 
                        && (!g_ascii_strcasecmp(subtype, "plain")
2327
 
                            || !strcmp(subtype, "*")));
 
2332
                return (!g_ascii_strcasecmp (type, "text")
 
2333
                        && (!g_ascii_strcasecmp (subtype, "plain")
 
2334
                        || !strcmp (subtype, "*")));
2328
2335
        }
2329
2336
 
2330
2337
        return (ct->type != NULL
2331
2338
                && (!g_ascii_strcasecmp (ct->type, type)
2332
 
                    && ((ct->subtype != NULL
2333
 
                         && !g_ascii_strcasecmp (ct->subtype, subtype))
2334
 
                        || !strcmp("*", subtype))));
 
2339
                && ((ct->subtype != NULL
 
2340
                && !g_ascii_strcasecmp (ct->subtype, subtype))
 
2341
                        || !strcmp ("*", subtype))));
2335
2342
}
2336
2343
 
2337
2344
/**
2420
2427
        const gchar *inptr = *in;
2421
2428
        gint go = TRUE;
2422
2429
        gchar *ret;
2423
 
        GString *domain = g_string_new("");
 
2430
        GString *domain = g_string_new ("");
2424
2431
 
2425
2432
        /* domain ref | domain literal */
2426
2433
        header_decode_lwsp (&inptr);
2437
2444
                                domain = g_string_append_c (domain, ']');
2438
2445
                                inptr++;
2439
2446
                        } else {
2440
 
                                w(g_warning("closing ']' not found in domain: %s", *in));
 
2447
                                w (g_warning ("closing ']' not found in domain: %s", *in));
2441
2448
                        }
2442
2449
                } else {
2443
2450
                        gchar *a = header_decode_atom (&inptr);
2445
2452
                                domain = g_string_append (domain, a);
2446
2453
                                g_free (a);
2447
2454
                        } else {
2448
 
                                w(g_warning("missing atom from domain-ref"));
 
2455
                                w (g_warning ("missing atom from domain-ref"));
2449
2456
                                break;
2450
2457
                        }
2451
2458
                }
2470
2477
{
2471
2478
        const gchar *inptr = *in;
2472
2479
        gchar *word;
2473
 
        GString *addr = g_string_new("");
 
2480
        GString *addr = g_string_new ("");
2474
2481
 
2475
2482
        header_decode_lwsp (&inptr);
2476
2483
 
2489
2496
                                header_decode_lwsp (&inptr);
2490
2497
                                g_free (word);
2491
2498
                        } else {
2492
 
                                w(g_warning("Invalid address spec: %s", *in));
 
2499
                                w (g_warning ("Invalid address spec: %s", *in));
2493
2500
                        }
2494
2501
                }
2495
2502
                if (*inptr == '@') {
2500
2507
                                addr = g_string_append (addr, word);
2501
2508
                                g_free (word);
2502
2509
                        } else {
2503
 
                                w(g_warning("Invalid address, missing domain: %s", *in));
 
2510
                                w (g_warning ("Invalid address, missing domain: %s", *in));
2504
2511
                        }
2505
2512
                } else {
2506
 
                        w(g_warning("Invalid addr-spec, missing @: %s", *in));
 
2513
                        w (g_warning ("Invalid addr-spec, missing @: %s", *in));
2507
2514
                }
2508
2515
        } else {
2509
 
                w(g_warning("invalid addr-spec, no local part"));
 
2516
                w (g_warning ("invalid addr-spec, no local part"));
2510
2517
                g_string_free (addr, TRUE);
2511
2518
 
2512
2519
                return NULL;
2545
2552
        struct _camel_header_address *address = NULL;
2546
2553
        const gchar *comment = NULL;
2547
2554
 
2548
 
        addr = g_string_new("");
 
2555
        addr = g_string_new ("");
2549
2556
 
2550
2557
        /* for each address */
2551
2558
        pre = header_decode_word (&inptr);
2578
2585
                                /* Fix for stupidly-broken-mailers that like to put '.''s in names unquoted */
2579
2586
                                /* see bug #8147 */
2580
2587
                                while (!pre && *inptr && *inptr != '<') {
2581
 
                                        w(g_warning("Working around stupid mailer bug #5: unescaped characters in names"));
 
2588
                                        w (g_warning ("Working around stupid mailer bug #5: unescaped characters in names"));
2582
2589
                                        name = g_string_append_c (name, *inptr++);
2583
2590
                                        pre = header_decode_word (&inptr);
2584
2591
                                }
2604
2611
                                if (*inptr == ':') {
2605
2612
                                        inptr++;
2606
2613
                                } else {
2607
 
                                        w(g_warning("broken route-address, missing ':': %s", *in));
 
2614
                                        w (g_warning ("broken route-address, missing ':': %s", *in));
2608
2615
                                }
2609
2616
                        }
2610
2617
                        pre = header_decode_word (&inptr);
2611
2618
                        /*header_decode_lwsp(&inptr);*/
2612
2619
                } else {
2613
 
                        w(g_warning("broken address? %s", *in));
 
2620
                        w (g_warning ("broken address? %s", *in));
2614
2621
                }
2615
2622
        }
2616
2623
 
2617
2624
        if (pre) {
2618
2625
                addr = g_string_append (addr, pre);
2619
2626
        } else {
2620
 
                w(g_warning("No local-part for email address: %s", *in));
 
2627
                w (g_warning ("No local-part for email address: %s", *in));
2621
2628
        }
2622
2629
 
2623
2630
        /* should be at word '.' localpart */
2651
2658
                        const gchar *name_part;
2652
2659
                        gboolean in_quote;
2653
2660
 
2654
 
                        w(g_warning("We didn't get an '@' where we expected in '%s', trying again", *in));
2655
 
                        w(g_warning("Name is '%s', Addr is '%s' we're at '%s'\n", name?name->str:"<UNSET>", addr->str, inptr));
 
2661
                        w (g_warning ("We didn't get an '@' where we expected in '%s', trying again", *in));
 
2662
                        w (g_warning ("Name is '%s', Addr is '%s' we're at '%s'\n", name ? name->str:"<UNSET>", addr->str, inptr));
2656
2663
 
2657
2664
                        /* need to keep *inptr, as try_address_again will drop the current character */
2658
2665
                        if (*inptr == '<')
2687
2694
                        text = camel_header_decode_string (addr->str, charset);
2688
2695
                        if (name == NULL) {
2689
2696
                                name = addr;
2690
 
                                addr = g_string_new("");
 
2697
                                addr = g_string_new ("");
2691
2698
                                if (text) {
2692
2699
                                        g_string_truncate (name, 0);
2693
2700
                                        g_string_append (name, text);
2707
2714
 
2708
2715
                        goto try_address_again;
2709
2716
                }
2710
 
                w(g_warning("invalid address, no '@' domain part at %c: %s", *inptr, *in));
 
2717
                w (g_warning ("invalid address, no '@' domain part at %c: %s", *inptr, *in));
2711
2718
        }
2712
2719
 
2713
2720
        if (closeme) {
2715
2722
                if (*inptr == '>') {
2716
2723
                        inptr++;
2717
2724
                } else {
2718
 
                        w(g_warning("invalid route address, no closing '>': %s", *in));
 
2725
                        w (g_warning ("invalid route address, no closing '>': %s", *in));
2719
2726
                }
2720
2727
        } else if (name == NULL && comment != NULL && inptr>comment) { /* check for comment after address */
2721
2728
                gchar *text, *tmp;
2726
2733
                /* FIXME: This wont detect comments inside the domain itself,
2727
2734
                 * but nobody seems to use that feature anyway ... */
2728
2735
 
2729
 
                d(printf("checking for comment from '%s'\n", comment));
 
2736
                d (printf ("checking for comment from '%s'\n", comment));
2730
2737
 
2731
2738
                comstart = strchr (comment, '(');
2732
2739
                if (comstart) {
2737
2744
                                comend--;
2738
2745
 
2739
2746
                        if (comend > comstart) {
2740
 
                                d(printf("  looking at subset '%.*s'\n", comend-comstart, comstart));
 
2747
                                d (printf ("  looking at subset '%.*s'\n", comend - comstart, comstart));
2741
2748
                                tmp = g_strndup (comstart, comend - comstart);
2742
2749
                                text = camel_header_decode_string (tmp, charset);
2743
2750
                                name = g_string_new (text);
2779
2786
 
2780
2787
                }
2781
2788
 
2782
 
                address = camel_header_address_new_name(name ? name->str : "", addr->str);
 
2789
                address = camel_header_address_new_name (name ? name->str : "", addr->str);
2783
2790
        }
2784
2791
 
2785
 
        d(printf("got mailbox: %s\n", addr->str));
 
2792
        d (printf ("got mailbox: %s\n", addr->str));
2786
2793
 
2787
2794
        g_string_free (addr, TRUE);
2788
2795
        if (name)
2797
2804
{
2798
2805
        const gchar *inptr = *in;
2799
2806
        gchar *pre;
2800
 
        GString *group = g_string_new("");
 
2807
        GString *group = g_string_new ("");
2801
2808
        struct _camel_header_address *addr = NULL, *member;
2802
2809
 
2803
2810
        /* pre-scan, trying to work out format, discard results */
2804
2811
        header_decode_lwsp (&inptr);
2805
2812
        while ((pre = header_decode_word (&inptr))) {
2806
2813
                group = g_string_append (group, pre);
2807
 
                group = g_string_append(group, " ");
 
2814
                group = g_string_append (group, " ");
2808
2815
                g_free (pre);
2809
2816
        }
2810
2817
        header_decode_lwsp (&inptr);
2811
2818
        if (*inptr == ':') {
2812
 
                d(printf("group detected: %s\n", group->str));
 
2819
                d (printf ("group detected: %s\n", group->str));
2813
2820
                addr = camel_header_address_new_group (group->str);
2814
2821
                /* that was a group spec, scan mailbox's */
2815
2822
                inptr++;
2830
2837
                        if (*inptr == ';') {
2831
2838
                                inptr++;
2832
2839
                        } else {
2833
 
                                w(g_warning("Invalid group spec, missing closing ';': %s", *in));
 
2840
                                w (g_warning ("Invalid group spec, missing closing ';': %s", *in));
2834
2841
                        }
2835
2842
                } else {
2836
2843
                        inptr++;
2851
2858
        const gchar *inptr = *in;
2852
2859
        gchar *msgid = NULL;
2853
2860
 
2854
 
        d(printf("decoding Message-ID: '%s'\n", *in));
 
2861
        d (printf ("decoding Message-ID: '%s'\n", *in));
2855
2862
 
2856
2863
        header_decode_lwsp (&inptr);
2857
2864
        if (*inptr == '<') {
2863
2870
                        if (*inptr == '>') {
2864
2871
                                inptr++;
2865
2872
                        } else {
2866
 
                                w(g_warning("Missing closing '>' on message id: %s", *in));
 
2873
                                w (g_warning ("Missing closing '>' on message id: %s", *in));
2867
2874
                        }
2868
2875
                } else {
2869
 
                        w(g_warning("Cannot find message id in: %s", *in));
 
2876
                        w (g_warning ("Cannot find message id in: %s", *in));
2870
2877
                }
2871
2878
        } else {
2872
 
                w(g_warning("missing opening '<' on message id: %s", *in));
 
2879
                w (g_warning ("missing opening '<' on message id: %s", *in));
2873
2880
        }
2874
2881
        *in = inptr;
2875
2882
 
2909
2916
        GString *addr;
2910
2917
        gchar *buf;
2911
2918
 
2912
 
        d(printf("decoding Content-ID: '%s'\n", in));
 
2919
        d (printf ("decoding Content-ID: '%s'\n", in));
2913
2920
 
2914
2921
        header_decode_lwsp (&inptr);
2915
2922
 
3098
3105
        const gchar *inptr = in, *last;
3099
3106
        struct _camel_header_address *list = NULL, *addr;
3100
3107
 
3101
 
        d(printf("decoding To: '%s'\n", in));
 
3108
        d (printf ("decoding To: '%s'\n", in));
3102
3109
 
3103
3110
        if (in == NULL)
3104
3111
                return NULL;
3120
3127
        } while (inptr != last);
3121
3128
 
3122
3129
        if (*inptr) {
3123
 
                w(g_warning("Invalid input detected at %c (%d): %s\n or at: %s", *inptr, inptr-in, in, inptr));
 
3130
                w (g_warning ("Invalid input detected at %c (%d): %s\n or at: %s", *inptr, inptr - in, in, inptr));
3124
3131
        }
3125
3132
 
3126
3133
        if (inptr == last) {
3127
 
                w(g_warning("detected invalid input loop at : %s", last));
 
3134
                w (g_warning ("detected invalid input loop at : %s", last));
3128
3135
        }
3129
3136
 
3130
3137
        return list;
3212
3219
        const gchar *inptr = in;
3213
3220
        gint major=-1, minor=-1;
3214
3221
 
3215
 
        d(printf("decoding MIME-Version: '%s'\n", in));
 
3222
        d (printf ("decoding MIME-Version: '%s'\n", in));
3216
3223
 
3217
3224
        if (in != NULL) {
3218
3225
                header_decode_lwsp (&inptr);
3233
3240
        if (min)
3234
3241
                *min = minor;
3235
3242
 
3236
 
        d(printf("major = %d, minor = %d\n", major, minor));
 
3243
        d (printf ("major = %d, minor = %d\n", major, minor));
3237
3244
}
3238
3245
 
3239
3246
struct _rfc2184_param {
3276
3283
        last->next = node;
3277
3284
        node->next = NULL;
3278
3285
        node->name = name;
3279
 
        if (strncmp(value, "=?", 2) == 0
 
3286
        if (strncmp (value, "=?", 2) == 0
3280
3287
            && (node->value = header_decode_text (value, FALSE, NULL))) {
3281
3288
                g_free (value);
3282
 
        } else if (g_ascii_strcasecmp (name, "boundary") != 0 && !g_utf8_validate(value, -1, NULL)) {
 
3289
        } else if (g_ascii_strcasecmp (name, "boundary") != 0 && !g_utf8_validate (value, -1, NULL)) {
3283
3290
                const gchar *charset = camel_iconv_locale_charset ();
3284
3291
 
3285
 
                if ((node->value = header_convert("UTF-8", charset?charset:"ISO-8859-1", value, strlen(value)))) {
 
3292
                if ((node->value = header_convert ("UTF-8", charset ? charset:"ISO-8859-1", value, strlen (value)))) {
3286
3293
                        g_free (value);
3287
3294
                } else {
3288
3295
                        node->value = value;
3357
3364
        /* Rejoin any RFC 2184 split parameters in the proper order */
3358
3365
        /* Parameters with the same index will be concatenated in undefined order */
3359
3366
        if (split) {
3360
 
                GString *value = g_string_new("");
 
3367
                GString *value = g_string_new ("");
3361
3368
                struct _rfc2184_param *first;
3362
3369
                gint i;
3363
3370
 
3448
3455
                return g_strdup ((gchar *) in);
3449
3456
        }
3450
3457
 
3451
 
        if (g_ascii_strcasecmp(charset, "UTF-8") != 0) {
3452
 
                if ((outbuf = (guchar *) header_convert(charset, "UTF-8", (const gchar *) in, strlen((gchar *) in))))
 
3458
        if (g_ascii_strcasecmp (charset, "UTF-8") != 0) {
 
3459
                if ((outbuf = (guchar *) header_convert (charset, "UTF-8", (const gchar *) in, strlen ((gchar *) in))))
3453
3460
                        inptr = outbuf;
3454
3461
                else
3455
3462
                        return g_strdup ((gchar *) in);
3457
3464
 
3458
3465
        /* FIXME: set the 'language' as well, assuming we can get that info...? */
3459
3466
        out = g_string_new (charset);
3460
 
        g_string_append(out, "''");
 
3467
        g_string_append (out, "''");
3461
3468
 
3462
3469
        while ((c = *inptr++)) {
3463
3470
                if (camel_mime_is_attrchar (c))
3502
3509
 
3503
3510
                value = header_encode_param ((guchar *) p->value, &encoded, is_filename);
3504
3511
                if (!value) {
3505
 
                        w(g_warning ("appending parameter %s=%s violates rfc2184", p->name, p->value));
 
3512
                        w (g_warning ("appending parameter %s=%s violates rfc2184", p->name, p->value));
3506
3513
                        value = g_strdup (p->value);
3507
3514
                }
3508
3515
 
3563
3570
                                else
3564
3571
                                        quote_word (out, TRUE, inptr, ptr - inptr);
3565
3572
 
3566
 
                                d(printf ("wrote: %s\n", out->str + here));
 
3573
                                d (printf ("wrote: %s\n", out->str + here));
3567
3574
 
3568
3575
                                used += (out->len - here);
3569
3576
 
3592
3599
gchar *
3593
3600
camel_header_param_list_format (struct _camel_header_param *p)
3594
3601
{
3595
 
        GString *out = g_string_new("");
 
3602
        GString *out = g_string_new ("");
3596
3603
        gchar *ret;
3597
3604
 
3598
3605
        camel_header_param_list_format_append (out, p);
3618
3625
                        inptr++;
3619
3626
                        subtype = decode_token (&inptr);
3620
3627
                }
3621
 
                if (subtype == NULL && (!g_ascii_strcasecmp(type, "text"))) {
3622
 
                        w(g_warning("text type with no subtype, resorting to text/plain: %s", in));
3623
 
                        subtype = g_strdup("plain");
 
3628
                if (subtype == NULL && (!g_ascii_strcasecmp (type, "text"))) {
 
3629
                        w (g_warning ("text type with no subtype, resorting to text/plain: %s", in));
 
3630
                        subtype = g_strdup ("plain");
3624
3631
                }
3625
3632
                if (subtype == NULL) {
3626
 
                        w(g_warning("MIME type with no subtype: %s", in));
 
3633
                        w (g_warning ("MIME type with no subtype: %s", in));
3627
3634
                }
3628
3635
 
3629
3636
                t = camel_content_type_new (type, subtype);
3632
3639
                g_free (subtype);
3633
3640
        } else {
3634
3641
                g_free (type);
3635
 
                d(printf("cannot find MIME type in header (2) '%s'", in));
 
3642
                d (printf ("cannot find MIME type in header (2) '%s'", in));
3636
3643
        }
3637
3644
        return t;
3638
3645
}
3642
3649
{
3643
3650
        struct _camel_header_param *p;
3644
3651
 
3645
 
        printf("Content-Type: ");
 
3652
        printf ("Content-Type: ");
3646
3653
        if (ct == NULL) {
3647
 
                printf("<NULL>\n");
 
3654
                printf ("<NULL>\n");
3648
3655
                return;
3649
3656
        }
3650
 
        printf("%s / %s", ct->type, ct->subtype);
 
3657
        printf ("%s / %s", ct->type, ct->subtype);
3651
3658
        p = ct->params;
3652
3659
        if (p) {
3653
3660
                while (p) {
3654
 
                        printf(";\n\t%s=\"%s\"", p->name, p->value);
 
3661
                        printf (";\n\t%s=\"%s\"", p->name, p->value);
3655
3662
                        p = p->next;
3656
3663
                }
3657
3664
        }
3658
 
        printf("\n");
 
3665
        printf ("\n");
3659
3666
}
3660
3667
 
3661
3668
gchar *
3670
3677
        out = g_string_new ("");
3671
3678
        if (ct->type == NULL) {
3672
3679
                g_string_append_printf (out, "text/plain");
3673
 
                w(g_warning ("Content-Type with no main type"));
 
3680
                w (g_warning ("Content-Type with no main type"));
3674
3681
        } else if (ct->subtype == NULL) {
3675
 
                w(g_warning ("Content-Type with no sub type: %s", ct->type));
 
3682
                w (g_warning ("Content-Type with no sub type: %s", ct->type));
3676
3683
                if (!g_ascii_strcasecmp (ct->type, "multipart"))
3677
3684
                        g_string_append_printf (out, "%s/mixed", ct->type);
3678
3685
                else
3692
3699
camel_content_type_simple (CamelContentType *ct)
3693
3700
{
3694
3701
        if (ct->type == NULL) {
3695
 
                w(g_warning ("Content-Type with no main type"));
 
3702
                w (g_warning ("Content-Type with no main type"));
3696
3703
                return g_strdup ("text/plain");
3697
3704
        } else if (ct->subtype == NULL) {
3698
 
                w(g_warning ("Content-Type with no sub type: %s", ct->type));
 
3705
                w (g_warning ("Content-Type with no sub type: %s", ct->type));
3699
3706
                if (!g_ascii_strcasecmp (ct->type, "multipart"))
3700
3707
                        return g_strdup_printf ("%s/mixed", ct->type);
3701
3708
                else
3726
3733
        d->refcount = 1;
3727
3734
        d->disposition = decode_token (&inptr);
3728
3735
        if (d->disposition == NULL) {
3729
 
                w(g_warning("Empty disposition type"));
 
3736
                w (g_warning ("Empty disposition type"));
3730
3737
        }
3731
3738
        d->params = header_decode_param_list (&inptr);
3732
3739
        return d;
3762
3769
        if (d == NULL)
3763
3770
                return NULL;
3764
3771
 
3765
 
        out = g_string_new("");
 
3772
        out = g_string_new ("");
3766
3773
        if (d->disposition)
3767
3774
                out = g_string_append (out, d->disposition);
3768
3775
        else
3769
 
                out = g_string_append(out, "attachment");
 
3776
                out = g_string_append (out, "attachment");
3770
3777
        camel_header_param_list_format_append (out, d->params);
3771
3778
 
3772
3779
        ret = out->str;
3856
3863
{
3857
3864
        struct tm tm;
3858
3865
 
3859
 
        d(printf("offset = %d\n", tz_offset));
 
3866
        d (printf ("offset = %d\n", tz_offset));
3860
3867
 
3861
 
        d(printf("converting date %s", ctime(&date)));
 
3868
        d (printf ("converting date %s", ctime (&date)));
3862
3869
 
3863
3870
        date += ((tz_offset / 100) * (60 * 60)) + (tz_offset % 100) * 60;
3864
3871
 
3865
 
        d(printf("converting date %s", ctime(&date)));
 
3872
        d (printf ("converting date %s", ctime (&date)));
3866
3873
 
3867
3874
        gmtime_r (&date, &tm);
3868
3875
 
3869
 
        return g_strdup_printf("%s, %02d %s %04d %02d:%02d:%02d %+05d",
3870
 
                               tm_days[tm.tm_wday],
3871
 
                               tm.tm_mday, tm_months[tm.tm_mon],
3872
 
                               tm.tm_year + 1900,
3873
 
                               tm.tm_hour, tm.tm_min, tm.tm_sec,
3874
 
                               tz_offset);
 
3876
        return g_strdup_printf (
 
3877
                "%s, %02d %s %04d %02d:%02d:%02d %+05d",
 
3878
                tm_days[tm.tm_wday],
 
3879
                tm.tm_mday,
 
3880
                tm_months[tm.tm_mon],
 
3881
                tm.tm_year + 1900,
 
3882
                tm.tm_hour,
 
3883
                tm.tm_min,
 
3884
                tm.tm_sec,
 
3885
                tz_offset);
3875
3886
}
3876
3887
 
3877
3888
/* This is where it gets ugly... */
4241
4252
        while (token) {
4242
4253
                if (is_weekday (token) && !got_wday) {
4243
4254
                        if ((n = get_wday (token->start, token->len)) != -1) {
4244
 
                                d(printf ("weekday; "));
 
4255
                                d (printf ("weekday; "));
4245
4256
                                got_wday = TRUE;
4246
4257
                                tm.tm_wday = n;
4247
4258
                                goto next;
4250
4261
 
4251
4262
                if (is_month (token) && !got_month) {
4252
4263
                        if ((n = get_month (token->start, token->len)) != -1) {
4253
 
                                d(printf ("month; "));
 
4264
                                d (printf ("month; "));
4254
4265
                                got_month = TRUE;
4255
4266
                                tm.tm_mon = n;
4256
4267
                                goto next;
4259
4270
 
4260
4271
                if (is_time (token) && !tm.tm_hour && !tm.tm_min && !tm.tm_sec) {
4261
4272
                        if (get_time (token->start, token->len, &hour, &min, &sec)) {
4262
 
                                d(printf ("time; "));
 
4273
                                d (printf ("time; "));
4263
4274
                                tm.tm_hour = hour;
4264
4275
                                tm.tm_min = min;
4265
4276
                                tm.tm_sec = sec;
4279
4290
                        struct _date_token *t = token;
4280
4291
 
4281
4292
                        if ((n = get_tzone (&t)) != -1) {
4282
 
                                d(printf ("tzone; "));
 
4293
                                d (printf ("tzone; "));
4283
4294
                                got_tzone = TRUE;
4284
4295
                                offset = n;
4285
4296
                                goto next;
4289
4300
                if (is_numeric (token)) {
4290
4301
                        if (token->len == 4 && !tm.tm_year) {
4291
4302
                                if ((n = get_year (token->start, token->len)) != -1) {
4292
 
                                        d(printf ("year; "));
 
4303
                                        d (printf ("year; "));
4293
4304
                                        tm.tm_year = n - 1900;
4294
4305
                                        goto next;
4295
4306
                                }
4299
4310
                                        if ((n = decode_int (token->start, token->len)) > 12) {
4300
4311
                                                goto mday;
4301
4312
                                        } else if (n > 0) {
4302
 
                                                d(printf ("mon; "));
 
4313
                                                d (printf ("mon; "));
4303
4314
                                                got_month = TRUE;
4304
4315
                                                tm.tm_mon = n - 1;
4305
4316
                                        }
4306
4317
                                        goto next;
4307
4318
                                } else if (!tm.tm_mday && (n = get_mday (token->start, token->len)) != -1) {
4308
4319
                                mday:
4309
 
                                        d(printf ("mday; "));
 
4320
                                        d (printf ("mday; "));
4310
4321
                                        tm.tm_mday = n;
4311
4322
                                        goto next;
4312
4323
                                } else if (!tm.tm_year) {
4313
4324
                                        if ((n = get_year (token->start, token->len)) != -1) {
4314
 
                                                d(printf ("2-digit year; "));
 
4325
                                                d (printf ("2-digit year; "));
4315
4326
                                                tm.tm_year = n - 1900;
4316
4327
                                        }
4317
4328
                                        goto next;
4319
4330
                        }
4320
4331
                }
4321
4332
 
4322
 
                d(printf ("???; "));
 
4333
                d (printf ("???; "));
4323
4334
 
4324
4335
        next:
4325
4336
 
4326
4337
                token = token->next;
4327
4338
        }
4328
4339
 
4329
 
        d(printf ("\n"));
 
4340
        d (printf ("\n"));
4330
4341
 
4331
4342
        t = camel_mktime_utc (&tm);
4332
4343
 
4387
4398
camel_header_location_decode (const gchar *in)
4388
4399
{
4389
4400
        gint quote = 0;
4390
 
        GString *out = g_string_new("");
 
4401
        GString *out = g_string_new ("");
4391
4402
        gchar c, *res;
4392
4403
 
4393
4404
        /* Sigh. RFC2557 says:
4438
4449
        cp = (guchar *) header->value;
4439
4450
        while (cp && *cp) {
4440
4451
                if (!isascii (*cp)) {
4441
 
                        w(g_warning("Appending header violates rfc: %s: %s", header->name, header->value));
 
4452
                        w (g_warning ("Appending header violates rfc: %s: %s", header->name, header->value));
4442
4453
                        return;
4443
4454
                }
4444
4455
                cp++;
4462
4473
        while (camel_mime_is_lwsp (*in))
4463
4474
                in++;
4464
4475
        if (fieldlen == 0 || header[fieldlen] != ':') {
4465
 
                printf("Invalid header line: '%s'\n", header);
 
4476
                printf ("Invalid header line: '%s'\n", header);
4466
4477
                return;
4467
4478
        }
4468
4479
        name = g_alloca (fieldlen + 1);
4480
4491
{
4481
4492
        struct _camel_header_raw *l, *n;
4482
4493
 
4483
 
        d(printf("Header: %s: %s\n", name, value));
 
4494
        d (printf ("Header: %s: %s\n", name, value));
4484
4495
 
4485
4496
        n = g_malloc (sizeof (*n));
4486
4497
        n->next = NULL;
4498
4509
 
4499
4510
        /* debug */
4500
4511
#if 0
4501
 
        if (!g_ascii_strcasecmp(name, "To")) {
4502
 
                printf("- Decoding To\n");
 
4512
        if (!g_ascii_strcasecmp (name, "To")) {
 
4513
                printf ("- Decoding To\n");
4503
4514
                camel_header_to_decode (value);
4504
 
        } else if (!g_ascii_strcasecmp(name, "Content-type")) {
4505
 
                printf("- Decoding content-type\n");
 
4515
        } else if (!g_ascii_strcasecmp (name, "Content-type")) {
 
4516
                printf ("- Decoding content-type\n");
4506
4517
                camel_content_type_dump (camel_content_type_decode (value));
4507
 
        } else if (!g_ascii_strcasecmp(name, "MIME-Version")) {
4508
 
                printf("- Decoding mime version\n");
 
4518
        } else if (!g_ascii_strcasecmp (name, "MIME-Version")) {
 
4519
                printf ("- Decoding mime version\n");
4509
4520
                camel_header_mime_decode (value);
4510
4521
        }
4511
4522
#endif
4715
4726
                        errstr = g_malloc0 (len + 1);
4716
4727
                        regerror (errcode, &mail_list_magic[i].regex, errstr, len);
4717
4728
 
4718
 
                        g_warning("Internal error, compiling regex failed: %s: %s", mail_list_magic[i].pattern, errstr);
 
4729
                        g_warning ("Internal error, compiling regex failed: %s: %s", mail_list_magic[i].pattern, errstr);
4719
4730
                        g_free (errstr);
4720
4731
                        failed++;
4721
4732
                }
4846
4857
                        g_free (h->v.addr);
4847
4858
                        h->v.addr = g_strdup (addr);
4848
4859
                } else {
4849
 
                        g_warning("Trying to set the address on a group");
 
4860
                        g_warning ("Trying to set the address on a group");
4850
4861
                }
4851
4862
        }
4852
4863
}
4863
4874
                        /* should this ref them? */
4864
4875
                        h->v.members = group;
4865
4876
                } else {
4866
 
                        g_warning("Trying to set the members on a name, not group");
 
4877
                        g_warning ("Trying to set the members on a name, not group");
4867
4878
                }
4868
4879
        }
4869
4880
}
5044
5055
                        len = strlen (inptr);
5045
5056
                }
5046
5057
 
5047
 
                d(printf("next word '%.*s'\n", len, inptr));
 
5058
                d (printf ("next word '%.*s'\n", len, inptr));
5048
5059
 
5049
5060
                if (outlen + len > CAMEL_FOLD_SIZE) {
5050
 
                        d(printf("outlen = %d wordlen = %d\n", outlen, len));
 
5061
                        d (printf ("outlen = %d wordlen = %d\n", outlen, len));
5051
5062
                        /* strip trailing space */
5052
5063
                        if (out->len > 0 && out->str[out->len - 1] == ' ')
5053
5064
                                g_string_truncate (out, out->len - 1);
5112
5123
        if (needunfold)
5113
5124
                inptr = in = camel_header_unfold (in);
5114
5125
 
5115
 
        out = g_string_new("");
 
5126
        out = g_string_new ("");
5116
5127
        outlen = headerlen + 2;
5117
5128
        while (*inptr) {
5118
5129
                space = inptr;
5124
5135
                else
5125
5136
                        len = space - inptr;
5126
5137
 
5127
 
                d(printf("next word '%.*s'\n", len, inptr));
 
5138
                d (printf ("next word '%.*s'\n", len, inptr));
5128
5139
                if (outlen + len > CAMEL_FOLD_SIZE) {
5129
 
                        d(printf("outlen = %d wordlen = %d\n", outlen, len));
 
5140
                        d (printf ("outlen = %d wordlen = %d\n", outlen, len));
5130
5141
                        /* strip trailing space */
5131
5142
                        if (out->len > 0 && (out->str[out->len - 1] == ' ' || out->str[out->len - 1] == '\t')) {
5132
5143
                                spc = out->str[out->len - 1];