]>
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.
17 static struct swit switches
[] = {
25 { "sequence name", 0 },
46 static void print_debug (struct msgs
*);
47 static void seq_printdebug (struct msgs
*);
51 main (int argc
, char **argv
)
53 int addsw
= 0, deletesw
= 0, debugsw
= 0;
54 int listsw
= 0, publicsw
= -1, zerosw
= 0;
56 char *cp
, *maildir
, *folder
= NULL
, buf
[BUFSIZ
];
57 char **argp
, **arguments
;
58 char *seqs
[NUMATTRS
+ 1];
59 struct msgs_array msgs
= { 0, 0, NULL
};
63 setlocale(LC_ALL
, "");
65 invo_name
= r1bindex (argv
[0], '/');
67 /* read user profile/context */
70 arguments
= getarguments (invo_name
, argc
, argv
, 1);
76 while ((cp
= *argp
++)) {
78 switch (smatch (++cp
, switches
)) {
80 ambigsw (cp
, switches
);
83 adios (NULL
, "-%s unknown\n", cp
);
86 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
88 print_help (buf
, switches
, 1);
91 print_version(invo_name
);
96 deletesw
= listsw
= 0;
104 addsw
= deletesw
= 0;
108 if (!(cp
= *argp
++) || *cp
== '-')
109 adios (NULL
, "missing argument to %s", argp
[-2]);
111 /* check if too many sequences specified */
112 if (seqp
>= NUMATTRS
)
113 adios (NULL
, "too many sequences (more than %d) specified", NUMATTRS
);
136 if (*cp
== '+' || *cp
== '@') {
138 adios (NULL
, "only one folder at a time!");
140 folder
= pluspath (cp
);
142 app_msgarg(&msgs
, cp
);
146 * If we haven't specified -add, -delete, or -list,
147 * then use -add if a sequence was specified, else
150 if (!addsw
&& !deletesw
&& !listsw
) {
157 if (!context_find ("path"))
158 free (path ("./", TFOLDER
));
160 app_msgarg(&msgs
, listsw
? "all" :"cur");
162 folder
= getfolder (1);
163 maildir
= m_maildir (folder
);
165 if (chdir (maildir
) == NOTOK
)
166 adios (maildir
, "unable to change directory to");
168 /* read folder and create message structure */
169 if (!(mp
= folder_read (folder
)))
170 adios (NULL
, "unable to read folder %s", folder
);
172 /* print some general debugging info */
176 /* check for empty folder */
178 adios (NULL
, "no messages in %s", folder
);
180 /* parse all the message ranges/sequences and set SELECTED */
181 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
182 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
185 if (publicsw
== 1 && is_readonly(mp
))
186 adios (NULL
, "folder %s is read-only, so -public not allowed", folder
);
189 * Make sure at least one sequence has been
190 * specified if we are adding or deleting.
192 if (seqp
== 0 && (addsw
|| deletesw
))
193 adios (NULL
, "-%s requires at least one -sequence argument",
194 addsw
? "add" : "delete");
197 /* Adding messages to sequences */
199 for (seqp
= 0; seqs
[seqp
]; seqp
++)
200 if (!seq_addsel (mp
, seqs
[seqp
], publicsw
, zerosw
))
204 /* Deleting messages from sequences */
206 for (seqp
= 0; seqs
[seqp
]; seqp
++)
207 if (!seq_delsel (mp
, seqs
[seqp
], publicsw
, zerosw
))
211 /* Listing messages in sequences */
214 /* print the sequences given */
215 for (seqp
= 0; seqs
[seqp
]; seqp
++)
216 seq_print (mp
, seqs
[seqp
]);
218 /* else print them all */
222 /* print debugging info about SELECTED messages */
227 seq_save (mp
); /* synchronize message sequences */
228 context_replace (pfolder
, folder
); /* update current folder */
229 context_save (); /* save the context file */
230 folder_free (mp
); /* free folder/message structure */
236 * Print general debugging info
239 print_debug (struct msgs
*mp
)
243 printf ("invo_name = %s\n", invo_name
);
244 printf ("mypath = %s\n", mypath
);
245 printf ("defpath = %s\n", defpath
);
246 printf ("ctxpath = %s\n", ctxpath
);
247 printf ("context flags = %s\n", snprintb (buf
, sizeof(buf
),
248 (unsigned) ctxflags
, DBITS
));
249 printf ("foldpath = %s\n", mp
->foldpath
);
250 printf ("folder flags = %s\n\n", snprintb(buf
, sizeof(buf
),
251 (unsigned) mp
->msgflags
, FBITS
));
252 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
253 mp
->lowmsg
, mp
->hghmsg
, mp
->nummsg
, mp
->curmsg
);
254 printf ("lowsel=%d hghsel=%d numsel=%d\n",
255 mp
->lowsel
, mp
->hghsel
, mp
->numsel
);
256 printf ("lowoff=%d hghoff=%d\n\n", mp
->lowoff
, mp
->hghoff
);
261 * Print debugging info about all the SELECTED
262 * messages and the sequences they are in.
265 seq_printdebug (struct msgs
*mp
)
271 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
272 if (is_selected (mp
, msgnum
))
273 printf ("%*d: %s\n", DMAXFOLDER
, msgnum
,
274 snprintb (buf
, sizeof(buf
),
275 (unsigned) mp
->msgstats
[msgnum
- mp
->lowoff
], seq_bits (mp
)));