kmime_headerfactory.cpp 2.56 KB
Newer Older
1
2
3
/*
    kmime_header_factory.cpp

Volker Krause's avatar
Volker Krause committed
4
    KMime, the KDE Internet mail/usenet news message library.
5
6
7
    SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>

    SPDX-License-Identifier: LGPL-2.0-or-later
8
9
10
11
12
13
14
15
16
17
18
19
20
*/

/**
  @file
  This file is part of the API for handling MIME data and
  defines the HeaderFactory class.

  @brief
  Defines the HeaderFactory class.

  @authors Constantin Berzan \<exit3219@gmail.com\>
*/

21
#include "kmime_headerfactory_p.h"
22
23
#include "kmime_headers.h"

24
25
#include <algorithm>

26
using namespace KMime;
27
using namespace KMime::Headers;
28

29
#define mk_header(hdr) \
30
31
    if (qstrnicmp(type, hdr ::staticType(), std::max(typeLen, strlen(hdr::staticType()))) == 0) \
        return new hdr;
32

33
Headers::Base *HeaderFactory::createHeader(const char *type, size_t typeLen)
34
{
35
36
    Q_ASSERT(type && *type);
    switch (*type) {
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
        case 'b':
        case 'B':
            mk_header(Bcc);
            break;
        case 'c':
        case 'C':
            mk_header(Cc);
            mk_header(ContentDescription);
            mk_header(ContentDisposition);
            mk_header(ContentID);
            mk_header(ContentLocation);
            mk_header(ContentTransferEncoding);
            mk_header(ContentType);
            mk_header(Control);
            break;
        case 'd':
        case 'D':
            mk_header(Date);
            break;
        case 'f':
        case 'F':
            mk_header(FollowUpTo);
            mk_header(From);
            break;
        case 'i':
        case 'I':
            mk_header(InReplyTo);
            break;
        case 'k':
        case 'K':
            mk_header(Keywords);
            break;
        case 'l':
        case 'L':
            mk_header(Lines);
            break;
        case 'm':
        case 'M':
            mk_header(MailCopiesTo);
            mk_header(MessageID);
            mk_header(MIMEVersion);
            break;
        case 'n':
        case 'N':
            mk_header(Newsgroups);
            break;
        case 'o':
        case 'O':
            mk_header(Organization);
            break;
        case 'r':
        case 'R':
            mk_header(References);
            mk_header(ReplyTo);
            mk_header(ReturnPath);
            break;
        case 's':
        case 'S':
            mk_header(Sender);
            mk_header(Subject);
            mk_header(Supersedes);
            break;
        case 't':
        case 'T':
            mk_header(To);
            break;
        case 'u':
        case 'U':
            mk_header(UserAgent);
            break;
Laurent Montel's avatar
Laurent Montel committed
107
    }
Laurent Montel's avatar
Laurent Montel committed
108
    return nullptr;
109
110
}

111
#undef mk_header