Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email

2016-08-14 Thread Shea Levy
Hi Jani,

Jani Nikula <j...@nikula.org> writes:

> On Tue, 09 Aug 2016, Shea Levy <s...@shealevy.com> wrote:
>> Currently, while notmuch-reply will recognize email addresses other than
>> the main address with user.other_email, it always sets the name part of
>> the address in the envelope-from and From headers to user.name. This
>> patchset enables specifying names on a per-address basis with a new
>> user.other_name property. Presumably other users of user.other_email
>> may want to use this as well, but those are not updated currently.
>
> I am not convinved by adding another configuration option, especially
> when it has to be in sync with another configuration option (ordering in
> user.other_name having to match user.other_email). I would much prefer
> allowing (but not requiring) "Name <u...@example.org>" style addresses
> both in user.primary_email and user.other_email.
>

This would be fine with me. Is there already code in place to separate
out the name and email values from that kind of email address?

>
> With a cursory glance at the implementation, I wonder if you could just
> pick the name based on the address you've picked earlier, and leave the
> address matching mostly as it is. Would save some passing of parameters
> around. Maybe.
>

Hmm, I'm not sure what you mean by this, sorry. Can you expand?

>
> Additionally, I'd very much like to have my series [1] merged
> first. It'll be *much* easier to rebase your series on top than the
> other way around...
>

Happy to rebase my work on yours.

>
> BR,
> Jani.
>
>
> [1] id:cover.1471088022.git.j...@nikula.org
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 4/4] Update NEWS for user.other_name

2016-08-09 Thread Shea Levy
---
 NEWS | 5 +
 1 file changed, 5 insertions(+)

diff --git a/NEWS b/NEWS
index 3a9c8d3..fdf9c81 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,11 @@ Ruby Bindings
 
 Add support for `notmuch_database_get_all_tags`
 
+General
+---
+
+Add the `user.other_name` configuration setting
+
 Notmuch 0.22.1 (2016-07-19)
 ===
 
-- 
2.7.4

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 2/4] notmuch-reply: respect users.other_name in From

2016-08-09 Thread Shea Levy
---
 notmuch-reply.c | 129 
 1 file changed, 92 insertions(+), 37 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 4951373..1c205f9 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -118,25 +118,41 @@ match_address (const char *str, const char *address, 
address_match_t mode)
 }
 
 /* Match given string against user's configured "primary" and "other"
- * addresses according to mode. */
+ * addresses according to mode.
+ *
+ * If 'user_from_name' is non-NULL and the address is found,
+ * *user_from_name is set to the corresponding name.
+ */
 static const char *
