]>
diplodocus.org Git - nmh/blob - uip/mark.c
eef5415683d6e1d502981ad35f03485b581178ba
1 /* mark.c -- add message(s) to sequences in given folder
2 * -- delete messages (s) from sequences in given folder
3 * -- list sequences in given folder
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 #include "sbr/seq_bits.h"
12 #include "sbr/seq_del.h"
13 #include "sbr/seq_print.h"
14 #include "sbr/seq_add.h"
15 #include "sbr/error.h"
18 #include "sbr/m_maildir.h"
20 #define MARK_SWITCHES \
22 X("delete", 0, DELSW) \
24 X("sequence name", 0, SEQSW) \
25 X("public", 0, PUBLSW) \
26 X("nopublic", 0, NPUBLSW) \
27 X("zero", 0, ZEROSW) \
28 X("nozero", 0, NZEROSW) \
29 X("version", 0, VERSIONSW) \
30 X("help", 0, HELPSW) \
31 X("debug", -5, DEBUGSW) \
33 #define X(sw, minchars, id) id,
34 DEFINE_SWITCH_ENUM(MARK
);
37 #define X(sw, minchars, id) { sw, minchars, id },
38 DEFINE_SWITCH_ARRAY(MARK
, switches
);
44 static void print_debug (struct msgs
*);
45 static void seq_printdebug (struct msgs
*);
49 main (int argc
, char **argv
)
52 bool deletesw
= false;
58 unsigned int seqp
= 0;
59 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
60 char **argp
, **arguments
;
61 svector_t seqs
= svector_create (0);
62 struct msgs_array msgs
= { 0, 0, NULL
};
65 if (nmh_init(argv
[0], true, true)) { return 1; }
67 arguments
= getarguments (invo_name
, argc
, argv
, 1);
73 while ((cp
= *argp
++)) {
75 switch (smatch (++cp
, switches
)) {
77 ambigsw (cp
, switches
);
80 die("-%s unknown\n", cp
);
83 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
85 print_help (buf
, switches
, 1);
88 print_version(invo_name
);
108 if (!(cp
= *argp
++) || *cp
== '-')
109 die("missing argument to %s", argp
[-2]);
111 svector_push_back (seqs
, cp
);
134 if (*cp
== '+' || *cp
== '@') {
136 die("only one folder at a time!");
137 folder
= pluspath (cp
);
139 app_msgarg(&msgs
, cp
);
143 * If we haven't specified -add, -delete, or -list,
144 * then use -add if a sequence was specified, else
147 if (!addsw
&& !deletesw
&& !listsw
) {
154 if (!context_find ("path"))
155 free (path ("./", TFOLDER
));
157 app_msgarg(&msgs
, listsw
? "all" :"cur");
159 folder
= getfolder (1);
160 maildir
= m_maildir (folder
);
162 if (chdir (maildir
) == NOTOK
)
163 adios (maildir
, "unable to change directory to");
165 /* read folder and create message structure */
166 if (!(mp
= folder_read (folder
, 1)))
167 die("unable to read folder %s", folder
);
169 /* print some general debugging info */
173 /* check for empty folder */
175 die("no messages in %s", folder
);
177 /* parse all the message ranges/sequences and set SELECTED */
178 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
179 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
182 if (publicsw
== 1 && is_readonly(mp
))
183 die("folder %s is read-only, so -public not allowed", folder
);
186 * Make sure at least one sequence has been
187 * specified if we are adding or deleting.
189 if (seqp
== 0 && (addsw
|| deletesw
))
190 die("-%s requires at least one -sequence argument",
191 addsw
? "add" : "delete");
193 /* Adding messages to sequences */
195 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
196 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
200 /* Deleting messages from sequences */
202 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
203 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
207 /* Listing messages in sequences */
210 /* print the sequences given */
211 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
212 seq_print (mp
, svector_at (seqs
, seqp
));
214 /* else print them all */
218 /* print debugging info about SELECTED messages */
224 seq_save (mp
); /* synchronize message sequences */
225 context_replace (pfolder
, folder
); /* update current folder */
226 context_save (); /* save the context file */
227 folder_free (mp
); /* free folder/message structure */
234 * Print general debugging info
237 print_debug (struct msgs
*mp
)
241 printf ("invo_name = %s\n", invo_name
);
242 printf ("mypath = %s\n", mypath
);
243 printf ("defpath = %s\n", defpath
);
244 printf ("ctxpath = %s\n", ctxpath
);
245 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
246 (unsigned) ctxflags
, DBITS
));
247 printf ("foldpath = %s\n", mp
->foldpath
);
248 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
249 (unsigned) mp
->msgflags
, FBITS
));
250 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
251 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
252 printf ("lowsel=%d hghsel=%d numsel=%d\n",
253 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
254 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
259 * Print debugging info about all the SELECTED
260 * messages and the sequences they are in.
261 * Due to limitations of snprintb(), only a limited
262 * number of sequences will be printed. See the
263 * comments in sbr/seq_bits.c.
266 seq_printdebug (struct msgs
*mp
)
272 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
273 if (is_selected (mp
, msgnum
))
274 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
275 snprintb (buf
, sizeof buf
,
276 (unsigned) bvector_first_bits (msgstat (mp
, msgnum
)),