File: mailinputstream.cpp

package info (click to toggle)
strigi 0.7.8-1.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,556 kB
  • ctags: 6,064
  • sloc: cpp: 41,963; ansic: 1,199; perl: 483; java: 367; python: 345; xml: 177; sh: 150; makefile: 27
file content (690 lines) | stat: -rw-r--r-- 22,468 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/* This file is part of Strigi Desktop Search
 *
 * Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif


#include <strigi/mailinputstream.h>
#include <strigi/subinputstream.h>
#include <strigi/stringterminatedsubstream.h>
#include "base64inputstream.h"
#include "iconv.h"
#include <cstring>
#include <sstream>
#include <iostream>

#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif

#ifdef ICONV_SECOND_ARGUMENT_IS_CONST
     #define ICONV_CONST const
#else
     #define ICONV_CONST
#endif

using namespace std;
using namespace Strigi;

char
decodeHex(char h) {
    if (h >= 'A' && h <= 'F') return (char)(10+h-'A');
    if (h >= 'a' && h <= 'f') return (char)(10+h-'a');
    return (char)(h - '0');
}

class Decoder {
private:
    char* buffer;
    size_t bufferlen;
    map<string, iconv_t> iconvs;
public:
    Decoder() :buffer(0), bufferlen(0) {}
    ~Decoder() {
        free(buffer);
        map<string, iconv_t>::const_iterator i;
        for (i = iconvs.begin(); i != iconvs.end(); ++i) {
            iconv_close(i->second);
        }
    }
    void decode(const string& enc, string& data);
};
void
Decoder::decode(const string& enc, string& data) {
    iconv_t conv;
    if (iconvs.find(enc) == iconvs.end()) {
        conv = iconvs[enc] = iconv_open("UTF-8", enc.c_str());
    } else {
        conv = iconvs[enc];
    }
    if (conv == (iconv_t)-1) return;
    ICONV_CONST char* in = (char*)data.c_str();
    size_t ilen = data.length();
    size_t olen = 4*ilen;
    if (olen > bufferlen) {
        bufferlen = olen;
        buffer = (char*)realloc(buffer, bufferlen);
    }
    if (olen > 0) {
        char* out = buffer;
        char* mem = out;
        size_t r = iconv(conv, &in, &ilen, &out, &olen);
        if (r != (size_t)-1) {
            data.assign(mem, out-mem);
        }
    }
}

class QuotedPrintableDecoder {
private:
    string decoded;
public:
    string& decodeQuotedPrintable(const char* v, uint32_t len);
};
class HeaderDecoder : public QuotedPrintableDecoder, Decoder {
private:
    string decoded;
public:
    const string& decodedHeaderValue(const char* v, uint32_t len);
};

string&
QuotedPrintableDecoder::decodeQuotedPrintable(const char* v, uint32_t len) {
    if (decoded.size() < len) {
        decoded.reserve(len);
    }
    decoded.resize(0);
    const char* pos = v;
    const char* end = v + len;
    char c;
    while (v < end) {
        if (*v == '=' && end - v > 2 && isxdigit(v[1]) && isxdigit(v[2])) {
            decoded.append(pos, v - pos);
            c = (char)(decodeHex(v[1])*16 + decodeHex(v[2]));
            decoded.append(&c, 1);
            pos = v = v + 3;
        } else if (*v == '_') {
            decoded.append(pos, v - pos);
            decoded.append(" ");
            pos = v = v + 1;
        } else {
            v++;
        }
    }
    if (pos < end) {
        decoded.append(pos, end-pos);
    }
    return decoded;
}
/**
 * This function can decode a mail header if it contains utf8 encoded in base64.
 **/
