Get NEWGROUPS command working
This commit is contained in:
parent
9763ea0cdf
commit
7fd142483f
1 changed files with 38 additions and 4 deletions
|
@ -291,6 +291,26 @@ class Session():
|
|||
|
||||
return self.end()
|
||||
|
||||
def _newsgroup_summary(self, newsgroup: Newsgroup):
|
||||
sql = """
|
||||
select
|
||||
min(id),
|
||||
max(id)
|
||||
from
|
||||
newsgroup_message
|
||||
where
|
||||
newsgroup_id = ?
|
||||
"""
|
||||
|
||||
cr = self.db.execute(sql, (newsgroup.id,))
|
||||
row = cr.fetchone()
|
||||
|
||||
return {
|
||||
'min': row[0],
|
||||
'max': row[1],
|
||||
'perms': 'n'
|
||||
}
|
||||
|
||||
def _cmd_newgroups(self, wildmat, datestr, timestr, *args):
|
||||
gmt = False
|
||||
|
||||
|
@ -298,11 +318,25 @@ class Session():
|
|||
if args[0] == "GMT":
|
||||
gmt = True
|
||||
else:
|
||||
return self.send_response(ResponseCode.NNTP_SYNTAX_ERROR, "Only optional 'GMT' allowed")
|
||||
return self.respond(ResponseCode.NNTP_SYNTAX_ERROR, "Only optional 'GMT' allowed")
|
||||
elif len(args) > 1:
|
||||
return self.send_response(ResponseCode.NNTP_SYNTAX_ERROR, "Too many arguments")
|
||||
return self.respond(ResponseCode.NNTP_SYNTAX_ERROR, "Too many arguments")
|
||||
|
||||
pass
|
||||
self.respond(ResponseCode.NNTP_GROUPS_NEW_FOLLOW)
|
||||
|
||||
for name in self.server.newsgroups:
|
||||
if fnmatch.fnmatch(name, wildmat):
|
||||
newsgroup = self.server.newsgroups[name]
|
||||
summary = self._newsgroup_summary(newsgroup)
|
||||
|
||||
self.print("%s %d %d %s" % (
|
||||
newsgroup.name,
|
||||
summary['min'],
|
||||
summary['max'],
|
||||
summary['perms']
|
||||
))
|
||||
|
||||
return self.end()
|
||||
|
||||
COMMANDS = {
|
||||
'CAPABILITIES': _cmd_capabilities,
|
||||
|
@ -310,7 +344,7 @@ class Session():
|
|||
'LISTGROUP': _cmd_listgroup,
|
||||
'LIST': _cmd_list,
|
||||
'NEWNEWS': _cmd_newnews,
|
||||
'NEWSGROUPS': _cmd_newgroups,
|
||||
'NEWGROUPS': _cmd_newgroups,
|
||||
}
|
||||
|
||||
def handle(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue