🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #45304

Re: [slrn] post_file_hook

#45304
From: Dawn Owens-Nicholson
Date: Fri, 11 Dec 1998 00:00
78 lines
3430 bytes
Gary Jones wrote:
> I'm trying to use a modification of the example post_file_hook provided with
> slrn. Unfortunately I need the Message-ID header in the file to achieve what
> I want, but it doesn't seem to be present.

There's no other hook you could use, but there might be a backhanded way to
get what you want: set save_posts in your slrn.rc, make post_file_hook scan
the file you set (get_variable_value("save_posts") will tell you what this
file is) and parse the headers you want from that file.  Assuming slrn saves
the file posted to save_posts *before* it runs post_file_hook(), this should
work.

Normally, I'd post a solution that would use fseek() so you could quickly
get the desired info by scanning from the bottom of the file (put data in a
buffer, scan the buffer) but I'm running short on time now, so here's a
quick solution that will take longer because it scans the /whole/ save_posts
file (in other words, execution time scales linearly with input file size).

define last_headers (file)
{
   !if (strlen (file)) return (NULL);

   variable
     line = "",
     position = 0,
     length = 0,
     header = "",
     hash = Assoc_Type[String_Type],
     fp = fopen (file, "r");

   if (fp == NULL)
     verror ("%s: Couldn\'t open %s: %s",
             _function_name (), file, errno_string (errno));

   % First is regex "^From e-mail@host date$" then headers and body.
   while (fgets (&line, fp) != -1)
     {
        if (string_match (line, "^From [^@]+@", 1))
          {
             hash = Assoc_Type[String_Type];
             while (andelse
                     { fgets (&line, fp) != -1 }
                     { string_match (line, "^\\([^:]+\\): \\(.*\\)$", 1) })
               {
                  (position, length) = string_match_nth (1);
                  header = substr (line, position + 1, length);
                  (position, length) = string_match_nth (2);
                  hash[header] = substr (line, position + 1, length);
               }
          }
     }
   if (fclose (fp))
     verror ("%s: Couldn\'t close file: %s",
             _function_name (), errno_string (errno));

   return (hash);
}

This will return a hash (associative array, dictionary) with the headers of
the last archived article.  It expects BSD mailbox-style files, so the
output slrn generates with save_posts should be fine.  Something like:

  define my_last_messageid ()
  {
     variable my_hash = last_headers (get_variable_value ("save_posts"));
     message (my_hash["Message-Id"]);
     .
     .
  }

might be up your alley (be sure to match the capitalization slrn uses for
headers when requesting headers from the hash).

> Dawn? This looks like one for you <g>

I hope this helps.

Technical Details
Message-ID: <slrn77195h.cai.bluemoon@ux6.cso.uiuc.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.mbox.zip!not-for-mail
References: <slrn76ts80.3vvipaj.news@manassa.demon.co.uk>

Show Full Headers
Complete Article Headers
Message-ID: <slrn77195h.cai.bluemoon@ux6.cso.uiuc.edu>
Subject: Re: [slrn] post_file_hook
Date: Fri, 11 Dec 1998 00:00:00 +0000
From: bluemoon@ux6.cso.uiuc.edu (Dawn Owens-Nicholson)
References: <slrn76ts80.3vvipaj.news@manassa.demon.co.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 421068832
Organization: University of Illinois at Urbana-Champaign
User-Agent: slrn/0.9.5.4 (UNIX)
Newsgroups: news.software.readers