440
|
1 /*
|
|
2 * b2m - a filter for Babyl -> Unix mail files
|
|
3 *
|
|
4 * usage: b2m < babyl > mailbox
|
|
5 *
|
|
6 * I find this useful whenever I have to use a
|
|
7 * system which - shock horror! - doesn't run
|
|
8 * Gnu emacs. At least now I can read all my
|
|
9 * Gnumacs Babyl format mail files!
|
|
10 *
|
|
11 * it's not much but it's free!
|
|
12 *
|
|
13 * Ed Wilkinson
|
|
14 * E.Wilkinson@massey.ac.nz
|
|
15 * Mon Nov 7 15:54:06 PDT 1988
|
|
16 */
|
|
17
|
|
18 #include <stdio.h>
|
|
19 #include <time.h>
|
998
|
20
|
|
21 #include "../src/config.h"
|
|
22
|
|
23 #ifdef USG
|
|
24 #include <string.h>
|
|
25 #else
|
440
|
26 #include <strings.h>
|
998
|
27 #endif
|
440
|
28
|
|
29 /* BSD's strings.h does not declare the type of strtok. */
|
|
30 extern char *strtok ();
|
|
31
|
|
32 #define TRUE (1)
|
|
33 #define FALSE (0)
|
|
34
|
|
35 int header = FALSE, printing;
|
|
36 long ltoday;
|
|
37 char from[256], labels[256], data[256], *p, *today;
|
|
38
|
|
39 main(argc, argv)
|
|
40 char **argv;
|
|
41 {
|
|
42 ltoday = time(0);
|
|
43 today = ctime(<oday);
|
|
44
|
|
45 if (gets(data))
|
|
46 if (strcmp(data, "BABYL OPTIONS:")) {
|
|
47 fprintf(stderr, "b2m: not a Babyl mailfile!\n");
|
|
48 exit(-1);
|
|
49 } else
|
|
50 printing = FALSE;
|
|
51 else
|
|
52 exit(-1);
|
|
53 if (printing)
|
|
54 puts(data);
|
|
55
|
|
56 while (gets(data)) {
|
|
57 if (!strcmp(data, ""))
|
|
58 exit(0);
|
|
59
|
|
60 if (!strcmp(data, "*** EOOH ***") && !printing) {
|
|
61 printing = header = TRUE;
|
|
62 printf("From b2m %s", today);
|
|
63 continue;
|
|
64 }
|
|
65
|
|
66 if (!strcmp(data, "")) {
|
|
67 /* save labels */
|
|
68 gets(data);
|
|
69 p = strtok(data, " ,\r\n\t");
|
|
70 strcpy(labels, "X-Babyl-Labels: ");
|
|
71
|
|
72 while (p = strtok(NULL, " ,\r\n\t")) {
|
|
73 strcat(labels, p);
|
|
74 strcat(labels, ", ");
|
|
75 }
|
|
76
|
|
77 labels[strlen(labels) - 2] = '\0';
|
|
78 printing = header = FALSE;
|
|
79 continue;
|
|
80 }
|
|
81
|
|
82 if (!strlen(data) && header) {
|
|
83 header = FALSE;
|
|
84 if (strcmp(labels, "X-Babyl-Labels"))
|
|
85 puts(labels);
|
|
86 }
|
|
87
|
|
88 if (printing)
|
|
89 puts(data);
|
|
90 }
|
|
91 }
|