2 ** mark.c -- add message(s) to sequences in given folder
3 ** -- delete messages (s) from sequences in given folder
4 ** -- list sequences in given folder
6 ** This code is Copyright (c) 2002, by the authors of nmh. See the
7 ** COPYRIGHT file in the root directory of the nmh distribution for
8 ** complete copyright information.
14 static struct swit switches[] = {
22 { "sequence name", 0 },
43 static void print_debug(struct msgs *);
44 static void seq_printdebug(struct msgs *);
48 main(int argc, char **argv)
50 int addsw = 0, deletesw = 0, debugsw = 0;
51 int listsw = 0, publicsw = -1, zerosw = 0, msgnum;
52 unsigned int seqp = 0;
53 char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
54 char **argp, **arguments;
55 char *seqs[NUMATTRS + 1];
56 struct msgs_array msgs = { 0, 0, NULL };
59 setlocale(LC_ALL, "");
60 invo_name = mhbasename(argv[0]);
62 /* read user profile/context */
65 arguments = getarguments(invo_name, argc, argv, 1);
71 while ((cp = *argp++)) {
73 switch (smatch(++cp, switches)) {
75 ambigsw(cp, switches);
78 adios(NULL, "-%s unknown\n", cp);
81 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
82 print_help(buf, switches, 1);
85 print_version(invo_name);
90 deletesw = listsw = 0;
102 if (!(cp = *argp++) || *cp == '-')
103 adios(NULL, "missing argument to %s",
106 /* check if too many sequences specified */
107 if (seqp >= NUMATTRS)
108 adios(NULL, "too many sequences (more than %d) specified", NUMATTRS);
131 if (*cp == '+' || *cp == '@') {
133 adios(NULL, "only one folder at a time!");
135 folder = getcpy(expandfol(cp));
137 app_msgarg(&msgs, cp);
141 ** If we haven't specified -add, -delete, or -list,
142 ** then use -add if a sequence was specified, else
145 if (!addsw && !deletesw && !listsw) {
153 app_msgarg(&msgs, listsw ? seq_all : seq_cur);
155 folder = getcurfol();
156 maildir = toabsdir(folder);
158 if (chdir(maildir) == NOTOK)
159 adios(maildir, "unable to change directory to");
161 /* read folder and create message structure */
162 if (!(mp = folder_read(folder)))
163 adios(NULL, "unable to read folder %s", folder);
165 /* print some general debugging info */
169 /* check for empty folder */
171 adios(NULL, "no messages in %s", folder);
173 /* parse all the message ranges/sequences and set SELECTED */
174 for (msgnum = 0; msgnum < msgs.size; msgnum++)
175 if (!m_convert(mp, msgs.msgs[msgnum]))
178 if (publicsw == 1 && is_readonly(mp))
179 adios(NULL, "folder %s is read-only, so -public not allowed",
183 ** Make sure at least one sequence has been
184 ** specified if we are adding or deleting.
186 if (seqp == 0 && (addsw || deletesw))
187 adios(NULL, "-%s requires at least one -sequence argument",
188 addsw ? "add" : "delete");
191 /* Adding messages to sequences */
193 for (seqp = 0; seqs[seqp]; seqp++)
194 if (!seq_addsel(mp, seqs[seqp], publicsw, zerosw))
198 /* Deleting messages from sequences */
200 for (seqp = 0; seqs[seqp]; seqp++)
201 if (!seq_delsel(mp, seqs[seqp], publicsw, zerosw))
205 /* Listing messages in sequences */
208 /* print the sequences given */
209 for (seqp = 0; seqs[seqp]; seqp++)
210 seq_print(mp, seqs[seqp]);
212 /* else print them all */
216 /* print debugging info about SELECTED messages */
221 seq_save(mp); /* synchronize message sequences */
222 context_replace(curfolder, folder); /* update current folder */
223 context_save(); /* save the context file */
224 folder_free(mp); /* free folder/message structure */
231 ** Print general debugging info
234 print_debug(struct msgs *mp)
238 printf("invo_name = %s\n", invo_name);
239 printf("mypath = %s\n", mypath);
240 printf("defpath = %s\n", defpath);
241 printf("ctxpath = %s\n", ctxpath);
242 printf("context flags = %s\n", snprintb(buf, sizeof(buf),
243 (unsigned) ctxflags, DBITS));
244 printf("foldpath = %s\n", mp->foldpath);
245 printf("folder flags = %s\n\n", snprintb(buf, sizeof(buf),
246 (unsigned) mp->msgflags, FBITS));
247 printf("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
248 mp->lowmsg, mp->hghmsg, mp->nummsg, mp->curmsg);
249 printf("lowsel=%d hghsel=%d numsel=%d\n",
250 mp->lowsel, mp->hghsel, mp->numsel);
251 printf("lowoff=%d hghoff=%d\n\n", mp->lowoff, mp->hghoff);
256 ** Print debugging info about all the SELECTED
257 ** messages and the sequences they are in.
260 seq_printdebug(struct msgs *mp)
266 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
267 if (is_selected(mp, msgnum))
268 printf("%*d: %s\n", DMAXFOLDER, msgnum, snprintb(buf, sizeof(buf), (unsigned) mp->msgstats[msgnum - mp->lowoff], seq_bits(mp)));