Thread View: news.software.readers
4 messages
4 total messages
Started by Dawn Owens-Nicholson
Fri, 11 Dec 1998 00:00
Re: [slrn] post_file_hook
Author: Dawn Owens-Nicholson
Date: Fri, 11 Dec 1998 00:00
Date: Fri, 11 Dec 1998 00:00
78 lines
3430 bytes
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.
Re: [slrn] post_file_hook
Author: Dawn Owens-Nicholson
Date: Fri, 11 Dec 1998 00:00
Date: Fri, 11 Dec 1998 00:00
6 lines
811 bytes
811 bytes
I wrote: > There's no other hook you could use [...] Glancing at src/post.c, I see post_filter_hook() is another alternative.
Re: [slrn] post_file_hook
Author: Dawn Owens-Nicholson
Date: Tue, 15 Dec 1998 00:00
Date: Tue, 15 Dec 1998 00:00
19 lines
1536 bytes
1536 bytes
Gary Jones wrote: > What was the 'Assoc_Type' BTW? I can't find it in any of the > documentation I have, and indeed I get error messages if I try to use > the code as-is. Sounds like you need to get the latest S-Lang snapshot (in ftp://space.mit.edu/pub/davis/slang/snapshots/). In S-Lang, associative arrays (Assoc_Type) are arrays indexed with strings instead of non-negative integers (they're also called hashes and dictionaries in other languages such as Perl and Smalltalk, respectively). > Thanks for the assist, Dawn. I will probably finish it up after > Christmas, as I'm off to Germany for 10 days on Friday, wahoo!. Sure. I might work on it again implementing the buffered read I mentioned earlier (that approach will work quickly no matter how long the archived post file is).
Re: [slrn] post_file_hook
Author: John E. Davis
Date: Thu, 17 Dec 1998 00:00
Date: Thu, 17 Dec 1998 00:00
45 lines
2150 bytes
2150 bytes
On 11 Dec 1998 04:51:01 GMT, Dawn Owens-Nicholson <bluemoon@ux6.cso.uiuc.edu>
wrote:
>define last_headers (file)
>{
[...]
> hash = Assoc_Type[String_Type],
[...]
> define my_last_messageid ()
> {
> variable my_hash = last_headers (get_variable_value ("save_posts"));
> message (my_hash["Message-Id"]);
> .
> .
> }
It is probably a good idea to declare the associative array as
follows:
hash = Assoc_Type [String_Type, ""];
This will cause "" to be returned when one tries to access a
non-existent entry in the associative array.
>might be up your alley (be sure to match the capitalization slrn uses for
>headers when requesting headers from the hash).
One can also use `strup' to convert a string to uppercase before
accessing the array, e.g.,
hash [strup(header_name)] = header_value;
.
.
message (hash[strup ("Message-Id")]);
Keep in mind that one needs slang version 1.3.x to use associative
arrays and all the other goodines that the new version provides. It
is available from ftp://space.mit.edu/pub/davis/slang/snapshots and is
a drop-in replacement for 1.2.x. The next officially released version
of slang will be 1.4.x. The 1.3.x versions are snapshots of what will
be 1.4.x.
--John
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads