THREAD curiosity

Ken Murchison murch at andrew.cmu.edu
Thu Oct 9 07:40:06 EDT 2008


David Carter wrote:
> On Wed, 8 Oct 2008, Ken Murchison wrote:
> 
>> Changing it to the following fixes it as long as References isn't the 
>> first header field:
>>
>> if ((refstr = stristr(headers, "\r\nreferences:"))) {
>>
>> If we're worried about it being the first header field, there is an 
>> easy test for that.  Comments?
> 
> That would certainly be better than the current situation.
> 
> Is there a particular reason that we can't use index_pruneheader()? It 
> does require a bit of scratch space. However we could do something like 
> index_readheader().
> 

How does this look?


--- index.c	30 Sep 2008 13:06:06 -0400	1.245
+++ index.c	09 Oct 2008 07:37:19 -0400	
@@ -173,7 +173,7 @@
  static char *index_extract_subject(const char *subj, size_t len, int 
*is_refwd);
  static char *_index_extract_subject(char *s, int *is_refwd);
  static void index_get_ids(MsgData *msgdata,
-			  char *envtokens[], const char *headers);
+			  char *envtokens[], const char *headers, unsigned size);
  static MsgData *index_msgdata_load(unsigned *msgno_list, int n,
  				   struct sortcrit *sortcrit);

@@ -3724,7 +3724,8 @@
   		cur->nannot++;
   		break;
  	    case LOAD_IDS:
-		index_get_ids(cur, envtokens, headers + CACHE_ITEM_SIZE_SKIP);
+		index_get_ids(cur, envtokens, headers + CACHE_ITEM_SIZE_SKIP,
+			      CACHE_ITEM_LEN(headers));
  		break;
  	    }
  	}
@@ -4101,27 +4102,42 @@
  }

  /* Get message-id, and references/in-reply-to */
-#define REFGROWSIZE 10
+#define REFGROWSIZE 20

-void index_get_ids(MsgData *msgdata, char *envtokens[], const char 
*headers)
+void index_get_ids(MsgData *msgdata, char *envtokens[], const char 
*headers,
+		   unsigned size)
  {
+    static char *buf;
+    static unsigned bufsize;
+    static struct strlist refhdr;
      char *refstr, *ref, *in_reply_to;
      int refsize = REFGROWSIZE;
-    char buf[100];
+
+    if (bufsize < size+2) {
+	bufsize = size+100;
+	buf = xrealloc(buf, bufsize);
+    }

      /* get msgid */
      msgdata->msgid = find_msgid(envtokens[ENV_MSGID], NULL);
       /* if we don't have one, create one */
      if (!msgdata->msgid) {
-	snprintf(buf, sizeof(buf), "<Empty-ID: %u>", msgdata->msgno);
+	snprintf(buf, bufsize, "<Empty-ID: %u>", msgdata->msgno);
  	msgdata->msgid = xstrdup(buf);
      }

+    /* Copy headers to the buffer */
+    memcpy(buf, headers, size);
+    buf[size] = '\0';
+
      /* grab the References header */
-    if ((refstr = stristr(headers, "references:"))) {
+    refhdr.s = "references";
+    index_pruneheader(buf, &refhdr, 0);
+    if (*buf) {
  	/* allocate some space for refs */
  	msgdata->ref = (char **) xmalloc(refsize * sizeof(char *));
  	/* find references */
+	refstr = buf;
  	while ((ref = find_msgid(refstr, &refstr)) != NULL) {
  	    /* reallocate space for this msgid if necessary */
  	    if (msgdata->nref == refsize) {


-- 
Kenneth Murchison
Systems Programmer
Project Cyrus Developer/Maintainer
Carnegie Mellon University


More information about the Cyrus-devel mailing list