Re: Best way to get From: email address?

Sergey Poznyakoff <[email protected]>
Newsgroups gmane.comp.gnu.mailutils.bugs
Organization GNU.org.ua
Message-ID <[email protected]>
Hi Jean,

> 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

_______________________________________________
Bug-mailutils mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-mailutils
ef.c (text/x-c, 955 B)
#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;
}
ef.mk (text/x-makefile, 123 B)
CPPFLAGS=`mailutils cflags`
LIBS=`mailutils ldflags mbox`
ef: ef.c
	cc $(CPPFLAGS) $(CFLAGS) -oef ef.c $(LDFLAGS) $(LIBS)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.