3 * mark.c -- add message(s) to sequences in given folder
4 * -- delete messages (s) from sequences in given folder
5 * -- list sequences in given folder
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
15 static struct swit switches[] = {
23 { "sequence name", 0 },
44 static void print_debug (struct msgs *);
45 static void seq_printdebug (struct msgs *);
49 main (int argc, char **argv)
51 int addsw = 0, deletesw = 0, debugsw = 0;
52 int listsw = 0, publicsw = -1, zerosw = 0, msgnum;
53 unsigned int seqp = 0;
54 char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
55 char **argp, **arguments;
56 char *seqs[NUMATTRS + 1];
57 struct msgs_array msgs = { 0, 0, NULL };
61 setlocale(LC_ALL, "");
63 invo_name = r1bindex (argv[0], '/');
65 /* read user profile/context */
68 arguments = getarguments (invo_name, argc, argv, 1);
74 while ((cp = *argp++)) {
76 switch (smatch (++cp, switches)) {
78 ambigsw (cp, switches);
81 adios (NULL, "-%s unknown\n", cp);
84 snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
86 print_help (buf, switches, 1);
89 print_version(invo_name);
94 deletesw = listsw = 0;
102 addsw = deletesw = 0;
106 if (!(cp = *argp++) || *cp == '-')
107 adios (NULL, "missing argument to %s", argp[-2]);
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 = pluspath (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) {
155 if (!context_find ("path"))
156 free (path ("./", TFOLDER));
158 app_msgarg(&msgs, listsw ? "all" :"cur");
160 folder = getfolder (1);
161 maildir = m_maildir (folder);
163 if (chdir (maildir) == NOTOK)
164 adios (maildir, "unable to change directory to");
166 /* read folder and create message structure */
167 if (!(mp = folder_read (folder)))
168 adios (NULL, "unable to read folder %s", folder);
170 /* print some general debugging info */
174 /* check for empty folder */
176 adios (NULL, "no messages in %s", folder);
178 /* parse all the message ranges/sequences and set SELECTED */
179 for (msgnum = 0; msgnum < msgs.size; msgnum++)
180 if (!m_convert (mp, msgs.msgs[msgnum]))
183 if (publicsw == 1 && is_readonly(mp))
184 adios (NULL, "folder %s is read-only, so -public not allowed", folder);
187 * Make sure at least one sequence has been
188 * specified if we are adding or deleting.
190 if (seqp == 0 && (addsw || deletesw))
191 adios (NULL, "-%s requires at least one -sequence argument",
192 addsw ? "add" : "delete");
195 /* Adding messages to sequences */
197 for (seqp = 0; seqs[seqp]; seqp++)
198 if (!seq_addsel (mp, seqs[seqp], publicsw, zerosw))
202 /* Deleting messages from sequences */
204 for (seqp = 0; seqs[seqp]; seqp++)
205 if (!seq_delsel (mp, seqs[seqp], publicsw, zerosw))
209 /* Listing messages in sequences */
212 /* print the sequences given */
213 for (seqp = 0; seqs[seqp]; seqp++)
214 seq_print (mp, seqs[seqp]);
216 /* else print them all */
220 /* print debugging info about SELECTED messages */
225 seq_save (mp); /* synchronize message sequences */
226 context_replace (pfolder, folder); /* update current folder */
227 context_save (); /* save the context file */
228 folder_free (mp); /* free folder/message structure */
235 * Print general debugging info
238 print_debug (struct msgs *mp)
242 printf ("invo_name = %s\n", invo_name);
243 printf ("mypath = %s\n", mypath);
244 printf ("defpath = %s\n", defpath);
245 printf ("ctxpath = %s\n", ctxpath);
246 printf ("context flags = %s\n", snprintb (buf, sizeof(buf),
247 (unsigned) ctxflags, DBITS));
248 printf ("foldpath = %s\n", mp->foldpath);
249 printf ("folder flags = %s\n\n", snprintb(buf, sizeof(buf),
250 (unsigned) mp->msgflags, FBITS));
251 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
252 mp->lowmsg, mp->hghmsg, mp->nummsg, mp->curmsg);
253 printf ("lowsel=%d hghsel=%d numsel=%d\n",
254 mp->lowsel, mp->hghsel, mp->numsel);
255 printf ("lowoff=%d hghoff=%d\n\n", mp->lowoff, mp->hghoff);
260 * Print debugging info about all the SELECTED
261 * messages and the sequences they are in.
264 seq_printdebug (struct msgs *mp)
270 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
271 if (is_selected (mp, msgnum))
272 printf ("%*d: %s\n", DMAXFOLDER, msgnum,
273 snprintb (buf, sizeof(buf),
274 (unsigned) mp->msgstats[msgnum - mp->lowoff], seq_bits (mp)));