Bincimap 2.0.16
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
39
41 headerlength = 0;
43 bodylength = 0;
44 messagerfc822 = false;
45 multipart = false;
46
47 nlines = 0;
48 nbodylines = 0;
49
51}
52
53//------------------------------------------------------------------------
54int Binc::MimePart::parseOnlyHeader(const string &toboundary) const
55{
56 string name;
57 string content;
58 char cqueue[4];
59 memset(cqueue, 0, sizeof(cqueue));
60
61 headerstartoffsetcrlf = mimeSource->getOffset();
62
63 bool quit = false;
64 char c = '\0';
65
66 while (!quit) {
67 // read name
68 while (1) {
69 if (!mimeSource->getChar(&c)) {
70 quit = true;
71 break;
72 }
73
74 if (c == '\n') ++nlines;
75 if (c == ':') break;
76 if (c == '\n') {
77 for (int i = name.length() - 1; i >= 0; --i)
79
80 quit = true;
81 name = "";
82 break;
83 }
84
85 name += c;
86
87 if (name.length() == 2 && name.substr(0, 2) == "\r\n") {
88 name = "";
89 quit = true;
90 break;
91 }
92 }
93
94 if (name.length() == 1 && name[0] == '\r') {
95 name = "";
96 break;
97 }
98
99 if (quit) break;
100
101 while (!quit) {
102 if (!mimeSource->getChar(&c)) {
103 quit = true;
104 break;
105 }
106
107 if (c == '\n') ++nlines;
108
109 for (int i = 0; i < 3; ++i)
110 cqueue[i] = cqueue[i + 1];
111
112 cqueue[3] = c;
113 if (strncmp(cqueue, "\r\n\r\n", 4) == 0) {
114 quit = true;
115 break;
116 }
117
118 if (cqueue[2] == '\n') {
119 // guess the mime rfc says what can not appear on the beginning
120 // of a line.
121 if (!isspace(cqueue[3])) {
122 if (content.length() > 2)
123 content.resize(content.length() - 2);
124
125 trim(content);
126 h.add(name, content);
127 name = c;
128 content = "";
129 break;
130 }
131 }
132
133 content += c;
134 }
135 }
136
137 if (name != "") {
138 if (content.length() > 2)
139 content.resize(content.length() - 2);
140 h.add(name, content);
141 }
142
143 headerlength = mimeSource->getOffset() - headerstartoffsetcrlf;
144
145 return 1;
146}
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
virtual 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