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