const string&
HeaderDecoder::decodedHeaderValue(const char* v, uint32_t len) {
    if (decoded.size() < len) {
        decoded.reserve(len*2);
    }
    decoded.resize(0);
    const char* s = v;
    const char* p = v;
    const char* e = s + len;
    while (s < e) {
        if (e-s > 8 && *s == '=' && s[1] == '?') {
            // start of encoded data, find the next position of '?','?' and '?='
            const char *q1, *q2, *end;
            q1 = s+2;
            while (q1 < e && *q1 != '?') q1++;
            q2 = q1+1;
            while (q2 < e && *q2 != '?') q2++;
            end = q2+1;
            while (end < e && *end != '?') end++;
            if (e - end < 1 || end[1] != '=') {
                s++;
                continue;
            }
            // save the stuff from before the encoding
            decoded.append(p, s-p);
            s += 2;
            q1++;
            q2++;
            // find the end
            if (*q1 == 'b' || *q1 == 'B') {
                string str(Base64InputStream::decode(q2, end-q2));
                if (strncasecmp("utf-8", s, 5)) {
                    string encoding(s, q1-s-1);
                    decode(encoding, str);
                }
                decoded.append(str);
            } else if (*q1 == 'q' || *q1 =='Q') {
                string& str(decodeQuotedPrintable(q2, end-q2));
                if (strncasecmp("utf-8", s, 5) != 0) {
                    string encoding(s, q1-s-1);
                    decode(encoding, str);
                }
                decoded.append(str);
            } else {
                s -= 1;
            }

            // continue after the quoted data
            s = p = end + 2;
        } else if (e-s > 3 && s[0] == 13 && s[1] == 10
                && (s[2] == 9 || s[2] == 32)) {
            // skip the CRLF WSP used for folding the header lines
            decoded.append(p, s-p);
            s = p = s + 4;
        } else {
            s++;
        }
    }
    if (p < e) {
        decoded.append(p, e-p);
    }
    return decoded;
}

/**
 * Validate a mail header. The header format is checked, but not the presence
 * of required fields. It is recommended to use a datasize of at least 512
 * bytes.
 **/
bool
MailInputStream::checkHeader(const char* data, int32_t datasize) {

    /**
     * Describes the possible states the parser can be in.
     */
    enum MessageParserState {
        InHeaderNameField,       ///< The header name is parsed
        InHeaderValueField,      ///< The header value is parsed
        MaybeOnNewLine,          ///< A \r has been discovered while InHeaderValueField
        PossibleHeaderNameField, ///< After a \r\n check if it is a new line or a folded line
        MaybeEndOfHeaders,       ///< A \r has been discovered while in PossibleHeaderNameField
        InBody                   ///< The body part is parsed
    };

    /**
     * The state machine of the parser has the following structure:
     *
     * @dot
     *   digraph MessageParser {
     *     InHeaderNameField -> InHeaderValueField [label=":"]
     *     InHeaderValueField -> MaybeNewLine [label="\\r"]
     *     MaybeOnNewLine -> PossibleHeaderNameField [label="\\n"]
     *     MaybeOnNewLine -> InHeaderValueField
     *     PossibleHeaderNameField -> InHeaderValueField [label="<SPACE>"]
     *     PossibleHeaderNameField -> MaybeEndOfHeaders [label="\\r"]
     *     PossibleHeaderNameField -> InHeaderNameField
     *     MaybeEndOfHeaders -> InBody [label="\\n"]
     *   }
     * @enddot
     */

    MessageParserState currentState = InHeaderNameField;

    int pos = 0;
    while (pos < datasize) {
        char currentChar = data[pos];

        switch(currentState) {
        case InHeaderNameField: 
            if (currentChar == ':') {
                currentState = InHeaderValueField;
            } else if (currentChar == ' ' || currentChar == '\t') {
                // is SPACE
                return false;
            } else if (currentChar < 0 || currentChar >= 128) {
                // is not CHAR
                return false;
            } else if ((currentChar >= 0 && currentChar <= 31) || currentChar == 127) {
                // is CTRL
                return false;
            }
            break;
        case InHeaderValueField:
            if (currentChar == '\r') {
                currentState = MaybeOnNewLine;
            } else if (currentChar < 0 || currentChar >= 128) {
                // is not CHAR
                return false;
            }
            break;
        case MaybeOnNewLine:
            if (currentChar == '\n') {
                currentState = PossibleHeaderNameField;
            } else {
                currentState = InHeaderValueField;
                continue; // re-evaluate this character in InHeaderValueField state
            }
            break;
        case PossibleHeaderNameField:
            if (currentChar == ' ' || currentChar == '\t') {
                currentState = InHeaderValueField;
            } else if (currentChar == '\r') {
                currentState = MaybeEndOfHeaders;
            } else {
                currentState = InHeaderNameField;
                continue; // re-evaluate this character in InHeaderNameField state
            }
            break;
        case MaybeEndOfHeaders:
            if (currentChar == '\n') {
                currentState = InBody;
            } else {
                // the only alternative follow state would be InHeaderNameField, but this doesn't allow \r
                return false;
            }
            break;
        case InBody:
            if (currentChar < 0 || currentChar >= 128) {
                // is not CHAR
                return false;
            }
            break;
        }

        pos++;
    }

    return true;
}