-address_match (const char *str, notmuch_config_t *config, address_match_t mode)
+address_match (const char *str, notmuch_config_t *config, const char 
**user_from_name, address_match_t mode)
 {
 const char *primary;
 const char **other;
-size_t i, other_len;
+const char **other_name;
+size_t i, other_len, other_name_len;
 
 if (!str || *str == '\0')
return NULL;
 
 primary = notmuch_config_get_user_primary_email (config);
-if (match_address (str, primary, mode))
+if (match_address (str, primary, mode)) {
+   if (user_from_name != NULL)
+   *user_from_name = notmuch_config_get_user_name (config);
return primary;
+}
 
 other = notmuch_config_get_user_other_email (config, _len);
 for (i = 0; i < other_len; i++) {
-   if (match_address (str, other[i], mode))
+   if (match_address (str, other[i], mode)) {
+   if (user_from_name != NULL) {
+   other_name = notmuch_config_get_user_other_name (config, 
_name_len);
+   if (i < other_name_len)
+   *user_from_name = other_name[i];
+   else
+   *user_from_name = NULL;
+   }
return other[i];
+   }
 }
 
 return NULL;
@@ -144,28 +160,41 @@ address_match (const char *str, notmuch_config_t *config, 
address_match_t mode)
 
 /* Does the given string contain an address configured as one of the
  * user's "primary" or "other" addresses. If so, return the matching
- * address, NULL otherwise. */
+ * address, NULL otherwise.
+ *
+ * If 'user_from_name' is non-NULL and the address is the user's,
+ * *user_from_name is set to the corresponding name.
+ */
 static const char *
-user_address_in_string (const char *str, notmuch_config_t *config)
+user_address_in_string (const char *str, notmuch_config_t *config, const char 
**user_from_name)
 {
-return address_match (str, config, USER_ADDRESS_IN_STRING);
+return address_match (str, config, user_from_name, USER_ADDRESS_IN_STRING);
 }
 
 /* Do any of the addresses configured as one of the user's "primary"
  * or "other" addresses contain the given string. If so, return the
- * matching address, NULL otherwise. */
+ * matching address, NULL otherwise.
+ *
+ * If 'user_from_name' is non-NULL and the address is the user's,
+ * *user_from_name is set to the corresponding name.
+ */
 static const char *
-string_in_user_address (const char *str, notmuch_config_t *config)
+string_in_user_address (const char *str, notmuch_config_t *config, const char 
**user_from_name)
 {
-return address_match (str, config, STRING_IN_USER_ADDRESS);
+return address_match (str, config, user_from_name, STRING_IN_USER_ADDRESS);
 }
 
 /* Is the given address configured as one of the user's "primary" or
- * "other" addresses. */
+ * "other" addresses.
+ *
+ * If 'user_from_name' is non-NULL and the address is the user's,
+ * *user_from_name is set to the corresponding name.
+ *
+ */
 static notmuch_bool_t
-address_is_users (const char *address, notmuch_config_t *config)
+address_is_users (const char *address, notmuch_config_t *config, const char 
**user_from_name)
 {
-return address_match (address, config, STRING_IS_USER_ADDRESS) != NULL;
+return address_match (address, config, user_from_name, 
STRING_IS_USER_ADDRESS) != NULL;
 }
 
 /* Scan addresses in 'list'.
@@ -178,6 +207,9 @@ address_is_users (const char *address, notmuch_config_t 
*config)
  * be set to the first address encountered in 'list' that is the
  * user's address.
  *
+ * If 'user_from_name' is non-NULL and *user_from is set by this call,
+ * *user_from_name will be set to the name corresponding to *user_from.
+ *
  * Return the number of addresses added to 'message'. (If 'message' is
  * NULL, the function returns 0 by definition.)
  */
@@ -186,7 +218,8 @@ scan_address_list (InternetAddressList *list,
   notmuch_config_t *config,
   GMimeMessage *message,
   GMimeRecipientType type,
-  const char **user_from)
+  const char **user_from,
+  const char **user_from_name)
 {
 InternetAddress *address;
 int i;
@@ -203,7 +236,7 @@ scan_address_list (InternetAddressList *list,
if (group_list == NULL)
continue;
 
-   n += 

[PATCH 3/4] Add documentation for user.other_name

2016-08-09 Thread Shea Levy
---
 doc/man1/notmuch-config.rst | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index 5a517eb..6844c8d 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -68,6 +68,16 @@ The available configuration items are described below.
 
 Default: not set.
 
+**user.other\_name**
+A list of other names associated with addresses in
+**user.other\_email**. Leave an entry empty to use
+**user.name** for the corresponding address. If the
+list of other names is shorter than the list of other
+addresses, all addresses after the last listed name will
+be associated with **user.name**.
+
+Default: not set.
+
 **new.tags**
 A list of tags that will be added to all messages incorporated
 by **notmuch new**.
-- 
2.7.4

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 0/4] Allow specifying alternate names for addresses in other_email

2016-08-09 Thread Shea Levy
Currently, while notmuch-reply will recognize email addresses other than
the main address with user.other_email, it always sets the name part of
the address in the envelope-from and From headers to user.name. This
patchset enables specifying names on a per-address basis with a new
user.other_name property. Presumably other users of user.other_email
may want to use this as well, but those are not updated currently.

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 1/4] Add user.other_name property to associate names with other_email.

