예제 #1
0
 protected function fetchArticle(Command $command, ClientContext $context) : Generator
 {
     // Current article?
     if ($command->argCount() === 0) {
         if (!$context->getCursor()->valid()) {
             yield from $context->writeResponse(new Response(412, 'No newsgroup selected'));
             return;
         }
         return $context->getCursor()->getArticle();
     } elseif (is_numeric($command->arg(0))) {
         $number = (int) $command->arg(0);
         if (!$context->getCursor()->valid()) {
             yield from $context->writeResponse(new Response(412, 'No newsgroup selected'));
             return;
         }
         if (!(yield from $context->getCursor()->seek($number))) {
             yield from $context->writeResponse(new Response(423, 'No article with that number'));
             return;
         }
         return $context->getCursor()->getArticle();
     } else {
         $article = (yield from $context->getAccessLayer()->getArticleById($command->arg(0)));
         if (!$article) {
             yield from $context->writeResponse(new Response(430, 'No article with that message-id'));
             return;
         }
     }
     return $article;
 }
예제 #2
0
 public function handle(Command $command, ClientContext $context) : Generator
 {
     if (!$context->getAccessLayer()->isPostingAllowed()) {
         yield from $context->writeResponse(new Response(440, 'Posting not permitted'));
         return;
     }
     yield from $context->writeResponse(new Response(340, 'Send article to be posted'));
     $data = (yield from $context->readData());
     $article = Article::parse($data);
     try {
         yield from $context->getAccessLayer()->postArticle($article);
         yield from $context->writeResponse(new Response(240, 'Article received OK'));
     } catch (\Throwable $e) {
         yield from $context->writeResponse(new Response(441, 'Posting failed'));
     }
 }
예제 #3
0
 public function handle(Command $command, ClientContext $context) : Generator
 {
     if ($command->argCount() === 0) {
         $group = $this->currentGroup;
     }
     $name = $command->arg(0);
     $group = (yield from $context->getAccessLayer()->getGroupByName($name));
     if (!$group) {
         yield from $context->writeResponse(new Response(411, 'No such newsgroup'));
         return;
     }
     $context->setCurrentGroup($group->name());
     $context->setCurrentArticle($group->lowWaterMark());
     yield from $context->writeResponse(new Response(211, $group->count() . ' ' . $group->lowWaterMark() . ' ' . $group->highWaterMark() . ' ' . $group->name() . ' Group successfully selected'));
 }
예제 #4
0
 public function handle(Command $command, ClientContext $context) : Generator
 {
     if ($command->argCount() !== 1) {
         yield from $context->writeResponse(new Response(501, 'Invalid number of arguments'));
         return;
     }
     try {
         $name = $command->arg(0);
         $cursor = (yield from $context->getAccessLayer()->getGroupCursor($name));
         $context->setCursor($cursor);
     } catch (NotFoundException $e) {
         yield from $context->writeResponse(new Response(411, 'No such newsgroup'));
         return;
     }
     $group = $context->getCursor()->getGroup();
     yield from $context->writeResponse(new Response(211, $group->count() . ' ' . $group->lowWaterMark() . ' ' . $group->highWaterMark() . ' ' . $group->name() . ' Group successfully selected'));
 }
예제 #5
0
 public function handle(Command $command, ClientContext $context) : Generator
 {
     yield from $context->writeResponse(new Response(215, 'List of newsgroups follows'));
     $groups = (yield from $context->getAccessLayer()->getGroups());
     $data = array_reduce($groups, function (string $s, Group $group) {
         switch ($group->status()) {
             case Group::POSTING_PERMITTED:
                 $status = 'y';
                 break;
             case Group::POSTING_NOT_PERMITTED:
                 $status = 'n';
                 break;
             case Group::POSTING_FORWARDED:
                 $status = 'm';
                 break;
             default:
                 $status = 'u';
                 break;
         }
         return $s . sprintf("%s %d %d %s\r\n", $group->name(), $group->highWaterMark(), $group->lowWaterMark(), $status);
     }, '');
     yield from $context->writeData($data);
 }