1 /* uminc.c - uucp to mmdf inc */
3 static char Id[] = "@(#)$Id: uminc.c,v 1.2 1993/08/25 17:31:30 jromine Exp $";
8 #include "../mts/mts.h"
10 #include <sys/types.h>
14 static int mmdf = NOTOK;
15 static int uucp = NOTOK;
16 static char mmdfbox[LINESIZ];
17 static char uucpbox[LINESIZ];
34 sprintf (uucpbox, "%s/%s", UUCPDIR, UUCPFIL);
35 if (stat (uucpbox, &st1) == NOTOK || st1.st_size == 0L)
37 if ((uucp = lkopen (uucpbox, 0)) == NOTOK)
38 die ("unable to lock and open %s", uucpbox);
41 switch (fd = uucp2mmdf (uucp, fd, FALSE)) {
46 die ("internal error while filtering UUCP mail");
49 die ("no free file pointers -- you lose");
52 die ("i/o error while filtering UUCP mail");
57 fprintf (stderr, "UUCP mailbox in bad format, patched...\n");
61 sprintf (mmdfbox, "%s/%s", MAILDIR, MAILFIL);
62 mmdf = mbx_open (mmdfbox);
65 lkclose (mmdf, mmdfbox), mmdf = NOTOK;
67 if (stat (uucpbox, &st2) != NOTOK && st1.st_mtime != st2.st_mtime)
68 fprintf (stderr, "UUCP mailbox has been updated... (%s)\n",
69 "so it won't be removed");
71 if (unlink (uucpbox) == NOTOK)
72 if ((fd = creat (uucpbox, st1.st_mode & ~S_IFMT)) != NOTOK)
75 fprintf (stderr, "unable to remove or zero UUCP mailbox\n");
76 lkclose (uucp, uucpbox), uucp = NOTOK;
83 static int mbx_open (file)
92 for (clear = FALSE, count = 2; count > 0; count--)
93 if ((fd = lkopen (file, 6)) == NOTOK)
108 if (fstat (fd, &stbuf) == NOTOK)
109 die ("unable to stat MMDF mailbox '%s'", file);
110 clear = stbuf.st_size == 0L;
116 if (errno == ETXTBSY)
117 die ("your MMDF mailbox '%s' is busy", file);
119 die ("unable to open MMDF mailbox '%s'", file);
129 static mbx_create (file)
134 if ((fd = creat (file, MBXMODE)) == NOTOK)
135 die ("unable to create MMDF mailbox '%s'", file);
141 static mbx_chk (fd, file)
148 count = strlen (mmdlm2);
150 if (lseek (fd, (off_t) - count, 2) == (off_t) NOTOK
151 || read (fd, ldelim, count) != count)
152 die ("error reading MMDF mailbox '%s'", file);
153 ldelim[count] = NULL;
155 if (strcmp (ldelim, mmdlm2)) {
157 "MMDF mailbox '%s' has bad delimiter, patching...\n",
159 if (write (fd, mmdlm2, count) != count)
160 die ("error writing MMDF mailbox '%s'", file);
166 static mbx_copy (in, out)
173 lseek (in, (off_t)0, 0);
175 while ((i = read (in, buffer, sizeof buffer)) > 0)
176 if (write (out, buffer, i) != i)
177 die ("error writing MMDF mailbox");
179 die ("error reading temporary file");
187 static int tmp_open (mbx_fd)
191 char tmpfil[LINESIZ];
193 strcpy (tmpfil, "/tmp/umincXXXXXX");
194 unlink (mktemp (tmpfil));
195 if ((fd = creat (tmpfil, TMPMODE)) == NOTOK)
196 die ("unable to create temporary file '%s'", tmpfil);
199 if ((fd = open (tmpfil, 2)) == NOTOK)
200 die ("unable to create temporary file '%s'", tmpfil);
203 if ((*mbx_fd = dup (fd)) == NOTOK)
204 die ("unable to duplicate fd for temporary file '%s'", tmpfil);
211 static die (fmt, a, b, c, d)
218 lkclose (mmdf, mmdfbox), mmdf = NOTOK;
219 lkclose (uucp, uucpbox), uucp = NOTOK;
222 fprintf (stderr, fmt, a, b, c, d);