annotate unread-threads.sl @ 1:e50b2ba42af7 default tip

Change license to GPL-2.0+
author Guido Berhoerster <guido+slrn@berhoerster.name>
date Sat, 25 Jul 2015 17:13:16 +0200
parents 4ec1eb102837
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
1 % unread-threads.sl - display complete threads if they contain unread articles
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
2 %
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
3 % Copyright (C) 2009 Guido Berhoerster <guido+slrn@berhoerster.name>
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
4 %
1
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
5 % This program is free software; you can redistribute it and/or
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
6 % modify it under the terms of the GNU General Public License
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
7 % as published by the Free Software Foundation; either version 2
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
8 % of the License, or (at your option) any later version.
0
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
9 %
1
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
10 % This program is distributed in the hope that it will be useful,
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
11 % but WITHOUT ANY WARRANTY; without even the implied warranty of
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
13 % GNU General Public License for more details.
0
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
14 %
1
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
15 % You should have received a copy of the GNU General Public License
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
16 % along with this program; if not, write to the Free Software
e50b2ba42af7 Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents: 0
diff changeset
17 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
18
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
19 %open_log_file(make_home_filename("slrn-debug.log"));
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
20 %_traceback = 1;
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
21
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
22 implements("UnreadThreads");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
23
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
24 define select_group_unread_threads()
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
25 {
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
26 variable msgid = NULL;
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
27 variable flags;
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
28 variable saved_header_flags = Assoc_Type[];
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
29 variable saved_show_article = get_variable_value("show_article");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
30
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
31 set_integer_variable("show_article", 0);
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
32 set_prefix_argument(4);
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
33 if (select_group() == -1)
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
34 return;
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
35 reset_prefix_arg();
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
36
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
37 uncollapse_threads();
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
38 while (((msgid == NULL) && (not get_header_flags() & HEADER_READ)) ||
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
39 header_next_unread())
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
40 {
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
41 msgid = extract_article_header("Message-ID");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
42 ifnot (strlen(msgid))
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
43 continue;
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
44
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
45 % move on to next unread article if this thread has already been
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
46 % processed
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
47 if (assoc_key_exists(saved_header_flags, msgid))
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
48 continue;
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
49
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
50 % move to first article of the current thread
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
51 while (has_parent())
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
52 () = header_up(1);
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
53
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
54 % save the flags of each article in this thread in saved_header_flags
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
55 % and mark it unread
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
56 loop (thread_size())
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
57 {
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
58 msgid = extract_article_header("Message-ID");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
59 saved_header_flags[msgid] = get_header_flags();
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
60 call("undelete");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
61 }
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
62
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
63 % move one article up since "undelete" except for the very last message
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
64 % moves one article down
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
65 ifnot (msgid == extract_article_header("Message-ID"))
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
66 () = header_up(1);
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
67 }
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
68
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
69 % return if there are no unread articles
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
70 ifnot (length(saved_header_flags))
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
71 {
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
72 collapse_threads();
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
73
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
74 % clear message area
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
75 message("");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
76
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
77 return;
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
78 }
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
79
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
80 % remove all read articles and restore flags for the remaining articles
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
81 call("expunge");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
82 foreach msgid, flags(saved_header_flags) using("keys", "values")
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
83 {
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
84 () = locate_header_by_msgid(msgid, 0);
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
85 set_header_flags(flags);
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
86 }
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
87
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
88 % place cursor on first unread article
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
89 collapse_threads();
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
90 call("header_bob");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
91 if (get_header_flags() & HEADER_READ)
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
92 header_next_unread();
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
93
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
94 % obey show_article setting
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
95 if (saved_show_article)
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
96 call("hide_article");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
97 set_integer_variable("show_article", saved_show_article);
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
98
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
99 % clear message area
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
100 message("");
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
101
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
102 return;
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
103 }
4ec1eb102837 Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff changeset
104