|
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.20 2007-12-13 06:58:22 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: mimeparse.cpp,v 1.21 2008-07-01 11:51:51 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
|
|
... |
|
... |
358 |
if (it->second.chunks.empty())
|
358 |
if (it->second.chunks.empty())
|
359 |
continue;
|
359 |
continue;
|
360 |
string nm = it->first;
|
360 |
string nm = it->first;
|
361 |
// Create the name entry
|
361 |
// Create the name entry
|
362 |
if (parsed.params.find(nm) == parsed.params.end())
|
362 |
if (parsed.params.find(nm) == parsed.params.end())
|
363 |
parsed.params[nm] = "";
|
363 |
parsed.params[nm].clear();
|
364 |
// Concatenate all chunks and decode the whole if the first one needs
|
364 |
// Concatenate all chunks and decode the whole if the first one needs
|
365 |
// to. Yes, this is not quite right.
|
365 |
// to. Yes, this is not quite right.
|
366 |
string value;
|
366 |
string value;
|
367 |
for (vector<Chunk>::const_iterator vi = it->second.chunks.begin();
|
367 |
for (vector<Chunk>::const_iterator vi = it->second.chunks.begin();
|
368 |
vi != it->second.chunks.end(); vi++) {
|
368 |
vi != it->second.chunks.end(); vi++) {
|
|
... |
|
... |
435 |
const std::string& value,
|
435 |
const std::string& value,
|
436 |
std::string &utf8)
|
436 |
std::string &utf8)
|
437 |
{
|
437 |
{
|
438 |
DPRINT((stderr, "DecodeParsed: charset [%s] enc [%s] val [%s]\n",
|
438 |
DPRINT((stderr, "DecodeParsed: charset [%s] enc [%s] val [%s]\n",
|
439 |
charset.c_str(), encoding.c_str(), value.c_str()));
|
439 |
charset.c_str(), encoding.c_str(), value.c_str()));
|
440 |
utf8 = "";
|
440 |
utf8.clear();
|
441 |
|
441 |
|
442 |
string decoded;
|
442 |
string decoded;
|
443 |
if (!stringlowercmp("b", encoding)) {
|
443 |
if (!stringlowercmp("b", encoding)) {
|
444 |
if (!base64_decode(value, decoded))
|
444 |
if (!base64_decode(value, decoded))
|
445 |
return false;
|
445 |
return false;
|
|
... |
|
... |
483 |
DPRINT((stderr, "rfc2047_decode: [%s]\n", in.c_str()));
|
483 |
DPRINT((stderr, "rfc2047_decode: [%s]\n", in.c_str()));
|
484 |
|
484 |
|
485 |
Rfc2047States state = rfc2047ready;
|
485 |
Rfc2047States state = rfc2047ready;
|
486 |
string encoding, charset, value, utf8;
|
486 |
string encoding, charset, value, utf8;
|
487 |
|
487 |
|
488 |
out = "";
|
488 |
out.clear();
|
489 |
|
489 |
|
490 |
for (string::size_type ii = 0; ii < in.length(); ii++) {
|
490 |
for (string::size_type ii = 0; ii < in.length(); ii++) {
|
491 |
char ch = in[ii];
|
491 |
char ch = in[ii];
|
492 |
switch (state) {
|
492 |
switch (state) {
|
493 |
case rfc2047base:
|
493 |
case rfc2047base:
|
|
... |
|
... |
521 |
// we sometimes find 8-bit chars in
|
521 |
// we sometimes find 8-bit chars in
|
522 |
// there. Interpret as Iso8859.
|
522 |
// there. Interpret as Iso8859.
|
523 |
if (value.length() > 0) {
|
523 |
if (value.length() > 0) {
|
524 |
transcode(value, utf8, "ISO-8859-1", "UTF-8");
|
524 |
transcode(value, utf8, "ISO-8859-1", "UTF-8");
|
525 |
out += utf8;
|
525 |
out += utf8;
|
526 |
value = "";
|
526 |
value.clear();
|
527 |
}
|
527 |
}
|
528 |
state = rfc2047charset;
|
528 |
state = rfc2047charset;
|
529 |
}
|
529 |
}
|
530 |
break;
|
530 |
break;
|
531 |
default: state = rfc2047base; out += '='; out += ch;break;
|
531 |
default: state = rfc2047base; out += '='; out += ch;break;
|
|
... |
|
... |
566 |
if (!rfc2047_decodeParsed(charset, encoding, value,
|
566 |
if (!rfc2047_decodeParsed(charset, encoding, value,
|
567 |
utf8)) {
|
567 |
utf8)) {
|
568 |
return false;
|
568 |
return false;
|
569 |
}
|
569 |
}
|
570 |
out += utf8;
|
570 |
out += utf8;
|
571 |
charset = encoding = value = "";
|
571 |
charset.clear();
|
|
|
572 |
encoding.clear();
|
|
|
573 |
value.clear();
|
572 |
}
|
574 |
}
|
573 |
break;
|
575 |
break;
|
574 |
default: state = rfc2047value; value += '?';value += ch;break;
|
576 |
default: state = rfc2047value; value += '?';value += ch;break;
|
575 |
}
|
577 |
}
|
576 |
}
|
578 |
}
|
|
... |
|
... |
581 |
}
|
583 |
}
|
582 |
|
584 |
|
583 |
if (value.length() > 0) {
|
585 |
if (value.length() > 0) {
|
584 |
transcode(value, utf8, "ISO-8859-1", "UTF-8");
|
586 |
transcode(value, utf8, "ISO-8859-1", "UTF-8");
|
585 |
out += utf8;
|
587 |
out += utf8;
|
586 |
value = "";
|
588 |
value.clear();
|
587 |
}
|
589 |
}
|
588 |
if (state != rfc2047base)
|
590 |
if (state != rfc2047base)
|
589 |
return false;
|
591 |
return false;
|
590 |
return true;
|
592 |
return true;
|
591 |
}
|
593 |
}
|