class MailInputStream::Private {
public:
    MailInputStream* const m;
    int64_t nextLineStartPosition;
    // variables that record the current read state
    int32_t entrynumber;
    int maxlinesize;
    const char* linestart;
    const char* lineend;

    StringTerminatedSubStream* substream;
    std::string m_contenttransferencoding;
    std::string m_contentdisposition;

    std::stack<std::string> boundary;

    HeaderDecoder decoder;

    void readHeaderLine();
    void readHeader();
    void scanBody();
    void handleHeaderLine();
    bool handleBodyLine();
    bool lineIsEndOfBlock();
    bool checkHeaderLine() const;
    void clearHeaders();
    void ensureFileName();
    std::string value(const char* n, const std::string& headerline) const;

    Private(MailInputStream* mail);
    ~Private();
};
MailInputStream::Private::Private(MailInputStream* mail) :m(mail) {
    substream = 0;
    entrynumber = 0;
    nextLineStartPosition = 0;
}
MailInputStream::Private::~Private() {
    if (substream && substream != m->m_entrystream) {
        delete substream;
    }
}
MailInputStream::MailInputStream(InputStream* input)
        : SubStreamProvider(input), p(new Private(this)) {
    // parse the header and store the imporant header fields
    p->readHeader();
    if (m_status != Ok) {
//        fprintf(stderr, "no valid header\n");
        return;
    }
}
MailInputStream::~MailInputStream() {
    delete p;
}
/**
 * This function read the input until the end of a header line.
 * A header line can span multiple normal lines. All normal lines after the
 * first normal line start with a whitespace.
 * This means a header line is ended by on of these patterns (where \S is
 *  a non-whitespace character).
 *   '\r\S', '\n\S', '\r\n\S', '\r\r', '\n\n', '\r\n\r'
 **/
void
MailInputStream::Private::readHeaderLine() {
    // state: 0 -> ok, 1 -> '\r', 2 -> '\n', 3 -> '\r\n'
    char state = 0;
    int32_t nread;
    int32_t linepos = 0;
    bool completeLine = false;
    char c = 0;

    m->m_input->reset(nextLineStartPosition);
    do {
        nread = m->m_input->read(linestart, linepos+1, maxlinesize);
        if (nread < linepos+1) {
            completeLine = true;
            lineend = linestart + nread;
            m->m_status = Eof;
            return;
        }
        m->m_input->reset(nextLineStartPosition);
        if (m->m_input->status() == Error) {
            m->m_status = Error;
            m->m_error = m->m_input->error();
            return;
        } else if (linepos >= maxlinesize) {
            // error line is too long
            m->m_status = Error;
            ostringstream out;
            out << "mail header line is too long: more than " << linepos
                << " bytes.";
            m->m_error = out.str();
            return;
        } else {
            while (linepos < nread) {
                c = linestart[linepos];
                if (state == 0) {
                    if (c == '\r') {
                        state = 1;
                    } else if (c == '\n') {
                        state = 2;
                    }
                } else if (state == 1) { // '\r'
                    if (c == '\n') {
                        state = 3;
                    } else if (c == '\r' || !isspace(c)) { // end
                        completeLine = true;
                        lineend = linestart + linepos - 1;
                        break;
                    } else {
                        state = 0;
                    }
                } else if (state == 2) { // '\n'
                    if (c == '\n' || !isspace(c)) { // end
                        completeLine = true;
                        lineend = linestart + linepos - 1;
                        break;
                    } else {
                        state = 0;
                    }
                } else { // state == 3   '\r\n'
                    if (c == '\r' || linepos == 2 || !isspace(c)) { // end
                        completeLine = true;
                        lineend = linestart + linepos - 2;
                        break;
                    } else {
                        state = 0;
                    }
                }
                linepos++;
            }
        }
    } while (!completeLine);
    nextLineStartPosition += linepos;
}
string
MailInputStream::Private::value(const char* n, const string& headerline) const {
    size_t nl = strlen(n);
    string value;
    // get the value
    const char* hl = headerline.c_str();
    const char* v = strcasestr(hl, n);
    if (v == 0) {
        // so far we just scan for a value attribute
        return value;
    }
    v += nl;
    v += strspn(v, "= \n\r");
    const char* vend = strchr(v, ';');
    if (vend == 0) {
        vend = hl + headerline.length();
    }
    if (*v == '"' && vend-v > 2) {
        value.assign(v+1, vend-v-2);
    } else {
        value.assign(v, vend-v);
    }
    return value;
}
void
MailInputStream::Private::readHeader() {
    maxlinesize = 1024*1024;

    readHeaderLine();
    while (m->m_status == Ok && linestart != lineend) {
        handleHeaderLine();
        readHeaderLine();
    }
}
/**
 * Read lines from the email until a line contains the boundary.
 * If a boundary is encountered, the block header is parsed.
 **/
