|
a |
|
b/src/bincimapmime/mime.cc |
|
|
1 |
/* -*- Mode: c++; -*- */
|
|
|
2 |
/* --------------------------------------------------------------------
|
|
|
3 |
* Filename:
|
|
|
4 |
* mime.cc
|
|
|
5 |
*
|
|
|
6 |
* Description:
|
|
|
7 |
* Implementation of main mime parser components
|
|
|
8 |
* --------------------------------------------------------------------
|
|
|
9 |
* Copyright 2002-2004 Andreas Aardal Hanssen
|
|
|
10 |
*
|
|
|
11 |
* This program is free software; you can redistribute it and/or modify
|
|
|
12 |
* it under the terms of the GNU General Public License as published by
|
|
|
13 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
14 |
* (at your option) any later version.
|
|
|
15 |
*
|
|
|
16 |
* This program is distributed in the hope that it will be useful,
|
|
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
19 |
* GNU General Public License for more details.
|
|
|
20 |
*
|
|
|
21 |
* You should have received a copy of the GNU General Public License
|
|
|
22 |
* along with this program; if not, write to the Free Software
|
|
|
23 |
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
|
|
24 |
* --------------------------------------------------------------------
|
|
|
25 |
*/
|
|
|
26 |
#ifdef HAVE_CONFIG_H
|
|
|
27 |
#include <config.h>
|
|
|
28 |
#endif
|
|
|
29 |
|
|
|
30 |
#include "mime.h"
|
|
|
31 |
#include "convert.h"
|
|
|
32 |
#include <string>
|
|
|
33 |
#include <vector>
|
|
|
34 |
#include <map>
|
|
|
35 |
#include <exception>
|
|
|
36 |
#include <iostream>
|
|
|
37 |
|
|
|
38 |
#include <string.h>
|
|
|
39 |
#include <ctype.h>
|
|
|
40 |
#include <stdio.h>
|
|
|
41 |
#include <errno.h>
|
|
|
42 |
|
|
|
43 |
using namespace ::std;
|
|
|
44 |
|
|
|
45 |
//------------------------------------------------------------------------
|
|
|
46 |
Binc::MimeDocument::MimeDocument(void) : MimePart()
|
|
|
47 |
{
|
|
|
48 |
allIsParsed = false;
|
|
|
49 |
headerIsParsed = false;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
//------------------------------------------------------------------------
|
|
|
53 |
Binc::MimeDocument::~MimeDocument(void)
|
|
|
54 |
{
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
//------------------------------------------------------------------------
|
|
|
58 |
void Binc::MimeDocument::clear(void) const
|
|
|
59 |
{
|
|
|
60 |
members.clear();
|
|
|
61 |
h.clear();
|
|
|
62 |
headerIsParsed = false;
|
|
|
63 |
allIsParsed = false;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
//------------------------------------------------------------------------
|
|
|
67 |
void Binc::MimePart::clear(void) const
|
|
|
68 |
{
|
|
|
69 |
members.clear();
|
|
|
70 |
h.clear();
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
//------------------------------------------------------------------------
|
|
|
74 |
Binc::MimePart::MimePart(void)
|
|
|
75 |
{
|
|
|
76 |
size = 0;
|
|
|
77 |
messagerfc822 = false;
|
|
|
78 |
multipart = false;
|
|
|
79 |
|
|
|
80 |
nlines = 0;
|
|
|
81 |
nbodylines = 0;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
//------------------------------------------------------------------------
|
|
|
85 |
Binc::MimePart::~MimePart(void)
|
|
|
86 |
{
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
//------------------------------------------------------------------------
|
|
|
90 |
Binc::HeaderItem::HeaderItem(void)
|
|
|
91 |
{
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
//------------------------------------------------------------------------
|
|
|
95 |
Binc::HeaderItem::HeaderItem(const string &key, const string &value)
|
|
|
96 |
{
|
|
|
97 |
this->key = key;
|
|
|
98 |
this->value = value;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
//------------------------------------------------------------------------
|
|
|
102 |
Binc::Header::Header(void)
|
|
|
103 |
{
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
//------------------------------------------------------------------------
|
|
|
107 |
Binc::Header::~Header(void)
|
|
|
108 |
{
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
//------------------------------------------------------------------------
|
|
|
112 |
bool Binc::Header::getFirstHeader(const string &key, HeaderItem &dest) const
|
|
|
113 |
{
|
|
|
114 |
string k = key;
|
|
|
115 |
lowercase(k);
|
|
|
116 |
|
|
|
117 |
for (vector<HeaderItem>::const_iterator i = content.begin();
|
|
|
118 |
i != content.end(); ++i) {
|
|
|
119 |
string tmp = (*i).getKey();
|
|
|
120 |
lowercase(tmp);
|
|
|
121 |
|
|
|
122 |
if (tmp == k) {
|
|
|
123 |
dest = *i;
|
|
|
124 |
return true;
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
return false;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
//------------------------------------------------------------------------
|
|
|
131 |
bool Binc::Header::getAllHeaders(const string &key, vector<HeaderItem> &dest) const
|
|
|
132 |
{
|
|
|
133 |
string k = key;
|
|
|
134 |
lowercase(k);
|
|
|
135 |
|
|
|
136 |
for (vector<HeaderItem>::const_iterator i = content.begin();
|
|
|
137 |
i != content.end(); ++i) {
|
|
|
138 |
string tmp = (*i).getKey();
|
|
|
139 |
lowercase(tmp);
|
|
|
140 |
if (tmp == k)
|
|
|
141 |
dest.push_back(*i);
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
return (dest.size() != 0);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
//------------------------------------------------------------------------
|
|
|
148 |
void Binc::Header::clear(void) const
|
|
|
149 |
{
|
|
|
150 |
content.clear();
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
//------------------------------------------------------------------------
|
|
|
154 |
void Binc::Header::add(const string &key, const string &value)
|
|
|
155 |
{
|
|
|
156 |
content.push_back(HeaderItem(key, value));
|
|
|
157 |
}
|