Article View: news.software.readers
Article #241962Re: [slrnpull] Logging of retrieved articles?
From: ernobe
Date: Fri, 06 Aug 2010 00:01
Date: Fri, 06 Aug 2010 00:01
421 lines
15779 bytes
15779 bytes
Here's an expanded version of it, which includes code that will write slrn
macros to tag the retrieved articles. I've been unable to get slrn to
automatically subscribe new groups, even setting unsubscribe_new_groups to 0
and check_new_groups to 1 explicitly in .slrnrc. Consequently, the
group_mode_startup_hook that the program creates does not recognize new groups
that have article bodies downloaded in accordance with the slrnpull score
file. But this is only the first run, you have to subscribe to the new
groups first, then the macro will set the GROUP_NEW_GROUP_FLAG on it ( N ) to
signal that it is one of the groups that has tagged articles. The program
runs slrn with a special group_mode_startup_hook that only enters and quits
the groups that have tagged articles, and then exits, in order to avoid
loosing tagged articles if the groups are not entered before another run of
slrnpull. So as the program stands, it is necessary to manually
subscribe and enter new groups that have tagged articles, before the next run
of slrnpull. Otherwise tagged articles could be lost in the ( somewhat rare
) eventuality that newer bodiless headers were received in the same thread as
the downloaded article bodies, and the threads OP is not present. Since the
program removes the old tags when the new articles are received, there is
nothing stopping the cleanthreads macro ( see below ) from deleting it and the
whole thread. It is necessary to enter the group once so that the tag
will prevent the cleanthreads macro from deleting it along with the rest of
the thread. Then the tag can be removed and it will cause the cleanthreads
macro to rebuild the thread the second time the group is entered. You will
have to edit four lines of the program according to your setup, and these are:
1. The location of your slrnpull conf file
2. The slrnpull command line
3. The location of where this program will keep its files
4. The location of the slrnpull spool directory
Also, for the call to slrn you need a copy of your .slrnrc file in the
directory you run this in, unless you edit that too. It must contain the
three calls to the macros being used ( two of which were created by the
program itself, and if you edited the location of the new .slrnrc file you
have to edit their location as well ):
interpret cleanthreads.sl
interpret mythreads.sl
interpret groups.sl
procedure main()
v := []
d := []
e := []
s := open( "/home/roy/spool/slrnpull.conf" ) | stop( "no slrnpull conf file" )
while s1 := read( s ) do {
if s1[ 1 ] == "#" then next
s1 ? {
s2 := tab( upto( ' ' ) | 0 )
if s2 == ( "default" | "" ) then next
else put( d, s2 )
} }
system( "slrnpull -d /home/roy/spool --fetch-score 1" ) | exit()
every put( v, m1( !d ) )
if *v > 0 then {
m := open( "mythreads.sl", "crw" )
n := open( "groups.sl", "crw" )
write( m, "define my_groups ()\n{ variable mm = current_newsgroup (),dma,hhh,list;" )
every b := !v do {
b1 := get( b )
b2 := get( b )
b3 := get( b )
write( m, "variable " || b[ 2 ] || "_threads = {" )
every u := open( b3 || "/" || !b1, "r" ) do
{
b2 -:= 1
while c := read( u ) do {
( c[ 1:9 ] == "Message-" ) & break
}
writes( m, "\"", c[ 13:0 ], "\"" )
if b2 > 0 then write( m, "," )
close( u )
}
write( m, " };" )
put( e, b )
}
write( m, "switch (mm)" )
every e1 := !e do {
write( m, "{ case \"", e1[ 1 ], "\" : list = ", e1[ 2 ] || "_threads; }" )
}
write( m, "{ list = {}; }\nhhh = length (list);\nwhile (hhh)\n{ hhh--;\n",
"dma = list[hhh];\nif (1 == locate_header_by_msgid (dma,0))\n",
"set_header_flags (12); }\ncollapse_threads ();\nmake_clean_threads (); }\n",
"() = register_hook (\"article_mode_startup_hook\",\"my_groups\");\n",
"define group_mode_startup_hook ()\n{variable dma, hhh, news = {" )
write( n, "define group_mode_startup_hook ()\n{variable dma, hhh, news = {" )
while e2 := get( e ) do {
writes( n, "\"", !e2, "\"" )
writes( m, "\"", !e2, "\"" )
if *e > 0 then { write( n, "," ); write( m, "," ) } }
write( n, " };\nhhh = length (news);\nwhile (hhh)\n{ hhh--;\ndma = news[hhh];\n",
"set_group_order (dma);\ngroup_up_n (1);\nif (dma == current_newsgroup ())\n",
"{select_group ();\ncall(\"quit\");}}\ncall(\"quit\");}" )
write( m, " };\nhhh = length (news);\nwhile (hhh)\n{ hhh--;\ndma = news[hhh];\n",
"set_group_order (dma);\ngroup_up_n (1);\nset_group_flags (2); } }" )
# must uncomment this to view the number of messages for each group ( see below )
# delay( 5000 )
system( "slrn -n -w0 -i groupmoderc --debug slrnfile" )
}
end
procedure m1( s )
s2 := ""
f := "/home/roy/spool/news/"
g := ""
k := []
g1 := "/home/roy/clean/"
g6 := []
g7 := []
s ? { while s1 := tab( upto( '.' ) ) do {
f ||:= s1 || "/"
s2 ||:= s1[ 1:2 ]
move( 1 ) }
s3 := tab( 0 )
f ||:= s3
s2 ||:= s3[ 1:4 ]
every g ||:= ( !s2 ** &letters )
}
n := ( open( f || "/.headers" ) | "" )
n1 := !n
\n1 ? {
repeat {
n2 := tab( upto( ',' ) | 0 )
if numeric( n2 ) then {
put( k, integer( n2 ) )
move( 1 ) | break
next
}
n2 ? {
k1 := integer( tab( upto( '-' ) ) )
move( 1 )
k2 := integer( tab( 0 ) )
put( k, k1 )
while k1 +:= 1 do {
put( k, k1 )
if k1 = k2 then break
}
}
move( 1 ) | break }
}
g2 := g1 || g || "-spool"
system( "ls " || f || " > " || g2 ) | stop( "unable to open directory" )
g3 := open( g2, "rw" )
g4 := g1 || g || "-allbodies"
g5 := open( g4, "rw" | "crw" )
# get existing headers and bodies
while put( g6, integer( read( g3 ) ) )
while put( g7, integer( read( g5 ) ) )
# find new total bodies and newer bodies
g8 := set( g6 ) -- set( k )
g9 := g8 -- set( g7 )
h := *g9
# if uncommented, this prints the number of new bodies for each group ( see above )
# write( s, ": ", h, " new messages" )
if h > 0 then {
g01 := g1 || g || "-bodies"
g02 := open( g01, "crw" )
g03 := open( g1 || g || "-newbodies", "crw" )
every write( g02, !g8 )
every write( g03, !g9 )
close( g02 )
close( g03 )
system( "mv " || g01 || " " || g4 )
return [ g9, h, f, s, g ] }
end
I'm wouldn't be posting this if I wasn't pretty certain it works as
advertized. It has been tested and corrected in every part that could
have errors. The only requirement for regular slrn use is to have
'interpret' lines for two of the macros ( without the groups.sl macro ). Here
is a copy of my current mythreads.sl macro:
define my_groups ()
{ variable mm = current_newsgroup (),dma,hhh,list;
variable apzen_threads = {
"<-c6dnZqA1_jX1GDWnZ2dnUVZ_q2dnZ2d@earthlink.com>" };
switch (mm)
{ case "alt.philosophy.zen" : list = apzen_threads; }
{ list = {}; }
hhh = length (list);
while (hhh)
{ hhh--;
dma = list[hhh];
if (1 == locate_header_by_msgid (dma,0))
set_header_flags (12); }
collapse_threads ();
make_clean_threads (); }
() = register_hook ("article_mode_startup_hook","my_groups");
define group_mode_startup_hook ()
{variable dma, hhh, news = {
"alt.philosophy.zen" };
hhh = length (news);
while (hhh)
{ hhh--;
dma = news[hhh];
set_group_order (dma);
group_up_n (1);
set_group_flags (2); } }
There is only one message-id for one newsgroup, both of which could obviously
be multiple. But this is enough to see what it's doing. Then here is the
groups.sl macro:
define group_mode_startup_hook ()
{variable dma, hhh, news = {
"alt.philosophy.zen" };
hhh = length (news);
while (hhh)
{ hhh--;
dma = news[hhh];
set_group_order (dma);
group_up_n (1);
if (dma == current_newsgroup ())
{select_group ();
call("quit");}}
call("quit");}
As you can see, they both define the group_mode_startup_hook, so the latter
is used when running slrnpull, the former when running slrn. Then here is the
make_clean_thread function:
define make_clean_threads ()
{
variable amd, dma, hhh, list;
list = {};
call ("header_bob");
do
{
if (not ("" == extract_article_header ("References")))
{
if (1 == get_body_status ())
{
call ("delete");
header_up (1);
}
else
{
amd = extract_article_header ("Message-ID");
list_insert (list, amd);
}
}
else if (1 == thread_size ())
set_header_flags (HEADER_HIGH_SCORE);
}
while (header_down (1));
call ("expunge");
hhh = length (list);
while (hhh)
{
hhh--;
dma = list[hhh];
() = locate_header_by_msgid (dma,0);
set_prefix_argument (2);
call ("get_parent_header");
}
collapse_threads ();
call("header_bob");
() = header_next_unread ();
}
The difference between this definition and the one given in the true offline
mode thread is that it sets a high score on posts that have no replies, and
moves the cursor to the next unread post. This is all that is required for
the Icon program to work. The others, mentioned below are complementary to
the offline mode way of doing things. It really doesn't make sense using this
unless some configuration variables are set in slrn:
server 'your slrnpull spool directory' 'your newsrc file'
set server_object "spool"
set sorting_method 12
set custom_sort_by_threads 1
set custom_sort_order "Highscore,body,lines|Body"
The capitalized body entry above ensures that articles with bodies will be
displayed first inside the threads.
set post_object "nntp"
set read_active 1
The read_active is set because you will use it instead of the nntp server to
subscribe to new groups. To add a group first add it to the slrnpull conf
file, as mentioned previously, then it will add it to the active
file, and unless this is set slrn will not find it.
set spool_inn_root "your slrnpull spool directory"
set spool_root "the spool directory news directory"
set spool_nov_root "same as above"
% These are relative to spool_inn_root unless they start with "/".
set spool_active_file "data/active"
% This value is relative to the directories under spool_nov_root:
set spool_nov_file ".overview"
set spool_check_up_on_nov 1
header_display_format 0 "%F%B %?C?%3c? %?P?%T%3l&%3l%15g%s? %r"
set overview_date_format " %d %b %H:%M"
set top_status_line " %d%-9g%t"
set header_status_line " Group: %n%-4g%P"
set art_status_line " %s %-4g%P"
set group_status_line " "
set group_help_line ""
set header_help_line ""
set art_help_line ""
set use_header_numbers 0
visible_headers ""
setkey article article_line_down "<Down>"
setkey article article_line_up "<Up>" % Scroll article up one line
setkey article article_page_down "<Space>" % Scroll article down one page
setkey article article_page_up "b" % Scroll article up one page
setkey article article_left "<" % Pan article to the left
setkey article article_right ">" % Pan article to the right
setkey article header_line_down "<PageDown>" % Move to next article
setkey article header_line_up "<PageUp>" % Move to previous article
setkey article header_page_up "<Backspace>"
% setkey article delete ( see below ) "d" % Mark article as read
setkey article hide_article "/" % Hide/Show the article window
setkey article toggle_collapse_threads "<Return>" % Collapse/Uncollapse thread
Here are some more definitions from the cleanthreads macro that
deal with posting, they call another Icon program that writes an slrnpull
scorefile to retrieve replies to it ( given below ).
define mycont_followup ()
{
variable cmd = "mycont", mdo, amd = current_newsgroup ();
call ("followup");
mdo = get_variable_value ("save_posts");
() = system (sprintf ("%s '%s' '%s'", cmd, mdo, amd));
}
define mycont_post ()
{
variable cmd = "mycont", mdo, amd = current_newsgroup ();
call ("post");
mdo = get_variable_value ("save_posts");
() = system (sprintf ("%s '%s' '%s'", cmd, mdo, amd));
}
define fudge_save_file ()
{
variable tm = localtime (_time ());
set_string_variable ("save_posts",
sprintf ("/home/roy/News/sent/%d%02d%02d-%02d%02d%02d.news",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec ));
}
() = register_hook ("post_file_hook", "fudge_save_file");
These are some definitions for navigating threads that have read articles:
define going_down ()
{
header_down (1);
article_line_down (1);
}
define going_up ()
{
header_up (1);
article_line_down (1);
}
This is one that replaces the delete function so that the next unread header
isn't jumped to after deleting one.
define del_my_tagged ()
{
variable amd;
if (0 == is_thread_collapsed ())
{
set_header_flags (HEADER_READ);
header_down (1);
}
else
{
uncollapse_thread ();
amd = thread_size ();
amd--;
while (amd)
{
amd--;
set_header_flags (HEADER_READ);
header_down (1);
}
set_header_flags (HEADER_READ);
collapse_thread ();
header_down (1);
}
}
definekey ("mycont_followup", "8", "article");
definekey ("mycont_post", "9", "article");
definekey ("going_down", "<Right>", "article");
definekey ("going_up", "<Left>", "article");
definekey ("del_my_tagged", "d", "article");
And finally here is the Icon program that writes the slrnpull scorefile:
procedure main( s )
r := open( s[ 1 ], "rw" ) | exit()
n := open( "/home/roy/spool/score", "rw" )
while b := read( r ) do {
case b[ 1:9 ] of {
"Subject:" : sub := b
"Message-" : mes := b[ 13:0 ] }
\sub & \mes & break
}
seek( n, 0 )
write( n, "[", s[ 2 ], "]", "\n",
"Score: 1", "\n",
"% ", sub, "\n",
"References: ", mes )
close( r )
close( n )
end
--
"The world of existence is an emanation of the merciful attribute of God."
Abdu'l-Baha
http://www.costarricense.cr/pagina/ernobe
Technical Details
Message-ID:
<i3fjdg$2l4$1@news.eternal-september.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!num2.nntp.dca.giganews.com!num1.nntp.dca.giganews.com!number.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!novia!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!.POSTED!not-for-mailReferences:
<i2chko$f8$1@news.eternal-september.org> <i2floq$gtt$1@news.eternal-september.org>Show Full Headers
Complete Article Headers
Message-ID: <i3fjdg$2l4$1@news.eternal-september.org> Subject: Re: [slrnpull] Logging of retrieved articles? Date: Fri, 06 Aug 2010 00:01:53 +0000 From: ernobe <ernobe@yahoo.com> References: <i2chko$f8$1@news.eternal-september.org> <i2floq$gtt$1@news.eternal-september.org> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!num2.nntp.dca.giganews.com!num1.nntp.dca.giganews.com!number.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!novia!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!.POSTED!not-for-mail Newsgroups: news.software.readers Organization: Baha'i Faith Lines: 421 Injection-Date: Fri, 6 Aug 2010 00:01:53 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="JELnH+BdEro/urHfghrQkg"; logging-data="2724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199mPU+DyvcKbbMwPLWcVrkam5011WcMpg=" User-Agent: slrn/pre1.0.0-18 (Linux) Cancel-Lock: sha1:ivTTxbV5fx8WZihUJl90x7LLdoY=