1 /* mark.c - mark messages */
3 static char ident[] = "@(#)$Id: mark.c,v 1.5 1995/12/06 23:44:31 jromine Exp $";
14 static struct swit switches[] = {
74 setlocale(LC_ALL, "");
76 invo_name = r1bindex (argv[0], '/');
77 if ((cp = m_find (invo_name)) != NULL) {
78 ap = brkstring (cp = getcpy (cp), " ", "\n");
79 ap = copyip (ap, arguments);
83 (void) copyip (argv + 1, ap);
88 while (cp = *argp++) {
90 switch (smatch (++cp, switches)) {
92 ambigsw (cp, switches);
95 adios (NULLCP, "-%s unknown\n", cp);
97 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
104 deletesw = listsw = 0;
112 addsw = deletesw = 0;
116 if (!(cp = *argp++) || *cp == '-')
117 adios (NULLCP, "missing argument to %s", argp[-2]);
121 adios (NULLCP, "only %d sequences allowed!", NATTRS);
142 if (*cp == '+' || *cp == '@') {
144 adios (NULLCP, "only one folder at a time!");
146 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
154 if (!addsw && !deletesw && !listsw)
160 if (!m_find ("path"))
161 free (path ("./", TFOLDER));
163 msgs[msgp++] = listsw ? "all" :"cur";
165 folder = m_getfolder ();
166 maildir = m_maildir (folder);
168 if (chdir (maildir) == NOTOK)
169 adios (maildir, "unable to change directory to");
170 if (!(mp = m_gmsg (folder)))
171 adios (NULLCP, "unable to read folder %s", folder);
172 if (mp -> hghmsg == 0)
173 adios (NULLCP, "no messages in %s", folder);
175 for (msgnum = 0; msgnum < msgp; msgnum++)
176 if (!m_convert (mp, msgs[msgnum]))
180 publicsw = mp -> msgflags & READONLY ? 0 : 1;
181 if (publicsw && (mp -> msgflags & READONLY))
182 adios (NULLCP, "folder %s is read-only, so -public not allowed",
188 printf ("invo_name=%s mypath=%s defpath=%s\n",
189 invo_name, mypath, defpath);
190 printf ("ctxpath=%s context flags=%s\n",
191 ctxpath, sprintb (buf, (unsigned) ctxflags, DBITS));
192 printf ("foldpath=%s flags=%s\n",
194 sprintb (buf, (unsigned) mp -> msgflags, FBITS));
195 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
196 mp -> lowmsg, mp -> hghmsg, mp -> nummsg, mp -> curmsg);
197 printf ("lowsel=%d hghsel=%d numsel=%d\n",
198 mp -> lowsel, mp -> hghsel, mp -> numsel);
200 printf ("lowoff=%d hghoff=%d\n",
201 mp -> lowoff, mp -> hghoff);
203 printf ("lowoff=%d hghoff=%d msgbase=0x%x msgstats=0x%x\n",
204 mp -> lowoff, mp -> hghoff, mp -> msgbase, mp -> msgstats);
208 if (seqp == 0 && (addsw || deletesw))
209 adios (NULLCP, "-%s requires at least one -sequence argument",
210 addsw ? "add" : "delete");
214 for (seqp = 0; seqs[seqp]; seqp++) {
215 if (zerosw && !m_seqnew (mp, seqs[seqp], publicsw))
217 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
218 if (mp -> msgstats[msgnum] & SELECTED)
219 if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw))
224 for (seqp = 0; seqs[seqp]; seqp++) {
226 for (msgnum = mp -> lowmsg; msgnum <= mp -> hghmsg; msgnum++)
227 if (mp -> msgstats[msgnum] & EXISTS)
228 if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw))
230 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
231 if (mp -> msgstats[msgnum] & SELECTED)
232 if (!m_seqdel (mp, seqs[seqp], msgnum))
237 int bits = FFATTRSLOT;
239 #define empty(s) ((s) ? (s) : "")
241 for (i = 0; mp -> msgattrs[i]; i++)
242 printf ("%s%s: %s\n", mp -> msgattrs[i],
243 mp -> attrstats & (1 << (bits + i))
245 empty(m_seq (mp, mp -> msgattrs[i])));
247 for (seqp = 0; seqs[seqp]; seqp++)
248 printf ("%s: %s\n", seqs[seqp], empty(m_seq (mp, seqs[seqp])));
252 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
253 if (mp -> msgstats[msgnum] & SELECTED)
254 printf ("%*d: %s\n", DMAXFOLDER, msgnum,
255 sprintb (buf, (unsigned) mp -> msgstats[msgnum],
259 m_replace (pfolder, folder);