Example #1
0
 /**
  * Post an article to usenet.
  *
  * @param $groups   mixed   (array)  Groups. ie.: $groups = array('alt.test', 'alt.testing', 'free.pt');
  *                          (string) Group.  ie.: $groups = 'alt.test';
  * @param $subject  string  The subject.     ie.: $subject = 'Test article';
  * @param $body     string  The message.     ie.: $message = 'This is only a test, please disregard.';
  * @param $from     string  The poster.      ie.: $from = '<*****@*****.**>';
  * @param $extra    string  Extra, separated by \r\n
  *                                           ie.: $extra  = 'Organization: <newznab>\r\nNNTP-Posting-Host: <127.0.0.1>';
  * @param $yEnc     bool    Encode the message with yEnc?
  * @param $compress bool    Compress the message with GZip?
  *
  * @return          mixed   On success : (bool)   True.
  *                          On failure : (object) PEAR_Error.
  *
  * @access public
  */
 public function postArticle($groups, $subject, $body, $from, $yEnc = true, $compress = true, $extra = '')
 {
     if (!$this->_postingAllowed) {
         $message = 'You do not have the right to post articles on server ' . $this->_currentServer;
         if ($this->_debugBool) {
             $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE);
         }
         return $this->throwError($this->pdo->log->error($message));
     }
     $connected = $this->_checkConnection();
     if ($connected !== true) {
         return $connected;
     }
     // Throw errors if subject or from are more than 510 chars.
     if (strlen($subject) > 510) {
         $message = 'Max length of subject is 510 chars.';
         if ($this->_debugBool) {
             $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_WARNING);
         }
         return $this->throwError($this->pdo->log->error($message));
     }
     if (strlen($from) > 510) {
         $message = 'Max length of from is 510 chars.';
         if ($this->_debugBool) {
             $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_WARNING);
         }
         return $this->throwError($this->pdo->log->error($message));
     }
     // Check if the group is string or array.
     if (is_array($groups)) {
         $groups = implode(', ', $groups);
     }
     // Check if we should encode to yEnc.
     if ($yEnc) {
         $body = $this->encodeYEnc($compress ? gzdeflate($body, 4) : $body, $subject);
         // If not yEnc, then check if the body is 510+ chars, split it at 510 chars and separate with \r\n
     } else {
         $body = $this->_splitLines($body, $compress);
     }
     // From is required by NNTP servers, but parent function mail does not require it, so format it.
     $from = 'From: ' . $from;
     // If we had extra stuff to post, format it with from.
     if ($extra != '') {
         $from = $from . "\r\n" . $extra;
     }
     return parent::mail($groups, $subject, $body, $from);
 }