在写一个基于数据库的新闻组.
netkiller
|
1#
发表于 2006-06-23 18:30
|
netkiller
|
1#
netkiller 发表于 2006-06-23 18:30
在写一个基于数据库的新闻组.
List 已经问题已经解决.没有反回215.哎,搞了两天.
|
netkiller
|
2#
netkiller 发表于 2006-06-23 18:31
现在的问题. xover后列不出文章列表..
我不知xover 列表的格式. #!/usr/bin/python # -*- coding: utf-8 -*- # Network News Transport Protocol Server Program import sys import socket import threading import time import asyncore, asynchat import string, StringIO from netkiller import * """ class NNTPD(asyncore.dispatcher): #,threading.Thread threadname def __init__(self, host, port): asyncore.dispatcher.__init__ (self) #threading.Thread.__init__(self, name = threadname) self.create_socket (socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.there = (host, port) here = ('', port + 8000) self.bind (here) self.listen (5) def handle_accept (self): nntp_receiver (self, self.accept()) def handle_close (self): self.close() def run(self): nntpd = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: nntpd.bind(('127.0.0.1', 119)) nntpd.listen(5) while 1: mycom = commands('com') mycom.connect(nntpd) mycom.start() time.sleep(1) except socket.error, msg: print msg nntpd.close() """ class nntp_server (asyncore.dispatcher): def __init__ (self, host, port): asyncore.dispatcher.__init__ (self) self.create_socket (socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.there = (host, port) self.bind (self.there) self.listen (5) def handle_connect(self): pass def handle_accept (self): conn, addr = self.accept() nntp_receiver (self, (conn, addr)) def handle_error(self): pass def handle_close (self): self.close() class nntp_receiver (asynchat.async_chat): channel_counter = 0 def __init__ (self, server, (conn, addr)): asynchat.async_chat.__init__ (self, conn) self.set_terminator ('\r\n') self.server = server #self.id = self.channel_counter self.channel_counter = self.channel_counter + 1 #self.sender = nntp_sender (self, server.there) #self.sender.id = self.id self.buffer = '' self.handle_connect() def handle_connect (self): self.push(Messages.banner) def collect_incoming_data (self, data): self.buffer = self.buffer + data def found_terminator (self): data = self.buffer self.buffer = '' commands(self,data) #self.handle_close() #self.send (data + '\r\n') #self.push (data + '\r\n') #self.sender.push (data + '\n') def handle_close (self): print 'Closing' self.channel_counter = self.channel_counter - 1 #self.sender.close() self.close() """ class nntp_sender (asynchat.async_chat): def __init__ (self, receiver, address): asynchat.async_chat.__init__ (self) self.receiver = receiver self.set_terminator (None) self.create_socket (socket.AF_INET, socket.SOCK_STREAM) self.buffer = '' self.set_terminator ('\n') self.connect (address) def handle_connect (self): print 'Connected' def collect_incoming_data (self, data): self.buffer = self.buffer + data def found_terminator (self): data = self.buffer self.buffer = '' print '==> (%d) %s' % (self.id, repr(data)) self.receiver.push (data + '\n') def handle_close (self): self.receiver.close() self.close() """ class commands: #threading.Thread conn = None addr = None buffer = None msg = None conn = None HELP = """ HELP 100 Legal commands authinfo user Name|pass Password article [MessageID|Number] body [MessageID|Number] check MessageID date group newsgroup head [MessageID|Number] help ihave last list [active|active.times|newsgroups|subscriptions] listgroup newsgroup mode stream mode reader newgroups yymmdd hhmmss [GMT] [<distributions>] newnews newsgroups yymmdd hhmmss [GMT] [<distributions>] next post slave stat [MessageID|Number] takethis MessageID xgtitle [group_pattern] xhdr header [range|MessageID] xover [range] xpat header range|MessageID pat [morepat...] . """ command = ('LIST','MODE READER','GROUP','XOVER') #def __init__(self, threadname): #threading.Thread.__init__(self, name = threadname) def __init__(self, conn,buffer): self.conn = conn self.buffer = buffer self.msg = Messages() print '<== (%d) %s' % (conn.channel_counter, repr(buffer)) self.nntp(self.buffer) def welcome(self): self.conn.send("200 \"Welcome to Netkiller News server\"\r\n") def nntp(self, buffer): if not buffer: return True if buffer[:11] == 'MODE READER': self.conn.push("200 \"Welcome to Neo News server\"\r\n") elif buffer[:4] == 'LIST': lists = self.msg.list() length = str(len(lists)) self.conn.send("215 list of newsgroups follows\r\n") for group in lists: self.conn.push(group+"\r\n") self.conn.push(".\r\n") elif buffer[:5] == 'GROUP': name = buffer[6:] #last, first = self.msg.group(name) self.conn.push("211 " + self.msg.group(name) + " "+name+" selected\r\n") elif buffer[:9] == 'NEWGROUPS': newgroups = self.msg.newgroups(950803,192708,'GMT') length = len(newgroups) self.conn.push(str(length)+ " New newsgroups follow.\r\n") for name in newgroups: self.conn.push(name+"\r\n") self.conn.send(".\r\n") #break elif buffer[:4] =='XHDR': subject = buffer[5:] #self.msg.xhdr('subject',first,last) xover_list = self.msg.xover(10,10) #length = len(xover_list) self.conn.push(" "+subject+" data follows\r\n") for xo in xover_list: self.conn.send( xo + "\r\n") self.conn.send(".\r\n") elif buffer[:7] =='ARTICLE': MessageID = buffer[8:] self.conn.push("220 "+MessageID+" <mailman.jobs@lists.mozilla.org>\r\n") self.conn.push(""" Path: number1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!border1.nntp.d ca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.mozilla.org !news.mozilla.org.POSTED!not-for-mail NNTP-Posting-Date: Mon, 20 Feb 2006 16:29:52 -0600 Return-Path: <michael.wechner@wyona.com> X-Original-To: jobs@lists.mozilla.org Delivered-To: jobs@lists.mozilla.org Date: Mon, 20 Feb 2006 23:29:44 +0100 From: Michael Wechner <michael.wechner@wyona.com> User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: en-us, en MIME-Version: 1.0 To: jobs@lists.mozilla.org Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: extending the attachments UI X-BeenThere: jobs@lists.mozilla.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: jobs.lists.mozilla.org List-Unsubscribe: <https://lists.mozilla.org/listinfo/jobs>, <mailto:jobs-request@lists.mozilla.org?subject=unsubscribe> List-Post: <mailto:jobs@lists.mozilla.org> List-Help: <mailto:jobs-request@lists.mozilla.org?subject=help> List-Subscribe: <https://lists.mozilla.org/listinfo/jobs>, <mailto:jobs-request@lists.mozilla.org?subject=subscribe> Newsgroups: mozilla.jobs Message-ID: <mailman.965.1140474591.18700.jobs@lists.mozilla.org> Lines: 23 NNTP-Posting-Host: 207.126.111.250 X-Trace: sv3-UCjGv4nX7s3Khjn1oIdyUUvrCsp4tVFVewIvQasbWtz3HHlBh5rx7h4Ju9YqZLVMr71 TL51novU023q!T7fQL/558cDeJgwGI3CMotBk4dLEIJOIAI7NOQOns7PHlidh9H3THFS1MZs3KhayohE dhiGTzL6C!RwjO5lqHSWxCR6uJXGsRrcz8 X-Complaints-To: abuse@mozilla.org X-DMCA-Complaints-To: abuse@mozilla.org X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint pro perly X-Postfilter: 1.3.32 Xref: number1.nntp.dca.giganews.com mozilla.jobs:8 Hi I am looking for someone helping us extending the attachments UI http://www.mozilla.org/mailnews/specs/threepane/Attachments1.html by saving an attachment directly to a Content Management System (e.g. Apache Lenya). We do have a spec and would be happy to send it re offering time estimate re money. Thanks Michael -- Michael Wechner Wyona Inc. - Open Source Content Management - Apache Lenya http://www.wyona.com http://cocoon.apache.org/lenya/ michael.wechner@wyona.com michi@apache.org """) self.conn.push(".\r\n") elif buffer[:4] =='HEAD': MessageID = buffer[5:] self.conn.push("221 "+MessageID+" <mailman.jobs@lists.mozilla.org>\r\n") self.conn.push(".\r\n") elif buffer[:4] =='BODY': MessageID = buffer[4:] self.conn.push("222 "+MessageID+" <mailman.jobs@lists.mozilla.org>\r\n") self.conn.push(".\r\n") elif self.buffer[:5] == 'XOVER': xover = buffer[6:] xover_list = self.msg.xover(10,10) length = len(xover_list) self.conn.push("224 xover information follows\r\n") for xo in xover_list: self.conn.push( xo + "\r\n") self.conn.push(".\r\n") elif buffer[:4] == 'POST': text = "" self.conn.push("340 send article\r\n") #self.conn.send("354 Start mail input; end with <CRLF>;.<CRLF>;\r\n") """ while True: buffer = self.conn.recv(1024) text = text + self.buffer if buffer[-3:] == ".\r\n": self.conn.send("250 OK\r\n") break self.buffer = text print self.buffer """ elif buffer[:4] == 'RSET': self.conn.push("250 OK\r\n") elif buffer[:4] =='HELP': self.conn.push(self.HELP) elif buffer[:4] =='QUIT': self.conn.push("221 Closing connection. Good bye.\r\n") return True else: self.conn.push("500 command not recognized\r\n") return False def close(self): self.conn.close() self.buffer = None self.conn = None self.addr = None class Messages: banner = '200 \"Welcome to Netkiler News server\"\r\n' subject = None mail_from = None rcpt_to = None data = None group = "" grouplist = ( ("cn.comp.linux", 5, 2, "y"), ("cn.comp.freebsd", 3, 2, "y"), ("cn.comp.dos", 10, 4, "y"), ("cn.test", 5, 2, "y"), ("comp.lang.python", 5, 2, "y") ) def welcome(self): return 'Welcome' def list (self): lists = [] for name, last, first, mode in self.grouplist: lists.append(name+ " " + str(last) + " " + str(first) +" "+ mode) return lists def group(self,groupname): group_rang = "" for name, last, first, mode in self.grouplist: if name == groupname: group_rang = str(last - first)+" "+ str(first)+" "+str(last) break return group_rang def xover(self,first,last): xover_tmp = [] xover_tmp.append("""2 Mozilla programmer needed for children's learning program "John Fodor, PhD" <fodor@ilt-inc.com> Mon, 23 Jan 2006 12:01:09 -0500 <mailman.349.1138141614.8933.jobs@lists.mozilla.org> 10532 276 Xref: number1.nntp.dca.giganews.com mozilla.jobs:2""") xover_tmp.append("""3 mozilla expert needed "Paul Sponagl" <sponagl@7val.com> Tue, 7 Mar 2006 20:00:52 +0100 <mailman.1692.1141758057.18700.jobs@lists.mozilla.org> 2913 41 Xref: number1.nntp.dca.giganews.com mozilla.jobs:10""") return xover_tmp def head(self): self.xover(first,last) def xhdr(self,first,last): xover_tmp = [] xover_tmp.append('1 HI "NNTP.HK" <admin@nntp.hk> 14 Jun 2006 14:43:05 +0800 <448faff9$1@news.nntp.hk> 1151 31 Xref: news.nntp.hk vip.cicefans:1\r\n') return xover_tmp def newgroups(self,data,time,gmt): lists = [] lists.append("cn.test.os") lists.append("cn.test.qa") return lists def main(): try: nntpd = nntp_server('127.0.0.1',119) asyncore.loop() except KeyboardInterrupt: print "Crtl+C pressed. Shutting down." if __name__ == '__main__': main() |