mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 20:08:10 +01:00
cli: slightly refactor "notmuch reply" address scanning functions
Slightly refactor "notmuch reply" recipient and user from address scanning functions in preparation for reply-to-sender feature. Add support for not adding recipients at all (just scan for user from address), and returning the number of recipients added. No externally visible functional changes. Signed-off-by: Jani Nikula <jani@nikula.org>
This commit is contained in:
parent
647c250989
commit
fb1c016cb5
1 changed files with 40 additions and 36 deletions
|
@ -168,22 +168,29 @@ address_is_users (const char *address, notmuch_config_t *config)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For each address in 'list' that is not configured as one of the
|
/* Scan addresses in 'list'.
|
||||||
* user's addresses in 'config', add that address to 'message' as an
|
|
||||||
* address of 'type'.
|
|
||||||
*
|
*
|
||||||
* The first address encountered that *is* the user's address will be
|
* If 'message' is non-NULL, then for each address in 'list' that is
|
||||||
* returned, (otherwise NULL is returned).
|
* not configured as one of the user's addresses in 'config', add that
|
||||||
|
* address to 'message' as an address of 'type'.
|
||||||
|
*
|
||||||
|
* If 'user_from' is non-NULL and *user_from is NULL, *user_from will
|
||||||
|
* be set to the first address encountered in 'list' that is the
|
||||||
|
* user's address.
|
||||||
|
*
|
||||||
|
* Return the number of addresses added to 'message'. (If 'message' is
|
||||||
|
* NULL, the function returns 0 by definition.)
|
||||||
*/
|
*/
|
||||||
static const char *
|
static unsigned int
|
||||||
add_recipients_for_address_list (GMimeMessage *message,
|
scan_address_list (InternetAddressList *list,
|
||||||
notmuch_config_t *config,
|
notmuch_config_t *config,
|
||||||
|
GMimeMessage *message,
|
||||||
GMimeRecipientType type,
|
GMimeRecipientType type,
|
||||||
InternetAddressList *list)
|
const char **user_from)
|
||||||
{
|
{
|
||||||
InternetAddress *address;
|
InternetAddress *address;
|
||||||
int i;
|
int i;
|
||||||
const char *ret = NULL;
|
unsigned int n = 0;
|
||||||
|
|
||||||
for (i = 0; i < internet_address_list_length (list); i++) {
|
for (i = 0; i < internet_address_list_length (list); i++) {
|
||||||
address = internet_address_list_get_address (list, i);
|
address = internet_address_list_get_address (list, i);
|
||||||
|
@ -196,8 +203,7 @@ add_recipients_for_address_list (GMimeMessage *message,
|
||||||
if (group_list == NULL)
|
if (group_list == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
add_recipients_for_address_list (message, config,
|
n += scan_address_list (group_list, config, message, type, NULL);
|
||||||
type, group_list);
|
|
||||||
} else {
|
} else {
|
||||||
InternetAddressMailbox *mailbox;
|
InternetAddressMailbox *mailbox;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -209,40 +215,41 @@ add_recipients_for_address_list (GMimeMessage *message,
|
||||||
addr = internet_address_mailbox_get_addr (mailbox);
|
addr = internet_address_mailbox_get_addr (mailbox);
|
||||||
|
|
||||||
if (address_is_users (addr, config)) {
|
if (address_is_users (addr, config)) {
|
||||||
if (ret == NULL)
|
if (user_from && *user_from == NULL)
|
||||||
ret = addr;
|
*user_from = addr;
|
||||||
} else {
|
} else if (message) {
|
||||||
g_mime_message_add_recipient (message, type, name, addr);
|
g_mime_message_add_recipient (message, type, name, addr);
|
||||||
|
n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For each address in 'recipients' that is not configured as one of
|
/* Scan addresses in 'recipients'.
|
||||||
* the user's addresses in 'config', add that address to 'message' as
|
|
||||||
* an address of 'type'.
|
|
||||||
*
|
*
|
||||||
* The first address encountered that *is* the user's address will be
|
* See the documentation of scan_address_list() above. This function
|
||||||
* returned, (otherwise NULL is returned).
|
* does exactly the same, but converts 'recipients' to an
|
||||||
|
* InternetAddressList first.
|
||||||
*/
|
*/
|
||||||
static const char *
|
static unsigned int
|
||||||
add_recipients_for_string (GMimeMessage *message,
|
scan_address_string (const char *recipients,
|
||||||
notmuch_config_t *config,
|
notmuch_config_t *config,
|
||||||
|
GMimeMessage *message,
|
||||||
GMimeRecipientType type,
|
GMimeRecipientType type,
|
||||||
const char *recipients)
|
const char **user_from)
|
||||||
{
|
{
|
||||||
InternetAddressList *list;
|
InternetAddressList *list;
|
||||||
|
|
||||||
if (recipients == NULL)
|
if (recipients == NULL)
|
||||||
return NULL;
|
return 0;
|
||||||
|
|
||||||
list = internet_address_list_parse_string (recipients);
|
list = internet_address_list_parse_string (recipients);
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
return NULL;
|
return 0;
|
||||||
|
|
||||||
return add_recipients_for_address_list (message, config, type, list);
|
return scan_address_list (list, config, message, type, user_from);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Does the address in the Reply-To header of 'message' already appear
|
/* Does the address in the Reply-To header of 'message' already appear
|
||||||
|
@ -324,7 +331,7 @@ add_recipients_from_message (GMimeMessage *reply,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
|
for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
|
||||||
const char *addr, *recipients;
|
const char *recipients;
|
||||||
|
|
||||||
recipients = notmuch_message_get_header (message,
|
recipients = notmuch_message_get_header (message,
|
||||||
reply_to_map[i].header);
|
reply_to_map[i].header);
|
||||||
|
@ -332,11 +339,8 @@ add_recipients_from_message (GMimeMessage *reply,
|
||||||
recipients = notmuch_message_get_header (message,
|
recipients = notmuch_message_get_header (message,
|
||||||
reply_to_map[i].fallback);
|
reply_to_map[i].fallback);
|
||||||
|
|
||||||
addr = add_recipients_for_string (reply, config,
|
scan_address_string (recipients, config, reply,
|
||||||
reply_to_map[i].recipient_type,
|
reply_to_map[i].recipient_type, &from_addr);
|
||||||
recipients);
|
|
||||||
if (from_addr == NULL)
|
|
||||||
from_addr = addr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return from_addr;
|
return from_addr;
|
||||||
|
|
Loading…
Reference in a new issue