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

Jani Nikula jani at nikula.org
Sun Aug 14 06:45:47 PDT 2016


On Sun, 14 Aug 2016, Jani Nikula <jani at nikula.org> wrote:
> I think we should use gmime for this, and expect the configuration to be
> a comma separated list of addresses, specifically in the format that
> internet_address_list_parse_string() parses [2].

Here's a little sample to get started and play around. Build using
something along the lines of:

gcc $(pkg-config --cflags gmime-2.6 --libs gmime-2.6) internetaddress.c

You can try e.g.

$ ./a.out "J. Random Hacker <jrh at example.org>, dude at example.org, \"Hacker, J. Random\" <hacker at example.com>"
name[0]: J. Random Hacker
addr[0]: jrh at example.org
name[1]: (null)
addr[1]: dude at example.org
name[2]: Hacker, J. Random
addr[2]: hacker at example.com

----------->%----------

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include <gmime/gmime.h>

int main(int argc, char *argv[])
{
	InternetAddressList *list;
	InternetAddress *mailbox;
	int i;

	if (argc != 2) {
		fprintf(stderr, "usage: %s address-list\n", argv[0]);
		return EXIT_FAILURE;
	}

	list = internet_address_list_parse_string(argv[1]);

	for (i = 0; i < internet_address_list_length(list); i++) {
		InternetAddress *addr;
		InternetAddressMailbox *mbox;

		addr = internet_address_list_get_address(list, i);

		if (INTERNET_ADDRESS_IS_GROUP(addr)) {
			printf("[%d] is a group, ignoring\n", i);
			continue;
		}

		mbox = INTERNET_ADDRESS_MAILBOX(addr);

		printf("name[%d]: %s\n", i, internet_address_get_name(addr));
		printf("addr[%d]: %s\n", i, internet_address_mailbox_get_addr(mbox));
	}

	return EXIT_SUCCESS;	
}


More information about the notmuch mailing list