🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #85203

Re: [XNews] Saving articles from particular newsgroups to certain directories

#85203
From: Murray Peterson
Date: Sat, 06 Oct 2001 23:39
94 lines
4015 bytes
BlueJAMC <BlueJAMC@noneofthatspamhereatnetzero.net> wrote in 
news:Xns9132AC1268BE4BJAMC@207.225.159.8:

> Also, 
> if anyone knows of any MBX "extractors"--something which will take an 
> MBX file, extract it to individual files for each entry, and use a 
> particular field for the filename, that could also work.

OK -- here's a Perl script which extracts articles from .mbx files and 
saves them by the subject name (mangled to force legal characters, with 
successive ".1" sequences added for multiple articles with the same subject 
line).  Personally, I would have thought that doing a "Save as" operation 
on the desired articles would have been much easier and neater.

# Program to extract individual files from an Xnews .mbx file
# Usage: "perl mbx-extract.pl <mbx file>"
#
# Copyright 1999 by Murray Peterson
# Freeware -- any use by anyone is acceptable
#
# ------------------------------------------------------------------------

use strict;
my (@article, $mbxfile, $file, $newfile, $line);
		 
# ------------------------------------------------------------------------
$mbxfile = $ARGV[0];

if ($mbxfile eq "")
{
	printf("Usage: perl $0 <mbx file>\n");
	exit(1);
}

if (!open(DAT, "$mbxfile"))
{
	printf("\nUnable to open mbx file $file\n");
	exit(1);
}

while(<DAT>)
{
	$line = $_;

	if ($line =~ /^From \?\?\?/)
	{
		# Its a new message - close off the old one
		if ($newfile ne "")
		{
			print NEWFILE @article;
			close(NEWFILE);
		}
		$newfile = "";
		@article = "";
	}
	elsif ($line =~ /^Subject:/)
	{
		# a new file name
		$line =~ s/^Subject: *//;
		$newfile = $line;
           # Clean up the file name so it will open
		chomp($newfile);
		$newfile =~ s/ +/-/g;
		$newfile =~ s/[^a-zA-Z0-9 ]/\-/g;
		$newfile .= ".txt";
		while (open(NEWFILE, "< $newfile"))
		{
			# It already exists -- add a digit to the end
			$newfile =~ s/.txt$/.1.txt/;
			close(NEWFILE);
		}
		if (!open(NEWFILE, "> $newfile"))
		{
			printf("Unable to open file: %s\n", $newfile);
			exit(1);
		}
	}
	push(@article, $line);	# save line
}
if ($newfile ne "")
{
	print NEWFILE @article;
	close(NEWFILE);
}
close(DAT);

# -------------------------------------------------------------------------
-

-- 
Murray Peterson
Email: murray_peterson@home.com (remove underscore)
URL:   http://www.members.home.net/murraypeterson
Technical Details
Message-ID: <Xns9132B3DCDDDCBfarkle@24.71.223.45>
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!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed1.uncensored-news.com!propagator-la!news-in-la.newsfeeds.com!news-in.superfeed.net!pd2nf1so.cg.shawcable.net!residential.shaw.ca!news1.calgary.shaw.ca.POSTED!not-for-mail
References: <Xns912C780CD877ABlueJAMC@207.225.159.8> <Xns912C89E6EFAE0imamidnighttoken@65.82.44.7> <Xns912D60F251C50BlueJAMC@207.225.159.7> <Xns912F9375A7650damiansmailandnewsco@64.152.100.102> <Xns9130916BC45DDBlueJAMC@207.225.159.7> <Xns9130BBD527020damiansmailandnewsco@64.152.100.102> <Xns9130B47515FC2imamidnighttoken@65.82.44.7> <Xns9130BAB6747D8BJAMC@207.225.159.6> <Xns9130C33E811DDimamidnighttoken@65.82.44.7> <Xns91321212940Crcamesz@127.0.0.1> <Xns913259E086C9BJAMC@207.225.159.7> <Xns913276D26DFCAimamidnighttoken@65.82.44.7> <Xns9132AC1268BE4BJAMC@207.225.159.8>

Show Full Headers
Complete Article Headers
Message-ID: <Xns9132B3DCDDDCBfarkle@24.71.223.45>
Subject: Re: [XNews] Saving articles from particular newsgroups to certain directories
Date: Sat, 06 Oct 2001 23:39:30 GMT
From: mwp@home.com.invalid (Murray Peterson)
References: <Xns912C780CD877ABlueJAMC@207.225.159.8> <Xns912C89E6EFAE0imamidnighttoken@65.82.44.7> <Xns912D60F251C50BlueJAMC@207.225.159.7> <Xns912F9375A7650damiansmailandnewsco@64.152.100.102> <Xns9130916BC45DDBlueJAMC@207.225.159.7> <Xns9130BBD527020damiansmailandnewsco@64.152.100.102> <Xns9130B47515FC2imamidnighttoken@65.82.44.7> <Xns9130BAB6747D8BJAMC@207.225.159.6> <Xns9130C33E811DDimamidnighttoken@65.82.44.7> <Xns91321212940Crcamesz@127.0.0.1> <Xns913259E086C9BJAMC@207.225.159.7> <Xns913276D26DFCAimamidnighttoken@65.82.44.7> <Xns9132AC1268BE4BJAMC@207.225.159.8>
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!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed1.uncensored-news.com!propagator-la!news-in-la.newsfeeds.com!news-in.superfeed.net!pd2nf1so.cg.shawcable.net!residential.shaw.ca!news1.calgary.shaw.ca.POSTED!not-for-mail
Newsgroups: news.software.readers
Organization: None
User-Agent: Xnews/4.05.11
Lines: 93
NNTP-Posting-Host: 24.64.73.53
X-Complaints-To: abuse@shaw.ca
X-Trace: news1.calgary.shaw.ca 1002411570 24.64.73.53 (Sat, 06 Oct 2001 17:39:30 MDT)
NNTP-Posting-Date: Sat, 06 Oct 2001 17:39:30 MDT