2 * b2m - a filter for Babyl -> Unix mail files
4 * usage: b2m < babyl > mailbox
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!
11 * it's not much but it's free!
14 * E.Wilkinson@massey.ac.nz
15 * Mon Nov 7 15:54:06 PDT 1988
20 #include <sys/types.h>
25 #include <../src/config.h>
27 /* BSD's strings.h does not declare the type of strtok. */
28 extern char *strtok ();
37 #define MAX_DATA_LEN 256 /* size for from[], labels[], and data[] arrays */
39 int header
= FALSE
, printing
;
41 char from
[MAX_DATA_LEN
], labels
[MAX_DATA_LEN
], data
[MAX_DATA_LEN
], *p
, *today
;
49 _fmode
= O_BINARY
; /* all of files are treated as binary files */
50 (stdout
)->_flag
&= ~_IOTEXT
;
51 (stdin
)->_flag
&= ~_IOTEXT
;
53 if (argc
>= 2 && strcmp (argv
[1], "--help") == 0)
55 fprintf (stderr
, "Usage: %s <babylmailbox >unixmailbox\n", argv
[0]);
59 today
= ctime (<oday
);
61 if (fgets (data
, MAX_DATA_LEN
, stdin
))
63 if (strncmp (data
, "BABYL OPTIONS:", 14))
65 fprintf (stderr
, "%s: not a Babyl mailfile!\n", argv
[0]);
76 while (fgets (data
, MAX_DATA_LEN
, stdin
))
80 /* What was this for? Does somebody have something against blank
82 if (!strcmp (data
, ""))
86 if (!strcmp (data
, "*** EOOH ***") && !printing
)
88 printing
= header
= TRUE
;
89 printf ("From %s %s", argv
[0], today
);
93 if (!strcmp (data
, "\037\f"))
96 fgets (data
, MAX_DATA_LEN
, stdin
);
97 p
= strtok (data
, " ,\r\n\t");
98 strcpy (labels
, "X-Babyl-Labels: ");
100 while (p
= strtok (NULL
, " ,\r\n\t"))
103 strcat (labels
, ", ");
106 labels
[strlen (labels
) - 2] = '\0';
107 printing
= header
= FALSE
;
111 if (!strlen (data
) && header
)
114 if (strcmp (labels
, "X-Babyl-Labels"))