Bincimap 2.0.17
Easy Imapping
Loading...
Searching...
No Matches
mime-parseonlyheader.cc
Go to the documentation of this file.
1
7#include "mime.h"
8#include "mime-utils.h"
9#include "mime-inputsource.h"
10#include "convert.h"
11#include <string>
12#include <vector>
13#include <map>
14#include <exception>
15#include <iostream>
16
17#include <string.h>
18#include <ctype.h>
19#include <stdio.h>
20#include <errno.h>
21
22using namespace ::std;
23
24//------------------------------------------------------------------------
26{
27 if (allIsParsed || headerIsParsed)
28 return;
29
30 headerIsParsed = true;
31
32 if (!mimeSource || mimeSource->getFileDescriptor() != fd) {
33 delete mimeSource;
35 } else {
37 }
38
40 headerlength = 0;
42 bodylength = 0;
43 messagerfc822 = false;
44 multipart = false;
45
46 nlines = 0;
47 nbodylines = 0;
48
50}
51
52//------------------------------------------------------------------------
53int Binc::MimePart::parseOnlyHeader(const string &toboundary) const
54{
55 string name;
56 string content;
57 char cqueue[4];
58 memset(cqueue, 0, sizeof(cqueue));
59
60 headerstartoffsetcrlf = mimeSource->getOffset();
61
62 bool quit = false;
63 char c = '\0';
64
65 while (!quit) {
66 // read name
67 while (1) {
68 if (!mimeSource->getChar(&c)) {
69 quit = true;
70 break;
71 }
72
73 if (c == '\n') ++nlines;
74 if (c == ':') break;
75 if (c == '\n') {
76 for (int i = name.length() - 1; i >= 0; --i)
78
79 quit = true;
80 name = "";
81 break;
82 }
83
84 name += c;
85
86 if (name.length() == 2 && name.substr(0, 2) == "\r\n") {
87 name = "";
88 quit = true;
89 break;
90 }
91 }
92
93 if (name.length() == 1 && name[0] == '\r') {
94 name = "";
95 break;
96 }
97
98 if (quit) break;
99
100 while (!quit) {
101 if (!mimeSource->getChar(&c)) {
102 quit = true;
103 break;
104 }
105
106 if (c == '\n') ++nlines;
107
108 for (int i = 0; i < 3; ++i)
109 cqueue[i] = cqueue[i + 1];
110
111 cqueue[3] = c;
112 if (strncmp(cqueue, "\r\n\r\n", 4) == 0) {
113 quit = true;
114 break;
115 }
116
117 if (cqueue[2] == '\n') {
118 // guess the mime rfc says what can not appear on the beginning
119 // of a line.
120 if (!isspace(cqueue[3])) {
121 if (content.length() > 2)
122 content.resize(content.length() - 2);
123
124 trim(content);
125 h.add(name, content);
126 name = c;
127 content = "";
128 break;
129 }
130 }
131
132 content += c;
133 }
134 }
135
136 if (name != "") {
137 if (content.length() > 2)
138 content.resize(content.length() - 2);
139 h.add(name, content);
140 }
141
142 headerlength = mimeSource->getOffset() - headerstartoffsetcrlf;
143
144 return 1;
145}
void parseOnlyHeader(int fd) const
virtual void reset(void)
int getFileDescriptor(void) const
unsigned int getOffset(void) const
unsigned int headerstartoffsetcrlf
Definition: mime.h:57
unsigned int nbodylines
Definition: mime.h:63
bool multipart
Definition: mime.h:52
bool messagerfc822
Definition: mime.h:53
int parseOnlyHeader(const std::string &toboundary) const
unsigned int bodylength
Definition: mime.h:61
unsigned int bodystartoffsetcrlf
Definition: mime.h:60
unsigned int headerlength
Definition: mime.h:58
unsigned int nlines
Definition: mime.h:62
Declaration of miscellaneous convertion functions.
The base class of the MIME input source.
Binc::MimeInputSource * mimeSource
Declaration of main mime parser components.
void trim(std::string &s_in, const std::string &chars=" \t\r\n")
Definition: convert.h:137