]>
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.
13 #include "sbr/m_maildir.h"
15 #define MARK_SWITCHES \
17 X("delete", 0, DELSW) \
19 X("sequence name", 0, SEQSW) \
20 X("public", 0, PUBLSW) \
21 X("nopublic", 0, NPUBLSW) \
22 X("zero", 0, ZEROSW) \
23 X("nozero", 0, NZEROSW) \
24 X("version", 0, VERSIONSW) \
25 X("help", 0, HELPSW) \
26 X("debug", -5, DEBUGSW) \
28 #define X(sw, minchars, id) id,
29 DEFINE_SWITCH_ENUM(MARK
);
32 #define X(sw, minchars, id) { sw, minchars, id },
33 DEFINE_SWITCH_ARRAY(MARK
, switches
);
39 static void print_debug (struct msgs
*);
40 static void seq_printdebug (struct msgs
*);
44 main (int argc
, char **argv
)
47 bool deletesw
= false;
53 unsigned int seqp
= 0;
54 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
55 char **argp
, **arguments
;
56 svector_t seqs
= svector_create (0);
57 struct msgs_array msgs
= { 0, 0, NULL
};
60 if (nmh_init(argv
[0], true, true)) { return 1; }
62 arguments
= getarguments (invo_name
, argc
, argv
, 1);
68 while ((cp
= *argp
++)) {
70 switch (smatch (++cp
, switches
)) {
72 ambigsw (cp
, switches
);
75 die("-%s unknown\n", cp
);
78 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
80 print_help (buf
, switches
, 1);
83 print_version(invo_name
);
103 if (!(cp
= *argp
++) || *cp
== '-')
104 die("missing argument to %s", argp
[-2]);
106 svector_push_back (seqs
, cp
);
129 if (*cp
== '+' || *cp
== '@') {
131 die("only one folder at a time!");
132 folder
= pluspath (cp
);
134 app_msgarg(&msgs
, cp
);
138 * If we haven't specified -add, -delete, or -list,
139 * then use -add if a sequence was specified, else
142 if (!addsw
&& !deletesw
&& !listsw
) {
149 if (!context_find ("path"))
150 free (path ("./", TFOLDER
));
152 app_msgarg(&msgs
, listsw
? "all" :"cur");
154 folder
= getfolder (1);
155 maildir
= m_maildir (folder
);
157 if (chdir (maildir
) == NOTOK
)
158 adios (maildir
, "unable to change directory to");
160 /* read folder and create message structure */
161 if (!(mp
= folder_read (folder
, 1)))
162 die("unable to read folder %s", folder
);
164 /* print some general debugging info */
168 /* check for empty folder */
170 die("no messages in %s", folder
);
172 /* parse all the message ranges/sequences and set SELECTED */
173 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
174 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
177 if (publicsw
== 1 && is_readonly(mp
))
178 die("folder %s is read-only, so -public not allowed", folder
);
181 * Make sure at least one sequence has been
182 * specified if we are adding or deleting.
184 if (seqp
== 0 && (addsw
|| deletesw
))
185 die("-%s requires at least one -sequence argument",
186 addsw
? "add" : "delete");
188 /* Adding messages to sequences */
190 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
191 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
195 /* Deleting messages from sequences */
197 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
198 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
202 /* Listing messages in sequences */
205 /* print the sequences given */
206 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
207 seq_print (mp
, svector_at (seqs
, seqp
));
209 /* else print them all */
213 /* print debugging info about SELECTED messages */
219 seq_save (mp
); /* synchronize message sequences */
220 context_replace (pfolder
, folder
); /* update current folder */
221 context_save (); /* save the context file */
222 folder_free (mp
); /* free folder/message structure */
229 * Print general debugging info
232 print_debug (struct msgs
*mp
)
236 printf ("invo_name = %s\n", invo_name
);
237 printf ("mypath = %s\n", mypath
);
238 printf ("defpath = %s\n", defpath
);
239 printf ("ctxpath = %s\n", ctxpath
);
240 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
241 (unsigned) ctxflags
, DBITS
));
242 printf ("foldpath = %s\n", mp
->foldpath
);
243 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
244 (unsigned) mp
->msgflags
, FBITS
));
245 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
246 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
247 printf ("lowsel=%d hghsel=%d numsel=%d\n",
248 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
249 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
254 * Print debugging info about all the SELECTED
255 * messages and the sequences they are in.
256 * Due to limitations of snprintb(), only a limited
257 * number of sequences will be printed. See the
258 * comments in sbr/seq_bits.c.
261 seq_printdebug (struct msgs
*mp
)
267 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
268 if (is_selected (mp
, msgnum
))
269 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
270 snprintb (buf
, sizeof buf
,
271 (unsigned) bvector_first_bits (msgstat (mp
, msgnum
)),