changeset 0:4ec1eb102837

Initial revision
author Guido Berhoerster <guido+slrn@berhoerster.name>
date Sat, 14 Mar 2015 11:46:41 +0100
parents
children e50b2ba42af7
files README unread-threads.sl
diffstat 2 files changed, 168 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README	Sat Mar 14 11:46:41 2015 +0100
@@ -0,0 +1,58 @@
+slrn Unread Threads Macro
+=========================
+
+The slrn unread threads macro displays complete threads if they contain at
+least one unread article.
+
+Usage
+-----
+
+The slrn unread threads macro can be used by including it in the .slrnrc user
+initialization file via the `interpret` command, e.g. provided that the file
+unread-threads.sl is located in one of the directories specified by the
+macro_directory configuration variable:
+
+    interpret "unread-threads.sl"
+
+
+Contact
+-------
+
+Please send any feedback, translations or bug reports via email to
+<guido+weechat@berhoerster.name>.
+
+Bug Reports
+-----------
+
+When sending bug reports, please always mention the exact version of the
+macro with which the issue occurs as well as the version of slrn, slang and
+the operating system you are using and make sure that you provide sufficient
+information to reproduce the issue and include any input, output, any error
+messages and slang stack traces.
+
+License
+-------
+
+Except otherwise noted, all files are Copyright (C) 2009 Guido Berhoerster and
+distributed under the following license terms:
+
+Copyright (C) 2009 Guido Berhoerster <guido+slrn@berhoerster.name>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/unread-threads.sl	Sat Mar 14 11:46:41 2015 +0100
@@ -0,0 +1,110 @@
+% unread-threads.sl - display complete threads if they contain unread articles
+%
+% Copyright (C) 2009 Guido Berhoerster <guido+slrn@berhoerster.name>
+%
+% Permission is hereby granted, free of charge, to any person obtaining
+% a copy of this software and associated documentation files (the
+% "Software"), to deal in the Software without restriction, including
+% without limitation the rights to use, copy, modify, merge, publish,
+% distribute, sublicense, and/or sell copies of the Software, and to
+% permit persons to whom the Software is furnished to do so, subject to
+% the following conditions:
+%
+% The above copyright notice and this permission notice shall be included
+% in all copies or substantial portions of the Software.
+%
+% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+% IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+% CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+% TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+% SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+%
+
+%open_log_file(make_home_filename("slrn-debug.log"));
+%_traceback = 1;
+
+implements("UnreadThreads");
+
+define select_group_unread_threads()
+{
+    variable msgid = NULL;
+    variable flags;
+    variable saved_header_flags = Assoc_Type[];
+    variable saved_show_article = get_variable_value("show_article");
+
+    set_integer_variable("show_article", 0);
+    set_prefix_argument(4);
+    if (select_group() == -1)
+        return;
+    reset_prefix_arg();
+
+    uncollapse_threads();
+    while (((msgid == NULL) && (not get_header_flags() & HEADER_READ)) ||
+            header_next_unread())
+    {
+        msgid = extract_article_header("Message-ID");
+        ifnot (strlen(msgid))
+            continue;
+
+        % move on to next unread article if this thread has already been
+        % processed
+        if (assoc_key_exists(saved_header_flags, msgid))
+            continue;
+
+        % move to first article of the current thread
+        while (has_parent())
+            () = header_up(1);
+
+        % save the flags of each article in this thread in saved_header_flags
+        % and mark it unread
+        loop (thread_size())
+        {
+            msgid = extract_article_header("Message-ID");
+            saved_header_flags[msgid] = get_header_flags();
+            call("undelete");
+        }
+
+        % move one article up since "undelete" except for the very last message
+        % moves one article down
+        ifnot (msgid == extract_article_header("Message-ID"))
+            () = header_up(1);
+    }
+
+    % return if there are no unread articles
+    ifnot (length(saved_header_flags))
+    {
+        collapse_threads();
+
+        % clear message area
+        message("");
+
+        return;
+    }
+
+    % remove all read articles and restore flags for the remaining articles
+    call("expunge");
+    foreach msgid, flags(saved_header_flags) using("keys", "values")
+    {
+        () = locate_header_by_msgid(msgid, 0);
+        set_header_flags(flags);
+    }
+
+    % place cursor on first unread article
+    collapse_threads();
+    call("header_bob");
+    if (get_header_flags() & HEADER_READ)
+        header_next_unread();
+
+    % obey show_article setting
+    if (saved_show_article)
+        call("hide_article");
+    set_integer_variable("show_article", saved_show_article);
+
+    % clear message area
+    message("");
+
+    return;
+}
+