Article View: news.software.readers
Article #53804[slrn] A macro for killing threads
From: Christian Perrier
Date: Sun, 07 Nov 1999 00:00
Date: Sun, 07 Nov 1999 00:00
167 lines
7007 bytes
7007 bytes
(for fr.usenet.logiciels readers : vous trouverez ci-dessous une
macro slrn que j'utilise pour "tuer" des enfilades enti�res de fa�on
plus efficace et rapide que par la touche "K" de slrn. La pr�sence
de la commande 'date' GNU est requise pour le bon fonctionnement de
cette macro ce qui exclut les utilisateurs Windows de slrn -d�sol�-
et ceux des Unix sur lesquels 'date' n'a pas l'option -date= .
Comme le dit le texte ci-dessous, la majorit� du code n'est pas de
moi, j'en serais bien incapable. Si vous r�pondez en fran�ais,
faites le sur fr.usenet.logiciels)
Something I want to share with other slrn users.
A few weeks ago, I raised the subject of killing threads with slrn.
With the default settings, the only way to kill threads is to go on
the first article of the thread, press 'K', then answer 'R' for
"References" and so on...
This is not really perfect for quickly killing threads because :
-this relies on the preservation of the very first Message-ID in the
References field by all articles in the thread. However, several
news reading software break this by removing this first Message-ID
when the References field reaches 1000 bytes length (Agent for instance)
-the user needs to enter an expiration date manually
So, I wanted to have something more automagical :
-be able to go on every article of the thread, press a key and then
have a ~/News/Score entry based on all Message-IDs of the References
field of this article with an expiration date automatically set to
XX days in the future (I use 30 days).
With the help of people like Dawn Owens-Nicholson and some others in
this group, I have been able to put the following in my .slrn.sl
file, though my skills in Slang programming are inredibly low...
First, there is a definition of a call_external function which
basically calls an external command and returns the output of this
command. This function uses a temporary file (a better way to have a
unique filename should be used here).
Then, a "kill_thread" function is defined. Be careful : the location
of the scorefile, the score to be given and the number of days in
the future for the expiration date are hardcoded in this function.
This function uses the GNU date command and thus will not work on
Windows systems as well as systems with a date command that doesn't
have the -date= switch (such as Solaris as far as I remember)
Of course, I'm open to all comments on these macros... They can
probably be made less system dependent.
Last comment: if you plan to use this macro, I recommaned to use
Felix Schueller's cleanscore.pl as a cron job for automatically
remove expired score entries. I do not have the location for getting
it. Felix gave it in news.software.readers a few weeks ago.
% The call_external function will call an external command
% and return its output
%
% this has been mainly written by Dawn Owens-Nicholson
%
% Don't forget to edit the tempfile location
define call_external (cmd)
{
% Could be better : find a way to have a unique filename?
variable
tempfile = "/tmp/tempfile",
retval = Global->system (sprintf ("%s >%s", cmd, tempfile)),
fp = fopen (tempfile, "r"),
contents = "";
if (fp == NULL) error ("Can\'t open temp file: " + errno_string (errno));
foreach (fp) using ("line") contents += ();
if (fclose (fp) == -1)
error ("Can\'t close temp file: " + errno_string (errno));
% If you want to use the return code, uncomment the following and
% adapt the call_external calls
% return (retval, contents);
return (contents);
}
% The kill_thread function will insert a score entry
% which will kill all articles containing in References
% at least one of the Message-IDs contained in the References field
% of the current article
%
% Should be able to kill an entire thread by positioning on any of
% its articles
%
% The main part was written by Dawn also
%
% Don't forget to set your own values for scorefile,
% killthread_score and killthread_duration
% This macro relies on the GNU 'date' command. It will thus work only
% on Unix systems with a GNU date command
define kill_thread ()
{
variable scorefile = "/home/bubulle/News/Score"; % <= EDIT THIS LINE!
variable killthread_score = "-100" ;
% Dawn's original code used get_variable_value ("kill_score") there
% but I wanted to have different values for threads killed like this
% and other kills
%
% Use the GNU date syntax below
variable killthread_duration = "30 days" ;
if (is_group_mode ())
error (_function_name () + " doesn\'t work in group mode.");%
variable fp = fopen (scorefile, "a");
% variable fp = fopen (get_variable_value ("scorefile"), "a");
if (fp == NULL) error ("Couldn\'t open scorefile: " + errno_string (errno));
variable line;
% foreach (["[*] % Killing " + extract_article_header ("Subject"),
foreach ([
"",
"[" + extract_article_header ("Newsgroups") + "]",
" % Killing thread : " + extract_article_header ("Subject"),
" Score:: =" + killthread_score,
" Expires: " + string (call_external ("date --date='" + killthread_duration +"' +%d-%m-%Y"))
])
{
line = () + "\n";
if (-1 == fputs (line, fp))
error ("Can\'t write to scorefile: " + errno_string (errno));
}
variable
msgID,
header = "References",
refs = extract_article_header (header);
!if (strlen (refs)) % Must be a thread-starter
{
header = "Message-ID";
refs = extract_article_header (header);
}
foreach (strtok (refs))
{
msgID = ();
if (-1 == fputs (sprintf (" %s: %s\n", header, msgID), fp))
error ("Can\'t write to scorefile: " + errno_string (errno));
}
if (-1 == fclose (fp))
error ("Can\'t close scorefile: " + errno_string (errno));
}
definekey ("kill_thread", "^K", "article");
--
Technical Details
Message-ID:
<slrn82akmh.bqg.bubulle@mykerinos.kheops.frmug.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <slrn82akmh.bqg.bubulle@mykerinos.kheops.frmug.org> Subject: [slrn] A macro for killing threads Date: Sun, 07 Nov 1999 00:00:00 +0000 From: bubulle@mykerinos.kheops.frmug.org (Christian Perrier) Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail X-Deja-AN: 545513108 Approved: Moderation de fr.usenet.logiciels <ful-mods@lists.freenix.org> Content-Transfer-Encoding: 8bit Mail-Copies-To: never Organization: | :noitazinagrO X-Server-Date: 7 Nov 1999 10:22:10 GMT Followup-To: news.software.readers Content-Type: text/plain; charset=iso-8859-15 User-Agent: slrn/0.9.5.7 (UNIX) Mime-Version: 1.0 Reply-To: bubulle@kheops.frmug.org Newsgroups: news.software.readers,fr.usenet.logiciels X-Approved-By: robomod