0
|
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
|
|
19 /* Synched up with: FSF 19.28. */
|
|
20
|
|
21 /* Serious bug: This program uses `gets', which is intrinsically
|
|
22 unreliable--long lines will cause crashes.
|
|
23 Someone should fix this program not to use `gets'. */
|
|
24 #include <stdio.h>
|
|
25 #include <time.h>
|
|
26 #include <sys/types.h>
|
|
27 #ifdef MSDOS
|
|
28 #include <fcntl.h>
|
|
29 #endif
|
|
30
|
|
31 #include <../src/config.h>
|
|
32
|
|
33 #if __STDC__ || defined(STDC_HEADERS)
|
|
34 # include <stdlib.h>
|
|
35 # include <string.h>
|
|
36 #else /* ! (__STDC__ || defined(STDC_HEADERS)) */
|
|
37 # ifdef USG
|
|
38 # include <string.h>
|
|
39 # else
|
|
40 # include <strings.h>
|
|
41 # endif
|
|
42
|
|
43 /* BSD's strings.h does not declare the type of strtok. */
|
|
44 extern char *strtok ();
|
|
45 #endif /* ! (__STDC__ || defined(STDC_HEADERS)) */
|
|
46
|
|
47
|
|
48 #ifndef TRUE
|
|
49 #define TRUE (1)
|
|
50 #endif
|
|
51 #ifndef FALSE
|
|
52 #define FALSE (0)
|
|
53 #endif
|
|
54
|
|
55 int header = FALSE, printing;
|
|
56 time_t ltoday;
|
|
57 char from[256], labels[256], data[256], *p, *today;
|
|
58
|
|
59 void
|
|
60 main (int argc, char **argv)
|
|
61 {
|
|
62 #ifdef MSDOS
|
|
63 _fmode = O_BINARY; /* all of files are treated as binary files */
|
|
64 (stdout)->_flag &= ~_IOTEXT;
|
|
65 (stdin)->_flag &= ~_IOTEXT;
|
|
66 #endif
|
|
67 if ((argc >= 2) && strcmp (argv[1], "--help") == 0)
|
|
68 {
|
|
69 fprintf (stderr, "%s - a filter for Babyl -> Unix mail files\n", argv[0]);
|
|
70 fprintf (stderr, "Usage: %s < babylmailbox > unixmailbox\n", argv[0]);
|
|
71 exit (0);
|
|
72 }
|
|
73
|
|
74 ltoday = time (0);
|
|
75 today = ctime (<oday);
|
|
76
|
|
77 /* BUG! Must not use gets in a reliable program! */
|
|
78 if (gets (data))
|
|
79 {
|
|
80 if (strncmp (data, "BABYL OPTIONS:", 14))
|
|
81 {
|
|
82 fprintf (stderr, "%s: not a Babyl mailfile!\n", argv[0]);
|
|
83 exit (-1);
|
|
84 }
|
|
85 else
|
|
86 printing = FALSE;
|
|
87 }
|
|
88 else
|
|
89 exit (-1);
|
|
90 if (printing)
|
|
91 puts (data);
|
|
92
|
|
93 while (gets (data))
|
|
94 {
|
|
95
|
|
96 #if 0
|
|
97 /* What was this for? Does somebody have something against blank
|
|
98 lines? */
|
|
99 if (!strcmp (data, ""))
|
|
100 exit (0);
|
|
101 #endif
|
|
102
|
|
103 if (!strcmp (data, "*** EOOH ***") && !printing)
|
|
104 {
|
|
105 printing = header = TRUE;
|
|
106 printf ("From %s %s", argv[0], today);
|
|
107 continue;
|
|
108 }
|
|
109
|
|
110 if (!strcmp (data, "\037\f"))
|
|
111 {
|
|
112 /* save labels */
|
|
113 gets (data);
|
|
114 p = strtok (data, " ,\r\n\t");
|
|
115 strcpy (labels, "X-Babyl-Labels: ");
|
|
116
|
|
117 while ((p = strtok (NULL, " ,\r\n\t")))
|
|
118 {
|
|
119 strcat (labels, p);
|
|
120 strcat (labels, ", ");
|
|
121 }
|
|
122
|
|
123 labels[strlen (labels) - 2] = '\0';
|
|
124 printing = header = FALSE;
|
|
125 continue;
|
|
126 }
|
|
127
|
|
128 if (!strlen (data) && header)
|
|
129 {
|
|
130 header = FALSE;
|
|
131 if (strcmp (labels, "X-Babyl-Labels"))
|
|
132 puts (labels);
|
|
133 }
|
|
134
|
|
135 if (printing)
|
|
136 puts (data);
|
|
137 }
|
|
138 }
|