Discussion:
[bug-mailutils] Best way to get From: email address?
Jean Louis
2017-08-12 13:11:56 UTC
Permalink
Hello,

What would be best way by using the mailutils to
get only the email address from the From: header
by using pipe and not a file?

I think that either frm or from shall have the
option to parse the standard input instead of
default folder, so to be able to see From: email
address from a pipe.

Then I can use Mutt when reading emails with more
professional solution than I have it now with my
own parsing.

Parsing From: email address on pipe is then
enabling me to:

- enter the TO-DO item into database just by
clicking one link as by email address the person
is found in the database, and subject can be
used as TO-DO subject

- it allows me to add new skills to recruitment
candidates based on their email address.

From: may contain some special characters and I
just guess it is better for me to use some
built-in function in mailutils then messing up
with parsing it myself, like I do it now.

If it exists, let me know.

Jean Louis
Sergey Poznyakoff
2017-08-12 19:48:20 UTC
Permalink
Hi Jean,
Post by Jean Louis
What would be best way by using the mailutils to
get only the email address from the From: header
by using pipe and not a file?
Please find attached the source file ef.c and makefile ef.mk.
To build: make -f ef.mk
Usage: (something) | ef
or: ef < INPUT

Regards,
Sergey
Jean Louis
2017-08-13 06:29:15 UTC
Permalink
Hello,

That is great solution, I suggest that such
feature is implemented in frm or from, to receive
text from standard input. Then shell scripts can
easily be used to relate emails to other factors.

Thank you much.

I do parse it in Lisp or Scheme, now is even
better for scripts.

For example I have 1,300 candidates who tells me
about their skills for employment, I can then make
a macro in mutt, I click let us say F5, then
something I can assign skills to people based on
their email address and database ID, or mark them
as prospective client, or subscribe them quickly
to some mailing list.

Jean Louis
Post by Sergey Poznyakoff
Hi Jean,
Post by Jean Louis
What would be best way by using the mailutils to
get only the email address from the From: header
by using pipe and not a file?
Please find attached the source file ef.c and makefile ef.mk.
To build: make -f ef.mk
Usage: (something) | ef
or: ef < INPUT
Regards,
Sergey
#include <mailutils/mailutils.h>
int
main (int argc, char **argv)
{
int rc;
mu_message_t msg;
mu_header_t hdr;
struct mu_address hint;
mu_address_t addr;
char *val;
char const *email;
mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
MU_ASSERT (mu_stdio_stream_create (&mu_strin, MU_STDIN_FD,
MU_STREAM_READ|MU_STREAM_SEEK));
mu_set_program_name (argv[0]);
mu_registrar_record (mu_mbox_record);
MU_ASSERT (mu_stream_to_message (mu_strin, &msg));
MU_ASSERT (mu_message_get_header (msg, &hdr));
rc = mu_header_aget_value_unfold (hdr, MU_HEADER_FROM, &val);
if (rc == MU_ERR_NOENT)
return 1;
memset (&hint, 0, sizeof hint);
rc = mu_address_create_hint (&addr, val, &hint, MU_ADDR_HINT_DOMAIN);
if (rc)
{
mu_error ("can't parse address %s: %s", val, mu_strerror (rc));
return 1;
}
MU_ASSERT (mu_address_sget_email (addr, 1, &email));
mu_printf ("%s\n", email);
return 0;
}
CPPFLAGS=`mailutils cflags`
LIBS=`mailutils ldflags mbox`
ef: ef.c
cc $(CPPFLAGS) $(CFLAGS) -oef ef.c $(LDFLAGS) $(LIBS)
Loading...