void
MailInputStream::Private::scanBody() {
    while (m->m_status == Ok) {
        readHeaderLine();
        int32_t len = (int32_t)(lineend - linestart);
        if (len > 2 && strncmp("--", linestart, 2) == 0) {
            int32_t blen = (int32_t)boundary.top().length();
            if (len == blen + 4 && strncmp(linestart + 2 + blen, "--", 2) == 0
                    && strncmp(linestart + 2, boundary.top().c_str(), blen)
                        == 0) {
                // check if this is the end of a multipart
                boundary.pop();
                if (boundary.size() == 0) {
                    m->m_status = Eof;
                }
            } else if (len == blen + 2
                    && strncmp(linestart + 2, boundary.top().c_str(), blen)
                        == 0) {
                if (handleBodyLine()) {
                    break;
                }
            }
        }
    }
}
void
MailInputStream::Private::handleHeaderLine() {
    static const char* subject = "Subject:";
    static const char* contenttype = "Content-Type:";
    static const char* to = "To:";
    static const char* from = "From:";
    static const char* cc = "Cc:";
    static const char* bcc = "Bcc:";
    static const char* messageid = "Message-ID:";
    static const char* inreplyto = "In-Reply-To:";
    static const char* references = "References:";
    static const char* contenttransferencoding = "Content-Transfer-Encoding:";
    static const char* contentdisposition = "Content-Disposition:";
    int32_t len = (int32_t)(lineend - linestart);
    if (len < 2) return;
    if (len < 8) {
        return;
    } else if (strncasecmp(linestart, subject, 8) == 0) {
        int32_t offset = 8;
        while (offset < len && isspace(linestart[offset])) offset++;
        m->m_subject = decoder.decodedHeaderValue(linestart+offset, len-offset);
    } else if (strncasecmp(linestart, to, 3) == 0) {
        int32_t offset = 3;
        // FIXME: should split for ','
        while (offset < len && isspace(linestart[offset])) offset++;
        m->m_to = decoder.decodedHeaderValue(linestart+offset, len-offset);
    } else if (strncasecmp(linestart, from, 5) == 0) {
        int32_t offset = 5;
        while (offset < len && isspace(linestart[offset])) offset++;
        m->m_from = decoder.decodedHeaderValue(linestart+offset, len-offset);
    } else if (strncasecmp(linestart, cc, 3) == 0) {
        int32_t offset = 3;
        while (offset < len && isspace(linestart[offset])) offset++;
        m->m_cc = decoder.decodedHeaderValue(linestart+offset, len-offset);
    } else if (strncasecmp(linestart, bcc, 4) == 0) {
        int32_t offset = 4;
        while (offset < len && isspace(linestart[offset])) offset++;
        m->m_bcc = decoder.decodedHeaderValue(linestart+offset, len-offset);
    } else if (strncasecmp(linestart, messageid, 11) == 0) {
        int32_t offset = 11;
        while (offset < len && isspace(linestart[offset])) offset++;
        m->m_messageid = decoder.decodedHeaderValue(linestart+offset, len-offset);
    } else if (strncasecmp(linestart, inreplyto, 12) == 0) {
        int32_t offset = 12;
        while (offset < len && isspace(linestart[offset])) offset++;
        m->m_inreplyto = decoder.decodedHeaderValue(linestart+offset, len-offset);
    } else if (strncasecmp(linestart, references, 11) == 0) {
        int32_t offset = 11;
        while (offset < len && isspace(linestart[offset])) offset++;
        m->m_references = decoder.decodedHeaderValue(linestart+offset, len-offset);
    } else if (strncasecmp(linestart, contenttype, 13) == 0) {
        int32_t offset = 13;
        while (offset < len && isspace(linestart[offset])) offset++;
        m->m_contenttype = std::string(linestart+offset, len-offset);
        // get the boundary
        string b = value("boundary", m->m_contenttype);
        if (b.size()) {
            boundary.push(b);
        }
    } else if (strncasecmp(linestart, contenttransferencoding, 26) == 0) {
        m_contenttransferencoding = std::string(linestart, len);
    } else if (strncasecmp(linestart, contentdisposition, 20) == 0) {
        m_contentdisposition = std::string(linestart, len);
    }
}
bool
MailInputStream::Private::checkHeaderLine() const {
    assert(lineend - linestart >= 0);
    bool validheader = linestart < lineend;
    if (validheader) {
        const char* colpos = linestart;
        while (*colpos != ':' && ++colpos != lineend) {}
        validheader = colpos != lineend || isblank(*linestart);
    }
    return validheader;
}
/**
 * Handle the body part header.
 **/
