]>
diplodocus.org Git - nmh/blob - uip/mark.c
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.
12 #include "sbr/print_version.h"
13 #include "sbr/print_help.h"
14 #include "sbr/seq_bits.h"
15 #include "sbr/seq_del.h"
16 #include "sbr/seq_print.h"
17 #include "sbr/seq_add.h"
18 #include "sbr/error.h"
21 #include "sbr/m_maildir.h"
23 #define MARK_SWITCHES \
25 X("delete", 0, DELSW) \
27 X("sequence name", 0, SEQSW) \
28 X("public", 0, PUBLSW) \
29 X("nopublic", 0, NPUBLSW) \
30 X("zero", 0, ZEROSW) \
31 X("nozero", 0, NZEROSW) \
32 X("version", 0, VERSIONSW) \
33 X("help", 0, HELPSW) \
34 X("debug", -5, DEBUGSW) \
36 #define X(sw, minchars, id) id,
37 DEFINE_SWITCH_ENUM(MARK
);
40 #define X(sw, minchars, id) { sw, minchars, id },
41 DEFINE_SWITCH_ARRAY(MARK
, switches
);
47 static void print_debug (struct msgs
*);
48 static void seq_printdebug (struct msgs
*);
52 main (int argc
, char **argv
)
55 bool deletesw
= false;
61 unsigned int seqp
= 0;
62 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
63 char **argp
, **arguments
;
64 svector_t seqs
= svector_create (0);
65 struct msgs_array msgs
= { 0, 0, NULL
};
68 if (nmh_init(argv
[0], true, true)) { return 1; }
70 arguments
= getarguments (invo_name
, argc
, argv
, 1);
76 while ((cp
= *argp
++)) {
78 switch (smatch (++cp
, switches
)) {
80 ambigsw (cp
, switches
);
83 die("-%s unknown\n", cp
);
86 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
88 print_help (buf
, switches
, 1);
91 print_version(invo_name
);
111 if (!(cp
= *argp
++) || *cp
== '-')
112 die("missing argument to %s", argp
[-2]);
114 svector_push_back (seqs
, cp
);
137 if (*cp
== '+' || *cp
== '@') {
139 die("only one folder at a time!");
140 folder
= pluspath (cp
);
142 app_msgarg(&msgs
, cp
);
146 * If we haven't specified -add, -delete, or -list,
147 * then use -add if a sequence was specified, else
150 if (!addsw
&& !deletesw
&& !listsw
) {
157 if (!context_find ("path"))
158 free (path ("./", TFOLDER
));
160 app_msgarg(&msgs
, listsw
? "all" :"cur");
162 folder
= getfolder (1);
163 maildir
= m_maildir (folder
);
165 if (chdir (maildir
) == NOTOK
)
166 adios (maildir
, "unable to change directory to");
168 /* read folder and create message structure */
169 if (!(mp
= folder_read (folder
, 1)))
170 die("unable to read folder %s", folder
);
172 /* print some general debugging info */
176 /* check for empty folder */
178 die("no messages in %s", folder
);
180 /* parse all the message ranges/sequences and set SELECTED */
181 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
182 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
185 if (publicsw
== 1 && is_readonly(mp
))
186 die("folder %s is read-only, so -public not allowed", folder
);
189 * Make sure at least one sequence has been
190 * specified if we are adding or deleting.
192 if (seqp
== 0 && (addsw
|| deletesw
))
193 die("-%s requires at least one -sequence argument",
194 addsw
? "add" : "delete");
196 /* Adding messages to sequences */
198 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
199 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
203 /* Deleting messages from sequences */
205 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
206 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
210 /* Listing messages in sequences */
213 /* print the sequences given */
214 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
215 seq_print (mp
, svector_at (seqs
, seqp
));
217 /* else print them all */
221 /* print debugging info about SELECTED messages */
227 seq_save (mp
); /* synchronize message sequences */
228 context_replace (pfolder
, folder
); /* update current folder */
229 context_save (); /* save the context file */
230 folder_free (mp
); /* free folder/message structure */
237 * Print general debugging info
240 print_debug (struct msgs
*mp
)
244 printf ("invo_name = %s\n", invo_name
);
245 printf ("mypath = %s\n", mypath
);
246 printf ("defpath = %s\n", defpath
);
247 printf ("ctxpath = %s\n", ctxpath
);
248 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
249 (unsigned) ctxflags
, DBITS
));
250 printf ("foldpath = %s\n", mp
->foldpath
);
251 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
252 (unsigned) mp
->msgflags
, FBITS
));
253 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
254 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
255 printf ("lowsel=%d hghsel=%d numsel=%d\n",
256 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
257 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
262 * Print debugging info about all the SELECTED
263 * messages and the sequences they are in.
264 * Due to limitations of snprintb(), only a limited
265 * number of sequences will be printed. See the
266 * comments in sbr/seq_bits.c.
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
,
278 snprintb (buf
, sizeof buf
,
279 (unsigned) bvector_first_bits (msgstat (mp
, msgnum
)),