]>
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
9 * This code is Copyright (c) 2002, by the authors of nmh. See the
10 * COPYRIGHT file in the root directory of the nmh distribution for
11 * complete copyright information.
18 * We allocate space for messages (msgs array)
19 * this number of elements at a time.
24 static struct swit switches
[] = {
32 { "sequence name", 0 },
53 static void print_debug (struct msgs
*);
54 static void seq_printdebug (struct msgs
*);
58 main (int argc
, char **argv
)
60 int addsw
= 0, deletesw
= 0, debugsw
= 0;
61 int listsw
= 0, publicsw
= -1, zerosw
= 0;
62 int seqp
= 0, msgnum
, nummsgs
, maxmsgs
;
63 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
64 char **argp
, **arguments
;
65 char *seqs
[NUMATTRS
+ 1], **msgs
;
69 setlocale(LC_ALL
, "");
71 invo_name
= r1bindex (argv
[0], '/');
73 /* read user profile/context */
76 arguments
= getarguments (invo_name
, argc
, argv
, 1);
80 * Allocate the initial space to record message
81 * names, ranges, and sequences.
85 msgs
= (char **) mh_xmalloc ((size_t) (maxmsgs
* sizeof(*msgs
)));
90 while ((cp
= *argp
++)) {
92 switch (smatch (++cp
, switches
)) {
94 ambigsw (cp
, switches
);
97 adios (NULL
, "-%s unknown\n", cp
);
100 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
102 print_help (buf
, switches
, 1);
105 print_version(invo_name
);
110 deletesw
= listsw
= 0;
118 addsw
= deletesw
= 0;
122 if (!(cp
= *argp
++) || *cp
== '-')
123 adios (NULL
, "missing argument to %s", argp
[-2]);
125 /* check if too many sequences specified */
126 if (seqp
>= NUMATTRS
)
127 adios (NULL
, "too many sequences (more than %d) specified", NUMATTRS
);
150 if (*cp
== '+' || *cp
== '@') {
152 adios (NULL
, "only one folder at a time!");
154 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
157 * Check if we need to allocate more space
158 * for message names/ranges/sequences.
160 if (nummsgs
>= maxmsgs
) {
162 msgs
= (char **) mh_xrealloc (msgs
,
163 (size_t) (maxmsgs
* sizeof(*msgs
)));
165 msgs
[nummsgs
++] = cp
;
170 * If we haven't specified -add, -delete, or -list,
171 * then use -add if a sequence was specified, else
174 if (!addsw
&& !deletesw
&& !listsw
) {
181 if (!context_find ("path"))
182 free (path ("./", TFOLDER
));
184 msgs
[nummsgs
++] = listsw
? "all" :"cur";
186 folder
= getfolder (1);
187 maildir
= m_maildir (folder
);
189 if (chdir (maildir
) == NOTOK
)
190 adios (maildir
, "unable to change directory to");
192 /* read folder and create message structure */
193 if (!(mp
= folder_read (folder
)))
194 adios (NULL
, "unable to read folder %s", folder
);
196 /* print some general debugging info */
200 /* check for empty folder */
202 adios (NULL
, "no messages in %s", folder
);
204 /* parse all the message ranges/sequences and set SELECTED */
205 for (msgnum
= 0; msgnum
< nummsgs
; msgnum
++)
206 if (!m_convert (mp
, msgs
[msgnum
]))
209 if (publicsw
== 1 && is_readonly(mp
))
210 adios (NULL
, "folder %s is read-only, so -public not allowed", folder
);
213 * Make sure at least one sequence has been
214 * specified if we are adding or deleting.
216 if (seqp
== 0 && (addsw
|| deletesw
))
217 adios (NULL
, "-%s requires at least one -sequence argument",
218 addsw
? "add" : "delete");
221 /* Adding messages to sequences */
223 for (seqp
= 0; seqs
[seqp
]; seqp
++)
224 if (!seq_addsel (mp
, seqs
[seqp
], publicsw
, zerosw
))
228 /* Deleting messages from sequences */
230 for (seqp
= 0; seqs
[seqp
]; seqp
++)
231 if (!seq_delsel (mp
, seqs
[seqp
], publicsw
, zerosw
))
235 /* Listing messages in sequences */
238 /* print the sequences given */
239 for (seqp
= 0; seqs
[seqp
]; seqp
++)
240 seq_print (mp
, seqs
[seqp
]);
242 /* else print them all */
246 /* print debugging info about SELECTED messages */
251 seq_save (mp
); /* synchronize message sequences */
252 context_replace (pfolder
, folder
); /* update current folder */
253 context_save (); /* save the context file */
254 folder_free (mp
); /* free folder/message structure */
260 * Print general debugging info
263 print_debug (struct msgs
*mp
)
267 printf ("invo_name = %s\n", invo_name
);
268 printf ("mypath = %s\n", mypath
);
269 printf ("defpath = %s\n", defpath
);
270 printf ("ctxpath = %s\n", ctxpath
);
271 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
272 (unsigned) ctxflags
, DBITS
));
273 printf ("foldpath = %s\n", mp
->foldpath
);
274 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
275 (unsigned) mp
->msgflags
, FBITS
));
276 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
277 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
278 printf ("lowsel=%d hghsel=%d numsel=%d\n",
279 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
280 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
285 * Print debugging info about all the SELECTED
286 * messages and the sequences they are in.
289 seq_printdebug (struct msgs
*mp
)
295 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
296 if (is_selected (mp
, msgnum
))
297 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
298 snprintb (buf
, sizeof(buf
),
299 (unsigned) mp
->msgstats
[msgnum
- mp
->lowoff
], seq_bits (mp
)));