/**
  */
 function delete_log_item()
 {
     // only do this for administrators
     if (PostmanUtils::isAdmin()) {
         $this->logger->trace('handling delete item');
         $postid = $_REQUEST['email'];
         if (wp_verify_nonce($_REQUEST['_wpnonce'], 'delete_email_log_item_' . $postid)) {
             $this->logger->trace(sprintf('nonce "%s" passed validation', $_REQUEST['_wpnonce']));
             $purger = new PostmanEmailLogPurger();
             $purger->verifyLogItemExistsAndRemove($postid);
             $mh = new PostmanMessageHandler();
             $mh->addMessage(__('Mail Log Entry was deleted.', 'postman-smtp'));
         } else {
             $this->logger->warn(sprintf('nonce "%s" failed validation', $_REQUEST['_wpnonce']));
         }
         $this->redirectToLogPage();
     }
 }
Пример #2
0
 public function handlePurgeDataAction()
 {
     if (wp_verify_nonce($_REQUEST['_wpnonce'], 'purge-data')) {
         $this->logger->debug('Purging stored data');
         delete_option(PostmanOptions::POSTMAN_OPTIONS);
         delete_option(PostmanOAuthToken::OPTIONS_NAME);
         delete_option(PostmanAdminController::TEST_OPTIONS);
         $logPurger = new PostmanEmailLogPurger();
         $logPurger->removeAll();
         $this->messageHandler->addMessage(__('Plugin data was removed.', 'postman-smtp'));
         PostmanUtils::redirect(PostmanUtils::POSTMAN_HOME_PAGE_RELATIVE_URL);
     } else {
         $this->logger->warn(sprintf('nonce "%s" failed validation', $_REQUEST['_wpnonce']));
     }
 }
Пример #3
0
 /**
  * This function handle the request to purge plugin data
  */
 public function handlePurgeDataAction()
 {
     $this->logger->debug('is wpnonce purge-data?');
     if (wp_verify_nonce($_REQUEST['_wpnonce'], PostmanAdminController::PURGE_DATA_SLUG)) {
         $this->logger->debug('Purging stored data');
         delete_option(PostmanOptions::POSTMAN_OPTIONS);
         delete_option(PostmanOAuthToken::OPTIONS_NAME);
         delete_option(PostmanAdminController::TEST_OPTIONS);
         $logPurger = new PostmanEmailLogPurger();
         $logPurger->removeAll();
         $this->messageHandler->addMessage(__('Plugin data was removed.', Postman::TEXT_DOMAIN));
         PostmanUtils::redirect(PostmanUtils::POSTMAN_HOME_PAGE_RELATIVE_URL);
     }
 }
Пример #4
0
 /**
  * Writes an email sending attempt to the Email Log
  *
  * From http://wordpress.stackexchange.com/questions/8569/wp-insert-post-php-function-and-custom-fields
  */
 private function writeToEmailLog(PostmanEmailLog $log)
 {
     // nothing here is sanitized as WordPress should take care of
     // making database writes safe
     $my_post = array('post_type' => PostmanEmailLogPostType::POSTMAN_CUSTOM_POST_TYPE_SLUG, 'post_title' => $log->subject, 'post_content' => $log->body, 'post_excerpt' => $log->statusMessage, 'post_status' => PostmanEmailLogService::POSTMAN_CUSTOM_POST_STATUS_PRIVATE);
     // Insert the post into the database (WordPress gives us the Post ID)
     $post_id = wp_insert_post($my_post);
     $this->logger->debug(sprintf('Saved message #%s to the database', $post_id));
     $this->logger->trace($log);
     // Write the meta data related to the email
     update_post_meta($post_id, 'success', $log->success);
     update_post_meta($post_id, 'from_header', $log->sender);
     if (!empty($log->toRecipients)) {
         update_post_meta($post_id, 'to_header', $log->toRecipients);
     }
     if (!empty($log->ccRecipients)) {
         update_post_meta($post_id, 'cc_header', $log->ccRecipients);
     }
     if (!empty($log->bccRecipients)) {
         update_post_meta($post_id, 'bcc_header', $log->bccRecipients);
     }
     if (!empty($log->replyTo)) {
         update_post_meta($post_id, 'reply_to_header', $log->replyTo);
     }
     update_post_meta($post_id, 'transport_uri', $log->transportUri);
     if (!$log->success || true) {
         // alwas add the meta data so we can re-send it
         update_post_meta($post_id, 'original_to', $log->originalTo);
         update_post_meta($post_id, 'original_subject', $log->originalSubject);
         update_post_meta($post_id, 'original_message', $log->originalMessage);
         update_post_meta($post_id, 'original_headers', $log->originalHeaders);
     }
     // we do not sanitize the session transcript - let the reader decide how to handle the data
     update_post_meta($post_id, 'session_transcript', $log->sessionTranscript);
     // truncate the log (remove older entries)
     $purger = new PostmanEmailLogPurger();
     $purger->truncateLogItems(PostmanOptions::getInstance()->getMailLoggingMaxEntries());
 }