Bug 3215 - [PATCH] Make wildcard address matching/autocomplete a bit smarter by sorting results in a more human way.
Summary: [PATCH] Make wildcard address matching/autocomplete a bit smarter by sorting ...
Status: RESOLVED FIXED
Alias: None
Product: Claws Mail (GTK 2)
Classification: Unclassified
Component: UI/Compose Window (show other bugs)
Version: 3.10.1
Hardware: PC FreeBSD
: P3 enhancement
Assignee: users
URL:
Depends on:
Blocks:
 
Reported: 2014-06-17 02:40 UTC by Michael Gmelin
Modified: 2014-07-05 09:32 UTC (History)
0 users

See Also:


Attachments
Patch to add reasonable ordering of autocomplete results. Rusty plain C and GTK, sorry. (2.85 KB, patch)
2014-06-17 02:40 UTC, Michael Gmelin
no flags Details | Diff
Additional patch (to be applied after the first one) that fixes the crash on group match (1.66 KB, patch)
2014-06-17 13:16 UTC, Michael Gmelin
no flags Details | Diff

Description Michael Gmelin 2014-06-17 02:40:32 UTC
Created attachment 1408 [details]
Patch to add reasonable ordering of autocomplete results. Rusty plain C and GTK, sorry.

Order of results:
1. Match beginning of name
2. Match beginning of additional names
3. Match complete email address before @
4. Match beginning of email address
5. Compare relative position of match
6. Compare name alphabetically
7. Compare address alphabetically.

e.g.
A) Michael Gmelin <mg@example.org>
B) Michael Gmelin <mgmelin@example.org>
C) Gmelin Michael <whatever@example.org>
D) Agme Xample <example@example.org>

Entering mg: A, B
Entering mgme: B
Entering gme: C, B, A, D
Comment 1 wwp 2014-06-17 12:28:44 UTC
First, I get a crash when I typed a two-letter combination ("mg") that matches two things in my AB: a group name, and the right part of one email address (after the @).
The crash can be immediate or after a long while where CM is 'dead', see:

#0  0x0000003355b3385f in __strlen_sse42 () from /lib64/libc.so.6
#1  0x0000000000454193 in weight_addr_match (addr=0xce2a50) at addr_compl.c:187
#2  0x00000000004542be in addr_comparison_func (a=0xb269f0, b=0xce2a50) at addr_compl.c:219
#3  0x000000335725f11f in ?? () from /lib64/libglib-2.0.so.0
#4  0x0000000000455192 in complete_address (str=0x2598430 "mg") at addr_compl.c:616
#5  0x0000000000456eb5 in address_completion_complete_address_in_entry (entry=0x13fd720, next=1) at addr_compl.c:1409
#6  0x0000000000456c5a in address_completion_entry_key_pressed (entry=0x13fd720, ev=0x1438d50, data=0xfeefaa) at addr_compl.c:1351

On a CentOS6 64-bit.
Comment 2 wwp 2014-06-17 12:32:41 UTC
And I forgot to add that I definitely agree with the principles behind this patch.
Comment 3 Michael Gmelin 2014-06-17 12:47:10 UTC
It's on the hacky side, it works for me as I don't use group names. I'll refine it later tonight or in the next few days and do some more thorough testing.
Comment 4 Michael Gmelin 2014-06-17 13:16:20 UTC
Created attachment 1409 [details]
Additional patch (to be applied after the first one) that fixes the crash on group match

Fixes the crash and slightly improves weighting in case both name and address match. To be applied *after* applying patch attachment 1408 [details]
Comment 5 wwp 2014-06-17 13:37:44 UTC
With this second patch applied I cannot reproduce the issue anymore.
Comment 6 Colin Leroy 2014-06-17 20:23:45 UTC
Thanks Michael, cool patch - much better than the hidden preference :)
I think there's at least three of us who wanted to do it, but you beat us to it.

Applied with a minor extra check!
Comment 7 Michael Gmelin 2014-06-17 22:23:37 UTC
Hi Colin,

The second extra check is important, but it seems to break the logic though by using the wrong operator (didn't test it yet):

      if (strlen(match) < strlen(g_completion_prefix)
       && *(match + strlen(g_completion_prefix)) == '@')
        a_weight--;

I think this should be:

if (strlen(match) > strlen(g_completion_prefix) ..

since strlen(match) is always >= strlen(g_completion_prefix) and never < strlen(g_completion_prefix).

e.g. search for mg in mg@example.org
=> strlen(match) == 15
=> strlen(g_completion_prefix) == 2
Comment 8 users 2014-06-17 22:30:02 UTC
Changes related to this bug have been committed.
Please check latest Git and update the bug accordingly.
You can also get the patch from:
http://git.claws-mail.org/

++ ChangeLog	2014-06-17 22:30:02.662353761 +0200
http://git.claws-mail.org/?p=claws.git;a=commitdiff;h=0af6a07abeb198f5c70962847d6ea035183410c6
Merge: feca001 93ffffa
Author: Colin Leroy <colin@colino.net>
Date:   Tue Jun 17 22:30:02 2014 +0200

    Merge branch 'master' of file:///home/git/claws

http://git.claws-mail.org/?p=claws.git;a=commitdiff;h=93ffffab990f8e21541ac13aec7e58a1b44b27b8
Author: Colin Leroy <colin@colino.net>
Date:   Tue Jun 17 22:29:08 2014 +0200

    Fix obvious mistake, thanks Michael (bug #3215)

Note You need to log in before you can comment on or make changes to this bug.