indent + comments + explicit std::
This commit is contained in:
parent
c700ea3a99
commit
385a7b9547
@ -102,7 +102,7 @@ bool rfc2231_decode(const string &in, string &out, string &charset)
|
|||||||
|
|
||||||
// The lexical token returned by find_next_token
|
// The lexical token returned by find_next_token
|
||||||
class Lexical {
|
class Lexical {
|
||||||
public:
|
public:
|
||||||
enum kind {none, token, separator};
|
enum kind {none, token, separator};
|
||||||
kind what;
|
kind what;
|
||||||
string value;
|
string value;
|
||||||
@ -490,7 +490,7 @@ bool rfc2047_decode(const std::string& in, std::string &out)
|
|||||||
DPRINT((stderr, "STATE: ready, ch %c\n", ch));
|
DPRINT((stderr, "STATE: ready, ch %c\n", ch));
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
// Whitespace: stay ready
|
// Whitespace: stay ready
|
||||||
case ' ': case ' ': value += ch;break;
|
case ' ': case '\t': value += ch;break;
|
||||||
// '=' -> forward to next state
|
// '=' -> forward to next state
|
||||||
case '=': state = rfc2047open_eq; break;
|
case '=': state = rfc2047open_eq; break;
|
||||||
DPRINT((stderr, "STATE: open_eq\n"));
|
DPRINT((stderr, "STATE: open_eq\n"));
|
||||||
@ -747,7 +747,7 @@ time_t rfc2822DateToUxTime(const string& dt)
|
|||||||
zonesecs = 3600 * hours;
|
zonesecs = 3600 * hours;
|
||||||
}
|
}
|
||||||
DATEDEB((stderr, "Tz: [%s] -> %d\n", it->c_str(), zonesecs));
|
DATEDEB((stderr, "Tz: [%s] -> %d\n", it->c_str(), zonesecs));
|
||||||
nozone:
|
nozone:
|
||||||
|
|
||||||
// Compute the UTC Unix time value
|
// Compute the UTC Unix time value
|
||||||
#ifndef sun
|
#ifndef sun
|
||||||
@ -792,14 +792,14 @@ extern time_t rfc2822DateToUxTime(const string& date);
|
|||||||
static const char *thisprog;
|
static const char *thisprog;
|
||||||
|
|
||||||
static char usage [] =
|
static char usage [] =
|
||||||
"-p: header value and parameter test\n"
|
"-p: header value and parameter test\n"
|
||||||
"-q: qp decoding\n"
|
"-q: qp decoding\n"
|
||||||
"-b: base64\n"
|
"-b: base64\n"
|
||||||
"-7: rfc2047\n"
|
"-7: rfc2047\n"
|
||||||
"-1: rfc2331\n"
|
"-1: rfc2331\n"
|
||||||
"-t: date time\n"
|
"-t: date time\n"
|
||||||
" \n\n"
|
" \n\n"
|
||||||
;
|
;
|
||||||
static void
|
static void
|
||||||
Usage(void)
|
Usage(void)
|
||||||
{
|
{
|
||||||
@ -855,13 +855,22 @@ main(int argc, const char **argv)
|
|||||||
"application/x-stuff;"
|
"application/x-stuff;"
|
||||||
"title*0*=us-ascii'en'This%20is%20even%20more%20;"
|
"title*0*=us-ascii'en'This%20is%20even%20more%20;"
|
||||||
"title*1*=%2A%2A%2Afun%2A%2A%2A%20;"
|
"title*1*=%2A%2A%2Afun%2A%2A%2A%20;"
|
||||||
"title*2=\"isn't it!\""
|
"title*2=\"isn't it!\"",
|
||||||
|
|
||||||
|
// The following are all invalid, trying to crash the parser...
|
||||||
|
"",
|
||||||
|
// This does not parse because of whitespace in the value.
|
||||||
|
" complete garbage;",
|
||||||
|
// This parses, but only the first word gets into the value
|
||||||
|
" some value",
|
||||||
|
" word ;", ";", "=", "; = ", "a;=\"toto tutu\"=", ";;;;a=b",
|
||||||
};
|
};
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(tr) / sizeof(char *); i++) {
|
for (unsigned int i = 0; i < sizeof(tr) / sizeof(char *); i++) {
|
||||||
MimeHeaderValue parsed;
|
MimeHeaderValue parsed;
|
||||||
if (!parseMimeHeaderValue(tr[i], parsed)) {
|
if (!parseMimeHeaderValue(tr[i], parsed)) {
|
||||||
fprintf(stderr, "PARSE ERROR for [%s]\n", tr[i]);
|
fprintf(stderr, "PARSE ERROR for [%s]\n", tr[i]);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
printf("Field value: [%s]\n", parsed.value.c_str());
|
printf("Field value: [%s]\n", parsed.value.c_str());
|
||||||
map<string, string>::iterator it;
|
map<string, string>::iterator it;
|
||||||
|
|||||||
@ -17,29 +17,29 @@
|
|||||||
#ifndef _MIME_H_INCLUDED_
|
#ifndef _MIME_H_INCLUDED_
|
||||||
#define _MIME_H_INCLUDED_
|
#define _MIME_H_INCLUDED_
|
||||||
/*
|
/*
|
||||||
Mime definitions RFC to 4-9-2006:
|
Mime definitions RFC to 4-9-2006:
|
||||||
|
|
||||||
2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of
|
2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of
|
||||||
Internet Message Bodies. N. Freed, N. Borenstein. November 1996.
|
Internet Message Bodies. N. Freed, N. Borenstein. November 1996.
|
||||||
(Format: TXT=72932 bytes) (Obsoletes RFC1521, RFC1522, RFC1590)
|
(Format: TXT=72932 bytes) (Obsoletes RFC1521, RFC1522, RFC1590)
|
||||||
(Updated by RFC2184, RFC2231) (Status: DRAFT STANDARD)
|
(Updated by RFC2184, RFC2231) (Status: DRAFT STANDARD)
|
||||||
|
|
||||||
2046 Multipurpose Internet Mail Extensions (MIME) Part Two: Media
|
2046 Multipurpose Internet Mail Extensions (MIME) Part Two: Media
|
||||||
Types. N. Freed, N. Borenstein. November 1996. (Format: TXT=105854
|
Types. N. Freed, N. Borenstein. November 1996. (Format: TXT=105854
|
||||||
bytes) (Obsoletes RFC1521, RFC1522, RFC1590) (Updated by RFC2646,
|
bytes) (Obsoletes RFC1521, RFC1522, RFC1590) (Updated by RFC2646,
|
||||||
RFC3798) (Status: DRAFT STANDARD)
|
RFC3798) (Status: DRAFT STANDARD)
|
||||||
|
|
||||||
2047 MIME (Multipurpose Internet Mail Extensions) Part Three: Message
|
2047 MIME (Multipurpose Internet Mail Extensions) Part Three: Message
|
||||||
Header Extensions for Non-ASCII Text. K. Moore. November 1996.
|
Header Extensions for Non-ASCII Text. K. Moore. November 1996.
|
||||||
(Format: TXT=33262 bytes) (Obsoletes RFC1521, RFC1522, RFC1590)
|
(Format: TXT=33262 bytes) (Obsoletes RFC1521, RFC1522, RFC1590)
|
||||||
(Updated by RFC2184, RFC2231) (Status: DRAFT STANDARD)
|
(Updated by RFC2184, RFC2231) (Status: DRAFT STANDARD)
|
||||||
|
|
||||||
2183 Communicating Presentation Information in Internet Messages: The
|
2183 Communicating Presentation Information in Internet Messages: The
|
||||||
Content-Disposition Header Field. R. Troost, S. Dorner, K. Moore,
|
Content-Disposition Header Field. R. Troost, S. Dorner, K. Moore,
|
||||||
Ed.. August 1997. (Format: TXT=23150 bytes) (Updates RFC1806)
|
Ed.. August 1997. (Format: TXT=23150 bytes) (Updates RFC1806)
|
||||||
(Updated by RFC2184, RFC2231) (Status: PROPOSED STANDARD)
|
(Updated by RFC2184, RFC2231) (Status: PROPOSED STANDARD)
|
||||||
|
|
||||||
2231 MIME Parameter Value and Encoded Word Extensions: Character Sets,
|
2231 MIME Parameter Value and Encoded Word Extensions: Character Sets,
|
||||||
Languages, and Continuations. N. Freed, K. Moore. November 1997.
|
Languages, and Continuations. N. Freed, K. Moore. November 1997.
|
||||||
(Format: TXT=19280 bytes) (Obsoletes RFC2184) (Updates RFC2045,
|
(Format: TXT=19280 bytes) (Obsoletes RFC2184) (Updates RFC2045,
|
||||||
RFC2047, RFC2183) (Status: PROPOSED STANDARD)
|
RFC2047, RFC2183) (Status: PROPOSED STANDARD)
|
||||||
@ -53,15 +53,11 @@ Mime definitions RFC to 4-9-2006:
|
|||||||
|
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
|
|
||||||
#ifndef NO_NAMESPACES
|
|
||||||
using std::string;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** A class to represent a MIME header value with parameters */
|
/** A class to represent a MIME header value with parameters */
|
||||||
class MimeHeaderValue {
|
class MimeHeaderValue {
|
||||||
public:
|
public:
|
||||||
string value;
|
std::string value;
|
||||||
std::map<string, string> params;
|
std::map<std::string, std::string> params;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,14 +66,17 @@ class MimeHeaderValue {
|
|||||||
* @param in the input string should be like: value; pn1=pv1; pn2=pv2.
|
* @param in the input string should be like: value; pn1=pv1; pn2=pv2.
|
||||||
* Example: text/plain; charset="iso-8859-1"
|
* Example: text/plain; charset="iso-8859-1"
|
||||||
*/
|
*/
|
||||||
extern bool parseMimeHeaderValue(const string& in, MimeHeaderValue& psd);
|
extern bool parseMimeHeaderValue(const std::string& in, MimeHeaderValue& psd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quoted printable decoding. Doubles up as rfc2231 decoder, hence the esc
|
* Quoted Printable decoding.
|
||||||
* RFC2045 Quoted printable uses '=' , rfc2331 uses '%'. The two encodings are
|
*
|
||||||
|
* Doubles up as rfc2231 decoder, with the help of the hence the @param esc
|
||||||
|
* parameter.
|
||||||
|
* RFC2045 Quoted Printable uses '=' , RFC2331 uses '%'. The two encodings are
|
||||||
* otherwise similar.
|
* otherwise similar.
|
||||||
*/
|
*/
|
||||||
extern bool qp_decode(const string& in, string &out, char esc = '=');
|
extern bool qp_decode(const std::string& in, std::string &out, char esc = '=');
|
||||||
|
|
||||||
/** Decode an Internet mail field value encoded according to rfc2047
|
/** Decode an Internet mail field value encoded according to rfc2047
|
||||||
*
|
*
|
||||||
@ -90,14 +89,14 @@ extern bool qp_decode(const string& in, string &out, char esc = '=');
|
|||||||
* @param in input string, ascii with rfc2047 markup
|
* @param in input string, ascii with rfc2047 markup
|
||||||
* @return out output string encoded in utf-8
|
* @return out output string encoded in utf-8
|
||||||
*/
|
*/
|
||||||
extern bool rfc2047_decode(const string& in, string &out);
|
extern bool rfc2047_decode(const std::string& in, std::string &out);
|
||||||
|
|
||||||
|
|
||||||
/** Decode RFC2822 date to unix time (gmt secs from 1970
|
/** Decode RFC2822 date to unix time (gmt secs from 1970)
|
||||||
*
|
*
|
||||||
* @param dt date string (the part after Date: )
|
* @param dt date string (the part after Date: )
|
||||||
* @return unix time
|
* @return unix time
|
||||||
*/
|
*/
|
||||||
time_t rfc2822DateToUxTime(const string& dt);
|
time_t rfc2822DateToUxTime(const std::string& dt);
|
||||||
|
|
||||||
#endif /* _MIME_H_INCLUDED_ */
|
#endif /* _MIME_H_INCLUDED_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user