diff --git a/lib/nntp/tiny/session.py b/lib/nntp/tiny/session.py index b1ea681..1b35429 100644 --- a/lib/nntp/tiny/session.py +++ b/lib/nntp/tiny/session.py @@ -233,7 +233,7 @@ class Session(): 'min': row[1], 'max': row[2], 'name': newsgroup.name, - 'perms': 'n' + 'perms': 'y' if newsgroup.active else 'n' } def _cmd_listgroup(self, *args): @@ -697,28 +697,30 @@ class Session(): RE_NEWSGROUPS_SPLIT = re.compile(r'\s*,\s*') - def _save_message(self, message: Message): + def _save_message(self, message: Message, success: ResponseCode): value = message.header('Newsgroups') if value is None or value == '': - return False + return ResponseCode.NNTP_POST_FAILED names = map(lambda s: s.lower(), self.RE_NEWSGROUPS_SPLIT.split(value)) newsgroups = list() for name in names: - if name not in self.server.newsgroups: - return False + newsgroup = self.server.newsgroups.get(name) + + if newsgroup is None or not newsgroup.active: + return ResponseCode.NNTP_POST_PROHIBITED newsgroups.append(self.server.newsgroups[name]) if len(newsgroups) == 0: - return False + return ResponseCode.NNTP_POST_FAILED message.message_id_assign() if not message.validate(): - return False + return ResponseCode.NNTP_POST_FAILED self.db.add(message) @@ -733,7 +735,7 @@ class Session(): self.db.commit() - return True + return success def _post_impl(self, message_id=None): if self.perms is None or not self.perms & UserPermission.POST: @@ -777,10 +779,9 @@ class Session(): if stripped == '.': message.finish() - if self._save_message(message): - return self.respond(code_received) - else: - return self.respond(ResponseCode.NNTP_POST_FAILED) + code = self._save_message(message, code_received) + + return self.respond(code) elif stripped == '..': line = line[1:]