🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #234893

Re: My dysfunctional attemp

#234893
From: John E. Davis
Date: Sat, 01 Aug 2009 21:48
163 lines
6026 bytes
On Sat, 1 Aug 2009 19:44:12 +0000 (UTC), ShadowTek <ShadowTek@invalid.invalid>
wrote:
> Anyway, I was building my own script that made use of a seprerate file
> to store the From and Message-ID headers, and everything seemed to be
> working great towards the end, but then it started failing to apply
> itself to all threads correctly. It's a shame, since it seemed like it was working
> perfectly there for a while. I m not sure if I screwed something up
> towards the end, or I had simply been missing something all along, but
> either way, I'm tired of screwing with it.
>
> I'll go ahead and post my last version of it in case anyone can or wants
> to do anything with it.
>
> Remember, *this version is NOT working properly*.

Below you will find a modified version that I believe works the way
that you intended.  My main purpose here is is to provide some
working examples of slang code.

[...]
> 	variable home_str;
>         variable home_file = popen ("echo $HOME", "r");
>         () = fgets (&home_str, home_file);
>         () = pclose (home_file);

The best way to get the value of an environment variable is to use the
getenv function.  The above should be replaced by:

    variable home_str = getenv ("HOME");

[...]

Here is the code.  I hope you find it instructive.  Thanks, --John

#v+

private variable MsgID_File = "$HOME/slrn_superplonk_mid.txt"$;
private variable From_File = "$HOME/slrn_superplonk_from.txt"$;

private define read_message_ids (file)
{
   variable msgid_list = Assoc_Type[];
   variable fp = fopen (file, "r");
   if (fp != NULL)
     {
	variable line;
	while (-1 != fgets (&line, fp))
	  {
	     % The format is: YYYY/MM/DD msgid.  Break it at the space
	     variable fields = strtok (line);
	     if (length (fields) < 2)
	       continue;
	     msgid_list[fields[1]] = fields[0];
	  }
	() = fclose (fp);
     }
   return msgid_list;
}

private define read_froms (file)
{
   variable from_list = Assoc_Type[];
   variable fp = fopen (file, "r");
   if (fp != NULL)
     {
	variable line;
	while (-1 != fgets (&line, fp))
	  {
	     % The format is: "YYYY/MM/DD from..."
	     variable date = substrbytes (line, 1, 10);
	     variable from = strtrim (substrbytes (line, 12, -1));
	     from_list[from] = date;
	  }
	() = fclose (fp);
     }
   return from_list;
}

private define write_message_ids (msgid_list, file)
{   
   variable fp = fopen (file, "w");
   if (fp == NULL)
     throw OpenError, "Error opening $file"$;
   
   variable date, msgid;
   foreach msgid, date (msgid_list) using ("keys", "values")
     {
	if (-1 == fprintf (fp, "%s %s\n", date, msgid))
	  throw WriteError;
     }
   if (-1 == fclose (fp))
     throw WriteError;
}

private define check_message_ids (msgid_list)
{
   call ("header_bob");
   do
     {
	variable ref, refs = extract_article_header ("References");
	foreach ref (strtok (refs, " "))
	  {
	     if (assoc_key_exists (msgid_list, ref))
	       {
		  set_header_flags(get_header_flags() | HEADER_READ);
		  break;
	       }
	   }
     } while (header_down(1));
}

private define check_from ()
{
   variable msgid_list = read_message_ids (MsgID_File);
   variable from_list = read_froms (From_File);

   call ("header_bob");

   variable today = strftime ("%Y/%m/%d");

   variable dirty = 0;
   do
     {
	variable from = extract_article_header ("From");
	if (assoc_key_exists (from_list, from))
	  {
	     variable msgid = extract_article_header ("Message-ID");
	     msgid_list[msgid] = today;
	     set_header_flags(get_header_flags() | HEADER_READ);
	     dirty = 1;
	  }
     } 
   while (header_down(1));

   check_message_ids (msgid_list);
   if (dirty) write_message_ids (msgid_list, MsgID_File);
}

% You can bind this to a key
public define superplonk ()
{
   variable from = extract_displayed_article_header ("From");
   if (1 != get_yes_no_cancel ("SuperPlonk " + from + " ?"))
     return;
   
   variable fp = fopen (From_File, "a");
   variable today = strftime ("%Y/%m/%d");
   
   if ((-1 == fprintf (fp, "%s %s\n", today, from))
       || (-1 == fclose (fp)))
     throw WriteError;

   set_input_string ("-9000\n+9999"); 
   set_input_chars ("fan");
   call ("create_score");
   call ("quit"); 
   
   message (from + " has been SuperPlonked");
}

() = register_hook ("article_mode_hook", &check_from);

#v-
Technical Details
Message-ID: <slrnh79e2l.3oi.jed@aluche.mit.edu>
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!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.freenet.de!news.unit0.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!bloom-beacon.mit.edu!micro-heart-of-gold.mit.edu!not-for-mail
References: <guhtt9$82j$1@news.motzarella.org> <slrnh0p4lk.9q2.catwheezel@ID-107770.user.individual.net> <slrnh6sm2b.be4.ShadowTek@desktop.localdomain> <20090729080451@usenet.piggo.com> <slrnh6v215.m8d.ShadowTek@desktop.localdomain> <20090729101510@usenet.piggo.com> <slrnh6vnoo.8ce.ShadowTek@desktop.localdomain> <slrnh73i74.imu.jed@aluche.mit.edu> <20090731083455@usenet.piggo.com> <slrnh749g4.qr1.usenet@news.piggo.com> <slrnh74t48.4ch.jed@aluche.mit.edu> <20090731235846@usenet.piggo.com> <slrnh769m0.nk4.jed@aluche.mit.edu> <slrnh796ag.n0g.ShadowTek@desktop.localdomain>

Show Full Headers
Complete Article Headers
Message-ID: <slrnh79e2l.3oi.jed@aluche.mit.edu>
Subject: Re: My dysfunctional attemp
Date: Sat, 01 Aug 2009 21:48:41 +0000
From: "John E. Davis" <jed@jedsoft.org>
References: <guhtt9$82j$1@news.motzarella.org> <slrnh0p4lk.9q2.catwheezel@ID-107770.user.individual.net> <slrnh6sm2b.be4.ShadowTek@desktop.localdomain> <20090729080451@usenet.piggo.com> <slrnh6v215.m8d.ShadowTek@desktop.localdomain> <20090729101510@usenet.piggo.com> <slrnh6vnoo.8ce.ShadowTek@desktop.localdomain> <slrnh73i74.imu.jed@aluche.mit.edu> <20090731083455@usenet.piggo.com> <slrnh749g4.qr1.usenet@news.piggo.com> <slrnh74t48.4ch.jed@aluche.mit.edu> <20090731235846@usenet.piggo.com> <slrnh769m0.nk4.jed@aluche.mit.edu> <slrnh796ag.n0g.ShadowTek@desktop.localdomain>
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!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.freenet.de!news.unit0.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!bloom-beacon.mit.edu!micro-heart-of-gold.mit.edu!not-for-mail
Newsgroups: news.software.readers
Organization: MIT EECS ECF
Lines: 163
Reply-To: davis@space.mit.edu
NNTP-Posting-Host: aluche.mit.edu
X-Trace: micro-heart-of-gold.mit.edu 1249163321 74188 18.75.2.45 (1 Aug 2009
X-Complaints-To: usenet@micro-heart-of-gold.mit.edu
NNTP-Posting-Date: Sat, 1 Aug 2009 21:48:41 +0000 (UTC)
User-Agent: slrn/pre1.0.0-12 (Linux)