<<< Date Index >>>     <<< Thread Index >>>

Re: sort-mailbox by spam tag score sorting strangeness



* On 2006.11.21, in <20061122055720.GC11624@xxxxxxxxxxxxxxxxxxx>,
*       "Bob Proulx" <bob@xxxxxxxxxx> wrote:
> 
> > There's no way to fix this in configuration -- it requires a code
> > change.  If you're comfortable recompiling mutt yourself, the change is
> > trivial: in sort.c, change both occurrences of "strtoul" to "strtol".
> 
> This did not work to fix the problem for me.  I applied the following

Sorry, my brain was apparently not fully engaged when I wrote that.
Here's a patch to current CVS mutt.  It should apply on your version,
too; sort.c has changed little.  (Summary: use double float conversion
instead of signed or unsigned long.)

I'll present this for inclusion in CVS.

-- 
 -D.    dgc@xxxxxxxxxxxx        NSIT    University of Chicago
CVSROOT = 
Using: /opt/bin/cvs diff sort.c
Index: sort.c
===================================================================
RCS file: /home/roessler/cvs/mutt/sort.c,v
retrieving revision 3.9
diff -u -r3.9 sort.c
--- sort.c      17 Sep 2005 20:46:11 -0000      3.9
+++ sort.c      22 Nov 2006 06:57:06 -0000
@@ -160,6 +160,7 @@
   char   *aptr, *bptr;
   int     ahas, bhas;
   int     result = 0;
+  double  difference;
 
   /* Firstly, require spam attributes for both msgs */
   /* to compare. Determine which msgs have one.     */
@@ -183,8 +184,11 @@
   /* Both have spam attrs. */
 
   /* preliminary numeric examination */
-  result = (strtoul((*ppa)->env->spam->data, &aptr, 10) -
-            strtoul((*ppb)->env->spam->data, &bptr, 10));
+  difference = (strtod((*ppa)->env->spam->data, &aptr) -
+                strtod((*ppb)->env->spam->data, &bptr));
+
+  /* map double into comparison (-1, 0, or 1) */
+  result = (difference < 0.0 ? -1 : difference > 0.0 ? 1 : 0);
 
   /* If either aptr or bptr is equal to data, there is no numeric    */
   /* value for that spam attribute. In this case, compare lexically. */