2016-08-09 Thread Shea Levy
Entries are paired with the email address at the same index in
other_email. To use user.name for a given other_email, leave that
entry blank or leave user.other_name shorter than the relevant index
altogether.
---
 notmuch-client.h |  9 +
 notmuch-config.c | 32 
 2 files changed, 41 insertions(+)

diff --git a/notmuch-client.h b/notmuch-client.h
index ebc092b..69c83a2 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -304,6 +304,15 @@ notmuch_config_set_user_other_email (notmuch_config_t 
*config,
 size_t length);
 
 const char **
+notmuch_config_get_user_other_name (notmuch_config_t *config,
+   size_t *length);
+
+void
+notmuch_config_set_user_other_name (notmuch_config_t *config,
+   const char *other_name[],
+   size_t length);
+
+const char **
 notmuch_config_get_new_tags (notmuch_config_t *config,
 size_t *length);
 void
diff --git a/notmuch-config.c b/notmuch-config.c
index e5d42a0..4ac16b7 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -63,6 +63,8 @@ static const char user_config_comment[] =
 "\tprimary_email   Your primary email address.\n"
 "\tother_email A list (separated by ';') of other email addresses\n"
 "\tat which you receive email.\n"
+"\tother_name  A list (separated by ';') of names corresponding to\n"
+"\tother_email addresses. Leave an entry blank to use default\n"
 "\n"
 " Notmuch will use the various email addresses configured here when\n"
 " formatting replies. It will avoid including your own addresses in the\n"
@@ -120,6 +122,8 @@ struct _notmuch_config {
 char *user_primary_email;
 const char **user_other_email;
 size_t user_other_email_length;
+const char **user_other_name;
+size_t user_other_name_length;
 const char **new_tags;
 size_t new_tags_length;
 const char **new_ignore;
@@ -237,6 +241,8 @@ get_username_from_passwd_file (void *ctx)
  *
  * user_other_email:   Not set.
  *
+ * user_other_name:Not set.
+ *
  * The default configuration also contains comments to guide the
  * user in editing the file directly.
  */
@@ -280,6 +286,8 @@ notmuch_config_open (void *ctx,
 config->user_primary_email = NULL;
 config->user_other_email = NULL;
 config->user_other_email_length = 0;
+config->user_other_name = NULL;
+config->user_other_name_length = 0;
 config->new_tags = NULL;
 config->new_tags_length = 0;
 config->new_ignore = NULL;
@@ -674,6 +682,23 @@ notmuch_config_set_user_other_email (notmuch_config_t 
*config,
 &(config->user_other_email));
 }
 
+const char **
+notmuch_config_get_user_other_name (notmuch_config_t *config, size_t *length)
+{
+return _config_get_list (config, "user", "other_name",
+&(config->user_other_name),
+&(config->user_other_name_length), length);
+}
+
+void
+notmuch_config_set_user_other_name (notmuch_config_t *config,
+   const char *list[],
+   size_t length)
+{
+_config_set_list (config, "user", "other_name", list, length,
+&(config->user_other_name));
+}
+
 void
 notmuch_config_set_new_tags (notmuch_config_t *config,
 const char *list[],
@@ -790,6 +815,13 @@ notmuch_config_command_get (notmuch_config_t *config, char 
*item)
other_email = notmuch_config_get_user_other_email (config, );
for (i = 0; i < length; i++)
printf ("%s\n", other_email[i]);
+} else if (strcmp(item, "user.other_name") == 0) {
+   const char **other_name;
+   size_t i, length;
+
+   other_name = notmuch_config_get_user_other_name (config, );
+   for (i = 0; i < length; i++)
+   printf ("%s\n", other_name[i]);
 } else if (strcmp(item, "new.tags") == 0) {
const char **tags;
size_t i, length;
-- 
2.7.4

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch