]>
diplodocus.org Git - nmh/blob - uip/mark.c
3 * mark.c -- add message(s) to sequences in given folder
4 * -- delete messages (s) from sequences in given folder
5 * -- list sequences in given folder
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
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!");
125 folder
= pluspath (cp
);
127 app_msgarg(&msgs
, cp
);
131 * If we haven't specified -add, -delete, or -list,
132 * then use -add if a sequence was specified, else
135 if (!addsw
&& !deletesw
&& !listsw
) {
142 if (!context_find ("path"))
143 free (path ("./", TFOLDER
));
145 app_msgarg(&msgs
, listsw
? "all" :"cur");
147 folder
= getfolder (1);
148 maildir
= m_maildir (folder
);
150 if (chdir (maildir
) == NOTOK
)
151 adios (maildir
, "unable to change directory to");
153 /* read folder and create message structure */
154 if (!(mp
= folder_read (folder
, 1)))
155 adios (NULL
, "unable to read folder %s", folder
);
157 /* print some general debugging info */
161 /* check for empty folder */
163 adios (NULL
, "no messages in %s", folder
);
165 /* parse all the message ranges/sequences and set SELECTED */
166 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
167 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
170 if (publicsw
== 1 && is_readonly(mp
))
171 adios (NULL
, "folder %s is read-only, so -public not allowed", folder
);
174 * Make sure at least one sequence has been
175 * specified if we are adding or deleting.
177 if (seqp
== 0 && (addsw
|| deletesw
))
178 adios (NULL
, "-%s requires at least one -sequence argument",
179 addsw
? "add" : "delete");
181 /* Adding messages to sequences */
183 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
184 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
188 /* Deleting messages from sequences */
190 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
191 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
195 /* Listing messages in sequences */
198 /* print the sequences given */
199 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
200 seq_print (mp
, svector_at (seqs
, seqp
));
202 /* else print them all */
206 /* print debugging info about SELECTED messages */
212 seq_save (mp
); /* synchronize message sequences */
213 context_replace (pfolder
, folder
); /* update current folder */
214 context_save (); /* save the context file */
215 folder_free (mp
); /* free folder/message structure */
222 * Print general debugging info
225 print_debug (struct msgs
*mp
)
229 printf ("invo_name = %s\n", invo_name
);
230 printf ("mypath = %s\n", mypath
);
231 printf ("defpath = %s\n", defpath
);
232 printf ("ctxpath = %s\n", ctxpath
);
233 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
234 (unsigned) ctxflags
, DBITS
));
235 printf ("foldpath = %s\n", mp
->foldpath
);
236 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
237 (unsigned) mp
->msgflags
, FBITS
));
238 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
239 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
240 printf ("lowsel=%d hghsel=%d numsel=%d\n",
241 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
242 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
247 * Print debugging info about all the SELECTED
248 * messages and the sequences they are in.
249 * Due limitattions of snprintb(), only a limited
250 * number of sequences will be printed. See the
251 * comments in sbr/seq_bits.c.
254 seq_printdebug (struct msgs
*mp
)
260 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
261 if (is_selected (mp
, msgnum
))
262 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
263 snprintb (buf
, sizeof buf
,
264 (unsigned) *bvector_bits (msgstat (mp
, msgnum
)),