comparison unread-threads.sl @ 0:4ec1eb102837

Initial revision
author Guido Berhoerster <guido+slrn@berhoerster.name>
date Sat, 14 Mar 2015 11:46:41 +0100
parents
children e50b2ba42af7
comparison
equal deleted inserted replaced
-1:000000000000 0:4ec1eb102837
1 % unread-threads.sl - display complete threads if they contain unread articles
2 %
3 % Copyright (C) 2009 Guido Berhoerster <guido+slrn@berhoerster.name>
4 %
5 % Permission is hereby granted, free of charge, to any person obtaining
6 % a copy of this software and associated documentation files (the
7 % "Software"), to deal in the Software without restriction, including
8 % without limitation the rights to use, copy, modify, merge, publish,
9 % distribute, sublicense, and/or sell copies of the Software, and to
10 % permit persons to whom the Software is furnished to do so, subject to
11 % the following conditions:
12 %
13 % The above copyright notice and this permission notice shall be included
14 % in all copies or substantial portions of the Software.
15 %
16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 %
24
25 %open_log_file(make_home_filename("slrn-debug.log"));
26 %_traceback = 1;
27
28 implements("UnreadThreads");
29
30 define select_group_unread_threads()
31 {
32 variable msgid = NULL;
33 variable flags;
34 variable saved_header_flags = Assoc_Type[];
35 variable saved_show_article = get_variable_value("show_article");
36
37 set_integer_variable("show_article", 0);
38 set_prefix_argument(4);
39 if (select_group() == -1)
40 return;
41 reset_prefix_arg();
42
43 uncollapse_threads();
44 while (((msgid == NULL) && (not get_header_flags() & HEADER_READ)) ||
45 header_next_unread())
46 {
47 msgid = extract_article_header("Message-ID");
48 ifnot (strlen(msgid))
49 continue;
50
51 % move on to next unread article if this thread has already been
52 % processed
53 if (assoc_key_exists(saved_header_flags, msgid))
54 continue;
55
56 % move to first article of the current thread
57 while (has_parent())
58 () = header_up(1);
59
60 % save the flags of each article in this thread in saved_header_flags
61 % and mark it unread
62 loop (thread_size())
63 {
64 msgid = extract_article_header("Message-ID");
65 saved_header_flags[msgid] = get_header_flags();
66 call("undelete");
67 }
68
69 % move one article up since "undelete" except for the very last message
70 % moves one article down
71 ifnot (msgid == extract_article_header("Message-ID"))
72 () = header_up(1);
73 }
74
75 % return if there are no unread articles
76 ifnot (length(saved_header_flags))
77 {
78 collapse_threads();
79
80 % clear message area
81 message("");
82
83 return;
84 }
85
86 % remove all read articles and restore flags for the remaining articles
87 call("expunge");
88 foreach msgid, flags(saved_header_flags) using("keys", "values")
89 {
90 () = locate_header_by_msgid(msgid, 0);
91 set_header_flags(flags);
92 }
93
94 % place cursor on first unread article
95 collapse_threads();
96 call("header_bob");
97 if (get_header_flags() & HEADER_READ)
98 header_next_unread();
99
100 % obey show_article setting
101 if (saved_show_article)
102 call("hide_article");
103 set_integer_variable("show_article", saved_show_article);
104
105 % clear message area
106 message("");
107
108 return;
109 }
110