home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume6
/
showhook.mh
< prev
next >
Wrap
Text File
|
1989-03-07
|
5KB
|
230 lines
Newsgroups: comp.sources.misc
From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
Subject: v06i057: MH Mail patch to allow some action to be taken when mail is read
Reply-To: pbrown@gldsyd.oz.au (Peter Brown)
Posting-number: Volume 6, Issue 57
Submitted-by: pbrown@gldsyd.oz.au (Peter Brown)
Archive-name: showhook.mh
[On looking this over, I note a few bugs: specifically, the use of $s instead
of %s in printf()'s (!). It also requires that MH be configured with RPATHS,
at least for the sample showhook. Oh, well ++bsa]
The following patch to mh's show.c and the associated code allow you to set up
the mail so that some action can be taken when the mail is actually read using
show, prev, or next.
The file regm.c is one that I set up to send a return receipt when the mail
being read has a field "Classification: Registered" such as Qoffice lets you
put in.
The file regm.c could be easily modified to take care of other circumstances.
# This is a shell archive. Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file". (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# show.diff regm.c
echo x - show.diff
cat > "show.diff" << '//E*O*F show.diff//'
39,41d38
< #define SHOWHOOKSW 12
< "showhook", 5,
<
66,67c63
< msgnum,
< showhook = 0;
---
> msgnum;
115,117d110
< case SHOWHOOKSW:
< showhook = 1;
< continue;
243d235
<
251,261d242
< /* The following fork exec code was put in to set up automatic responce to
< registered mail
< */
< if (showhook)
< if ( fork () == 0 )
< {
< vec[0] = "showhook";
< execvp ("showhook", vec);
< adios ("showhook", "unable to exec");
< }
<
268c249
< (void) mhl (vecp, vec);
---
> (void) mhl (vecp, vec);
//E*O*F show.diff//
echo x - regm.c
cat > "regm.c" << '//E*O*F regm.c//'
#define RETURNT 0x01
#define FROMT 0x02
#define DATET 0x04
#define SUBJECTT 0x08
#define CLASST 0x10
#include <stdio.h>
#include <string.h>
static char msgfname[] = { "/tmp/REGMXXXXXX" },
outfname[] = { "/tmp/REGMXXXXXX" };
main (argc, argv)
int argc;
char *argv[];
{
static char *args[] = { "sendmail", "-i", "-t", (char *) 0 };
char sender[256],
time[256],
subject[256],
buf[256],
copybuf[BUFSIZ],
**argsp,
*tokp,
c;
int n,
passflag = 0;
FILE *msgf,
*outf,
*inf;
while (argc-- > 1)
{
mktemp (msgfname);
if ((msgf = fopen (msgfname, "w+")) == (FILE *) NULL)
{
fprintf (stderr, "$s: Couldn't open file\n", argv[0]);
lgooh (1);
}
mktemp (outfname);
if ((outf = fopen (outfname, "w+")) == (FILE *) NULL)
{
fprintf (stderr, "$s: Couldn't open file\n", argv[0]);
lgooh (1);
}
if ((inf = fopen (argv[argc], "r+")) == (FILE *) NULL)
{
fprintf (stderr, "$s: Couldn't open %s\n",
argv[0], argv[argc]);
lgooh (1);
}
while (fgets (buf, 256, inf) != (char *) NULL)
{
fputs (buf, outf);
tokp = strtok (buf, " ");
if ((strcmp (tokp, "Return-Path:")) == 0)
{
tokp = strtok (((char *) NULL), "\n");
strcpy (sender, tokp);
passflag |= RETURNT;
continue;
}
if ((strcmp (tokp, "From:")) == 0 &&
(passflag & RETURNT) != RETURNT)
{
tokp = strtok (((char *) NULL), " \n");
strcpy (sender, tokp);
passflag |= FROMT;
continue;
}
if ((strcmp (tokp, "Date:")) == 0)
{
tokp = strtok (((char *) NULL), "\n");
strcpy (time, tokp);
passflag |= DATET;
continue;
}
if ((strcmp (tokp, "Subject:")) == 0)
{
tokp = strtok (((char *) NULL), "\n");
strcpy (subject, tokp);
passflag |= SUBJECTT;
continue;
}
if ((strcmp (tokp, "Classification:")) == 0)
{
tokp = strtok (((char *) NULL), " \n");
if ((strcmp (tokp, "Registered")) == 0)
{
fseek (outf, -11L, 1);
fprintf (outf, "Return Receipt Sent\n");
passflag = CLASST;
}
else
lgooh (0);
}
}
if ((passflag & CLASST) != CLASST)
lgooh (0);
fprintf (msgf, "To: %s\n", sender);
fprintf (msgf, "Subject: Return Receipt for: %s\n", time);
fprintf (msgf, "--------\n");
fprintf (msgf, "This message acknowledges receipt of your ");
fprintf (msgf, "message of %s ", time);
fprintf (msgf, "on the subject of: %s\n", subject);
if ( freopen( msgfname, "r", stdin) == (FILE *) NULL)
{
fprintf (stderr, "\n\n%s: unable to reopen %s\n\n",
argv[0], msgfname);
lgooh (1);
}
rewind (inf);
rewind (outf);
do
{
n = fread (copybuf, sizeof (char), BUFSIZ, outf);
fwrite (copybuf, sizeof (char), n, inf);
}
while (n == BUFSIZ);
fclose (inf);
if (fork () == 0)
{
execv ("/usr/lib/sendmail", args);
fprintf (stderr,
"%s: Unable to exec /usr/lib/sendmail\n",
argv[0]);
}
else lgooh (0);
}
}
lgooh (exitval)
int exitval;
{
if ((unlink (msgfname)) < 0)
fprintf (stderr, "Unable to unlink %s\n", msgfname);
if ((unlink (outfname)) < 0)
fprintf (stderr, "Unable to unlink %s\n", outfname);
exit (exitval);
}
//E*O*F regm.c//
exit 0