9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.11.04.00.58.11; author jromine; state Exp;
19 date 92.11.04.00.23.24; author jromine; state Exp;
24 date 92.01.31.22.25.26; author jromine; state Exp;
29 date 92.01.31.16.34.39; author jromine; state Exp;
34 date 91.01.14.16.27.20; author mh; state Exp;
39 date 90.04.05.15.02.18; author sources; state Exp;
44 date 90.03.27.19.11.48; author sources; state Exp;
49 date 90.02.06.13.29.10; author sources; state Exp;
54 date 90.02.06.13.28.51; author sources; state Exp;
68 @/* refile.c - file messages away */
70 static char ident[] = "@@(#)$Id: refile.c,v 1.9 1992/11/04 00:58:11 jromine Exp jromine $";
76 #include <sys/types.h>
84 static struct swit switches[] = {
105 "rmmproc program", 0,
120 static char maildir[BUFSIZ];
128 static opnfolds(), clsfolds(), removeit();
151 *filevec[NFOLDERS + 2],
152 **files = &filevec[1], /* leave room for removeit:vec[0] */
154 struct st_fold folders[NFOLDERS + 1];
158 setlocale(LC_ALL, "");
160 invo_name = r1bindex (argv[0], '/');
161 if ((cp = m_find (invo_name)) != NULL) {
162 ap = brkstring (cp = getcpy (cp), " ", "\n");
163 ap = copyip (ap, arguments);
167 (void) copyip (argv + 1, ap);
172 while (cp = *argp++) {
174 switch (smatch (++cp, switches)) {
176 ambigsw (cp, switches);
179 adios (NULLCP, "-%s unknown\n", cp);
181 (void) sprintf (buf, "%s [msgs] [switches] +folder ...",
183 help (buf, switches);
202 adios (NULLCP, "only one source folder at a time!");
203 if (!(cp = *argp++) || *cp == '-')
204 adios (NULLCP, "missing argument to %s", argp[-2]);
205 folder = path (*cp == '+' || *cp == '@@' ? cp + 1 : cp,
206 *cp != '@@' ? TFOLDER : TSUBCWF);
209 if (filep > NFOLDERS)
210 adios (NULLCP, "only %d files allowed!", NFOLDERS);
212 files[filep++] = getcpy (m_draft (NULLCP, NULLCP, 1, &isdf));
215 if (filep > NFOLDERS)
216 adios (NULLCP, "only %d files allowed!", NFOLDERS);
217 if (!(cp = *argp++) || *cp == '-')
218 adios (NULLCP, "missing argument to %s", argp[-2]);
219 files[filep++] = path (cp, TFILE);
223 if (!(rmmproc = *argp++) || *rmmproc == '-')
224 adios (NULLCP, "missing argument to %s", argp[-2]);
230 if (*cp == '+' || *cp == '@@') {
231 if (foldp > NFOLDERS)
232 adios (NULLCP, "only %d folders allowed!", NFOLDERS);
233 folders[foldp++].f_name =
234 path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
242 if (!m_find ("path"))
243 free (path ("./", TFOLDER));
245 adios (NULLCP, "no folder specified");
248 if (!msgp && !foldp && !filep && (cp = getenv ("mhdraft")) && *cp)
254 adios (NULLCP, "use -file or some messages, not both");
255 opnfolds (folders, foldp);
256 for (i = 0; i < filep; i++)
257 if (m_file (files[i], folders, foldp, prsrvf))
260 removeit (NULLMP, filep, filevec);
265 msgs[msgp++] = "cur";
267 folder = m_getfolder ();
268 (void) strcpy (maildir, m_maildir (folder));
270 if (chdir (maildir) == NOTOK)
271 adios (maildir, "unable to change directory to");
272 if (!(mp = m_gmsg (folder)))
273 adios (NULLCP, "unable to read folder %s", folder);
274 if (mp -> hghmsg == 0)
275 adios (NULLCP, "no messages in %s", folder);
277 for (msgnum = 0; msgnum < msgp; msgnum++)
278 if (!m_convert (mp, msgs[msgnum]))
282 opnfolds (folders, foldp);
283 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
284 if (mp -> msgstats[msgnum] & SELECTED) {
285 cp = getcpy (m_name (msgnum));
286 if (m_file (cp, folders, foldp, prsrvf))
291 mp -> msgstats[msgnum] |= DELETED;
293 mp -> msgstats[msgnum] &= ~EXISTS;
297 mp -> msgflags |= SEQMOD;
298 clsfolds (folders, foldp);
300 m_replace (pfolder, folder);
301 if (mp -> hghsel != mp -> curmsg
302 && (mp -> numsel != mp -> nummsg || linkf))
303 m_setcur (mp, mp -> hghsel);
308 removeit (mp, filep, filevec);
315 static opnfolds (folders, nfolders)
316 register struct st_fold *folders;
320 char nmaildir[BUFSIZ];
321 register struct st_fold *fp,
323 register struct msgs *mp;
326 for (ep = (fp = folders) + nfolders; fp < ep; fp++) {
327 (void) chdir (m_maildir (""));
328 (void) strcpy (nmaildir, m_maildir (fp -> f_name));
330 if (stat (nmaildir, &st) == NOTOK) {
332 adios (nmaildir, "error on folder");
333 cp = concat ("Create folder \"", nmaildir, "\"? ", NULLCP);
337 if (!makedir (nmaildir))
338 adios (NULLCP, "unable to create folder %s", nmaildir);
341 if (chdir (nmaildir) == NOTOK)
342 adios (nmaildir, "unable to change directory to");
343 if (!(mp = m_gmsg (fp -> f_name)))
344 adios (NULLCP, "unable to read folder %s", fp -> f_name);
349 (void) chdir (maildir);
355 static clsfolds (folders, nfolders)
356 register struct st_fold *folders;
359 register struct st_fold *fp,
361 register struct msgs *mp;
363 for (ep = (fp = folders) + nfolders; fp < ep; fp++) {
372 static removeit (mp, filep, files)
373 register struct msgs *mp;
375 register char **files;
384 vec = files++; /* filevec[1] */
388 if (mp -> numsel > MAXARGS - 2)
389 adios (NULLCP, "more than %d messages for %s exec",
390 MAXARGS - 2, rmmproc);
391 vec = (char **) calloc ((unsigned) (mp -> numsel + 2), sizeof *vec);
393 adios (NULLCP, "unable to allocate exec vector");
395 for (i = mp -> lowsel; i <= mp -> hghsel; i++)
396 if (mp -> msgstats[i] & SELECTED)
397 vec[vecp++] = getcpy (m_name (i));
401 (void) fflush (stdout);
402 vec[0] = r1bindex (rmmproc, '/');
403 execvp (rmmproc, vec);
404 adios (rmmproc, "unable to exec");
408 files++; /* filevec[1] */
409 for (i = 0; i < filep; i++)
410 if (unlink (files[i]) == NOTOK)
411 admonish (files[i], "unable to unlink");
414 for (i = mp -> lowsel; i <= mp -> hghsel; i++)
415 if (mp -> msgstats[i] & SELECTED)
416 if (unlink (cp = m_name (i)) == NOTOK)
417 admonish (cp, "unable to unlink");
422 m_file (msg, folders, nfolders, prsrvf)
424 struct st_fold *folders;
434 register struct st_fold *fp,
436 register struct msgs *mp;
440 for (ep = (fp = folders) + nfolders; fp < ep; fp++) {
442 if (prsrvf && (msgnum = m_atoi (nmsg = msg)) > 0) {
443 if (msgnum >= mp -> hghoff)
444 if (mp = m_remsg (mp, 0, msgnum + MAXFOLDER))
447 adios (NULLCP, "unable to allocate folder storage");
448 if (!(mp -> msgstats[msgnum] & EXISTS)) {
449 mp -> msgstats[msgnum] |= EXISTS;
451 mp -> msgstats[msgnum] &= ~DELETED;
455 mp -> msgstats[msgnum] |= SELECTED;
456 if (msgnum > mp -> hghmsg)
457 mp -> hghmsg = msgnum;
460 if (mp -> hghmsg >= mp -> hghoff)
461 if (mp = m_remsg (mp, 0, mp -> hghoff + MAXFOLDER))
464 adios (NULLCP, "unable to allocate folder storage");
466 nmsg = m_name (msgnum = ++mp -> hghmsg);
468 mp -> msgstats[msgnum] |= EXISTS | SELECTED;
470 if (mp -> lowmsg == 0)
471 mp -> lowmsg = msgnum;
472 if (mp -> lowsel == 0 || msgnum < mp -> lowsel)
473 mp -> lowsel = msgnum;
474 if (msgnum > mp -> hghsel)
475 mp -> hghsel = msgnum;
479 (void) sprintf (newmsg, "%s/%s", mp -> foldpath, nmsg);
480 if (link (msg, newmsg) == NOTOK) {
483 #else /* EISREMOTE */
484 if ((linkerr = errno) == EISREMOTE)
486 #endif /* EISREMOTE */
487 if (linkerr == EEXIST
488 || (linkerr == EXDEV && stat (newmsg, &st) != NOTOK)) {
489 if (linkerr != EEXIST
490 || stat (msg, &s1) == NOTOK
491 || stat (newmsg, &st) == NOTOK
492 || s1.st_ino != st.st_ino) {
493 advise (NULLCP, "message %s:%s already exists",
494 fp -> f_name, newmsg);
499 if (linkerr == EXDEV) {
500 if ((in = open (msg, 0)) == NOTOK) {
501 advise (msg, "unable to open message %s");
504 (void) fstat (in, &st);
505 if ((out = creat (newmsg, (int) st.st_mode & 0777))
507 advise (newmsg, "unable to create");
511 cpydata (in, out, msg, newmsg);
516 advise (newmsg, "error linking %s to", msg);
534 static char ident[] = "@@(#)$Id: refile.c,v 1.8 1992/11/04 00:23:24 jromine Exp jromine $";
556 @when called with -file, make sure to pass the first filename
557 to the rmmproc. (hack!)
562 static char ident[] = "@@(#)$Id: refile.c,v 1.7 1992/01/31 22:25:26 jromine Exp jromine $";
575 static char ident[] = "@@(#)$Id: refile.c,v 1.6 1992/01/31 16:34:39 jromine Exp jromine $";
578 *files[NFOLDERS + 1],
581 removeit (NULLMP, filep, files);
584 removeit (mp, filep, files);
600 static char ident[] = "@@(#)$Id: refile.c,v 1.5 91/01/14 16:27:20 mh Exp $";
615 static char ident[] = "@@(#)$Id: refile.c,v 1.4 90/04/05 15:02:18 sources Exp Locker: mh $";
618 if (!msgp && !filep && (cp = getenv ("mhdraft")) && *cp)
629 static char ident[] = "@@(#)$Id:$";
639 @"remove" -> "removeit"
653 static opnfolds(), clsfolds(), remove();
656 remove (NULLMP, filep, files);
659 remove (mp, filep, files);
662 static remove (mp, filep, files)