X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fseq_setunseen.c;h=bd57a2c5be8db2410b212d23c4bca4bd2e1abeaa;hp=ea18d176d30344e60efbd1cf90e2caf1efdc7be9;hb=88b2142594d5ea1e8385dae5eca81eed1018c555;hpb=5dd6771b28c257af405d7248639ed0e3bcdce38b diff --git a/sbr/seq_setunseen.c b/sbr/seq_setunseen.c index ea18d17..bd57a2c 100644 --- a/sbr/seq_setunseen.c +++ b/sbr/seq_setunseen.c @@ -1,60 +1,70 @@ - /* - * seq_setunseen.c -- add/delete all messages which have the SELECT_UNSEEN - * -- bit set to/from the Unseen-Sequence - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ +** seq_setunseen.c -- add/delete all messages which have the SELECT_UNSEEN +** -- bit set to/from the Unseen-Sequence +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ #include +#include /* - * We scan through the folder and act upon all messages - * that are marked with the SELECT_UNSEEN bit. - * - * If seen == 1, delete messages from unseen sequence. - * If seen == 0, add messages to unseen sequence. - */ - +** We scan through the folder and act upon all messages +** that are marked with the SELECT_UNSEEN bit. +** +** Either add messages to or (if doadd is false) delete messages from +** the unseen sequence(s). +*/ void -seq_setunseen (struct msgs *mp, int seen) +seq_setunseen(struct msgs *mp, int doadd) { - int msgnum; - char **ap, *cp, *dp; + int n; + char **ap, *cp, *dp; - /* - * Get the list of sequences for Unseen-Sequence - * and split them. - */ - if ((cp = context_find (usequence))) { - dp = getcpy (cp); - if (!(ap = brkstring (dp, " ", "\n")) || !*ap) { - free (dp); - return; + if (mp->lowmsg == 0) { + return; } - } else { - return; - } - /* - * Now add/delete each message which has the SELECT_UNSEEN - * bit set to/from each of these sequences. - */ - for (; *ap; ap++) { - if (seen) { - /* make sure sequence exists first */ - if (seq_getnum(mp, *ap) != -1) - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_unseen (mp, msgnum)) - seq_delmsg (mp, *ap, msgnum); + /* + ** Get the list of sequences for Unseen-Sequence + ** and split them. + */ + if ((cp = context_find(usequence))) { + dp = mh_xstrdup(cp); } else { - for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) - if (is_unseen (mp, msgnum)) - seq_addmsg (mp, *ap, msgnum, -1, 0); + /* not set in profile, thus use the default */ + dp = mh_xstrdup(seq_unseen); + } + if (!(ap = brkstring(dp, " ", "\n")) || !*ap) { + /* contains no sequence name, i.e. we're finished */ + mh_free0(&dp); + return; + } + + /* + ** Now add/delete each message which has the SELECT_UNSEEN + ** bit set to/from each of these sequences. + */ + for (; *ap; ap++) { + if (doadd) { + for (n = mp->lowmsg; n <= mp->hghmsg; n++) { + if (is_unseen(mp, n)) { + seq_addmsg(mp, *ap, n, -1, 0); + } + } + } else { + /* make sure sequence exists first */ + if (seq_getnum(mp, *ap) != -1) { + for (n = mp->lowsel; n <= mp->hghsel; n++) { + if (is_unseen(mp, n)) { + seq_delmsg(mp, *ap, n); + } + } + } + } } - } - free (dp); + mh_free0(&dp); }