[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepim/akonadi/resources/mbox/libmbox
From: Bertjan Broeksema <b.broeksema () home ! nl>
Date: 2009-04-06 19:51:08
Message-ID: 1239047468.124261.10697.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 950305 by bbroeksema:
Add the unescapeFrom method.
M +38 -1 mbox.cpp
M +5 -0 mbox.h
--- trunk/KDE/kdepim/akonadi/resources/mbox/libmbox/mbox.cpp #950304:950305
@@ -201,7 +201,6 @@
d->mMboxFile.seek(offset);
-
QByteArray line = d->mMboxFile.readLine();
QRegExp regexp("^From .*[0-9][0-9]:[0-9][0-9]");
if (regexp.indexIn(line) < 0)
@@ -216,6 +215,8 @@
line = d->mMboxFile.readLine();
}
+ unescapeFrom(message.data(), message.size());
+
return message;
}
@@ -366,3 +367,39 @@
return rc;
}
+
+#define STRDIM(x) (sizeof(x)/sizeof(*x)-1)
+// performs (\n|^)>{n}From_ -> \1>{n-1}From_ conversion
+void MBox::unescapeFrom(char* str, size_t strLen)
+{
+ if (!str)
+ return;
+ if ( strLen <= STRDIM(">From ") )
+ return;
+
+ // yes, *d++ = *s++ is a no-op as long as d == s (until after the
+ // first >From_), but writes are cheap compared to reads and the
+ // data is already in the cache from the read, so special-casing
+ // might even be slower...
+ const char * s = str;
+ char * d = str;
+ const char * const e = str + strLen - STRDIM(">From ");
+
+ while ( s < e ) {
+ if ( *s == '\n' && *(s+1) == '>' ) { // we can do the lookahead, since e is 6 chars from the end!
+ *d++ = *s++; // == '\n'
+ *d++ = *s++; // == '>'
+ while ( s < e && *s == '>' )
+ *d++ = *s++;
+ if ( qstrncmp( s, "From ", STRDIM("From ") ) == 0 )
+ --d;
+ }
+ *d++ = *s++; // yes, s might be e here, but e is not the end :-)
+ }
+ // copy the rest:
+ while ( s < str + strLen )
+ *d++ = *s++;
+ if ( d < s ) // only NUL-terminate if it's shorter
+ *d = 0;
+}
+#undef STRDIM
--- trunk/KDE/kdepim/akonadi/resources/mbox/libmbox/mbox.h #950304:950305
@@ -138,6 +138,11 @@
*/
int unlock();
+ /**
+ * Unescapes the raw message read from the file.
+ */
+ static void unescapeFrom(char *msg, size_t size);
+
private:
class Private;
Private *d;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic