]>
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
)
46 int addsw
= 0, deletesw
= 0, debugsw
= 0;
47 int listsw
= 0, publicsw
= -1, zerosw
= 0, msgnum
;
48 unsigned int seqp
= 0;
49 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
50 char **argp
, **arguments
;
51 svector_t seqs
= svector_create (0);
52 struct msgs_array msgs
= { 0, 0, NULL
};
55 if (nmh_init(argv
[0], 1)) { return 1; }
57 arguments
= getarguments (invo_name
, argc
, argv
, 1);
63 while ((cp
= *argp
++)) {
65 switch (smatch (++cp
, switches
)) {
67 ambigsw (cp
, switches
);
70 adios (NULL
, "-%s unknown\n", cp
);
73 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
75 print_help (buf
, switches
, 1);
78 print_version(invo_name
);
83 deletesw
= listsw
= 0;
95 if (!(cp
= *argp
++) || *cp
== '-')
96 adios (NULL
, "missing argument to %s", argp
[-2]);
98 svector_push_back (seqs
, cp
);
121 if (*cp
== '+' || *cp
== '@') {
123 adios (NULL
, "only one folder at a time!");
124 folder
= pluspath (cp
);
126 app_msgarg(&msgs
, cp
);
130 * If we haven't specified -add, -delete, or -list,
131 * then use -add if a sequence was specified, else
134 if (!addsw
&& !deletesw
&& !listsw
) {
141 if (!context_find ("path"))
142 free (path ("./", TFOLDER
));
144 app_msgarg(&msgs
, listsw
? "all" :"cur");
146 folder
= getfolder (1);
147 maildir
= m_maildir (folder
);
149 if (chdir (maildir
) == NOTOK
)
150 adios (maildir
, "unable to change directory to");
152 /* read folder and create message structure */
153 if (!(mp
= folder_read (folder
, 1)))
154 adios (NULL
, "unable to read folder %s", folder
);
156 /* print some general debugging info */
160 /* check for empty folder */
162 adios (NULL
, "no messages in %s", folder
);
164 /* parse all the message ranges/sequences and set SELECTED */
165 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
166 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
169 if (publicsw
== 1 && is_readonly(mp
))
170 adios (NULL
, "folder %s is read-only, so -public not allowed", folder
);
173 * Make sure at least one sequence has been
174 * specified if we are adding or deleting.
176 if (seqp
== 0 && (addsw
|| deletesw
))
177 adios (NULL
, "-%s requires at least one -sequence argument",
178 addsw
? "add" : "delete");
180 /* Adding messages to sequences */
182 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
183 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
187 /* Deleting messages from sequences */
189 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
190 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
194 /* Listing messages in sequences */
197 /* print the sequences given */
198 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
199 seq_print (mp
, svector_at (seqs
, seqp
));
201 /* else print them all */
205 /* print debugging info about SELECTED messages */
211 seq_save (mp
); /* synchronize message sequences */
212 context_replace (pfolder
, folder
); /* update current folder */
213 context_save (); /* save the context file */
214 folder_free (mp
); /* free folder/message structure */
221 * Print general debugging info
224 print_debug (struct msgs
*mp
)
228 printf ("invo_name = %s\n", invo_name
);
229 printf ("mypath = %s\n", mypath
);
230 printf ("defpath = %s\n", defpath
);
231 printf ("ctxpath = %s\n", ctxpath
);
232 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
233 (unsigned) ctxflags
, DBITS
));
234 printf ("foldpath = %s\n", mp
->foldpath
);
235 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
236 (unsigned) mp
->msgflags
, FBITS
));
237 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
238 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
239 printf ("lowsel=%d hghsel=%d numsel=%d\n",
240 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
241 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
246 * Print debugging info about all the SELECTED
247 * messages and the sequences they are in.
248 * Due to limitations of snprintb(), only a limited
249 * number of sequences will be printed. See the
250 * comments in sbr/seq_bits.c.
253 seq_printdebug (struct msgs
*mp
)
259 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
260 if (is_selected (mp
, msgnum
))
261 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
262 snprintb (buf
, sizeof buf
,
263 (unsigned) bvector_first_bits (msgstat (mp
, msgnum
)),