undigestifier

By Ted Kim (Random Dude ·

TML message #1272From bundle 105Read the whole thread (2 messages)All messages with this subject

Replies:
TML submission:

A while back, I asked if anyone had pointers to an undigestifier
program, so that I could be more selective when saving articles from
this mailing list. While better mail programs (mh, mush, etc.) have
them builtin, I did not want to switch just to read this mailing list.
Well, after receiving no suggestions and turning up nothing at uunet,
I wrote my own.

I make no claim it works for anything in particular or in general at all.
<add legalistic disclaimer mumbo-jumbo here>

The program is specific to the formatting used in the TML Nightly and
probably dependent on the BSD UNIX way of doing mail. (James, please
don't change the format, or my fragile program will break!)

Basically, Berkeley mail users can just pipe the TML Nightly into this
program and get the inidividual articles mailed to themselves. Due to
the way TML is formatted, they generally show up with the correct
author and date. (Some articles have no "from" line, and show you as
the author!). Of course, the actual delivery history will show you
mailed to yourself.

- -ted

Ted Kim
UCLA Computer Science Department  Internet: [email removed]
3804C Boelter Hall                UUCP:    ...!{uunet|ucbvax}!cs.ucla.edu!tek
[address removed]    		  Phone:   [phone removed]
====================================cut here====================================
/*
 * udt: undigestifier for TML Nightly
 * by [email removed]
 */

#include <stdio.h>

extern char *getenv();
extern void get_line();
extern void peek_line();
extern void put_line();
extern void write_marker();
extern void write_repeated();

#define BUFLEN (1024)
#define HEADER_DASHES (60)
#define ARTICLE_DASHES (30)
#define END_MARKER "End of TML Nightly\n"
#define TMP_FILENAME "/tmp/udXXXXXX"

#define WRITE_EMPTY putc('\n', fp)
#define CLEAR_BUF peeked = 0

main()
{
  register int cont;
  int article, peeked = 0;
  char buf[BUFLEN];

  char filename[256];
  int fd;
  FILE *fp;

  char cmd[BUFLEN];
  char *user = getenv("USER");

  /* header */
  for (cont = 1; cont; ) {
    do get_line(buf, BUFLEN, &peeked); /* anything, blank line */
      while (strlen(buf) > 1);
    peek_line(buf, BUFLEN, &peeked); /* dashes */
    if (!check_repeated(buf, '-', HEADER_DASHES))
      continue;
    CLEAR_BUF;
    get_line(buf, BUFLEN, &peeked); /* blank line */
    if (strlen(buf) == 1)
      cont = 0;
  }
  printf("header removed\n");

  /* articles */
  for (;;) {

    /* open tmp file */
    strcpy(filename, TMP_FILENAME);
    fd = mkstemp(filename);
    fp = fdopen(fd, "w");

    for (;;) {
      get_line(buf, BUFLEN, &peeked);

      /* check for end of article */
      if (strlen(buf) == 1) {	/* blank line */
	peek_line(buf, BUFLEN, &peeked); /* dashes */
	if (!check_repeated(buf, '-', ARTICLE_DASHES)) {
	  WRITE_EMPTY;
	  continue;
	}
	peek_line(buf, BUFLEN, &peeked); /* blank line */
	if (strlen(buf) > 1) {
	  WRITE_EMPTY;
	  write_repeated(fp, '-', ARTICLE_DASHES);
	  continue;
	}
	CLEAR_BUF;
	fclose(fp);		/* mail article */
	sprintf(cmd, "/bin/mail %s < %s\n", user, filename);
	system(cmd);
	unlink(filename);
	printf("sent article %d\n", ++article);
	break;
      }

      /* check for end of digest */
      else if (strcmp(buf, END_MARKER) == 0) { /* end marker */
	peek_line(buf, BUFLEN, &peeked); /* stars */
	if (!check_repeated(buf, '*', strlen(END_MARKER) - 1 )) { /* no nl */
	  write_marker(fp);
	  continue;
	}
	peek_line(buf, BUFLEN, &peeked); /* blank line */
	if (strlen(buf) > 1) {
	  write_marker(fp);
	  write_repeated(fp, '*', strlen(END_MARKER) - 1);
	  continue;
	}
	fclose(fp);		/* exit */
	unlink(filename);
	printf("end of digest\n");
	exit(0);
      }

      else
	put_line(buf, fp, &peeked);
    }
  }
}

void
get_line(buf, len, pp)
     char *buf;
     int len, *pp;
{
  if (*pp)
    *pp = 0;
  else
    fgets(buf, len, stdin);
}

void
peek_line(buf, len, pp)
     char *buf;
     int len, *pp;
{
  fgets(buf, len, stdin);
  *pp = 1;
}

void
put_line(buf, fp, pp)
     char *buf;
     FILE *fp;
     int *pp;
{
   fputs(buf, fp);
   *pp = 0;
}

void
write_marker(fp)
     FILE *fp;
{
  fputs(END_MARKER, fp);
  WRITE_EMPTY;
}

int
check_repeated(buf, c, len)
     char *buf;
     register char c;
     register int len;
{
  register int i;
  register char *cp;

  for (i = 1, cp = buf; i < len; i++, cp++) /* check all but the newline */
    if (*cp != c)
      return 0;
  return 1;
}

void
write_repeated(fp, c, len)
     FILE *fp;
     char c;
     register int len;
{
  register int i;

  for (i = 0; i < len; i++)
    putc(c, fp);
  WRITE_EMPTY;
}
====================================cut here====================================