]>
diplodocus.org Git - nmh/blob - uip/mark.c
4709d7e40a672b56ac66dd8c9697a7c4f57fca6c
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/print_version.h"
12 #include "sbr/print_help.h"
13 #include "sbr/seq_bits.h"
14 #include "sbr/seq_del.h"
15 #include "sbr/seq_print.h"
16 #include "sbr/seq_add.h"
17 #include "sbr/error.h"
20 #include "sbr/m_maildir.h"
22 #define MARK_SWITCHES \
24 X("delete", 0, DELSW) \
26 X("sequence name", 0, SEQSW) \
27 X("public", 0, PUBLSW) \
28 X("nopublic", 0, NPUBLSW) \
29 X("zero", 0, ZEROSW) \
30 X("nozero", 0, NZEROSW) \
31 X("version", 0, VERSIONSW) \
32 X("help", 0, HELPSW) \
33 X("debug", -5, DEBUGSW) \
35 #define X(sw, minchars, id) id,
36 DEFINE_SWITCH_ENUM(MARK
);
39 #define X(sw, minchars, id) { sw, minchars, id },
40 DEFINE_SWITCH_ARRAY(MARK
, switches
);
46 static void print_debug (struct msgs
*);
47 static void seq_printdebug (struct msgs
*);
51 main (int argc
, char **argv
)
54 bool deletesw
= false;
60 unsigned int seqp
= 0;
61 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
62 char **argp
, **arguments
;
63 svector_t seqs
= svector_create (0);
64 struct msgs_array msgs
= { 0, 0, NULL
};
67 if (nmh_init(argv
[0], true, true)) { return 1; }
69 arguments
= getarguments (invo_name
, argc
, argv
, 1);
75 while ((cp
= *argp
++)) {
77 switch (smatch (++cp
, switches
)) {
79 ambigsw (cp
, switches
);
82 die("-%s unknown\n", cp
);
85 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
87 print_help (buf
, switches
, 1);
90 print_version(invo_name
);
110 if (!(cp
= *argp
++) || *cp
== '-')
111 die("missing argument to %s", argp
[-2]);
113 svector_push_back (seqs
, cp
);
136 if (*cp
== '+' || *cp
== '@') {
138 die("only one folder at a time!");
139 folder
= pluspath (cp
);
141 app_msgarg(&msgs
, cp
);
145 * If we haven't specified -add, -delete, or -list,
146 * then use -add if a sequence was specified, else
149 if (!addsw
&& !deletesw
&& !listsw
) {
156 if (!context_find ("path"))
157 free (path ("./", TFOLDER
));
159 app_msgarg(&msgs
, listsw
? "all" :"cur");
161 folder
= getfolder (1);
162 maildir
= m_maildir (folder
);
164 if (chdir (maildir
) == NOTOK
)
165 adios (maildir
, "unable to change directory to");
167 /* read folder and create message structure */
168 if (!(mp
= folder_read (folder
, 1)))
169 die("unable to read folder %s", folder
);
171 /* print some general debugging info */
175 /* check for empty folder */
177 die("no messages in %s", folder
);
179 /* parse all the message ranges/sequences and set SELECTED */
180 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
181 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
184 if (publicsw
== 1 && is_readonly(mp
))
185 die("folder %s is read-only, so -public not allowed", folder
);
188 * Make sure at least one sequence has been
189 * specified if we are adding or deleting.
191 if (seqp
== 0 && (addsw
|| deletesw
))
192 die("-%s requires at least one -sequence argument",
193 addsw
? "add" : "delete");
195 /* Adding messages to sequences */
197 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
198 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
202 /* Deleting messages from sequences */
204 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
205 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
209 /* Listing messages in sequences */
212 /* print the sequences given */
213 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
214 seq_print (mp
, svector_at (seqs
, seqp
));
216 /* else print them all */
220 /* print debugging info about SELECTED messages */
226 seq_save (mp
); /* synchronize message sequences */
227 context_replace (pfolder
, folder
); /* update current folder */
228 context_save (); /* save the context file */
229 folder_free (mp
); /* free folder/message structure */
236 * Print general debugging info
239 print_debug (struct msgs
*mp
)
243 printf ("invo_name = %s\n", invo_name
);
244 printf ("mypath = %s\n", mypath
);
245 printf ("defpath = %s\n", defpath
);
246 printf ("ctxpath = %s\n", ctxpath
);
247 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
248 (unsigned) ctxflags
, DBITS
));
249 printf ("foldpath = %s\n", mp
->foldpath
);
250 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
251 (unsigned) mp
->msgflags
, FBITS
));
252 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
253 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
254 printf ("lowsel=%d hghsel=%d numsel=%d\n",
255 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
256 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
261 * Print debugging info about all the SELECTED
262 * messages and the sequences they are in.
263 * Due to limitations of snprintb(), only a limited
264 * number of sequences will be printed. See the
265 * comments in sbr/seq_bits.c.
268 seq_printdebug (struct msgs
*mp
)
274 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
275 if (is_selected (mp
, msgnum
))
276 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
277 snprintb (buf
, sizeof buf
,
278 (unsigned) bvector_first_bits (msgstat (mp
, msgnum
)),