]>
diplodocus.org Git - nmh/blob - uip/mark.c
719b534e2f5d946e2780244d8c09b5f7b2877afd
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/context_find.h"
12 #include "sbr/ambigsw.h"
14 #include "sbr/print_version.h"
15 #include "sbr/print_help.h"
16 #include "sbr/seq_bits.h"
17 #include "sbr/seq_del.h"
18 #include "sbr/seq_print.h"
19 #include "sbr/seq_add.h"
20 #include "sbr/error.h"
23 #include "sbr/m_maildir.h"
25 #define MARK_SWITCHES \
27 X("delete", 0, DELSW) \
29 X("sequence name", 0, SEQSW) \
30 X("public", 0, PUBLSW) \
31 X("nopublic", 0, NPUBLSW) \
32 X("zero", 0, ZEROSW) \
33 X("nozero", 0, NZEROSW) \
34 X("version", 0, VERSIONSW) \
35 X("help", 0, HELPSW) \
36 X("debug", -5, DEBUGSW) \
38 #define X(sw, minchars, id) id,
39 DEFINE_SWITCH_ENUM(MARK
);
42 #define X(sw, minchars, id) { sw, minchars, id },
43 DEFINE_SWITCH_ARRAY(MARK
, switches
);
49 static void print_debug (struct msgs
*);
50 static void seq_printdebug (struct msgs
*);
54 main (int argc
, char **argv
)
57 bool deletesw
= false;
63 unsigned int seqp
= 0;
64 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
65 char **argp
, **arguments
;
66 svector_t seqs
= svector_create (0);
67 struct msgs_array msgs
= { 0, 0, NULL
};
70 if (nmh_init(argv
[0], true, true)) { return 1; }
72 arguments
= getarguments (invo_name
, argc
, argv
, 1);
78 while ((cp
= *argp
++)) {
80 switch (smatch (++cp
, switches
)) {
82 ambigsw (cp
, switches
);
85 die("-%s unknown\n", cp
);
88 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
90 print_help (buf
, switches
, 1);
93 print_version(invo_name
);
113 if (!(cp
= *argp
++) || *cp
== '-')
114 die("missing argument to %s", argp
[-2]);
116 svector_push_back (seqs
, cp
);
139 if (*cp
== '+' || *cp
== '@') {
141 die("only one folder at a time!");
142 folder
= pluspath (cp
);
144 app_msgarg(&msgs
, cp
);
148 * If we haven't specified -add, -delete, or -list,
149 * then use -add if a sequence was specified, else
152 if (!addsw
&& !deletesw
&& !listsw
) {
159 if (!context_find ("path"))
160 free (path ("./", TFOLDER
));
162 app_msgarg(&msgs
, listsw
? "all" :"cur");
164 folder
= getfolder (1);
165 maildir
= m_maildir (folder
);
167 if (chdir (maildir
) == NOTOK
)
168 adios (maildir
, "unable to change directory to");
170 /* read folder and create message structure */
171 if (!(mp
= folder_read (folder
, 1)))
172 die("unable to read folder %s", folder
);
174 /* print some general debugging info */
178 /* check for empty folder */
180 die("no messages in %s", folder
);
182 /* parse all the message ranges/sequences and set SELECTED */
183 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
184 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
187 if (publicsw
== 1 && is_readonly(mp
))
188 die("folder %s is read-only, so -public not allowed", folder
);
191 * Make sure at least one sequence has been
192 * specified if we are adding or deleting.
194 if (seqp
== 0 && (addsw
|| deletesw
))
195 die("-%s requires at least one -sequence argument",
196 addsw
? "add" : "delete");
198 /* Adding messages to sequences */
200 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
201 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
205 /* Deleting messages from sequences */
207 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
208 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
212 /* Listing messages in sequences */
215 /* print the sequences given */
216 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
217 seq_print (mp
, svector_at (seqs
, seqp
));
219 /* else print them all */
223 /* print debugging info about SELECTED messages */
229 seq_save (mp
); /* synchronize message sequences */
230 context_replace (pfolder
, folder
); /* update current folder */
231 context_save (); /* save the context file */
232 folder_free (mp
); /* free folder/message structure */
239 * Print general debugging info
242 print_debug (struct msgs
*mp
)
246 printf ("invo_name = %s\n", invo_name
);
247 printf ("mypath = %s\n", mypath
);
248 printf ("defpath = %s\n", defpath
);
249 printf ("ctxpath = %s\n", ctxpath
);
250 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
251 (unsigned) ctxflags
, DBITS
));
252 printf ("foldpath = %s\n", mp
->foldpath
);
253 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
254 (unsigned) mp
->msgflags
, FBITS
));
255 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
256 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
257 printf ("lowsel=%d hghsel=%d numsel=%d\n",
258 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
259 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
264 * Print debugging info about all the SELECTED
265 * messages and the sequences they are in.
266 * Due to limitations of snprintb(), only a limited
267 * number of sequences will be printed. See the
268 * comments in sbr/seq_bits.c.
271 seq_printdebug (struct msgs
*mp
)
277 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
278 if (is_selected (mp
, msgnum
))
279 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
280 snprintb (buf
, sizeof buf
,
281 (unsigned) bvector_first_bits (msgstat (mp
, msgnum
)),