2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
10 #include <sys/types.h>
16 int all
, hdrflag
, foldp
;
18 char folder
[128], *folds
[NFOLDERS
];
19 int msgtot
, foldtot
, totonly
, fshort
;
21 struct swit switches
[] = {
27 "noheader", 0, /* 5 */
38 extern char _sobuf
[]; /* MLW standard out buffer */
44 register char *cp
, *curm
;
47 int up
, down
, def_short
= 0;
48 char *arguments
[50], **argp
, **ap
;
57 setbuf(stdout
, _sobuf
);
64 /* set -all if program name ends in 's' -- "folders" */
65 if(argv
[0][strlen(argv
[0])-1] == 's') /* Plural name?? */
67 cp
= r1bindex(argv
[0], '/');
68 if((cp
= m_find(cp
)) != NULL
) {
69 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
70 ap
= copyip(ap
, arguments
);
73 VOID
copyip(argv
+1, ap
);
77 switch(smatch(++cp
, switches
)) {
78 case -2:ambigsw(cp
, switches
); /* ambiguous */
81 case -1:fprintf(stderr
, "folder: -%s unknown\n", cp
);
83 case 0: all
++; continue; /* -all */
84 case 1: down
++; continue; /* -down */
86 case 8: fshort
= 1; continue; /* -short */
87 case 3: fshort
= 0; continue; /* -nofast */
88 case 4: hdrflag
= -1; continue; /* -header */
89 case 5: hdrflag
= 0; continue; /* -noheader */
90 case 6: fpack
= 1; continue; /* -pack */
91 case 7: fpack
= 0; continue; /* -nopack */
92 case 9: all
++; totonly
= 1; /* -total */
94 case 10:if(totonly
) all
--; /* -nototal */
96 case 11:up
++; continue; /* -up */
98 case 12:help("folder [+folder] [msg] [switches]",
104 fprintf(stderr
, "Only one folder at a time.\n");
107 argfolder
= path(cp
+1, TFOLDER
);
109 fprintf(stderr
, "Only one current may be given.\n");
114 /* free() has side affects!!! */
115 if(!m_find("path")) free(path("./", TFOLDER
));
120 for(np
= m_defs
; np
; np
= np
->n_next
) {
121 if(!ssequal("cur-", np
->n_name
))
125 printf("%s\n", np
->n_name
+4);
127 addfold(np
->n_name
+4);
134 execl(lsproc
, r1bindex(lsproc
, '/'), "-x", cp
, 0);
135 fprintf(stderr
, "Can't exec: ");
140 fprintf(stderr
, "Can't chdir to: ");
144 if((cp
= m_find(pfolder
)) == NULL
)
147 VOID
copy(cp
, folder
);
150 while(read(i
, (char *)&ent
.inum
,
151 sizeof ent
.name
+ sizeof ent
.inum
))
152 if(ent
.inum
&& ent
.name
[0] != '.' &&
153 stat(ent
.name
, &stbf
) >= 0 &&
154 (stbf
.st_mode
&S_IFMT
) == S_IFDIR
)
157 for(i
= 0; i
< foldp
; i
++) {
158 VOID
pfold(folds
[i
], NULLCP
); VOID
fflush(stdout
);
162 printf("TOTAL= %3d message%c in %d Folder%s.\n",
163 msgtot
, msgtot
!=1? 's':' ',
164 foldtot
, foldtot
!=1? "s":"");
168 cp
= copy(argfolder
, folder
);
170 cp
= copy(m_getfolder(), folder
);
172 while(cp
> folder
&& *cp
!= '/') --cp
;
177 VOID
copy(listname
, copy("/", cp
));
180 if(pfold(folder
, curm
) && argfolder
)
181 m_replace(pfolder
, argfolder
);
196 if(foldp
>= NFOLDERS
) {
197 fprintf(stderr
, "More than %d folders!!\n", NFOLDERS
);
201 for(i
= 0; i
< foldp
; i
++)
202 if(compare(cp
, folds
[i
]) < 0) {
203 for(j
= foldp
- 1; j
>= i
; j
--)
204 folds
[j
+1] = folds
[j
];
217 register char *mailfile
;
218 register int msgnum
, hole
;
219 char newmsg
[8], oldmsg
[8];
221 mailfile
= m_maildir(fold
);
222 if(chdir(mailfile
) < 0) {
223 fprintf(stderr
, "Can't chdir to: ");
228 printf("%s\n", fold
);
231 if(!(mp
= m_gmsg(folder
))) {
232 fprintf(stderr
, "Can't read folder %s!?\n",folder
);
236 msgtot
+= mp
->nummsg
;
238 for(msgnum
= mp
->lowmsg
, hole
= 1; msgnum
<= mp
->hghmsg
; msgnum
++) {
239 if(mp
->msgstats
[msgnum
]&EXISTS
) {
241 VOID
copy(m_name(hole
), newmsg
);
242 VOID
copy(m_name(msgnum
), oldmsg
);
243 if(link(oldmsg
, newmsg
) == -1 ||
244 unlink(oldmsg
) == -1) {
245 fprintf(stderr
, "Error moving %s to ", oldmsg
);
249 if (msgnum
== mp
->curmsg
)
250 m_setcur(mp
->curmsg
= hole
);
251 mp
->msgstats
[hole
] = mp
->msgstats
[msgnum
];
252 if(msgnum
== mp
->lowsel
)
254 if(msgnum
== mp
->hghsel
)
262 mp
->hghmsg
= hole
- 1;
271 fprintf(stderr
, "Can't set current msg to range: %s\n", curm
);
274 m_setcur(mp
->curmsg
= mp
->hghsel
);
277 printf("\t\tFolder # of messages ( range ); cur msg (other files)\n");
278 printf("%22s", fold
);
279 if(strcmp(folder
, fold
) == 0)
284 printf("has no messages");
286 printf("has %3d message%s (%3d-%3d)",
287 mp
->nummsg
, (mp
->nummsg
==1)?" ":"s",
288 mp
->lowmsg
, mp
->hghmsg
);
289 if(mp
->curmsg
>= mp
->lowmsg
&& mp
->curmsg
<= mp
->hghmsg
)
290 printf("; cur=%3s", m_name(mp
->curmsg
));
292 if(mp
->selist
|| mp
->others
) {
295 printf("%s", listname
);
315 register char *c1
, *c2
;
320 if(i
= *c1
++ - *c2
++)