[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    Re: proposal for threading improvements
From:       Till Adam <till () adam-lilienthal ! de>
Date:       2003-02-26 22:30:12
[Download RAW message or body]

On Tuesday 25 February 2003 11:26, Carsten Burghardt wrote:
> On Sunday 23 February 2003 18:18, Ingo Klöcker wrote:

> > IIRC (it was mentioned a while ago by someone) one can fetch single
> > headers from the IMAP server. So the clean approach would be to fetch
> > the ENVELOPE and the References header from the IMAP server. Carsten
> > (or someone else who knows more about IMAP than me) can probably give
> > you a better answer.
>
> That's probably the way to go. So you need to extend the fetch and also get
> the references header.
> uid fetch <uid> (uid envelope rfc822.size internaldate flags
> BODY[HEADER.FIELDS (REFERENCES)])
> Is it allowed to have more than one reference?

The attached patch against kdebase/kioslave/imap4 (HEAD) does that. I've 
overloaded the ENVELOPE request for now, I don't know if you want to 
introduce a new one, something like EXTENDED_ENV or so instead. As you can 
see, I had to teach the parser to understand the reply, tell me if I've gone 
about this the wrong way.

This, in conjunction  with my other patch to kmail in the other thread (ueber 
den sieben Bergen, bei den sieben Zwergen), produces nicely threaded imap 
folders in kmail for me. I am now a fairly happy ex mutt-user. : )

Cheers,

Till

["references.diff" (text/x-diff)]

? .exrc
? references.diff
Index: imap4.cc
===================================================================
RCS file: /home/kde/kdebase/kioslave/imap4/imap4.cc,v
retrieving revision 1.127
diff -u -w -r1.127 imap4.cc
--- imap4.cc	21 Feb 2003 11:45:48 -0000	1.127
+++ imap4.cc	26 Feb 2003 22:05:50 -0000
@@ -191,6 +191,7 @@
     else if (aSection.find ("ENVELOPE", 0, false) != -1)
     {
       aSection = "UID ENVELOPE";
+      aSection += " BODY.PEEK[HEADER.FIELDS (REFERENCES)]";
     }
     else
     {
Index: imapparser.cc
===================================================================
RCS file: /home/kde/kdebase/kioslave/imap4/imapparser.cc,v
retrieving revision 1.45
diff -u -w -r1.45 imapparser.cc
--- imapparser.cc	18 Jan 2003 17:43:31 -0000	1.45
+++ imapparser.cc	26 Feb 2003 22:05:52 -0000
@@ -1036,13 +1036,13 @@
   if (inWords[0] == '[')
   {
     QByteArray specifier;
+    QByteArray label;
     inWords.pos++;
 
     specifier = parseOneWord (inWords, TRUE);
 
     if (inWords[0] == '(')
     {
-      QByteArray label;
       inWords.pos++;
 
       while (!inWords.isEmpty () && inWords[0] != ')')
@@ -1082,6 +1082,40 @@
 
       }
     }
+    else if (qstrncmp(specifier, "HEADER.FIELDS", specifier.size()) == 0)
+    {
+      // BODY[HEADER.FIELDS (References)] {n} 
+      kdDebug(7116) << "imapParser::parseBody - HEADER.FIELDS: " 
+	<< QCString(label.data(), label.size()+1) << endl;
+      if (qstrncmp(label, "REFERENCES", label.size()) == 0)
+      {
+	mailHeader *envelope = NULL;
+	if (lastHandled)
+	  envelope = lastHandled->getHeader ();
+
+	if (!envelope || seenUid.isEmpty ())
+	{
+	  kdDebug(7116) << "imapParser::parseBody - discarding " << envelope << " " << \
seenUid.ascii () << endl; +	  // don't know where to put it, throw it away
+	  parseLiteral (inWords, true);
+	}
+	else
+	{
+	  QByteArray res = parseLiteral (inWords, true);
+	  QCString references = QCString(res.data(), res.size()+1);
+	  int start = references.find ('<');
+	  int end = references.findRev ('>');
+	  if (start < end)
+		  references = references.mid (start, end - start + 1);
+
+	  envelope->setReferences(references);
+	}
+      }
+      else
+      { // not a header we care about throw it away
+        parseLiteral (inWords, true);
+      }
+    }
     else
     {
       // throw it away
@@ -1131,6 +1165,7 @@
     else
     {
       QString word = parseLiteral (inWords);
+
       switch (word[0].latin1 ())
       {
       case 'E':
@@ -1334,7 +1369,6 @@
   else
   {
     imapCommand *current = sentQueue.at (0);
-
     switch (result[0])
     {
     case '*':
@@ -1523,7 +1557,7 @@
   }
   else
   {
-    retVal = parseOneWord(inWords);
+    retVal = parseOneWord(inWords, TRUE);
   }
   skipWS (inWords);
   return retVal;
Index: mailheader.cc
===================================================================
RCS file: /home/kde/kdebase/kioslave/imap4/mailheader.cc,v
retrieving revision 1.10
diff -u -w -r1.10 mailheader.cc
--- mailheader.cc	18 Jan 2003 17:43:31 -0000	1.10
+++ mailheader.cc	26 Feb 2003 22:05:52 -0000
@@ -148,6 +148,11 @@
     useIO.
       outputMimeLine (mimeHdrLine::
                       truncateLine (QCString ("In-Reply-To: ") + inReplyTo));
+  if (!references.isEmpty ())
+    useIO.
+      outputMimeLine (mimeHdrLine::
+                      truncateLine (QCString ("References: ") + references));
+
   if (!mDate.isEmpty())
     useIO.outputMimeLine (QCString ("Date: ") + mDate);
   mimeHeader::outputHeader (useIO);
Index: mailheader.h
===================================================================
RCS file: /home/kde/kdebase/kioslave/imap4/mailheader.h,v
retrieving revision 1.10
diff -u -w -r1.10 mailheader.h
--- mailheader.h	12 Feb 2002 17:40:26 -0000	1.10
+++ mailheader.h	26 Feb 2003 22:05:52 -0000
@@ -89,6 +89,15 @@
     inReplyTo = _str;
   };
 
+  QCString getReferences ()
+  {
+    return references;
+  };
+  void setReferences (const QCString & _str)
+  {
+    references = _str;
+  };
+
   // set a unicode subject
   void setSubject (const QString & _str)
   {
@@ -166,6 +175,7 @@
   int gmt_offset;
   QCString messageID;
   QCString inReplyTo;
+  QCString references;
 };
 
 #endif


_______________________________________________
KMail Developers mailing list
kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic