Switch to unified view

a/src/utils/mimeparse.cpp b/src/utils/mimeparse.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: mimeparse.cpp,v 1.17 2006-11-30 13:38:44 dockes Exp $ (C) 2004 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: mimeparse.cpp,v 1.18 2007-01-18 14:23:42 dockes Exp $ (C) 2004 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
35
35
36
36
37
#ifndef NO_NAMESPACES
37
#ifndef NO_NAMESPACES
38
using namespace std;
38
using namespace std;
39
#endif /* NO_NAMESPACES */
39
#endif /* NO_NAMESPACES */
40
41
//#define DEBUG_MIMEPARSE 
42
#ifdef DEBUG_MIMEPARSE
43
#define DPRINT(X) fprintf X
44
#else
45
#define DPRINT(X)
46
#endif
40
47
41
// Parsing a header value. Only content-type and content-disposition
48
// Parsing a header value. Only content-type and content-disposition
42
// have parameters, but others are compatible with content-type
49
// have parameters, but others are compatible with content-type
43
// syntax, only, parameters are not used. So we can parse all like:
50
// syntax, only, parameters are not used. So we can parse all like:
44
//
51
//
...
...
424
static bool rfc2047_decodeParsed(const std::string& charset, 
431
static bool rfc2047_decodeParsed(const std::string& charset, 
425
                 const std::string& encoding, 
432
                 const std::string& encoding, 
426
                 const std::string& value, 
433
                 const std::string& value, 
427
                 std::string &utf8)
434
                 std::string &utf8)
428
{
435
{
429
    //    fprintf(stderr, "DecodeParsed: charset [%s] enc [%s] val [%s]\n",
436
    DPRINT((stderr, "DecodeParsed: charset [%s] enc [%s] val [%s]\n",
430
    //       charset.c_str(), encoding.c_str(), value.c_str());
437
        charset.c_str(), encoding.c_str(), value.c_str()));
431
    utf8 = "";
438
    utf8 = "";
432
439
433
    string decoded;
440
    string decoded;
434
    if (!stringlowercmp("b", encoding)) {
441
    if (!stringlowercmp("b", encoding)) {
435
    if (!base64_decode(value, decoded))
442
    if (!base64_decode(value, decoded))
436
        return false;
443
        return false;
437
    //    fprintf(stderr, "FromB64: [%s]\n", decoded.c_str());
444
    DPRINT((stderr, "FromB64: [%s]\n", decoded.c_str()));
438
    } else if (!stringlowercmp("q", encoding)) {
445
    } else if (!stringlowercmp("q", encoding)) {
439
    if (!qp_decode(value, decoded))
446
    if (!qp_decode(value, decoded))
440
        return false;
447
        return false;
441
    // Need to translate _ to ' ' here
448
    // Need to translate _ to ' ' here
442
    string temp;
449
    string temp;
...
...
444
        if (decoded[pos] == '_')
451
        if (decoded[pos] == '_')
445
        temp += ' ';
452
        temp += ' ';
446
        else 
453
        else 
447
        temp += decoded[pos];
454
        temp += decoded[pos];
448
    decoded = temp;
455
    decoded = temp;
449
    //    fprintf(stderr, "FromQP: [%s]\n", decoded.c_str());
456
    DPRINT((stderr, "FromQP: [%s]\n", decoded.c_str()));
450
    } else {
457
    } else {
451
    //    fprintf(stderr, "Bad encoding [%s]\n", encoding.c_str());
458
    DPRINT((stderr, "Bad encoding [%s]\n", encoding.c_str()));
452
    return false;
459
    return false;
453
    }
460
    }
454
461
455
    if (!transcode(decoded, utf8, charset, "UTF-8")) {
462
    if (!transcode(decoded, utf8, charset, "UTF-8")) {
456
    //    fprintf(stderr, "Transcode failed\n");
463
    DPRINT((stderr, "Transcode failed\n"));
457
    return false;
464
    return false;
458
    }
465
    }
459
    return true;
466
    return true;
460
}
467
}
461
468
...
...
469
           rfc2047charset, rfc2047encoding, 
476
           rfc2047charset, rfc2047encoding, 
470
           rfc2047value, rfc2047close_q} Rfc2047States;
477
           rfc2047value, rfc2047close_q} Rfc2047States;
471
478
472
bool rfc2047_decode(const std::string& in, std::string &out) 
479
bool rfc2047_decode(const std::string& in, std::string &out) 
473
{
480
{
481
    DPRINT((stderr, "rfc2047_decode: [%s]\n", in.c_str()));
482
474
    Rfc2047States state = rfc2047ready;
483
    Rfc2047States state = rfc2047ready;
475
    string encoding, charset, value, utf8;
484
    string encoding, charset, value, utf8;
476
485
477
    out = "";
486
    out = "";
478
487