bool
MailInputStream::Private::handleBodyLine() {
    clearHeaders();

    // start of new block
    // read part header
    bool validheader;
    size_t n = boundary.size();
    do {
        readHeaderLine();
        validheader = m->m_status == Ok && checkHeaderLine();
        if (validheader) {
            handleHeaderLine();
        }
    } while (m->m_status == Ok && validheader);
    if (boundary.size() > n) {
        return false;
    }
    readHeaderLine();
    if (m->m_status != Ok) {
        return false;
    }

    // get the filename
    m->m_entryinfo.filename = value("filename", m_contentdisposition);
    if (m->m_entryinfo.filename.length() == 0) {
        m->m_entryinfo.filename = value("name", m->m_contenttype);
    }

    // create a stream that's limited to the content
    substream = new StringTerminatedSubStream(m->m_input, "--"+boundary.top());
    // set a reasonable buffer size
    if (strcasestr(m_contenttransferencoding.c_str(), "base64")) {
        m->m_entrystream = new Base64InputStream(substream);
    } else {
        m->m_entrystream = substream;
    }
    return true;
}
/**
 * Not all parts of multipart emails have a name. This function keeps a running
 * number to make sure all parts have a name so that they can be referenced
 * later.
 **/
void
MailInputStream::Private::ensureFileName() {
    entrynumber++;
    if (m->m_entryinfo.filename.length() == 0) {
        ostringstream o;
        o << entrynumber;
        m->m_entryinfo.filename = o.str();
    }
    m->m_entryinfo.type = EntryInfo::File;
}
InputStream*
MailInputStream::nextEntry() {
    if (m_status != Ok) return 0;
    // if the mail does not consist of multiple parts, we give a pointer to
    // the input stream
    if (p->boundary.size() == 0) {
        // signal eof because we only return eof once
        m_status = Eof;
        m_entrystream = new SubInputStream(m_input);
        m_entryinfo.filename = "body";
        return m_entrystream;
    }
    // read anything that's left over in the previous stream
    if (p->substream) {
        const char* dummy;
        while (p->substream->status() == Ok) {
            p->substream->read(dummy, 1, 0);
        }
        if (p->substream->status() == Error) {
            m_status = Error;
        } else {
            p->nextLineStartPosition = p->substream->offset()
                + p->substream->size();
        }
        if (p->substream && p->substream != m_entrystream) {
            delete p->substream;
        }
        p->substream = 0;
        delete m_entrystream;
        m_entrystream = 0;

        if (m_status != Ok) {
            return 0;
        }
    }
    p->scanBody();

    if (m_entrystream == 0) {
        m_status = Eof;
    }
    p->ensureFileName();
    return m_entrystream;
}
void
MailInputStream::Private::clearHeaders() {
    m->m_contenttype.resize(0);
    m_contenttransferencoding.resize(0);
    m_contentdisposition.resize(0);
}