Commit | Line | Data |
---|---|---|
cc9940c7 JB |
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> | |
312752df | 20 | #include <sys/types.h> |
fbfed6f0 | 21 | |
18160b98 | 22 | #include <../src/config.h> |
fbfed6f0 JB |
23 | |
24 | #ifdef USG | |
25 | #include <string.h> | |
26 | #else | |
cc9940c7 | 27 | #include <strings.h> |
fbfed6f0 | 28 | #endif |
cc9940c7 JB |
29 | |
30 | /* BSD's strings.h does not declare the type of strtok. */ | |
31 | extern char *strtok (); | |
32 | ||
cbc61077 | 33 | #ifndef TRUE |
cc9940c7 | 34 | #define TRUE (1) |
cbc61077 RS |
35 | #endif |
36 | #ifndef FALSE | |
cc9940c7 | 37 | #define FALSE (0) |
cbc61077 | 38 | #endif |
cc9940c7 JB |
39 | |
40 | int header = FALSE, printing; | |
312752df | 41 | time_t ltoday; |
cc9940c7 JB |
42 | char from[256], labels[256], data[256], *p, *today; |
43 | ||
5d13f393 JB |
44 | main (argc, argv) |
45 | int argc; | |
46 | char **argv; | |
cc9940c7 JB |
47 | { |
48 | ltoday = time(0); | |
49 | today = ctime(<oday); | |
50 | ||
51 | if (gets(data)) | |
52 | if (strcmp(data, "BABYL OPTIONS:")) { | |
53 | fprintf(stderr, "b2m: not a Babyl mailfile!\n"); | |
54 | exit(-1); | |
55 | } else | |
56 | printing = FALSE; | |
57 | else | |
58 | exit(-1); | |
59 | if (printing) | |
60 | puts(data); | |
61 | ||
62 | while (gets(data)) { | |
5d13f393 JB |
63 | |
64 | #if 0 | |
65 | /* What was this for? Does somebody have something against blank | |
66 | lines? */ | |
cc9940c7 JB |
67 | if (!strcmp(data, "")) |
68 | exit(0); | |
5d13f393 | 69 | #endif |
cc9940c7 JB |
70 | |
71 | if (!strcmp(data, "*** EOOH ***") && !printing) { | |
72 | printing = header = TRUE; | |
73 | printf("From b2m %s", today); | |
74 | continue; | |
75 | } | |
76 | ||
77 | if (!strcmp(data, "\f")) { | |
78 | /* save labels */ | |
79 | gets(data); | |
80 | p = strtok(data, " ,\r\n\t"); | |
81 | strcpy(labels, "X-Babyl-Labels: "); | |
82 | ||
83 | while (p = strtok(NULL, " ,\r\n\t")) { | |
84 | strcat(labels, p); | |
85 | strcat(labels, ", "); | |
86 | } | |
87 | ||
88 | labels[strlen(labels) - 2] = '\0'; | |
89 | printing = header = FALSE; | |
90 | continue; | |
91 | } | |
92 | ||
93 | if (!strlen(data) && header) { | |
94 | header = FALSE; | |
95 | if (strcmp(labels, "X-Babyl-Labels")) | |
96 | puts(labels); | |
97 | } | |
98 | ||
99 | if (printing) | |
100 | puts(data); | |
101 | } | |
102 | } |