1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
All commands require a 'package require nntp'
1. Connecting to default news server
nntp::nntp
2. Connecting to non-default news server at non-default port
nntp::nntp nntpserver.example.net 110
3. Connection to default nntp server and getting a list of newsgroups.
# It might take awhile to print all the newsgroups
set connection [nntp::nntp]
set newsgroups [list ]
foreach newsgroup [$connection list] {
lappend newsgroups [lindex $newsgroup 0]
}
puts [join $newsgroups ", "]
4. Get basic information about a newsgroup
set connection [nntp::nntp]
foreach {total first last group} [$connection group comp.lang.tcl] {
break
}
puts " newsgroup: $group\n message count: $total\n first message: $first\n\
last message: $last"
5. Get your daily dose of c.l.t. from a tcl prompt
set connection [nntp::nntp]
$connection group comp.lang.tcl
puts [join [$connection article] \n]
# Repeat this until there are no more messages to read:
$connection next
puts [join [$connection article] \n]
6. Get the number, who sent the message, and the subjects of the first
10 messages in c.l.t
set connection [nntp::nntp]
$connection group comp.lang.tcl
set messageList [list ]
foreach {total first last group} [$connection group comp.lang.tcl] {
break
}
# Since we only want to see the first 10 messages, set last to $first + 10
set last [expr {$first + 10}]
set subjectList [$connection xhdr subject "$first-$last"]
set fromList [$connection xhdr from "$first-$last"]
foreach subject $subjectList from $fromList {
if {([regexp {(\d+)\s+([^\s].*)} $from match number from] > 0) &&
([regexp {\d+\s+([^\s].*)} $subject match subject] > 0)} {
lappend messageList "$number\t$from\t$subject"
}
}
puts [join $messageList \n]
7. Search for all messages written by Jeff Hobbs in c.l.t
set connection [nntp::nntp]
$connection group comp.lang.tcl
foreach {total first last group} [$connection group comp.lang.tcl] {
break
}
$connection xpat from $first-$last "*Jeffrey Hobbs*"
|