function perform()
 {
     // try to load the message
     $messageId = $this->_request->getValue("messageId");
     $mailMessages = new MailMessages();
     $message = $mailMessages->getMessage($messageId);
     if (!$message) {
         // if something went wrong loading the message, quit
         $view = new MailCentreMessageListView($this->_blogInfo);
         $view->setErrorMessage($this->_locale->tr("mailcentre_incorrect_message_id"));
         $this->setValidationErrorView($view);
         $this->setCommonData();
         return false;
     }
     // pass the data to the template if everything's ok
     $this->_view = new MailCentreSendMessageView($this->_blogInfo, false);
     $this->_view->setValue("messageRecipient", $message->getTo());
     $this->_view->setValue("messageBcc", $message->getBcc());
     $this->_view->setValue("messageCc", $message->getCc());
     $this->_view->setValue("messageText", $message->getText());
     $this->_view->setValue("messageSubject", $message->getSubject());
     $this->_view->setValue("messageSentDate", $message->getSentTimestamp());
     $this->setCommonData();
     return true;
 }
 function render()
 {
     // load all the mail messages sent so far
     $messages = new MailMessages();
     $allMessages = $messages->getMessages();
     $this->setValue("messages", $allMessages);
     parent::render();
 }
 /**
  * deletes comments
  * @private
  */
 function _deleteMessages()
 {
     $messages = new MailMessages();
     $errorMessage = "";
     $successMessage = "";
     $totalOk = 0;
     // loop through the messages and remove them
     foreach ($this->_messageIds as $messageId) {
         $message = $messages->getMessage($messageId);
         if (!$message) {
             $errorMessage .= $this->_locale->pr("mailcentre_error_deleting_message2", $messageId);
         } else {
             if (!$messages->deleteMessage($messageId)) {
                 $errorMessage .= $this->_locale->pr("mailcentre_error_deleting_message", $message->getSubject()) . "<br/>";
             } else {
                 $totalOk++;
                 if ($totalOk < 2) {
                     $successMessage .= $this->_locale->pr("mailcentre_message_deleted_ok", $message->getSubject()) . "<br/>";
                 } else {
                     $successMessage = $this->_locale->pr("mailcentre_messages_deleted_ok", $totalOk);
                 }
             }
         }
     }
     // if everything fine, then display the same view again with the feedback
     $this->_view = new MailCentreMessageListView($this->_blogInfo);
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 function perform()
 {
     // extract the data
     $recipients = $this->_request->getValue("messageRecipient");
     $recipientsCc = $this->_request->getValue("messageCc");
     $recipientsBcc = $this->_request->getValue("messageBcc");
     $text = $this->_request->getValue("messageText");
     $subject = $this->_request->getValue("messageSubject");
     // check that we've got either a 'to','cc' or 'bcc'
     if ($recipients == "" && $recipientsCc == "" && $recipientsBcc == "") {
         // force an error
         $this->_view = new MailCentreSendMessageView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("mailcentre_error_sending_message"));
         $this->_form->setFieldValidationStatus("messageRecipient", false);
         $this->setCommonData(true);
     }
     // pre-process some of the data
     $recipients = str_replace(" ", "", $recipients);
     $recipientsCc = str_replace(" ", "", $recipientsCc);
     $recipientsBcc = str_replace(" ", "", $recipientsBcc);
     // and get the list of recipients
     $listUnexpanded = explode(",", $recipients);
     $list = array();
     foreach ($listUnexpanded as $recipient) {
         $result = $this->_expandRecipients($recipient);
         $list = array_merge($list, $result);
     }
     $listCcUnexpanded = explode(",", $recipientsCc);
     $listCc = array();
     foreach ($listCcUnexpanded as $recipient) {
         $result = $this->_expandRecipients($recipient);
         $listCc = array_merge($listCc, $result);
     }
     $listBccUnexpanded = explode(",", $recipientsBcc);
     $listBcc = array();
     foreach ($listBccUnexpanded as $recipient) {
         $result = $this->_expandRecipients($recipient);
         $listBcc = array_merge($listBcc, $result);
     }
     // create a mail message that includes all the recipients
     $message = new EmailMessage();
     $val = new EmailValidator();
     $totalTo = 0;
     $totalCc = 0;
     $totalBcc = 0;
     foreach ($list as $to) {
         // add each one of the recipients
         if ($val->validate($to)) {
             $message->addTo($to);
             $totalTo++;
         }
     }
     foreach ($listCc as $cc) {
         // add each one of the recipients
         if ($val->validate($cc)) {
             $message->addCc($cc);
             $totalCc++;
         }
     }
     foreach ($listBcc as $bcc) {
         // add each one of the recipients
         if ($val->validate($bcc)) {
             $message->addBcc($bcc);
             $totalBcc++;
         }
     }
     // check that we are really sending the message to somebody
     if ($totalTo == 0 && $totalCc == 0 && $totalBcc == 0) {
         // force an error
         $this->_view = new MailCentreSendMessageView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("mailcentre_error_sending_message"));
         $this->_form->setFieldValidationStatus("messageRecipient", false);
         $this->setCommonData(true);
     }
     // and now set the subject and body...
     $message->setSubject($subject);
     $message->setBody($text);
     // set the encoding based on the current blog settings
     $locale =& $this->_blogInfo->getLocale();
     $message->setCharset($locale->getCharset());
     // and the "from" address
     $config =& Config::getConfig();
     $from = $config->getValue("post_notification_source_address");
     $message->setFrom($from);
     // now send the message
     $service = new EmailService();
     if (!$service->sendMessage($message)) {
         // if something went wrong, go back to the previous view
         $this->_view = new MailCentreSendMessageView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("mailcentre_error_sending_message"));
         // show the view and keep the data that was in the form
         $this->setCommonData(true);
     }
     $recipients = implode(",", $list);
     $recipientsCc = implode(",", $listCc);
     $recipientsBcc = implode(",", $listBcc);
     // if everything went ok, create our own MailMessage object and save it to the database
     $mailMessage = new MailMessage($subject, $text, $recipients, $recipientsCc, $recipientsBcc);
     $mailMessages = new MailMessages();
     $mailMessages->addMessage($mailMessage);
     // show the resulting view
     $this->_view = new MailCentreMessageListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->tr("mailcentre_message_sent_ok"));
     $this->setCommonData();
     return true;
 }