]>
diplodocus.org Git - nmh/blob - uip/mark.c
d2f90571ce7ebd55c01ca3db18a67e6f74b27f6e
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_del.h"
12 #include "sbr/seq_print.h"
13 #include "sbr/seq_add.h"
14 #include "sbr/error.h"
17 #include "sbr/m_maildir.h"
19 #define MARK_SWITCHES \
21 X("delete", 0, DELSW) \
23 X("sequence name", 0, SEQSW) \
24 X("public", 0, PUBLSW) \
25 X("nopublic", 0, NPUBLSW) \
26 X("zero", 0, ZEROSW) \
27 X("nozero", 0, NZEROSW) \
28 X("version", 0, VERSIONSW) \
29 X("help", 0, HELPSW) \
30 X("debug", -5, DEBUGSW) \
32 #define X(sw, minchars, id) id,
33 DEFINE_SWITCH_ENUM(MARK
);
36 #define X(sw, minchars, id) { sw, minchars, id },
37 DEFINE_SWITCH_ARRAY(MARK
, switches
);
43 static void print_debug (struct msgs
*);
44 static void seq_printdebug (struct msgs
*);
48 main (int argc
, char **argv
)
51 bool deletesw
= false;
57 unsigned int seqp
= 0;
58 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
59 char **argp
, **arguments
;
60 svector_t seqs
= svector_create (0);
61 struct msgs_array msgs
= { 0, 0, NULL
};
64 if (nmh_init(argv
[0], true, true)) { return 1; }
66 arguments
= getarguments (invo_name
, argc
, argv
, 1);
72 while ((cp
= *argp
++)) {
74 switch (smatch (++cp
, switches
)) {
76 ambigsw (cp
, switches
);
79 die("-%s unknown\n", cp
);
82 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
84 print_help (buf
, switches
, 1);
87 print_version(invo_name
);
107 if (!(cp
= *argp
++) || *cp
== '-')
108 die("missing argument to %s", argp
[-2]);
110 svector_push_back (seqs
, cp
);
133 if (*cp
== '+' || *cp
== '@') {
135 die("only one folder at a time!");
136 folder
= pluspath (cp
);
138 app_msgarg(&msgs
, cp
);
142 * If we haven't specified -add, -delete, or -list,
143 * then use -add if a sequence was specified, else
146 if (!addsw
&& !deletesw
&& !listsw
) {
153 if (!context_find ("path"))
154 free (path ("./", TFOLDER
));
156 app_msgarg(&msgs
, listsw
? "all" :"cur");
158 folder
= getfolder (1);
159 maildir
= m_maildir (folder
);
161 if (chdir (maildir
) == NOTOK
)
162 adios (maildir
, "unable to change directory to");
164 /* read folder and create message structure */
165 if (!(mp
= folder_read (folder
, 1)))
166 die("unable to read folder %s", folder
);
168 /* print some general debugging info */
172 /* check for empty folder */
174 die("no messages in %s", folder
);
176 /* parse all the message ranges/sequences and set SELECTED */
177 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
178 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
181 if (publicsw
== 1 && is_readonly(mp
))
182 die("folder %s is read-only, so -public not allowed", folder
);
185 * Make sure at least one sequence has been
186 * specified if we are adding or deleting.
188 if (seqp
== 0 && (addsw
|| deletesw
))
189 die("-%s requires at least one -sequence argument",
190 addsw
? "add" : "delete");
192 /* Adding messages to sequences */
194 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
195 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
199 /* Deleting messages from sequences */
201 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
202 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
206 /* Listing messages in sequences */
209 /* print the sequences given */
210 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
211 seq_print (mp
, svector_at (seqs
, seqp
));
213 /* else print them all */
217 /* print debugging info about SELECTED messages */
223 seq_save (mp
); /* synchronize message sequences */
224 context_replace (pfolder
, folder
); /* update current folder */
225 context_save (); /* save the context file */
226 folder_free (mp
); /* free folder/message structure */
233 * Print general debugging info
236 print_debug (struct msgs
*mp
)
240 printf ("invo_name = %s\n", invo_name
);
241 printf ("mypath = %s\n", mypath
);
242 printf ("defpath = %s\n", defpath
);
243 printf ("ctxpath = %s\n", ctxpath
);
244 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
245 (unsigned) ctxflags
, DBITS
));
246 printf ("foldpath = %s\n", mp
->foldpath
);
247 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
248 (unsigned) mp
->msgflags
, FBITS
));
249 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
250 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
251 printf ("lowsel=%d hghsel=%d numsel=%d\n",
252 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
253 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
258 * Print debugging info about all the SELECTED
259 * messages and the sequences they are in.
260 * Due to limitations of snprintb(), only a limited
261 * number of sequences will be printed. See the
262 * comments in sbr/seq_bits.c.
265 seq_printdebug (struct msgs
*mp
)
271 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
272 if (is_selected (mp
, msgnum
))
273 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
274 snprintb (buf
, sizeof buf
,
275 (unsigned) bvector_first_bits (msgstat (mp
, msgnum
)),