Dear P. Mazart,

Thanks, I think I have solved the first part of my need, though it is
not any more the same as what I was doing before.

Here is the macro:

macro index,pager r "<pipe-entry>ef > ~/tmp/ef-email<enter><reply>"

program `ef' is compiled with GNU Mailutils libraries, but it could be
probably a specialized `grep' command to capture the recipient's email
address. This command did not fail me yet. Recipient is the one in the
From: field, thus `ef' implies "Email from". It is small program made
by Sergey, the maintainer of GNU Mailutils https://www.mailutils.org
and I am attaching the program in this message. I am using it reliably
for years. It is nothing special, it just extracts email address from
the From: field. There is also `et.c' file attached which I have
slightly modified that it captures the To: recipient.

When replying on email the From: the program will simple save the
current email address in the file ~/tmp/ef/email -- and then when
editing I have got the reference for automatic further
hyperlinking. When I say "hyperlinking" I don't mean HTML or
similar. I mean functions which allow me to quickly switch to
information pertaining to the recipient, let us say the phone number
if I wish to call recipeint during email writing, or maybe I wish to
see which other previous emails did same recipient receive, SMS list
or notes related to recipient. This works well in Emacs as it is
programming language.

* P. Mazart <pmaz...@web.de> [2021-06-30 10:01]:
> I think you could always create a {python,bash,ruby} script or c-program
> and let it “mimic” an editor when you reply:
> 
> :macro index r "<enter-command>set 
> editor=\"edit-id-then-reply.py\"<enter><reply><enter-command>set 
> editor=\"vim\"<enter>"

Now I found simpler solution, instead of injecting it in the body of
email, I am saving the current recipient's email address in the
outside file.

This may not work well in my case as I am also using background
editing. So that could be solved if I would have some reference to
hook on it. That could be the file name, but I do not know how is
temporary file name generated or if I can change the name of it. Let
us say if I could change the name of temporary file, then I could have
a reference to hook (not in mutt's context) the email address to the
temporary file generated. That would solve the problem with background
editing.

In any case, I can put some attention not to make a mistake.

Another solution could be searching for the email address in the
buffer as a reference. Anyway I have to be able to invoke personal
relationship management options on the email address.

> > Is there a way to intercept the recipient's address, like making a
> > macro for the `y' key binding?
> 
> Similar to the above, you could create a sendmail-compatible wrapper,
> that does the interception and later actually runs sendmail or msmtp or
> else.

I was looking in my current setup and I was counting generally when
emails were sent but not to which person they were sent.

Following macro was and is still recording the inaccurate time when
email has been sent from Mutt:

macro compose y ":set wait_key=no<enter>!general-log.lisp 'mutt: message 
sent'<enter><send-message>"

Instead of that I will then soon implement very similar piping as in
the previous macro, so that program `general-log.lisp' can get the
recipient's email address in real time from the message, extract it
and use it to record that email has been sent to person at specific
time. 

That again also solves the problem with background editing as then
specific recipients are captured before sending the email and will not
collide with other background edited emails.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/
#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;
}
# Extracts the email from

CPPFLAGS=`mailutils cflags`
LIBS=`mailutils ldflags mbox`
ef: ef.c
        cc $(CPPFLAGS) $(CFLAGS) -oef ef.c $(LDFLAGS) $(LIBS)

#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_TO, &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;
}

Reply via email to