]>
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
};
56 setlocale(LC_ALL
, "");
58 invo_name
= r1bindex (argv
[0], '/');
60 /* read user profile/context */
63 arguments
= getarguments (invo_name
, argc
, argv
, 1);
69 while ((cp
= *argp
++)) {
71 switch (smatch (++cp
, switches
)) {
73 ambigsw (cp
, switches
);
76 adios (NULL
, "-%s unknown\n", cp
);
79 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
81 print_help (buf
, switches
, 1);
84 print_version(invo_name
);
89 deletesw
= listsw
= 0;
101 if (!(cp
= *argp
++) || *cp
== '-')
102 adios (NULL
, "missing argument to %s", argp
[-2]);
104 svector_push_back (seqs
, cp
);
127 if (*cp
== '+' || *cp
== '@') {
129 adios (NULL
, "only one folder at a time!");
131 folder
= pluspath (cp
);
133 app_msgarg(&msgs
, cp
);
137 * If we haven't specified -add, -delete, or -list,
138 * then use -add if a sequence was specified, else
141 if (!addsw
&& !deletesw
&& !listsw
) {
148 if (!context_find ("path"))
149 free (path ("./", TFOLDER
));
151 app_msgarg(&msgs
, listsw
? "all" :"cur");
153 folder
= getfolder (1);
154 maildir
= m_maildir (folder
);
156 if (chdir (maildir
) == NOTOK
)
157 adios (maildir
, "unable to change directory to");
159 /* read folder and create message structure */
160 if (!(mp
= folder_read (folder
, 1)))
161 adios (NULL
, "unable to read folder %s", folder
);
163 /* print some general debugging info */
167 /* check for empty folder */
169 adios (NULL
, "no messages in %s", folder
);
171 /* parse all the message ranges/sequences and set SELECTED */
172 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
173 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
176 if (publicsw
== 1 && is_readonly(mp
))
177 adios (NULL
, "folder %s is read-only, so -public not allowed", folder
);
180 * Make sure at least one sequence has been
181 * specified if we are adding or deleting.
183 if (seqp
== 0 && (addsw
|| deletesw
))
184 adios (NULL
, "-%s requires at least one -sequence argument",
185 addsw
? "add" : "delete");
187 /* Adding messages to sequences */
189 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
190 if (!seq_addsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
194 /* Deleting messages from sequences */
196 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
197 if (!seq_delsel (mp
, svector_at (seqs
, seqp
), publicsw
, zerosw
))
201 /* Listing messages in sequences */
204 /* print the sequences given */
205 for (seqp
= 0; seqp
< svector_size (seqs
); seqp
++)
206 seq_print (mp
, svector_at (seqs
, seqp
));
208 /* else print them all */
212 /* print debugging info about SELECTED messages */
218 seq_save (mp
); /* synchronize message sequences */
219 context_replace (pfolder
, folder
); /* update current folder */
220 context_save (); /* save the context file */
221 folder_free (mp
); /* free folder/message structure */
228 * Print general debugging info
231 print_debug (struct msgs
*mp
)
235 printf ("invo_name = %s\n", invo_name
);
236 printf ("mypath = %s\n", mypath
);
237 printf ("defpath = %s\n", defpath
);
238 printf ("ctxpath = %s\n", ctxpath
);
239 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
240 (unsigned) ctxflags
, DBITS
));
241 printf ("foldpath = %s\n", mp
->foldpath
);
242 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
243 (unsigned) mp
->msgflags
, FBITS
));
244 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
245 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
246 printf ("lowsel=%d hghsel=%d numsel=%d\n",
247 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
248 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
253 * Print debugging info about all the SELECTED
254 * messages and the sequences they are in.
255 * Due limitattions of snprintb(), only a limited
256 * number of sequences will be printed. See the
257 * comments in sbr/seq_bits.c.
260 seq_printdebug (struct msgs
*mp
)
266 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
267 if (is_selected (mp
, msgnum
))
268 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
269 snprintb (buf
, sizeof buf
,
270 (unsigned) *bvector_bits (msgstat (mp
, msgnum
)),