]>
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/m_maildir.h"
14 #define MARK_SWITCHES \
16 X("delete", 0, DELSW) \
18 X("sequence name", 0, SEQSW) \
19 X("public", 0, PUBLSW) \
20 X("nopublic", 0, NPUBLSW) \
21 X("zero", 0, ZEROSW) \
22 X("nozero", 0, NZEROSW) \
23 X("version", 0, VERSIONSW) \
24 X("help", 0, HELPSW) \
25 X("debug", -5, DEBUGSW) \
27 #define X(sw, minchars, id) id,
28 DEFINE_SWITCH_ENUM(MARK
);
31 #define X(sw, minchars, id) { sw, minchars, id },
32 DEFINE_SWITCH_ARRAY(MARK
, switches
);
38 static void print_debug (struct msgs
*);
39 static void seq_printdebug (struct msgs
*);
43 main (int argc
, char **argv
)
45 int addsw
= 0, deletesw
= 0, debugsw
= 0;
46 int listsw
= 0, publicsw
= -1, zerosw
= 0, msgnum
;
47 unsigned int seqp
= 0;
48 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
49 char **argp
, **arguments
;
50 svector_t seqs
= svector_create (0);
51 struct msgs_array msgs
= { 0, 0, NULL
};
54 if (nmh_init(argv
[0], 1)) { return 1; }
56 arguments
= getarguments (invo_name
, argc
, argv
, 1);
62 while ((cp
= *argp
++)) {
64 switch (smatch (++cp
, switches
)) {
66 ambigsw (cp
, switches
);
69 adios (NULL
, "-%s unknown\n", cp
);
72 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
74 print_help (buf
, switches
, 1);
77 print_version(invo_name
);
82 deletesw
= listsw
= 0;
94 if (!(cp
= *argp
++) || *cp
== '-')
95 adios (NULL
, "missing argument to %s", argp
[-2]);
97 svector_push_back (seqs
, cp
);
120 if (*cp
== '+' || *cp
== '@') {
122 adios (NULL
, "only one folder at a time!");
123 folder
= pluspath (cp
);
125 app_msgarg(&msgs
, cp
);
129 * If we haven't specified -add, -delete, or -list,
130 * then use -add if a sequence was specified, else
133 if (!addsw
&& !deletesw
&& !listsw
) {
140 if (!context_find ("path"))
141 free (path ("./", TFOLDER
));
143 app_msgarg(&msgs
, listsw
? "all" :"cur");
145 folder
= getfolder (1);
146 maildir
= m_maildir (folder
);
148 if (chdir (maildir
) == NOTOK
)
149 adios (maildir
, "unable to change directory to");
151 /* read folder and create message structure */
152 if (!(mp
= folder_read (folder
, 1)))
153 adios (NULL
, "unable to read folder %s", folder
);
155 /* print some general debugging info */
159 /* check for empty folder */
161 adios (NULL
, "no messages in %s", folder
);
163 /* parse all the message ranges/sequences and set SELECTED */
164 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
165 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
168 if (publicsw
== 1 && is_readonly(mp
))
169 adios (NULL
, "folder %s is read-only, so -public not allowed", folder
);
172 * Make sure at least one sequence has been
173 * specified if we are adding or deleting.
175 if (seqp
== 0 && (addsw
|| deletesw
))
176 adios (NULL
, "-%s requires at least one -sequence argument",
177 addsw
? "add" : "delete");
179 /* Adding messages to sequences */
181 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
182 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
186 /* Deleting messages from sequences */
188 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
189 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
193 /* Listing messages in sequences */
196 /* print the sequences given */
197 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
198 seq_print (mp
, svector_at (seqs
, seqp
));
200 /* else print them all */
204 /* print debugging info about SELECTED messages */
210 seq_save (mp
); /* synchronize message sequences */
211 context_replace (pfolder
, folder
); /* update current folder */
212 context_save (); /* save the context file */
213 folder_free (mp
); /* free folder/message structure */
220 * Print general debugging info
223 print_debug (struct msgs
*mp
)
227 printf ("invo_name = %s\n", invo_name
);
228 printf ("mypath = %s\n", mypath
);
229 printf ("defpath = %s\n", defpath
);
230 printf ("ctxpath = %s\n", ctxpath
);
231 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
232 (unsigned) ctxflags
, DBITS
));
233 printf ("foldpath = %s\n", mp
->foldpath
);
234 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
235 (unsigned) mp
->msgflags
, FBITS
));
236 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
237 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
238 printf ("lowsel=%d hghsel=%d numsel=%d\n",
239 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
240 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
245 * Print debugging info about all the SELECTED
246 * messages and the sequences they are in.
247 * Due to limitations of snprintb(), only a limited
248 * number of sequences will be printed. See the
249 * comments in sbr/seq_bits.c.
252 seq_printdebug (struct msgs
*mp
)
258 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
259 if (is_selected (mp
, msgnum
))
260 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
261 snprintb (buf
, sizeof buf
,
262 (unsigned) bvector_first_bits (msgstat (mp
, msgnum
)),