Changeset View
Changeset View
Standalone View
Standalone View
src/kmime_parsers.cpp
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | 17 | | |||
18 | You should have received a copy of the GNU Library General Public License | 18 | You should have received a copy of the GNU Library General Public License | ||
19 | along with this library; see the file COPYING.LIB. If not, write to | 19 | along with this library; see the file COPYING.LIB. If not, write to | ||
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
21 | Boston, MA 02110-1301, USA. | 21 | Boston, MA 02110-1301, USA. | ||
22 | */ | 22 | */ | ||
23 | #include "kmime_parsers.h" | 23 | #include "kmime_parsers.h" | ||
24 | 24 | | |||
25 | #include <QRegExp> | 25 | #include <QRegularExpression> | ||
26 | #include <QByteArray> | 26 | #include <QByteArray> | ||
27 | 27 | | |||
28 | using namespace KMime::Parser; | 28 | using namespace KMime::Parser; | ||
29 | 29 | | |||
30 | namespace KMime | 30 | namespace KMime | ||
31 | { | 31 | { | ||
32 | namespace Parser | 32 | namespace Parser | ||
33 | { | 33 | { | ||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Line(s) | 171 | UUEncoded::UUEncoded(const QByteArray &src, const QByteArray &subject) : | |||
172 | NonMimeParser(src), m_subject(subject) | 172 | NonMimeParser(src), m_subject(subject) | ||
173 | {} | 173 | {} | ||
174 | 174 | | |||
175 | bool UUEncoded::parse() | 175 | bool UUEncoded::parse() | ||
176 | { | 176 | { | ||
177 | int currentPos = 0; | 177 | int currentPos = 0; | ||
178 | bool success = true, firstIteration = true; | 178 | bool success = true, firstIteration = true; | ||
179 | 179 | | |||
180 | const auto srcStr = QString::fromLatin1(m_src); | ||||
181 | const QRegularExpression regex(QStringLiteral("begin [0-9][0-9][0-9]")); | ||||
182 | | ||||
180 | while (success) { | 183 | while (success) { | ||
181 | int beginPos = currentPos, uuStart = currentPos, endPos = 0, lineCount = 0, MCount = 0, pos = 0, len = 0; | 184 | int beginPos = currentPos, uuStart = currentPos, endPos = 0, lineCount = 0, MCount = 0, pos = 0, len = 0; | ||
182 | bool containsBegin = false, containsEnd = false; | 185 | bool containsBegin = false, containsEnd = false; | ||
183 | QByteArray tmp, fileName; | 186 | QByteArray tmp, fileName; | ||
184 | 187 | | |||
185 | if ((beginPos = QString::fromLatin1(m_src).indexOf(QRegExp(QStringLiteral("begin [0-9][0-9][0-9]")), | 188 | if ((beginPos = srcStr.indexOf(regex, currentPos)) > -1 && | ||
186 | currentPos)) > -1 && | | |||
187 | (beginPos == 0 || m_src.at(beginPos - 1) == '\n')) { | 189 | (beginPos == 0 || m_src.at(beginPos - 1) == '\n')) { | ||
188 | containsBegin = true; | 190 | containsBegin = true; | ||
189 | uuStart = m_src.indexOf('\n', beginPos); | 191 | uuStart = m_src.indexOf('\n', beginPos); | ||
190 | if (uuStart == -1) { //no more line breaks found, we give up | 192 | if (uuStart == -1) { //no more line breaks found, we give up | ||
191 | success = false; | 193 | success = false; | ||
192 | break; | 194 | break; | ||
193 | } else { | 195 | } else { | ||
194 | uuStart++; //points now at the beginning of the next line | 196 | uuStart++; //points now at the beginning of the next line | ||
Show All 27 Lines | 223 | if (MCount == 0 || (lineCount - MCount) > 10 || | |||
222 | ((!containsBegin || !containsEnd) && (MCount < 15))) { | 224 | ((!containsBegin || !containsEnd) && (MCount < 15))) { | ||
223 | // harder check for split-articles | 225 | // harder check for split-articles | ||
224 | success = false; | 226 | success = false; | ||
225 | break; //too many "non-M-Lines" found, we give up | 227 | break; //too many "non-M-Lines" found, we give up | ||
226 | } | 228 | } | ||
227 | 229 | | |||
228 | if ((!containsBegin || !containsEnd) && !m_subject.isNull()) { | 230 | if ((!containsBegin || !containsEnd) && !m_subject.isNull()) { | ||
229 | // message may be split up => parse subject | 231 | // message may be split up => parse subject | ||
230 | QRegExp rx(QStringLiteral("[0-9]+/[0-9]+")); | 232 | const QRegularExpression rx(QStringLiteral("[0-9]+/[0-9]+")); | ||
mlaurent: PErhaps this line can be move on top as other QRegularExpression no ?
not necessary to recreate… | |||||
231 | pos = rx.indexIn(QLatin1String(m_subject), 0); | 233 | const auto match = rx.match(QLatin1String(m_subject)); | ||
232 | len = rx.matchedLength(); | 234 | pos = match.capturedStart(0); | ||
235 | len = match.capturedLength(0); | ||||
233 | if (pos != -1) { | 236 | if (pos != -1) { | ||
234 | tmp = m_subject.mid(pos, len); | 237 | tmp = m_subject.mid(pos, len); | ||
235 | pos = tmp.indexOf('/'); | 238 | pos = tmp.indexOf('/'); | ||
236 | m_partNr = tmp.left(pos).toInt(); | 239 | m_partNr = tmp.left(pos).toInt(); | ||
237 | m_totalNr = tmp.right(tmp.length() - pos - 1).toInt(); | 240 | m_totalNr = tmp.right(tmp.length() - pos - 1).toInt(); | ||
238 | } else { | 241 | } else { | ||
239 | success = false; | 242 | success = false; | ||
240 | break; //no "part-numbers" found in the subject, we give up | 243 | break; //no "part-numbers" found in the subject, we give up | ||
▲ Show 20 Lines • Show All 267 Lines • Show Last 20 Lines |
PErhaps this line can be move on top as other QRegularExpression no ?
not necessary to recreate it all the time.