Fixed make_bcc_file () to use contents of From: in draft, if draft_from masquerade...
[mmh] / sbr / ext_hook.c
1 /*      $Id$
2  *
3  *      Run a program that hooks into some other system.  The first argument is
4  *      name of the hook to use, the second is the full path name of a mail message.
5  *      The third argument is also the full path name of a mail message, or a NULL
6  *      pointer if it isn't needed.  Look in the context for an error message if
7  *      something goes wrong; there is a built-in message in case one isn't specified.
8  *      Only produce the error message once.
9  */
10
11 #include <h/mh.h>
12
13 int
14 ext_hook(char *hook_name, char *message_file_name_1, char *message_file_name_2)
15 {
16     char        *hook;                  /* hook program from context */
17     pid_t       pid;                    /* ID of child process */
18     int         status;                 /* exit or other child process status */
19     char        *vec[4];                /* argument vector for child process */
20
21     static  int did_message = 0;        /* set if we've already output a message */
22
23     if ((hook = context_find(hook_name)) == (char *)0)
24         return (OK);
25
26     switch (pid = vfork()) {
27     case -1:
28         status = NOTOK;
29         advise(NULL, "external database may be out-of-date.");
30         break;
31
32     case 0:
33         vec[0] = r1bindex(hook, '/');
34         vec[1] = message_file_name_1;
35         vec[2] = message_file_name_2;
36         vec[3] = (char *)0;
37         execvp(hook, vec);
38         _exit(-1);
39         /* NOTREACHED */
40
41     default:
42         status = pidwait(pid, -1);
43         break;
44     }
45
46     if (status != OK) {
47         if (did_message == 0) {
48             if ((hook = context_find("msg-hook")) != (char *)0)
49                 advise(NULL, hook);
50             else
51                 advise(NULL, "external hook (%s) did not work properly.", hook);
52         
53             did_message = 1;
54         }
55
56         return (NOTOK);
57     }
58
59     else
60         return (OK);
61 }