-
- if (!strcmp(data, "\f")) {
- /* save labels */
- gets(data);
- p = strtok(data, " ,\r\n\t");
- strcpy(labels, "X-Babyl-Labels: ");
-
- while (p = strtok(NULL, " ,\r\n\t")) {
- strcat(labels, p);
- strcat(labels, ", ");
- }
-
- labels[strlen(labels) - 2] = '\0';
- printing = header = FALSE;
- continue;
+
+ if (optind != argc)
+ {
+ fprintf (stderr, "Usage: %s <babylmailbox >unixmailbox\n", progname);
+ exit (EXIT_SUCCESS);
+ }
+
+ labels_saved = printing = header = FALSE;
+ ltoday = time (0);
+ /* Convert to a string, checking for out-of-range time stamps.
+ Don't use 'ctime', as that might dump core if the hardware clock
+ is set to a bizarre value. */
+ tm = localtime (<oday);
+ if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year)
+ && (today = asctime (tm))))
+ fatal ("current time is out of range");
+ data.size = 200;
+ data.buffer = xnew (200, char);
+
+ if (readline (&data, stdin) == 0
+ || !strneq (data.buffer, "BABYL OPTIONS:", 14))
+ fatal ("standard input is not a Babyl mailfile.");
+
+ while (readline (&data, stdin) > 0)
+ {
+ if (streq (data.buffer, "*** EOOH ***") && !printing)
+ {
+ printing = header = TRUE;
+ printf ("From \"Babyl to mail by %s\" %s", progname, today);
+ continue;
+ }
+
+ if (data.buffer[0] == '\037')
+ {
+ if (data.buffer[1] == '\0')
+ continue;
+ else if (data.buffer[1] == '\f')
+ {
+ /* Save labels. */
+ readline (&data, stdin);
+ p = strtok (data.buffer, " ,\r\n\t");
+ labels = "X-Babyl-Labels: ";
+
+ while ((p = strtok (NULL, " ,\r\n\t")))
+ labels = concat (labels, p, ", ");
+
+ p = &labels[strlen (labels) - 2];
+ if (*p == ',')
+ *p = '\0';
+ printing = header = FALSE;
+ labels_saved = TRUE;
+ continue;
+ }
+ }
+
+ if ((data.buffer[0] == '\0') && header)
+ {
+ header = FALSE;
+ if (labels_saved)
+ puts (labels);
+ }
+
+ if (printing)
+ puts (data.buffer);