head	1.2;
access;
symbols
	tcllib-1-13:1.2
	tcllib-1-12:1.2
	tklib-0-5:1.2
	tcllib-1-11-1:1.2
	tcllib-1-11:1.2
	tcllib-1-10:1.2
	tcllib-1-9:1.2
	tcllib-1-8:1.2
	tcllib-1-7:1.2
	tcllib-1-6-1:1.1.6.1
	tcllib-1-6-branch:1.1.0.6
	tcllib-1-6:1.1
	tcllib-1-4-0:1.1
	tcllib-1-3-0:1.1
	tcllib-1-2-0:1.1.0.4
	RELEASES:1.1.0.2
	tcllib-1-1-0:1.1;
locks; strict;
comment	@# @;


1.2
date	2004.03.09.08.20.18;	author andreas_kupries;	state Exp;
branches;
next	1.1;

1.1
date	2001.08.23.05.24.48;	author andreas_kupries;	state Exp;
branches
	1.1.6.1;
next	;

1.1.6.1
date	2004.05.24.02.58.09;	author andreas_kupries;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Unified the startup header of all applications, using
suggestions made by Stuart Cassof <stwo@@telus.net>.
@
text
@#! /bin/sh
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@@"}

# This application is like 'postit', but written in tcl.
# The only package used is 'nntp' from 'tcllib'.
#
# Takes two arguments: 
# 1) The path to the file listing the articles to push
#    into the NNTP network
# 2) The name of the newsserver to push the articles to.
#
# The path to the spool directory is 1 level above the
# article file.

# Check number of arguments

if {[llength $argv] != 2} {
    puts stderr "$argv0: wrong # args, should be \"$argv0 articles newsserver\""
    exit 1
}

# Retrieve arguments

set articlefile [lindex $argv 0]
set newsserver  [lindex $argv 1]

# Validate file

if {![file exists $articlefile]} {
    puts stderr "$argv0: $articlefile does not exist"
    exit 1
}
if {[file isdirectory $articlefile]} {
    puts stderr "$argv0: $articlefile is not a file"
    exit 1
}
if {![file readable $articlefile]} {
    puts stderr "$argv0: $articlefile is not readable"
    exit 1
}

# Get path and article information

set spoolpath [file dirname [file dirname [file join [pwd] $articlefile]]]
set articles  [split [read [set fh [open $articlefile r]]][close $fh] \n]

puts "spooling from $spoolpath"

# Now we are ready to deal with the newsserver

package require nntp ; # from tcllib

proc nntp_cmd {exit title cmd {oktitle {}}} {
    global argv0 

    puts -nonewline stdout $title
    flush stdout
    if {[catch {
	set res [uplevel 1 $cmd]
    } msg]} {
	puts stdout " error: $msg"
	#puts stderr "$argv0: nntp error: $msg"
	if {$exit} {
	    exit 1
	}
	return 0
    } else {
	if {$oktitle != {}} {
	    puts stdout " $res $oktitle"
	} else {
	    puts stdout " $res"
	}
	return 1
    }
}

# Introduce us to the server

nntp_cmd 1 {open       } {set news [nntp::nntp $newsserver]}
nntp_cmd 1 {mode reader} {$news mode_reader}

# Iterate over all articles in the file.

set lastgroup {}

foreach article $articles {
    set article [string trim $article]
    if {$article == {}} {continue}

    foreach {msgfile id} [split $article] {break}

    # We have to validate the message files too.
    # Invalid files are skipped.

    set msgpath [file join $spoolpath $msgfile]

    if {![file exists $msgpath]} {
	puts stderr "article error: $msgfile does not exist"
	continue
    }
    if {[file isdirectory $msgpath]} {
	puts stderr "article error: $msgfile is not a file"
	continue
    }
    if {![file readable $msgpath]} {
	puts stderr "article error: $msgfile is not readable"
	continue
    }

    set group [join [file split [file dirname $msgfile]] .]

    if {[string compare $group $lastgroup] != 0} {

	if {![nntp_cmd 0 {set group  } {$news group $group}]} {
	    # Group does not exist or other error.
	    # Skip the article, can't post it.
	    continue
	}

	set lastgroup $group
    }

    # Group of the message is current, the message file itself is valid.
    # Proceed and check for existence of the article on the server.
    #                mode reader
    if {[nntp_cmd 0 {stat       } {$news stat $id} {article is present, skip}]} {
	continue
    }

    #continue

    if {[catch {
	set msg [read [set fh [open $msgpath r]]][close $fh]
    }]} {
	puts stderr "article error: $msgfile was deleted between check and actual posting"
        continue
    }

    puts stdout "post [llength [split $msg \n]] lines $id"

    nntp_cmd 0 {post       } {$news post $msg}
}

nntp_cmd 1 {quit       } {$news quit}
exit
@


1.1
log
@2001-08-22  Andreas Kupries <andreas_kupries@@users.sourceforge.net>

	* examples/nntp: Added new example application 'postnews'. This is
	  an example how to use the 'nntp'-client library provided by
	  tcllib.
@
text
@d1 4
a4 3
#!/usr/local/bin/tclsh
# -*- tcl -*-
#
@


1.1.6.1
log
@Downgraded to version 1.3.6, removed -decode extension from
this branch.

Import of ftpd bugfix by Gerald Lester.

Last commit was a bad update, caused duplicates of changes
to appear. Failed testsuite. Removed all the duplicates now.

Fixed SF Tcllib Bug 954328. Mime now adapts at runtime to
whatever version of md5 has been loaded.

Updated test for rewritten adjust which fixed the infinite
looping demonstrated by tests 2.6 and 2.7. Also fixed a var
usage typo which caused a copy of the input to appear in the
output, before the expected formatted result.

Fixed bug in the processing of multi-word section titles for
text based formats.

Fixed bug 951568, regarding the usage of Trf's generic
transform.

Fixed problems with jpeg recognition (was unable to detect a
jpeg file, if it contained exif data).

Changelog for last patch, and updates in related package.

Completed application of code for various fixes.

Rewritten text adjustment and hyphenation, fixing SF TCllib
Bug 882402.

Fixed SF Tcllib Bug 936064, and evals more robust.

Fixed SF Tcllib Bug 893516

Fixed SF Tcllib Patch 763712

Fixed SF Tcllib Patch 758742

Fixed SF Tcllib Bug 620852

Eval usage made more robust and similar.

Fixed SF Tcllib Bug 943146.

Fixed SF Tcllib Bug 940651

SF Tcllib Bug 784519 fixed.

Pat: sak.tcl update for better use of critcl.

Joe: Fix in doctools xml support.

Import bugfix by Pat Thoyts, Handling of data starting with
hyphen/dash

Import of uuencode changes by Jeff Hobbs.

Changed defaults for package 'log'. No output for the all
levels below 'error'.

Unified the startup header of all applications, using
suggestions made by Stuart Cassof <stwo@@telus.net>.

Added testcase for Tcllib SF Bug 860753. The bug itself was
already fixed for Tcllib 1.6.

Fix for bug 899204. Test data file is opened read-only, and
tests made independent of each other.

Bugfix 899152, 899209. Require Tcl 8.2 for installer, delete
file before writing over it.

Import of time fix by Pat Thoyts, patch #905132.

Cleanup fix: Snit depends on Tcl 8.4, this is documented,
however neither package index, nor testsuite enforced the
restriction, allowing for errors. This has been changed now.

Fixed typos
@
text
@d1 3
a3 4
#! /bin/sh
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@@"}

@


