Esempio n. 1
0
 /**
  * @param integer $priority
  * @param array $recipients
  * @param string $subject
  * @param Logic_WebService_Mail_Content $content
  * @param mixed $attachments
  * @param string $charCode
  * @param boolean $isHtml
  * @throws Logic_WebService_Exception
  * @return Logic_WebService_Mail_Response
  */
 public function handler($priority, array $recipients, $subject, $content, Logic_WebService_Mail_Attachment $attachments, $charCode = 'UTF-8', $isHtml = false)
 {
     $timeLimit = 30;
     // zabezpieczenie przed przekroczeniem limitu czasu wykonywania skryptu
     $modelCounter = new MailCounter();
     $modelPackageStorage = new MailPackageStorage();
     $modelStorage = new MailStorage();
     $content = new Logic_WebService_Mail_Content($content);
     $limit = new Logic_WebService_Element_Limit($this->_client, $this->_service);
     $response = new Logic_WebService_Mail_Response();
     $response->setStatus(true);
     $toReport = array();
     $numAdded = 0;
     $numRejected = 0;
     if (empty($recipients)) {
         throw new Logic_WebService_Mail_Exception('Nie podano adresow e-mail do rozsylki', 450);
     }
     $modelPackage = new MailPackage();
     $packageId = $modelPackage->addPackage(array('ws_client_id' => $this->_client->getParams()->id, 'ws_service_id' => $this->_service->getParams()->id, 'is_active' => 'true', 'mailer_priority' => $priority, 'package_comment' => null));
     if (is_object($attachments) && $attachments->areAttachments()) {
         $model = new MailAttachment();
         $model->addAttachment($packageId, $attachments->mapToModel());
     }
     $isSomethindToSend = false;
     foreach ($recipients as $mail => $individualContent) {
         set_time_limit($timeLimit + 30);
         try {
             $recipient = new Logic_WebService_Mail_Recipient($mail);
             if (!$this->_environment->checkStatus()) {
                 $recipient->checkEmailOnWhiteList();
             }
             if ($recipient->checkEmailOnBlackList($this->_client->getParams()->id, $recipent)) {
                 $mailBlacklistModel = new MailBlacklistStorage();
                 $mailBlacklistModel->addMail($this->_client->getParams()->id, $this->_service->getParams()->id, $recipient, $subject, $content, $packageId);
                 continue;
             }
             $limit->check($modelCounter, $recipient->getRecipient()->id);
             $mailContent = $individualContent ? new Logic_WebService_Mail_Content($individualContent) : $content;
             $limit->checkByContent($modelCounter, $recipient->getRecipient()->id, $mailContent);
             $isSomethindToSend = true;
             // jednak ktorys e-mail przeszedl weryfikacje
             $numAdded++;
             $modelPackageStorage->addPackage(array('mail_package_id' => $packageId, 'mail_address' => $mail, 'mail_subject' => $subject, 'mail_content' => $mailContent->getContent(), 'mail_content_charcode' => $charCode, 'mail_content_is_html' => $isHtml));
             $modelStorage->addMail($this->_client->getParams()->id, $this->_service->getParams()->id, $recipient, $subject, $mailContent, $response, $packageId);
         } catch (Logic_WebService_Exception $e) {
             $numRejected++;
             $toReport[] = array('address' => $mail, 'content' => $individualContent, 'reason' => $e->getMessage());
         } catch (Exception $e) {
             throw new Logic_WebService_Exception($e->getMessage());
         }
     }
     if ($isSomethindToSend) {
         // przygodowano pakiet danych do rozsylki
         $response->setMailId($packageId)->setStatus(true)->setMessage('Dodano do kolejki')->setAdded($numAdded)->setRejected($numRejected)->setReport($toReport);
     } else {
         // wszystkie adresy odpadly
         $response->setStatus(false)->setMessage('Brak adresow do rozsylki')->setAdded($numAdded)->setRejected($numRejected)->setReport($toReport);
     }
     return $response;
 }
Esempio n. 2
0
 /**
  *  This function handle the "delete" http request
  * 
  * @param  string|null correspond to the URL after /Lan
  * 
  * @throws RestException
  */
 public function delete($padId = null)
 {
     if (isset($padId)) {
         $data = RestHandler::getData();
         $pad = NotesFactory::build(PadComponent::getClass(), array('id' => $padId));
         if (!$pad) {
             throw new RestException("Pad not found", 404);
         } else {
             if ($pad->mail_owner != Auth::user()->email) {
                 throw new RestException("Access denied", 403);
             } else {
                 // Export datas if asked
                 if (isset($data->exportContent) && $data->exportContent === true) {
                     $padContent = $this->exportPadContent($pad);
                     // Setting informations
                     $infos = array(array('pad' => array('pad_name' => $pad->pad_name)));
                     // Send by mail to pad owner
                     $attachment = new MailAttachment(str_ireplace(' ', '', $pad->pad_name) . '_' . date('YmdHis') . '.html');
                     $attachment->content = $padContent;
                     $attachment->build();
                     $this->sendPadInformationsByMail($pad, Auth::user()->email, 'delete_pad', $infos, $attachment);
                 }
                 $cdatas = array('padID' => $pad->pad_name, 'apikey' => $this->etherpadApiKey);
                 $result = RestUtilities::callAPI($this->etherpadURLApi . 'deletePad', RestMethods::GET, $cdatas);
                 //                    $result = json_encode(array('code' => 0));
                 if ($result) {
                     if (isset($result->error)) {
                         throw new RestException($result->error);
                     } else {
                         if ($result->code == 0) {
                             $pad->delete();
                             return array('status' => "success", 'content' => $pad);
                         } else {
                             throw new RestException("Pad not found", 404);
                         }
                     }
                 }
             }
         }
     } else {
         throw new RestException("Invalid pad ID", 500);
     }
 }