|
a/src/internfile/mh_text.cpp |
|
b/src/internfile/mh_text.cpp |
|
... |
|
... |
25 |
#include <string>
|
25 |
#include <string>
|
26 |
#ifndef NO_NAMESPACES
|
26 |
#ifndef NO_NAMESPACES
|
27 |
using namespace std;
|
27 |
using namespace std;
|
28 |
#endif /* NO_NAMESPACES */
|
28 |
#endif /* NO_NAMESPACES */
|
29 |
|
29 |
|
|
|
30 |
#include "cstr.h"
|
30 |
#include "mh_text.h"
|
31 |
#include "mh_text.h"
|
31 |
#include "csguess.h"
|
32 |
#include "csguess.h"
|
32 |
#include "debuglog.h"
|
33 |
#include "debuglog.h"
|
33 |
#include "readfile.h"
|
34 |
#include "readfile.h"
|
34 |
#include "transcode.h"
|
35 |
#include "transcode.h"
|
|
... |
|
... |
120 |
// this validates the encoding.
|
121 |
// this validates the encoding.
|
121 |
LOGDEB1(("MimeHandlerText::mkDoc: transcod from %s to utf-8\n",
|
122 |
LOGDEB1(("MimeHandlerText::mkDoc: transcod from %s to utf-8\n",
|
122 |
m_dfltInputCharset.c_str()));
|
123 |
m_dfltInputCharset.c_str()));
|
123 |
int ecnt;
|
124 |
int ecnt;
|
124 |
bool ret;
|
125 |
bool ret;
|
125 |
string& itext = m_metaData["content"];
|
126 |
string& itext = m_metaData[cstr_content];
|
126 |
if (!(ret=transcode(m_text, itext, m_dfltInputCharset, "UTF-8", &ecnt)) ||
|
127 |
if (!(ret=transcode(m_text, itext, m_dfltInputCharset, "UTF-8", &ecnt)) ||
|
127 |
ecnt > int(itext.size() / 4)) {
|
128 |
ecnt > int(itext.size() / 4)) {
|
128 |
LOGERR(("MimeHandlerText::mkDoc: transcode to utf-8 failed "
|
129 |
LOGERR(("MimeHandlerText::mkDoc: transcode to utf-8 failed "
|
129 |
"for input charset [%s] ret %d ecnt %d\n",
|
130 |
"for input charset [%s] ret %d ecnt %d\n",
|
130 |
m_dfltInputCharset.c_str(), ret, ecnt));
|
131 |
m_dfltInputCharset.c_str(), ret, ecnt));
|
131 |
itext.erase();
|
132 |
itext.erase();
|
132 |
return false;
|
133 |
return false;
|
133 |
}
|
134 |
}
|
134 |
m_metaData["origcharset"] = m_dfltInputCharset;
|
135 |
m_metaData["origcharset"] = m_dfltInputCharset;
|
135 |
m_metaData["charset"] = "utf-8";
|
136 |
m_metaData[cstr_charset] = "utf-8";
|
136 |
m_metaData["mimetype"] = "text/plain";
|
137 |
m_metaData[cstr_mimetype] = cstr_textplain;
|
137 |
|
138 |
|
138 |
// If text length is 0 (the file is empty or oversize), or we have
|
139 |
// If text length is 0 (the file is empty or oversize), or we have
|
139 |
// read all at once, we're done
|
140 |
// read all at once, we're done
|
140 |
if (m_text.length() == 0 || !m_paging) {
|
141 |
if (m_text.length() == 0 || !m_paging) {
|
141 |
m_havedoc = false;
|
142 |
m_havedoc = false;
|
|
... |
|
... |
149 |
// be to use a different mtype for files over the page size,
|
150 |
// be to use a different mtype for files over the page size,
|
150 |
// and keep text/plain only for smaller files.
|
151 |
// and keep text/plain only for smaller files.
|
151 |
char buf[30];
|
152 |
char buf[30];
|
152 |
sprintf(buf, "%lld", (long long)(m_offs - m_text.length()));
|
153 |
sprintf(buf, "%lld", (long long)(m_offs - m_text.length()));
|
153 |
if (m_offs - m_text.length() != 0)
|
154 |
if (m_offs - m_text.length() != 0)
|
154 |
m_metaData["ipath"] = buf;
|
155 |
m_metaData[cstr_ipath] = buf;
|
155 |
readnext();
|
156 |
readnext();
|
156 |
return true;
|
157 |
return true;
|
157 |
}
|
158 |
}
|
158 |
}
|
159 |
}
|
159 |
|
160 |
|