9 date 93.08.27.23.23.06; author jromine; state Exp;
14 date 93.08.26.22.30.09; author jromine; state Exp;
19 date 92.12.15.00.20.22; author jromine; state Exp;
24 date 92.11.04.00.43.01; author jromine; state Exp;
29 date 92.05.19.18.01.13; author jromine; state Exp;
34 date 92.02.07.20.16.40; author jromine; state Exp;
39 date 92.02.06.21.38.18; author jromine; state Exp;
44 date 90.04.05.14.56.54; author sources; state Exp;
49 date 90.02.09.09.48.38; author sources; state Exp;
54 date 90.02.06.13.18.44; author sources; state Exp;
59 date 90.02.05.14.41.04; author sources; state Exp;
64 date 89.11.17.15.57.53; author sources; state Exp;
69 date 89.06.26.14.36.39; author sources; state Exp;
80 @add -[no]create instead of -create policy
83 @/* folder(s).c - report on folders */
85 static char ident[] = "@@(#)$Id: folder.c,v 2.10 1993/08/26 22:30:09 jromine Exp jromine $";
89 #include "../h/local.h"
96 static dodir(), addir(), addfold(), dother();
97 static int pfold(), sfold(), compare();
100 static struct swit switches[] = {
161 static int fshort = 0;
162 static int fcreat = 0;
163 static int fpack = 0;
164 static int fverb = 0;
165 static int fheader = 0;
166 static int frecurse = 0;
167 static int ftotonly = 0;
168 static int msgtot = 0;
169 static int foldtot = 0;
170 static int start = 0;
171 static int foldp = 0;
174 static char *stack = "Folder-Stack";
175 static char folder[BUFSIZ];
176 static char *folds[NFOLDERS + 1];
178 struct msgs *tfold ();
203 setlocale(LC_ALL, "");
205 invo_name = r1bindex (argv[0], '/');
206 if (argv[0][strlen (argv[0]) - 1] == 's')
208 if ((cp = m_find (invo_name)) != NULL) {
209 ap = brkstring (cp = getcpy (cp), " ", "\n");
210 ap = copyip (ap, arguments);
214 (void) copyip (argv + 1, ap);
219 while (cp = *argp++) {
221 switch (smatch (++cp, switches)) {
223 ambigsw (cp, switches);
226 adios (NULLCP, "-%s unknown", cp);
228 (void) sprintf (buf, "%s [+folder] [msg] [switches]",
230 help (buf, switches);
314 if (*cp == '+' || *cp == '@@')
316 adios (NULLCP, "only one folder at a time!");
318 argfolder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
321 adios (NULLCP, "only one (current) message at a time!");
328 if (!m_find ("path"))
329 free (path ("./", TFOLDER));
330 mhdir = concat (m_maildir (""), "/", NULLCP);
332 if (pushsw == 0 && popsw == 0 && listsw == 0)
336 if ((cp = m_find (stack)) == NULL
337 || (ap = brkstring (dp = getcpy (cp), " ", "\n")) == NULL
338 || (argfolder = *ap++) == NULL)
339 adios (NULLCP, "no other folder");
340 for (cp = getcpy (m_getfolder ()); *ap; ap++)
341 cp = add (*ap, add (" ", cp));
343 m_replace (stack, cp);
347 (cp = m_find (stack))
348 ? concat (m_getfolder (), " ", cp, NULLCP)
349 : getcpy (m_getfolder ()));
353 adios (NULLCP, "sorry, no folders allowed with -pop");
354 if ((cp = m_find (stack)) == NULL
355 || (ap = brkstring (dp = getcpy (cp), " ", "\n")) == NULL
356 || (argfolder = *ap++) == NULL)
357 adios (NULLCP, "folder stack empty");
358 for (cp = NULL; *ap; ap++)
359 cp = cp ? add (*ap, add (" ", cp)) : getcpy (*ap);
362 m_replace (stack, cp);
364 (void) m_delete (stack);
366 if (pushsw || popsw) {
367 if (access (cp = m_maildir (argfolder), 0) == NOTOK)
368 adios (cp, "unable to find folder");
369 m_replace (pfolder, argfolder);
374 printf ("%s", argfolder ? argfolder : m_getfolder ());
375 if (cp = m_find (stack)) {
376 for (ap = brkstring (dp = getcpy (cp), " ", "\n"); *ap; ap++)
391 (void) strcpy (folder, argfolder);
392 if (pfold (argfolder, msg)) {
393 m_replace (pfolder, argfolder);
396 if (!frecurse) /* recurse not done in pfold(), */
397 dodir (folder); /* so just list all level-1 sub-folders */
401 admonish (NULLCP, "no folder given for message %s", msg);
404 (void) strcpy (folder, (cp = m_find (pfolder)) ? cp : "");
411 printf ("TOTAL= %*d message%c in %d folder%s.\n",
412 DMAXFOLDER, msgtot, msgtot != 1 ? 's' : ' ',
413 foldtot, foldtot != 1 ? "s" : "");
419 (void) strcpy (folder, argfolder ? argfolder : m_getfolder ());
420 if (stat (strcpy (buf, m_maildir (folder)), &st) == NOTOK) {
422 adios (buf, "error on folder");
424 case 0: /* ask before create */
425 cp = concat ("Create folder \"", buf, "\"? ", NULLCP);
430 case -1: /* do not create */
435 adios (NULLCP, "unable to create folder %s", buf);
438 if (pfold (folder, msg) && argfolder)
439 m_replace (pfolder, argfolder);
458 if (chdir (mhdir) == NOTOK)
459 adios (mhdir, "unable to change directory to");
461 addir (strcpy (buffer, dir));
462 for (i = start; i < foldp; i++)
463 (void) pfold (folds[i], NULLCP), (void) fflush (stdout);
471 static int pfold (fold, msg)
478 register char *mailfile;
479 register struct msgs *mp = NULL;
481 mailfile = m_maildir (fold);
482 if (chdir (mailfile) == NOTOK) {
484 admonish (mailfile, "unable to change directory to");
486 printf ("%22s%c unreadable\n",
487 fold, strcmp (folder, fold) ? ' ' : '+');
492 printf ("%s\n", fold);
494 if (!msg && !fpack) {
501 if (!(mp = m_gmsg (fold))) {
502 admonish (NULLCP, "unable to read folder %s", fold);
506 if (msg && !sfold (mp, msg))
514 msgtot += mp -> nummsg;
520 printf ("\t\tFolder %*s# of messages (%*srange%*s); cur%*smsg (other files)\n",
521 DMAXFOLDER, "", DMAXFOLDER - 2, "", DMAXFOLDER - 2, "",
524 printf ("%22s%c ", fold, strcmp (folder, fold) ? ' ' : '+');
527 if (mp -> hghmsg == 0)
528 printf ("has no messages%*s",
529 mp -> msgflags & OTHERS ? DMAXFOLDER * 2 + 4 : 0, "");
531 printf ("has %*d message%s (%*d-%*d)",
532 DMAXFOLDER, mp -> nummsg, (mp -> nummsg == 1) ? " " : "s",
533 DMAXFOLDER, mp -> lowmsg, DMAXFOLDER, mp -> hghmsg);
534 if (mp -> curmsg >= mp -> lowmsg && mp -> curmsg <= mp -> hghmsg)
535 printf ("; cur=%*d", DMAXFOLDER, hack = mp -> curmsg);
538 if (mp -> msgflags & OTHERS)
539 printf (";%*s (others)", hack ? 0 : DMAXFOLDER + 6, "");
543 others = mp -> msgflags & OTHERS;
546 if (frecurse && others)
554 static int sfold (mp, msg)
555 register struct msgs *mp;
558 if (!m_convert (mp, msg))
561 if (mp -> numsel > 1) {
562 admonish (NULLCP, "only one message at a time!");
566 m_setcur (mp, mp -> lowsel);
574 struct msgs *tfold (mp)
575 register struct msgs *mp;
582 if (mp -> lowmsg > 1 && (mp = m_remsg (mp, 1, mp -> hghmsg)) == NULL)
583 adios (NULLCP, "unable to allocate folder storage");
585 for (msgnum = mp -> lowmsg, hole = 1; msgnum <= mp -> hghmsg; msgnum++)
586 if (mp -> msgstats[msgnum] & EXISTS) {
587 if (msgnum != hole) {
588 (void) strcpy (newmsg, m_name (hole));
589 (void) strcpy (oldmsg, m_name (msgnum));
591 printf ("message %s becomes %s\n", oldmsg, newmsg);
592 if (rename (oldmsg, newmsg) == NOTOK)
593 adios (newmsg, "unable to rename %s to", oldmsg);
594 if (msgnum == mp -> curmsg)
595 m_setcur (mp, mp -> curmsg = hole);
596 mp -> msgstats[hole] = mp -> msgstats[msgnum];
597 mp -> msgflags |= SEQMOD;
598 if (msgnum == mp -> lowsel)
600 if (msgnum == mp -> hghsel)
605 if (mp -> nummsg > 0) {
607 mp -> hghmsg = hole - 1;
624 register struct dirent *dp;
626 register struct direct *dp;
630 cp = name + strlen (name);
634 base = strcmp (name, "./") ? name : name + 2;/* hack */
636 if ((dd = opendir (name)) == NULL) {
637 admonish (name, "unable to read directory ");
640 while (dp = readdir (dd))
641 if (strcmp (dp -> d_name, ".") && strcmp (dp -> d_name, "..")) {
643 if (cp + dp -> d_reclen + 2 >= name + BUFSIZ)
645 if (cp + strlen (dp -> d_name) + 2 >= name + BUFSIZ)
648 (void) strcpy (cp, dp -> d_name);
649 if (stat (name, &st) != NOTOK && (st.st_mode & S_IFMT) == S_IFDIR)
659 static addfold (fold)
666 if (foldp > NFOLDERS)
667 adios (NULLCP, "more than %d folders to report on", NFOLDERS);
670 for (i = start; i < foldp; i++)
671 if (compare (cp, folds[i]) < 0) {
672 for (j = foldp - 1; j >= i; j--)
673 folds[j + 1] = folds[j];
684 static int compare (s1, s2)
691 if (i = *s1++ - *s2++)
702 register struct node *np;
704 (void) sprintf (atrcur, "atr-%s-", current);
705 atrlen = strlen (atrcur);
708 for (np = m_defs; np; np = np -> n_next)
709 if (ssequal (atrcur, np -> n_name)
710 && !ssequal (mhdir, np -> n_name + atrlen))
711 (void) pfold (np -> n_name + atrlen, NULLCP);
723 static char ident[] = "@@(#)$Id: folder.c,v 2.9 1992/12/15 00:20:22 jromine Exp jromine $";
785 static struct swit creats[] = {
786 #define CREAT_ALWAYS 0
790 #define CREAT_NEVER 2
798 static int fcreat = CREAT_ASK;
802 if (!(cp = *argp++) || *cp == '-')
803 adios (NULLCP, "missing argument to %s", argp[-2]);
804 switch (fcreat = smatch (cp, creats)) {
806 ambigsw (cp, creats);
809 adios (NULLCP, "%s unknown", cp);
832 static char ident[] = "@@(#)$Id: folder.c,v 2.8 1992/11/04 00:43:01 jromine Exp jromine $";
895 cp = concat ("Create folder \"", buf, "\"? ", NULLCP);
909 static char ident[] = "@@(#)$Id: folder.c,v 2.7 1992/05/19 18:01:13 jromine Exp jromine $";
921 static char ident[] = "@@(#)$Id: folder.c,v 2.6 1992/02/07 20:16:40 jromine Exp jromine $";
930 let -nolist turn -list off if -push/-pop
935 static char ident[] = "@@(#)$Id: folder.c,v 2.5 1992/02/06 21:38:18 jromine Exp jromine $";
962 @complain if -all w/o +folder w/ msg
963 allow -[push|pop] -nolist
968 static char ident[] = "@@(#)$Id: folder.c,v 2.4 1990/04/05 14:56:54 sources Exp jromine $";
988 static char ident[] = "@@(#)$Id:$";
996 if (pushsw || popsw || listsw) {
999 if (argfolder || msg) {
1000 (void) strcpy (folder, argfolder ? argfolder : m_getfolder ());
1002 if (pfold (argfolder, msg) && argfolder) {
1005 if (!frecurse) /* counter-intuitive */
1013 @Fixes from Van Jacobson
1076 @changes for SUN40 shared libraries and NNTP under bbc
1081 if (cp + dp -> d_namlen + 2 >= name + BUFSIZ)