From 2449b226f7ada670c907c56665ae7c02c22a6dcd Mon Sep 17 00:00:00 2001 From: Stefan Taferner Date: Thu, 18 Dec 1997 22:43:08 +0000 Subject: [PATCH] - improved importing of mail messages and index creation. Annother step towards mail folder sharing with pine :-) - fixed a small bug in decoding of quoted-printable header lines svn path=/trunk/kdenetwork/kmail/; revision=3535 --- kmfolder.cpp | 26 +++++++++++++++++++++----- kmmessage.cpp | 13 +++++++++++++ kmmessage.h | 4 ++++ kmmsgbase.cpp | 30 ++++++++++++++++++++++++------ kmmsgbase.h | 2 +- 5 files changed, 63 insertions(+), 12 deletions(-) diff --git a/kmfolder.cpp b/kmfolder.cpp index 4898a0907..ee5d4e2e4 100644 --- a/kmfolder.cpp +++ b/kmfolder.cpp @@ -276,7 +276,7 @@ bool KMFolder::isIndexOutdated(void) int KMFolder::createIndexFromContents(void) { char line[MAX_LINE]; - char status[8]; + char status[8], xstatus[8]; QString subjStr, dateStr, fromStr; unsigned long offs, size, pos; bool atEof = FALSE; @@ -284,6 +284,7 @@ int KMFolder::createIndexFromContents(void) QString msgStr(256); QRegExp regexp(MSG_SEPERATOR_REGEX); int i, num; + short needStatus; assert(mStream != NULL); rewind(mStream); @@ -296,7 +297,9 @@ int KMFolder::createIndexFromContents(void) dateStr = ""; fromStr = ""; subjStr = ""; - strcpy(status, "RO"); + *status = '\0'; + *xstatus = '\0'; + needStatus = 3; while (!atEof) { @@ -323,10 +326,14 @@ int KMFolder::createIndexFromContents(void) { mi = new KMMsgInfo(this); mi->init(subjStr, fromStr, 0, KMMsgStatusNew, offs, size); + mi->setStatus(status,xstatus); mi->setDate(dateStr); + mi->setDirty(FALSE); mMsgList.append(mi); - strcpy(status, "RO"); + *status = '\0'; + *xstatus = '\0'; + needStatus = 3; dateStr = ""; fromStr = ""; subjStr = ""; @@ -337,11 +344,19 @@ int KMFolder::createIndexFromContents(void) offs = ftell(mStream); num++; } - else if (strncmp(line, "Status: ", 8) == 0) + else if ((needStatus & 1) && strncmp(line, "Status: ", 8) == 0) { - for(i=0; i<8 && line[i+8] > ' '; i++) + for(i=0; i<4 && line[i+8] > ' '; i++) status[i] = line[i+8]; status[i] = '\0'; + needStatus &= ~1; + } + else if ((needStatus & 2) && strncmp(line, "X-Status: ", 10) == 0) + { + for(i=0; i<4 && line[i+10] > ' '; i++) + xstatus[i] = line[i+10]; + xstatus[i] = '\0'; + needStatus &= ~2; } else if (strncmp(line, "Date: ", 6) == 0) dateStr = QString(line+6).copy(); @@ -593,6 +608,7 @@ int KMFolder::addMsg(KMMessage* aMsg, int* aIndex_ret) if (idx >= 0) msgParent->take(idx); } + aMsg->setStatusFields(); msgText = aMsg->asString(); len = msgText.length(); diff --git a/kmmessage.cpp b/kmmessage.cpp index 9f254db63..ee467f3bd 100644 --- a/kmmessage.cpp +++ b/kmmessage.cpp @@ -66,6 +66,7 @@ const QString KMMessage::followup(void) const else return ""; } } + //----------------------------------------------------------------------------- void KMMessage::setFollowup(const QString aStr) { @@ -197,6 +198,18 @@ const QString KMMessage::asString(void) return resultStr; } +//----------------------------------------------------------------------------- +void KMMessage::setStatusFields(void) +{ + char str[3]; + + str[0] = (char)status(); + str[1] = '\0'; + + setHeaderField("Status", status()==KMMsgStatusNew ? "R " : "RO"); + setHeaderField("X-Status", str); +} + //---------------------------------------------------------------------------- const QString KMMessage::headerAsString(void) { diff --git a/kmmessage.h b/kmmessage.h index 5f6e70692..463022892 100644 --- a/kmmessage.h +++ b/kmmessage.h @@ -211,6 +211,10 @@ public: /** Open a window containing the complete, unparsed, message. */ virtual void viewSource(const QString windowCaption) const; + /** Set "Status" and "X-Status" fields of the message from the + * internal message status. */ + virtual void setStatusFields(void); + /** Strip email address from string. Examples: * "Stefan Taferner " returns "Stefan Taferner" * "joe@nowhere.com" returns "joe@nowhere.com" */ diff --git a/kmmsgbase.cpp b/kmmsgbase.cpp index fb8c1f2a8..53696f02a 100644 --- a/kmmsgbase.cpp +++ b/kmmsgbase.cpp @@ -76,14 +76,31 @@ void KMMsgBase::setStatus(KMMsgStatus aStatus) //----------------------------------------------------------------------------- -void KMMsgBase::setStatus(const char* aStatusStr) +void KMMsgBase::setStatus(const char* aStatusStr, const char* aXStatusStr) { int i; - for (i=0; iheaderOfMsgChanged(this); @@ -274,7 +291,7 @@ const QString KMMsgBase::decodeQuotedPrintableString(const QString aStr) if (beg > start) result += aStr.mid(start, beg-start); mid = aStr.find("?Q?", beg+2); - end = aStr.find("?=", beg+2); + if (mid>beg) end = aStr.find("?=", mid+3); if (mid < 0 || end < 0) { // no quoted printable part -- skip it @@ -289,7 +306,8 @@ const QString KMMsgBase::decodeQuotedPrintableString(const QString aStr) } else if (aStr[mid+3]==' ') mid++; - result += decodeQuotedPrintable(aStr.mid(mid+3, end-mid-3).data()); + if (end-mid-3 > 0) + result += decodeQuotedPrintable(aStr.mid(mid+3, end-mid-3).data()); start = end+2; } return result; diff --git a/kmmsgbase.h b/kmmsgbase.h index 2cc927568..37efa4290 100644 --- a/kmmsgbase.h +++ b/kmmsgbase.h @@ -46,7 +46,7 @@ public: /** Set status and mark dirty. */ virtual void setStatus(const KMMsgStatus status); - virtual void setStatus(const char* statusStr); + virtual void setStatus(const char* statusField, const char* xstatusField=0); /** Important header fields of the message that are also kept in the index. */ virtual const QString subject(void) const = 0;