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.
16 static struct swit switches[] = {
24 { "sequence name", 0 },
45 static void print_debug(struct msgs *);
46 static void seq_printdebug(struct msgs *);
50 main(int argc, char **argv)
52 int addsw = 0, deletesw = 0, debugsw = 0;
53 int listsw = 0, publicsw = -1, zerosw = 0, msgnum;
54 unsigned int seqp = 0;
55 char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
56 char **argp, **arguments;
57 char *seqs[NUMATTRS + 1];
58 struct msgs_array msgs = { 0, 0, NULL };
61 setlocale(LC_ALL, "");
62 invo_name = mhbasename(argv[0]);
64 /* read user profile/context */
67 arguments = getarguments(invo_name, argc, argv, 1);
73 while ((cp = *argp++)) {
75 switch (smatch(++cp, switches)) {
77 ambigsw(cp, switches);
78 /*sysexits.h EX_USAGE*/
81 adios(NULL, "-%s unknown\n", cp);
84 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
85 print_help(buf, switches, 1);
88 print_version(invo_name);
93 deletesw = listsw = 0;
101 addsw = deletesw = 0;
105 if (!(cp = *argp++) || *cp == '-')
106 adios(NULL, "missing argument to %s",
109 /* check if too many sequences specified */
110 if (seqp >= NUMATTRS)
111 adios(NULL, "too many sequences (more than %d) specified", NUMATTRS);
134 if (*cp == '+' || *cp == '@') {
136 adios(NULL, "only one folder at a time!");
138 folder = getcpy(expandfol(cp));
140 app_msgarg(&msgs, cp);
144 ** If we haven't specified -add, -delete, or -list,
145 ** then use -add if a sequence was specified, else
148 if (!addsw && !deletesw && !listsw) {
156 app_msgarg(&msgs, listsw ? seq_all : seq_cur);
158 folder = getcurfol();
159 maildir = toabsdir(folder);
161 if (chdir(maildir) == NOTOK)
162 adios(maildir, "unable to change directory to");
164 /* read folder and create message structure */
165 if (!(mp = folder_read(folder)))
166 adios(NULL, "unable to read folder %s", folder);
168 /* print some general debugging info */
172 /* check for empty folder */
174 adios(NULL, "no messages in %s", folder);
176 /* parse all the message ranges/sequences and set SELECTED */
177 for (msgnum = 0; msgnum < msgs.size; msgnum++) {
178 if (!m_convert(mp, msgs.msgs[msgnum])) {
179 /*sysexits.h EX_USAGE*/
184 if (publicsw == 1 && is_readonly(mp))
185 adios(NULL, "folder %s is read-only, so -public not allowed",
189 ** Make sure at least one sequence has been
190 ** specified if we are adding or deleting.
192 if (seqp == 0 && (addsw || deletesw))
193 adios(NULL, "-%s requires at least one -sequence argument",
194 addsw ? "add" : "delete");
197 /* Adding messages to sequences */
199 for (seqp = 0; seqs[seqp]; seqp++) {
200 if (!seq_addsel(mp, seqs[seqp], publicsw, zerosw)) {
201 /*TODO find best exitcode*/
207 /* Deleting messages from sequences */
209 for (seqp = 0; seqs[seqp]; seqp++)
210 if (!seq_delsel(mp, seqs[seqp], publicsw, zerosw))
211 /*TODO find best exitcode*/
215 /* Listing messages in sequences */
218 /* print the sequences given */
219 for (seqp = 0; seqs[seqp]; seqp++)
220 seq_print(mp, seqs[seqp]);
222 /* else print them all */
226 /* print debugging info about SELECTED messages */
231 seq_save(mp); /* synchronize message sequences */
232 context_replace(curfolder, folder); /* update current folder */
233 context_save(); /* save the context file */
234 folder_free(mp); /* free folder/message structure */
240 ** Print general debugging info
243 print_debug(struct msgs *mp)
247 printf("invo_name = %s\n", invo_name);
248 printf("mypath = %s\n", mypath);
249 printf("defpath = %s\n", defpath);
250 printf("ctxpath = %s\n", ctxpath);
251 printf("context flags = %s\n", snprintb(buf, sizeof(buf),
252 (unsigned) ctxflags, DBITS));
253 printf("foldpath = %s\n", mp->foldpath);
254 printf("folder flags = %s\n\n", snprintb(buf, sizeof(buf),
255 (unsigned) mp->msgflags, FBITS));
256 printf("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
257 mp->lowmsg, mp->hghmsg, mp->nummsg, mp->curmsg);
258 printf("lowsel=%d hghsel=%d numsel=%d\n",
259 mp->lowsel, mp->hghsel, mp->numsel);
260 printf("lowoff=%d hghoff=%d\n\n", mp->lowoff, mp->hghoff);
265 ** Print debugging info about all the SELECTED
266 ** messages and the sequences they are in.
269 seq_printdebug(struct msgs *mp)
275 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
276 if (is_selected(mp, msgnum))
277 printf("%*d: %s\n", DMAXFOLDER, msgnum, snprintb(buf, sizeof(buf), (unsigned) mp->msgstats[msgnum - mp->lowoff], seq_bits(mp)));