public function testNoop() { $mail = new Zend_Mail_Storage_Pop3($this->_params); try { $mail->noop(); } catch (Exception $e) { $this->fail('exception raised while doing nothing (noop)'); } }
/** * CLI Bot action * */ public function botAction() { // Retrieve configuration $config = Zend_Registry::get('config'); // URI to be called $uri = $config->snsServerUrlScheme . '://' . $config->snsServerUrlHost . $config->snsServerUrlPath . 'default/wikiarticle/create'; try { // Connect to POP3 mail storage $mail = new Zend_Mail_Storage_Pop3(array('host' => $config->wikiarticle->pop3->host, 'port' => $config->wikiarticle->pop3->port, 'user' => $config->wikiarticle->pop3->user, 'password' => $config->wikiarticle->pop3->pass)); } catch (Exception $ex) { //SWAT_Log::get()->MailPuller()->err($ex->getMessage()); Zend_Registry::get('log')->err($ex->getMessage()); } // Generate mail puller instance $puller = new SWAT_Mail_Puller(); $puller->setFileDir(sys_get_temp_dir()); $puller->setFileTypes(array_map('trim', explode(',', $config->wikiarticleAllowedMimeTypes))); //echo 'We have ' . $mail->countMessages() . ' messages to process.<br />'; //echo 'Attachments will be stored in directory: ' . sys_get_temp_dir() . '<br />'; // Foreach mail found foreach ($mail as $number => $message) { //echo 'Found message with title: ' . $message->subject . '<br />'; // Check if it's a wiki article to be created if (strtoupper(substr($message->subject, 0, 5)) === 'WIKI:') { try { // Retrieve message information $info = $puller->getMessageInfo($message); // Post found information to wiki article creator $client = new Zend_Http_Client($uri); $client->setRawData(Zend_Json::encode($info)); $response = $client->request(Zend_Http_Client::POST); //echo 'Response: <pre>' . var_export($response->getBody(), true) . '</pre>'; // Switch to each response status switch ($response->getStatus()) { case 400: throw new Exception('Invalid request.'); break; case 500: throw new Exception('Internal server error.'); break; default: // Decode response $body = SWAT_Encoder::decode($response->getRawBody()); // If error code is not 201, we need to report the issue if ($body['code'] != 201) { throw new Exception($body['message']); } // Generate log entry //SWAT_Log::get()->MailPuller()->debug($body['message']); Zend_Registry::get('log')->debug($body['message']); break; } } catch (Exception $ex) { //SWAT_Log::get()->MailPuller()->err($ex->getMessage()); Zend_Registry::get('log')->err($ex->getMessage()); } } $mail->noop(); } }