]> code.delx.au - gnu-emacs/blob - lib-src/b2m.c
dc0d81b6a9311f7945c610c19ff7510f48d09dd6
[gnu-emacs] / lib-src / b2m.c
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>
20 #include <sys/types.h>
21 #ifdef MSDOS
22 #include <fcntl.h>
23 #endif
24
25 #include <../src/config.h>
26
27 #ifdef USG
28 #include <string.h>
29 #else
30 #include <strings.h>
31 #endif
32
33 /* BSD's strings.h does not declare the type of strtok. */
34 extern char *strtok ();
35
36 #ifndef TRUE
37 #define TRUE (1)
38 #endif
39 #ifndef FALSE
40 #define FALSE (0)
41 #endif
42
43 int header = FALSE, printing;
44 time_t ltoday;
45 char from[256], labels[256], data[256], *p, *today;
46
47 main (argc, argv)
48 int argc;
49 char **argv;
50 {
51 #ifdef MSDOS
52 _fmode = O_BINARY; /* all of files are treated as binary files */
53 (stdout)->_flag &= ~_IOTEXT;
54 (stdin)->_flag &= ~_IOTEXT;
55 #endif
56 if (strcmp(argv[1], "--help") == 0)
57 {
58 fprintf(stderr, "Usage: %s <babylmailbox >unixmailbox\n", argv[0]);
59 exit (0);
60 }
61 ltoday = time(0);
62 today = ctime(&ltoday);
63
64 if (gets(data))
65 if (strncmp(data, "BABYL OPTIONS:", 14))
66 {
67 fprintf(stderr, "%s: not a Babyl mailfile!\n", argv[0]);
68 exit (-1);
69 } else
70 printing = FALSE;
71 else
72 exit(-1);
73 if (printing)
74 puts(data);
75
76 while (gets(data)) {
77
78 #if 0
79 /* What was this for? Does somebody have something against blank
80 lines? */
81 if (!strcmp(data, ""))
82 exit(0);
83 #endif
84
85 if (!strcmp(data, "*** EOOH ***") && !printing) {
86 printing = header = TRUE;
87 printf("From %s %s", argv[0], today);
88 continue;
89 }
90
91 if (!strcmp(data, "\037\f")) {
92 /* save labels */
93 gets(data);
94 p = strtok(data, " ,\r\n\t");
95 strcpy(labels, "X-Babyl-Labels: ");
96
97 while (p = strtok(NULL, " ,\r\n\t")) {
98 strcat(labels, p);
99 strcat(labels, ", ");
100 }
101
102 labels[strlen(labels) - 2] = '\0';
103 printing = header = FALSE;
104 continue;
105 }
106
107 if (!strlen(data) && header) {
108 header = FALSE;
109 if (strcmp(labels, "X-Babyl-Labels"))
110 puts(labels);
111 }
112
113 if (printing)
114 puts(data);
115 }
116 }