* [PATCH] config: allow custom separators in author lists
@ 2023-12-22 21:15 Lars Kotthoff
2023-12-22 22:20 ` Sandra Snan
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Lars Kotthoff @ 2023-12-22 21:15 UTC (permalink / raw)
To: notmuch
[-- Attachment #1: Type: text/plain, Size: 419 bytes --]
The attached patch allows to customize the default ", " and "| " separators in author lists. The main rationale for supporting this is that the Python API uses the same functionality to get the list of authors -- if I want to separate them again afterwards, I have to split the returned string, which is error-prone with comma separators (e.g. name in email address is of form Lastname, Firstname).
Cheers,
Lars
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-config-allow-custom-separators-in-author-lists.patch --]
[-- Type: text/x-patch, Size: 7788 bytes --]
From 60aab0c8a9a8164abb32ea306b7fd894a18a2477 Mon Sep 17 00:00:00 2001
From: Lars Kotthoff <lars@larsko.org>
Date: Fri, 22 Dec 2023 14:06:34 -0700
Subject: [PATCH] config: allow custom separators in author lists
---
NEWS | 11 +++++++++++
doc/man1/notmuch-config.rst | 13 +++++++++++++
lib/config.cc | 8 ++++++++
lib/notmuch.h | 2 ++
lib/thread.cc | 19 ++++++++++++++-----
test/T030-config.sh | 2 ++
test/T055-path-config.sh | 4 ++++
test/T590-libconfig.sh | 10 ++++++++++
8 files changed, 64 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index 315f4136..b306d095 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,14 @@
+Notmuch 0.38.3 (?)
+=========================
+
+General
+-------
+
+Allow to customize the separator between individual and matched and non-matched
+authors when showing threads. See `search.authors_separator` and
+`search.authors_matched_separator` in notmuch-config(1).
+
+
Notmuch 0.38.2 (2023-12-01)
===========================
diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index bd34afa4..5106655f 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -273,6 +273,19 @@ paths are presumed relative to `$HOME` for items in section
Default: empty list. Note that :any:`notmuch-setup(1)` puts
``deleted;spam`` here when creating new configuration file.
+.. nmconfig:: search.authors_separator
+
+ The string to separate authors when showing a thread.
+
+ Default: ,
+
+.. nmconfig:: search.authors_matched_separator
+
+ The string to separate matched from non-matched authors when showing a
+ thread.
+
+ Default: |
+
.. nmconfig:: show.extra_headers
By default :any:`notmuch-show(1)` includes the following headers
diff --git a/lib/config.cc b/lib/config.cc
index 6cd15fab..a3102dce 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -608,6 +608,10 @@ _notmuch_config_key_to_string (notmuch_config_key_t key)
return "database.autocommit";
case NOTMUCH_CONFIG_EXTRA_HEADERS:
return "show.extra_headers";
+ case NOTMUCH_CONFIG_AUTHORS_SEPARATOR:
+ return "search.authors_separator";
+ case NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR:
+ return "search.authors_matched_separator";
case NOTMUCH_CONFIG_INDEX_AS_TEXT:
return "index.as_text";
default:
@@ -658,6 +662,10 @@ _notmuch_config_default (notmuch_database_t *notmuch, notmuch_config_key_t key)
return "";
case NOTMUCH_CONFIG_AUTOCOMMIT:
return "8000";
+ case NOTMUCH_CONFIG_AUTHORS_SEPARATOR:
+ return ", ";
+ case NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR:
+ return "| ";
case NOTMUCH_CONFIG_EXTRA_HEADERS:
case NOTMUCH_CONFIG_HOOK_DIR:
case NOTMUCH_CONFIG_BACKUP_DIR:
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 4e2b0fa4..937fa24e 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -2565,6 +2565,8 @@ typedef enum {
NOTMUCH_CONFIG_AUTOCOMMIT,
NOTMUCH_CONFIG_EXTRA_HEADERS,
NOTMUCH_CONFIG_INDEX_AS_TEXT,
+ NOTMUCH_CONFIG_AUTHORS_SEPARATOR,
+ NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR,
NOTMUCH_CONFIG_LAST
} notmuch_config_key_t;
diff --git a/lib/thread.cc b/lib/thread.cc
index 60e9a666..8d70b489 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -122,21 +122,28 @@ _thread_add_matched_author (notmuch_thread_t *thread,
/* Construct an authors string from matched_authors_array and
* authors_array. The string contains matched authors first, then
- * non-matched authors (with the two groups separated by '|'). Within
- * each group, authors are listed in date order. */
+ * non-matched authors (with the two groups separated by '|' or the custom
+ * separator defined in the configuration). Within each group, authors are
+ * listed in date order and separated by ',' or the custom separator defined in
+ * the configuration. */
static void
_resolve_thread_authors_string (notmuch_thread_t *thread)
{
unsigned int i;
char *author;
int first_non_matched_author = 1;
+ const char *authors_sep = notmuch_config_get (thread->notmuch,
+ NOTMUCH_CONFIG_AUTHORS_SEPARATOR);
+ const char *authors_matched_sep = notmuch_config_get (thread->notmuch,
+ NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR);
/* First, list all matched authors in date order. */
for (i = 0; i < thread->matched_authors_array->len; i++) {
author = (char *) g_ptr_array_index (thread->matched_authors_array, i);
if (thread->authors)
- thread->authors = talloc_asprintf (thread, "%s, %s",
+ thread->authors = talloc_asprintf (thread, "%s%s%s",
thread->authors,
+ authors_sep,
author);
else
thread->authors = author;
@@ -149,12 +156,14 @@ _resolve_thread_authors_string (notmuch_thread_t *thread)
author, NULL, NULL))
continue;
if (first_non_matched_author) {
- thread->authors = talloc_asprintf (thread, "%s| %s",
+ thread->authors = talloc_asprintf (thread, "%s%s%s",
thread->authors,
+ authors_matched_sep,
author);
} else {
- thread->authors = talloc_asprintf (thread, "%s, %s",
+ thread->authors = talloc_asprintf (thread, "%s%s%s",
thread->authors,
+ authors_sep,
author);
}
diff --git a/test/T030-config.sh b/test/T030-config.sh
index 621e0b69..1d2b7df8 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -63,6 +63,8 @@ index.as_text=
maildir.synchronize_flags=true
new.ignore=
new.tags=unread;inbox
+search.authors_matched_separator=|
+search.authors_separator=,
search.exclude_tags=
user.name=Notmuch Test Suite
user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
index 1feb5624..049b745e 100755
--- a/test/T055-path-config.sh
+++ b/test/T055-path-config.sh
@@ -303,6 +303,8 @@ index.as_text=
maildir.synchronize_flags=true
new.ignore=
new.tags=unread;inbox
+search.authors_matched_separator=|
+search.authors_separator=,
search.exclude_tags=
user.name=Notmuch Test Suite
user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
@@ -325,6 +327,8 @@ database.mail_root
database.path
maildir.synchronize_flags
new.tags
+search.authors_matched_separator
+search.authors_separator
user.name
user.other_email
user.primary_email
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index 9326ba3e..9b364895 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -441,6 +441,8 @@ cat <<'EOF' >EXPECTED
11: '8000'
12: 'NULL'
13: ''
+14: ', '
+15: '| '
== stderr ==
EOF
unset MAILDIR
@@ -725,6 +727,8 @@ test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "list by keys (ndlc)"
notmuch config set search.exclude_tags "foo;bar;fub"
+notmuch config set search.authors_matched_separator "| "
+notmuch config set search.authors_separator ", "
notmuch config set new.ignore "sekrit_junk"
notmuch config set index.as_text "text/"
cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
@@ -754,6 +758,8 @@ cat <<'EOF' >EXPECTED
11: '8000'
12: 'NULL'
13: 'text/'
+14: ', '
+15: '| '
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
@@ -789,6 +795,8 @@ cat <<'EOF' >EXPECTED
11: '8000'
12: 'NULL'
13: ''
+14: ', '
+15: '| '
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT.clean
@@ -865,6 +873,8 @@ key with spaces value, with, spaces!
maildir.synchronize_flags true
new.ignore sekrit_junk
new.tags unread;inbox
+search.authors_matched_separator |
+search.authors_separator ,
search.exclude_tags foo;bar;fub
show.extra_headers (null)
test.key1 testvalue1
--
2.43.0
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] config: allow custom separators in author lists
2023-12-22 21:15 [PATCH] config: allow custom separators in author lists Lars Kotthoff
@ 2023-12-22 22:20 ` Sandra Snan
2023-12-22 22:23 ` Sandra Snan
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Sandra Snan @ 2023-12-22 22:20 UTC (permalink / raw)
To: Lars Kotthoff, notmuch
Lars Kotthoff <lists@larsko.org> writes:
> Python […] I have to split the returned string, which is
> error-prone with comma separators (e.g. name in email address is
> of form Lastname, Firstname).
email_list = "Diaz, Marco <m@nachos.com>, star@mewni.com, Marco
Diaz <m@nachos.com>, star@mewni.com" addresses = []
current_address = "" for char in email_list:
if char == ',' and '@' in current_address:
addresses.append(current_address.strip()) current_address
= ""
else:
current_address += char
addresses.append(current_address.strip()) # Adding the last
address print(addresses)
## prints ['Diaz, Marco <m@nachos.com>', 'star@mewni.com', 'Marco
Diaz <m@nachos.com>', 'star@mewni.com']
\r
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] config: allow custom separators in author lists
2023-12-22 21:15 [PATCH] config: allow custom separators in author lists Lars Kotthoff
2023-12-22 22:20 ` Sandra Snan
@ 2023-12-22 22:23 ` Sandra Snan
2023-12-22 22:24 ` Sandra Snan
2024-02-15 21:41 ` Lars Kotthoff
2024-02-16 10:28 ` Tomi Ollila
3 siblings, 1 reply; 11+ messages in thread
From: Sandra Snan @ 2023-12-22 22:23 UTC (permalink / raw)
To: Lars Kotthoff, notmuch
Lars Kotthoff <lists@larsko.org> writes:
> Python […] I have to split the returned string, which is
> error-prone with comma separators (e.g. name in email address is
> of form Lastname, Firstname).
email_list = "Diaz, Marco <m@nachos.com>, star@mewni.com, Marco
Diaz <m@nachos.com>, star@mewni.com" addresses = []
current_address = "" for char in email_list:
if char == ',' and '@' in current_address:
addresses.append(current_address.strip()) current_address
= ""
else:
current_address += char
addresses.append(current_address.strip()) # Adding the last
address print(addresses)
## prints ['Diaz, Marco <m@nachos.com>', 'star@mewni.com', 'Marco
Diaz <m@nachos.com>', 'star@mewni.com']
## (Trying again since use-hard-newlines borked the flow)\r
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] config: allow custom separators in author lists
2023-12-22 22:23 ` Sandra Snan
@ 2023-12-22 22:24 ` Sandra Snan
2023-12-22 23:53 ` Lars Kotthoff
0 siblings, 1 reply; 11+ messages in thread
From: Sandra Snan @ 2023-12-22 22:24 UTC (permalink / raw)
To: Lars Kotthoff, notmuch
[-- Attachment #1: Type: text/plain, Size: 54 bytes --]
Curses, flowed again! I'm just gonna attach the file
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: staddress.py --]
[-- Type: text/x-python, Size: 418 bytes --]
email_list = "Diaz, Marco <m@nachos.com>, star@mewni.com, Marco Diaz <m@nachos.com>, star@mewni.com"
addresses = []
current_address = ""
for char in email_list:
if char == ',' and '@' in current_address:
addresses.append(current_address.strip())
current_address = ""
else:
current_address += char
addresses.append(current_address.strip()) # Adding the last address
print(addresses)
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] config: allow custom separators in author lists
2023-12-22 22:24 ` Sandra Snan
@ 2023-12-22 23:53 ` Lars Kotthoff
0 siblings, 0 replies; 11+ messages in thread
From: Lars Kotthoff @ 2023-12-22 23:53 UTC (permalink / raw)
To: Sandra Snan, notmuch
Thanks for your suggestion! This doesn't work unfortunately because the author string doesn't contain the email addresses, i.e. no @ symbols (unless somebody includes that in their name).
Cheers,
Lars
On Fri, 22 Dec 2023 23:24:37 +0100, Sandra Snan <sandra.snan@idiomdrottning.org> wrote:
> Curses, flowed again! I'm just gonna attach the file
>
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] config: allow custom separators in author lists
2023-12-22 21:15 [PATCH] config: allow custom separators in author lists Lars Kotthoff
2023-12-22 22:20 ` Sandra Snan
2023-12-22 22:23 ` Sandra Snan
@ 2024-02-15 21:41 ` Lars Kotthoff
2024-02-16 10:28 ` Tomi Ollila
3 siblings, 0 replies; 11+ messages in thread
From: Lars Kotthoff @ 2024-02-15 21:41 UTC (permalink / raw)
To: notmuch
Any chance of this being included?
Thanks,
Lars
On Fri, 22 Dec 2023 14:15:32 -0700, Lars Kotthoff <lists@larsko.org> wrote:
> The attached patch allows to customize the default ", " and "| " separators in author lists. The main rationale for supporting this is that the Python API uses the same functionality to get the list of authors -- if I want to separate them again afterwards, I have to split the returned string, which is error-prone with comma separators (e.g. name in email address is of form Lastname, Firstname).
>
> Cheers,
>
> Lars
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] config: allow custom separators in author lists
2023-12-22 21:15 [PATCH] config: allow custom separators in author lists Lars Kotthoff
` (2 preceding siblings ...)
2024-02-15 21:41 ` Lars Kotthoff
@ 2024-02-16 10:28 ` Tomi Ollila
3 siblings, 0 replies; 11+ messages in thread
From: Tomi Ollila @ 2024-02-16 10:28 UTC (permalink / raw)
To: Lars Kotthoff, notmuch
On Fri, Dec 22 2023, Lars Kotthoff wrote:
> The attached patch allows to customize the default ", " and "| "
> separators in author lists. The main rationale for supporting this is
> that the Python API uses the same functionality to get the list of
> authors -- if I want to separate them again afterwards, I have to split
> the returned string, which is error-prone with comma separators
> (e.g. name in email address is of form Lastname, Firstname).
>
> Cheers,
>
> Lars
> From 60aab0c8a9a8164abb32ea306b7fd894a18a2477 Mon Sep 17 00:00:00 2001
> From: Lars Kotthoff <lars@larsko.org>
> Date: Fri, 22 Dec 2023 14:06:34 -0700
> Subject: [PATCH] config: allow custom separators in author lists
>
> ---
> NEWS | 11 +++++++++++
> doc/man1/notmuch-config.rst | 13 +++++++++++++
> lib/config.cc | 8 ++++++++
> lib/notmuch.h | 2 ++
> lib/thread.cc | 19 ++++++++++++++-----
> test/T030-config.sh | 2 ++
> test/T055-path-config.sh | 4 ++++
> test/T590-libconfig.sh | 10 ++++++++++
> 8 files changed, 64 insertions(+), 5 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index 315f4136..b306d095 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -1,3 +1,14 @@
> +Notmuch 0.38.3 (?)
> +=========================
The format for yet-unreleased news block here would be:
Notmuch 0.39 (UNRELEASED)
=========================
If there is going to be 0.38.3 with this included, then,
at that time the version string is adjusted accordingly.
> +
> +General
> +-------
> +
> +Allow to customize the separator between individual and matched and non-matched
> +authors when showing threads. See `search.authors_separator` and
> +`search.authors_matched_separator` in notmuch-config(1).
> +
> +
> Notmuch 0.38.2 (2023-12-01)
> ===========================
>
// stuff deleted //
> diff --git a/lib/config.cc b/lib/config.cc
> index 6cd15fab..a3102dce 100644
> --- a/lib/config.cc
> +++ b/lib/config.cc
> @@ -608,6 +608,10 @@ _notmuch_config_key_to_string (notmuch_config_key_t key)
> return "database.autocommit";
> case NOTMUCH_CONFIG_EXTRA_HEADERS:
> return "show.extra_headers";
> + case NOTMUCH_CONFIG_AUTHORS_SEPARATOR:
> + return "search.authors_separator";
> + case NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR:
> + return "search.authors_matched_separator";
> case NOTMUCH_CONFIG_INDEX_AS_TEXT:
> return "index.as_text";
> default:
> @@ -658,6 +662,10 @@ _notmuch_config_default (notmuch_database_t *notmuch, notmuch_config_key_t key)
> return "";
> case NOTMUCH_CONFIG_AUTOCOMMIT:
> return "8000";
> + case NOTMUCH_CONFIG_AUTHORS_SEPARATOR:
> + return ", ";
> + case NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR:
> + return "| ";
Spaces instead of tabs above ?
> case NOTMUCH_CONFIG_EXTRA_HEADERS:
> case NOTMUCH_CONFIG_HOOK_DIR:
> case NOTMUCH_CONFIG_BACKUP_DIR:
> diff --git a/lib/notmuch.h b/lib/notmuch.h
Just noticed the above and that there are more tabs/spaces inconsistencies,
-- and using 4 (instead of 8) in tab width is another thing that makes
the code to be inconsistently laid out.
Otherwise the code looks pretty straightforward, we'll see...
Tomi
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] config: allow custom separators in author lists
@ 2024-07-01 18:40 Lars Kotthoff
2024-07-25 8:33 ` David Bremner
0 siblings, 1 reply; 11+ messages in thread
From: Lars Kotthoff @ 2024-07-01 18:40 UTC (permalink / raw)
To: notmuch
[-- Attachment #1: Type: text/plain, Size: 676 bytes --]
Sorry, I dropped the ball on this -- here's the patch again with space/tab inconsistencies fixed. I wasn't entirely sure about this as it's inconsistent in the existing source, so I tried to make it as consistent as possible. Cover included again below.
The attached patch allows to customize the default ", " and "| " separators in author lists. The main rationale for supporting this is that the Python API uses the same functionality to get the list of authors -- if I want to separate them again afterwards, I have to split the returned string, which is error-prone with comma separators (e.g. name in email address is of form Lastname, Firstname).
Thanks,
Lars
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-config-allow-custom-separators-in-author-lists.patch --]
[-- Type: text/x-patch, Size: 7789 bytes --]
From 60aab0c8a9a8164abb32ea306b7fd894a18a2477 Mon Sep 17 00:00:00 2001
From: Lars Kotthoff <larsko@uwyo.edu>
Date: Fri, 22 Dec 2023 14:06:34 -0700
Subject: [PATCH] config: allow custom separators in author lists
---
NEWS | 11 +++++++++++
doc/man1/notmuch-config.rst | 13 +++++++++++++
lib/config.cc | 8 ++++++++
lib/notmuch.h | 2 ++
lib/thread.cc | 19 ++++++++++++++-----
test/T030-config.sh | 2 ++
test/T055-path-config.sh | 4 ++++
test/T590-libconfig.sh | 10 ++++++++++
8 files changed, 64 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index 315f4136..b306d095 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,14 @@
+Notmuch 0.39 (UNRELEASED)
+=========================
+
+General
+-------
+
+Allow to customize the separator between individual and matched and non-matched
+authors when showing threads. See `search.authors_separator` and
+`search.authors_matched_separator` in notmuch-config(1).
+
+
Notmuch 0.38.2 (2023-12-01)
===========================
diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index bd34afa4..5106655f 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -273,6 +273,19 @@ paths are presumed relative to `$HOME` for items in section
Default: empty list. Note that :any:`notmuch-setup(1)` puts
``deleted;spam`` here when creating new configuration file.
+.. nmconfig:: search.authors_separator
+
+ The string to separate authors when showing a thread.
+
+ Default: ,
+
+.. nmconfig:: search.authors_matched_separator
+
+ The string to separate matched from non-matched authors when showing a
+ thread.
+
+ Default: |
+
.. nmconfig:: show.extra_headers
By default :any:`notmuch-show(1)` includes the following headers
diff --git a/lib/config.cc b/lib/config.cc
index 6cd15fab..a3102dce 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -608,6 +608,10 @@ _notmuch_config_key_to_string (notmuch_config_key_t key)
return "database.autocommit";
case NOTMUCH_CONFIG_EXTRA_HEADERS:
return "show.extra_headers";
+ case NOTMUCH_CONFIG_AUTHORS_SEPARATOR:
+ return "search.authors_separator";
+ case NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR:
+ return "search.authors_matched_separator";
case NOTMUCH_CONFIG_INDEX_AS_TEXT:
return "index.as_text";
default:
@@ -658,6 +662,10 @@ _notmuch_config_default (notmuch_database_t *notmuch, notmuch_config_key_t key)
return "";
case NOTMUCH_CONFIG_AUTOCOMMIT:
return "8000";
+ case NOTMUCH_CONFIG_AUTHORS_SEPARATOR:
+ return ", ";
+ case NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR:
+ return "| ";
case NOTMUCH_CONFIG_EXTRA_HEADERS:
case NOTMUCH_CONFIG_HOOK_DIR:
case NOTMUCH_CONFIG_BACKUP_DIR:
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 4e2b0fa4..937fa24e 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -2565,6 +2565,8 @@ typedef enum {
NOTMUCH_CONFIG_AUTOCOMMIT,
NOTMUCH_CONFIG_EXTRA_HEADERS,
NOTMUCH_CONFIG_INDEX_AS_TEXT,
+ NOTMUCH_CONFIG_AUTHORS_SEPARATOR,
+ NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR,
NOTMUCH_CONFIG_LAST
} notmuch_config_key_t;
diff --git a/lib/thread.cc b/lib/thread.cc
index 60e9a666..8d70b489 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -122,21 +122,28 @@ _thread_add_matched_author (notmuch_thread_t *thread,
/* Construct an authors string from matched_authors_array and
* authors_array. The string contains matched authors first, then
- * non-matched authors (with the two groups separated by '|'). Within
- * each group, authors are listed in date order. */
+ * non-matched authors (with the two groups separated by '|' or the custom
+ * separator defined in the configuration). Within each group, authors are
+ * listed in date order and separated by ',' or the custom separator defined in
+ * the configuration. */
static void
_resolve_thread_authors_string (notmuch_thread_t *thread)
{
unsigned int i;
char *author;
int first_non_matched_author = 1;
+ const char *authors_sep = notmuch_config_get (thread->notmuch,
+ NOTMUCH_CONFIG_AUTHORS_SEPARATOR);
+ const char *authors_matched_sep = notmuch_config_get (thread->notmuch,
+ NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR);
/* First, list all matched authors in date order. */
for (i = 0; i < thread->matched_authors_array->len; i++) {
author = (char *) g_ptr_array_index (thread->matched_authors_array, i);
if (thread->authors)
- thread->authors = talloc_asprintf (thread, "%s, %s",
+ thread->authors = talloc_asprintf (thread, "%s%s%s",
thread->authors,
+ authors_sep,
author);
else
thread->authors = author;
@@ -149,12 +156,14 @@ _resolve_thread_authors_string (notmuch_thread_t *thread)
author, NULL, NULL))
continue;
if (first_non_matched_author) {
- thread->authors = talloc_asprintf (thread, "%s| %s",
+ thread->authors = talloc_asprintf (thread, "%s%s%s",
thread->authors,
+ authors_matched_sep,
author);
} else {
- thread->authors = talloc_asprintf (thread, "%s, %s",
+ thread->authors = talloc_asprintf (thread, "%s%s%s",
thread->authors,
+ authors_sep,
author);
}
diff --git a/test/T030-config.sh b/test/T030-config.sh
index 621e0b69..1d2b7df8 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -63,6 +63,8 @@ index.as_text=
maildir.synchronize_flags=true
new.ignore=
new.tags=unread;inbox
+search.authors_matched_separator=|
+search.authors_separator=,
search.exclude_tags=
user.name=Notmuch Test Suite
user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
index 1feb5624..049b745e 100755
--- a/test/T055-path-config.sh
+++ b/test/T055-path-config.sh
@@ -303,6 +303,8 @@ index.as_text=
maildir.synchronize_flags=true
new.ignore=
new.tags=unread;inbox
+search.authors_matched_separator=|
+search.authors_separator=,
search.exclude_tags=
user.name=Notmuch Test Suite
user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
@@ -325,6 +327,8 @@ database.mail_root
database.path
maildir.synchronize_flags
new.tags
+search.authors_matched_separator
+search.authors_separator
user.name
user.other_email
user.primary_email
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index 9326ba3e..9b364895 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -441,6 +441,8 @@ cat <<'EOF' >EXPECTED
11: '8000'
12: 'NULL'
13: ''
+14: ', '
+15: '| '
== stderr ==
EOF
unset MAILDIR
@@ -725,6 +727,8 @@ test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "list by keys (ndlc)"
notmuch config set search.exclude_tags "foo;bar;fub"
+notmuch config set search.authors_matched_separator "| "
+notmuch config set search.authors_separator ", "
notmuch config set new.ignore "sekrit_junk"
notmuch config set index.as_text "text/"
cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
@@ -754,6 +758,8 @@ cat <<'EOF' >EXPECTED
11: '8000'
12: 'NULL'
13: 'text/'
+14: ', '
+15: '| '
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
@@ -789,6 +795,8 @@ cat <<'EOF' >EXPECTED
11: '8000'
12: 'NULL'
13: ''
+14: ', '
+15: '| '
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT.clean
@@ -865,6 +873,8 @@ key with spaces value, with, spaces!
maildir.synchronize_flags true
new.ignore sekrit_junk
new.tags unread;inbox
+search.authors_matched_separator |
+search.authors_separator ,
search.exclude_tags foo;bar;fub
show.extra_headers (null)
test.key1 testvalue1
--
2.45.2
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] config: allow custom separators in author lists
2024-07-01 18:40 Lars Kotthoff
@ 2024-07-25 8:33 ` David Bremner
2024-07-25 16:26 ` Lars Kotthoff
0 siblings, 1 reply; 11+ messages in thread
From: David Bremner @ 2024-07-25 8:33 UTC (permalink / raw)
To: Lars Kotthoff, notmuch
Lars Kotthoff <lists@larsko.org> writes:
> Sorry, I dropped the ball on this -- here's the patch again with space/tab inconsistencies fixed. I wasn't entirely sure about this as it's inconsistent in the existing source, so I tried to make it as consistent as possible. Cover included again below.
>
Hi Lars,
Thanks for sticking with this, and sorry I did not respond to the first
thread. There are still one or two minor whitespace issues. If you have
"uncrustify" installed, then ./devel/check-notmuch-commit && git diff
will find the ones I'm thinking of. You can ignore the problems you
didn't introduce.
> The attached patch allows to customize the default ", " and "| "
> separators in author lists. The main rationale for supporting this is
> that the Python API uses the same functionality to get the list of
> authors -- if I want to separate them again afterwards, I have to
> split the returned string, which is error-prone with comma separators
> (e.g. name in email address is of form Lastname, Firstname).
Can you add a brief summary of the motivation to the commit message?
> test/T030-config.sh | 2 ++
> test/T055-path-config.sh | 4 ++++
> test/T590-libconfig.sh | 10 ++++++++++
Thanks for adjusting the existing test suite.
Can you also add a simple test to check the functionality you
introduced? Testing the CLI is fine, or if you prefer something in the
style of test/T590-libconfig.sh
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] config: allow custom separators in author lists
2024-07-25 8:33 ` David Bremner
@ 2024-07-25 16:26 ` Lars Kotthoff
2024-07-26 7:06 ` David Bremner
0 siblings, 1 reply; 11+ messages in thread
From: Lars Kotthoff @ 2024-07-25 16:26 UTC (permalink / raw)
To: David Bremner, notmuch
[-- Attachment #1: Type: text/plain, Size: 1778 bytes --]
Thanks David, I've attached the modified patch that I think addresses all your comments -- I'm still not 100% sure about the whitespace though.
Thanks,
Lars
On Thu, 25 Jul 2024 17:33:48 +0900, David Bremner <david@tethera.net> wrote:
> Lars Kotthoff <lists@larsko.org> writes:
>
> > Sorry, I dropped the ball on this -- here's the patch again with space/tab inconsistencies fixed. I wasn't entirely sure about this as it's inconsistent in the existing source, so I tried to make it as consistent as possible. Cover included again below.
> >
>
> Hi Lars,
>
> Thanks for sticking with this, and sorry I did not respond to the first
> thread. There are still one or two minor whitespace issues. If you have
> "uncrustify" installed, then ./devel/check-notmuch-commit && git diff
> will find the ones I'm thinking of. You can ignore the problems you
> didn't introduce.
>
> > The attached patch allows to customize the default ", " and "| "
> > separators in author lists. The main rationale for supporting this is
> > that the Python API uses the same functionality to get the list of
> > authors -- if I want to separate them again afterwards, I have to
> > split the returned string, which is error-prone with comma separators
> > (e.g. name in email address is of form Lastname, Firstname).
>
> Can you add a brief summary of the motivation to the commit message?
>
> > test/T030-config.sh | 2 ++
> > test/T055-path-config.sh | 4 ++++
> > test/T590-libconfig.sh | 10 ++++++++++
>
> Thanks for adjusting the existing test suite.
>
> Can you also add a simple test to check the functionality you
> introduced? Testing the CLI is fine, or if you prefer something in the
> style of test/T590-libconfig.sh
>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-config-allow-custom-separators-in-author-lists.patch --]
[-- Type: text/x-patch, Size: 9484 bytes --]
From 60aab0c8a9a8164abb32ea306b7fd894a18a2477 Mon Sep 17 00:00:00 2001
From: Lars Kotthoff <larsko@uwyo.edu>
Date: Fri, 22 Dec 2023 14:06:34 -0700
Subject: [PATCH] config: allow custom separators in author lists to allow to distinguish between commas separating authors and separating first and last names
---
NEWS | 11 +++++++++++
doc/man1/notmuch-config.rst | 13 +++++++++++++
lib/config.cc | 8 ++++++++
lib/notmuch.h | 2 ++
lib/thread.cc | 19 ++++++++++++++-----
test/T030-config.sh | 2 ++
test/T055-path-config.sh | 4 ++++
test/T590-libconfig.sh | 10 ++++++++++
8 files changed, 64 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index 315f4136..b306d095 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,14 @@
+Notmuch 0.39 (UNRELEASED)
+=========================
+
+General
+-------
+
+Allow to customize the separator between individual and matched and non-matched
+authors when showing threads. See `search.authors_separator` and
+`search.authors_matched_separator` in notmuch-config(1).
+
+
Notmuch 0.38.2 (2023-12-01)
===========================
diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index bd34afa4..5106655f 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -273,6 +273,19 @@ paths are presumed relative to `$HOME` for items in section
Default: empty list. Note that :any:`notmuch-setup(1)` puts
``deleted;spam`` here when creating new configuration file.
+.. nmconfig:: search.authors_separator
+
+ The string to separate authors when showing a thread.
+
+ Default: ,
+
+.. nmconfig:: search.authors_matched_separator
+
+ The string to separate matched from non-matched authors when showing a
+ thread.
+
+ Default: |
+
.. nmconfig:: show.extra_headers
By default :any:`notmuch-show(1)` includes the following headers
diff --git a/lib/config.cc b/lib/config.cc
index 6cd15fab..a3102dce 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -608,6 +608,10 @@ _notmuch_config_key_to_string (notmuch_config_key_t key)
return "database.autocommit";
case NOTMUCH_CONFIG_EXTRA_HEADERS:
return "show.extra_headers";
+ case NOTMUCH_CONFIG_AUTHORS_SEPARATOR:
+ return "search.authors_separator";
+ case NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR:
+ return "search.authors_matched_separator";
case NOTMUCH_CONFIG_INDEX_AS_TEXT:
return "index.as_text";
default:
@@ -658,6 +662,10 @@ _notmuch_config_default (notmuch_database_t *notmuch, notmuch_config_key_t key)
return "";
case NOTMUCH_CONFIG_AUTOCOMMIT:
return "8000";
+ case NOTMUCH_CONFIG_AUTHORS_SEPARATOR:
+ return ", ";
+ case NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR:
+ return "| ";
case NOTMUCH_CONFIG_EXTRA_HEADERS:
case NOTMUCH_CONFIG_HOOK_DIR:
case NOTMUCH_CONFIG_BACKUP_DIR:
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 4e2b0fa4..937fa24e 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -2565,6 +2565,8 @@ typedef enum {
NOTMUCH_CONFIG_AUTOCOMMIT,
NOTMUCH_CONFIG_EXTRA_HEADERS,
NOTMUCH_CONFIG_INDEX_AS_TEXT,
+ NOTMUCH_CONFIG_AUTHORS_SEPARATOR,
+ NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR,
NOTMUCH_CONFIG_LAST
} notmuch_config_key_t;
diff --git a/lib/thread.cc b/lib/thread.cc
index 60e9a666..8d70b489 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -122,21 +122,28 @@ _thread_add_matched_author (notmuch_thread_t *thread,
/* Construct an authors string from matched_authors_array and
* authors_array. The string contains matched authors first, then
- * non-matched authors (with the two groups separated by '|'). Within
- * each group, authors are listed in date order. */
+ * non-matched authors (with the two groups separated by '|' or the custom
+ * separator defined in the configuration). Within each group, authors are
+ * listed in date order and separated by ',' or the custom separator defined in
+ * the configuration. */
static void
_resolve_thread_authors_string (notmuch_thread_t *thread)
{
unsigned int i;
char *author;
int first_non_matched_author = 1;
+ const char *authors_sep = notmuch_config_get (thread->notmuch,
+ NOTMUCH_CONFIG_AUTHORS_SEPARATOR);
+ const char *authors_matched_sep = notmuch_config_get (thread->notmuch,
+ NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR);
/* First, list all matched authors in date order. */
for (i = 0; i < thread->matched_authors_array->len; i++) {
author = (char *) g_ptr_array_index (thread->matched_authors_array, i);
if (thread->authors)
- thread->authors = talloc_asprintf (thread, "%s, %s",
+ thread->authors = talloc_asprintf (thread, "%s%s%s",
thread->authors,
+ authors_sep,
author);
else
thread->authors = author;
@@ -149,12 +156,14 @@ _resolve_thread_authors_string (notmuch_thread_t *thread)
author, NULL, NULL))
continue;
if (first_non_matched_author) {
- thread->authors = talloc_asprintf (thread, "%s| %s",
+ thread->authors = talloc_asprintf (thread, "%s%s%s",
thread->authors,
+ authors_matched_sep,
author);
} else {
- thread->authors = talloc_asprintf (thread, "%s, %s",
+ thread->authors = talloc_asprintf (thread, "%s%s%s",
thread->authors,
+ authors_sep,
author);
}
diff --git a/test/T030-config.sh b/test/T030-config.sh
index 621e0b69..1d2b7df8 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -63,6 +63,8 @@ index.as_text=
maildir.synchronize_flags=true
new.ignore=
new.tags=unread;inbox
+search.authors_matched_separator=|
+search.authors_separator=,
search.exclude_tags=
user.name=Notmuch Test Suite
user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
index 1feb5624..049b745e 100755
--- a/test/T055-path-config.sh
+++ b/test/T055-path-config.sh
@@ -303,6 +303,8 @@ index.as_text=
maildir.synchronize_flags=true
new.ignore=
new.tags=unread;inbox
+search.authors_matched_separator=|
+search.authors_separator=,
search.exclude_tags=
user.name=Notmuch Test Suite
user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
@@ -325,6 +327,8 @@ database.mail_root
database.path
maildir.synchronize_flags
new.tags
+search.authors_matched_separator
+search.authors_separator
user.name
user.other_email
user.primary_email
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index 9326ba3e..9b364895 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -441,6 +441,8 @@ cat <<'EOF' >EXPECTED
11: '8000'
12: 'NULL'
13: ''
+14: ', '
+15: '| '
== stderr ==
EOF
unset MAILDIR
@@ -725,6 +727,8 @@ test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "list by keys (ndlc)"
notmuch config set search.exclude_tags "foo;bar;fub"
+notmuch config set search.authors_matched_separator "| "
+notmuch config set search.authors_separator ", "
notmuch config set new.ignore "sekrit_junk"
notmuch config set index.as_text "text/"
cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
@@ -754,6 +758,8 @@ cat <<'EOF' >EXPECTED
11: '8000'
12: 'NULL'
13: 'text/'
+14: ', '
+15: '| '
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
@@ -789,6 +795,8 @@ cat <<'EOF' >EXPECTED
11: '8000'
12: 'NULL'
13: ''
+14: ', '
+15: '| '
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT.clean
@@ -865,6 +873,8 @@ key with spaces value, with, spaces!
maildir.synchronize_flags true
new.ignore sekrit_junk
new.tags unread;inbox
+search.authors_matched_separator |
+search.authors_separator ,
search.exclude_tags foo;bar;fub
show.extra_headers (null)
test.key1 testvalue1
diff --git a/test/T206-author-separator.sh b/test/T206-author-separator.sh
new file mode 100755
index 00000000..b8b1afb4
--- /dev/null
+++ b/test/T206-author-separator.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+test_description="custom separator for authors"
+. $(dirname "$0")/test-lib.sh || exit 1
+
+test_begin_subtest "Adding parent message"
+generate_message [body]=findme [id]=new-parent-id [subject]=author-reorder-threadtest '[from]="User <user@example.com>"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
+output=$(NOTMUCH_NEW)
+test_expect_equal "$output" "Added 1 new message to the database."
+
+test_begin_subtest "Adding initial child message"
+generate_message [body]=findme "[in-reply-to]=\<new-parent-id\>" [subject]=author-reorder-threadtest '[from]="last name, first name <user1@example.com>"' '[date]="Sat, 01 Jan 2000 12:01:00 -0000"'
+output=$(NOTMUCH_NEW)
+test_expect_equal "$output" "Added 1 new message to the database."
+
+test_begin_subtest "Adding second child message"
+generate_message [body]=findme "[in-reply-to]=\<new-parent-id\>" [subject]=author-reorder-threadtest '[from]="first last <user2@example.com>"' '[date]="Sat, 01 Jan 2000 12:02:00 -0000"'
+output=$(NOTMUCH_NEW)
+test_expect_equal "$output" "Added 1 new message to the database."
+
+test_begin_subtest "Custom separarator is used"
+notmuch config set search.authors_matched_separator "#"
+notmuch config set search.authors_separator ";"
+output=$(notmuch search from:user | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2000-01-01 [1/3] User#last name, first name;first last; author-reorder-threadtest (inbox unread)"
+
+test_done
--
2.45.2
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] config: allow custom separators in author lists
2024-07-25 16:26 ` Lars Kotthoff
@ 2024-07-26 7:06 ` David Bremner
0 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2024-07-26 7:06 UTC (permalink / raw)
To: Lars Kotthoff, notmuch
Lars Kotthoff <lists@larsko.org> writes:
> Thanks David, I've attached the modified patch that I think addresses
> all your comments -- I'm still not 100% sure about the whitespace
> though.
tweaked version applied to master.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-07-26 7:06 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-22 21:15 [PATCH] config: allow custom separators in author lists Lars Kotthoff
2023-12-22 22:20 ` Sandra Snan
2023-12-22 22:23 ` Sandra Snan
2023-12-22 22:24 ` Sandra Snan
2023-12-22 23:53 ` Lars Kotthoff
2024-02-15 21:41 ` Lars Kotthoff
2024-02-16 10:28 ` Tomi Ollila
-- strict thread matches above, loose matches on Subject: below --
2024-07-01 18:40 Lars Kotthoff
2024-07-25 8:33 ` David Bremner
2024-07-25 16:26 ` Lars Kotthoff
2024-07-26 7:06 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).