b2evolution PHP Cross Reference Blogging Systems

Source: /inc/tools/email.ctrl.php - 383 lines - 11898 bytes - Text - Print

Description: This file implements the UI controller for browsing the email tools. This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}. See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**

   3   * This file implements the UI controller for browsing the email tools.

   4   *

   5   * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}.

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}.

   9   *

  10   * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)

  11   *

  12   * {@internal Open Source relicensing agreement:

  13   * Vegar BERG GULDAL grants Francois PLANQUE the right to license

  14   * Vegar BERG GULDAL's contributions to this file and the b2evolution project

  15   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  16   * }}

  17   *

  18   * @package admin

  19   *

  20   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  21   * @author fplanque: Francois PLANQUE

  22   *

  23   * @version $Id: email.ctrl.php 368 2011-11-21 15:51:22Z yura $

  24   */
  25  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  26  
  27  /**

  28   * @var User

  29   */
  30  global $current_User;
  31  
  32  global $DB;
  33  
  34  // Check permission:

  35  $current_User->check_perm( 'emails', 'view', true );
  36  
  37  load_funcs('tools/model/_email.funcs.php');
  38  
  39  param_action();
  40  
  41  $tab = param( 'tab', 'string', 'blocked', true );
  42  
  43  param( 'action', 'string' );
  44  
  45  if( $tab == 'blocked' )
  46  {    // Email addresses
  47      load_class( 'tools/model/_emailblocked.class.php', 'EmailBlocked' );
  48      if( param( 'emblk_ID', 'integer', '', true) )
  49      {    // Load Email Blocked object
  50          $EmailBlockedCache = & get_EmailBlockedCache();
  51          if( ( $edited_EmailBlocked = & $EmailBlockedCache->get_by_ID( $emblk_ID, false ) ) === false )
  52          {    // We could not find the goal to edit:
  53              unset( $edited_EmailBlocked );
  54              forget_param( 'emblk_ID' );
  55              $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Email Blocked') ), 'error' );
  56          }
  57      }
  58  }
  59  
  60  switch( $action )
  61  {
  62      case 'settings': // Update the email settings
  63          // Check that this action request is not a CSRF hacked request:

  64          $Session->assert_received_crumb( 'emailsettings' );
  65  
  66          // Check permission:

  67          $current_User->check_perm( 'emails', 'edit', true );
  68  
  69          /** Email notifications **/

  70  
  71          // Sender email address

  72          $sender_email = param( 'notification_sender_email', 'string', '' );
  73          param_check_email( 'notification_sender_email', true );
  74          $Settings->set( 'notification_sender_email',  $sender_email );
  75  
  76          // Return path

  77          $return_path = param( 'notification_return_path', 'string', '' );
  78          param_check_email( 'notification_return_path', true );
  79          $Settings->set( 'notification_return_path', $return_path );
  80  
  81          // Sender name

  82          $sender_name = param( 'notification_sender_name', 'string', '' );
  83          param_check_not_empty( 'notification_sender_name' );
  84          $Settings->set( 'notification_sender_name',  $sender_name );
  85  
  86          // Site short name

  87          $short_name = param( 'notification_short_name', 'string', '' );
  88          param_check_not_empty( 'notification_short_name' );
  89          $Settings->set( 'notification_short_name',  $short_name );
  90  
  91          // Site long name

  92          $Settings->set( 'notification_long_name',  param( 'notification_long_name', 'string', '' ) );
  93  
  94          // Site logo url

  95          $Settings->set( 'notification_logo',  param( 'notification_logo', 'string', '' ) );
  96  
  97          /** Settings to decode the returned emails **/

  98          param( 'repath_enabled', 'boolean', 0 );
  99          $Settings->set( 'repath_enabled', $repath_enabled );
 100  
 101          param( 'repath_method', 'string', true );
 102          $Settings->set( 'repath_method', strtolower( $repath_method ) );
 103  
 104          param( 'repath_server_host', 'string', true );
 105          $Settings->set( 'repath_server_host', evo_strtolower( $repath_server_host ) );
 106  
 107          param( 'repath_server_port', 'integer', true );
 108          $Settings->set( 'repath_server_port', $repath_server_port );
 109  
 110          param( 'repath_encrypt', 'string', true );
 111          $Settings->set( 'repath_encrypt', $repath_encrypt );
 112  
 113          param( 'repath_novalidatecert', 'boolean', 0 );
 114          $Settings->set( 'repath_novalidatecert', $repath_novalidatecert );
 115  
 116          param( 'repath_username', 'string', true );
 117          $Settings->set( 'repath_username', $repath_username );
 118  
 119          param( 'repath_password', 'string', true );
 120          $Settings->set( 'repath_password', $repath_password );
 121  
 122          param( 'repath_delete_emails', 'boolean', 0 );
 123          $Settings->set( 'repath_delete_emails', $repath_delete_emails );
 124  
 125          param( 'repath_subject', 'text', true );
 126          $Settings->set( 'repath_subject', $repath_subject );
 127  
 128          param( 'repath_body_terminator', 'text', true );
 129          $Settings->set( 'repath_body_terminator', $repath_body_terminator );
 130  
 131          param( 'repath_errtype', 'text', true );
 132          if( strlen( $repath_errtype ) > 5000 )
 133          {    // Crop the value by max available size
 134              $Messages->add( T_('Maximum length of the field "Error message decoding configuration" is 5000 symbols, the big value will be cropped.'), 'note' );
 135              $repath_errtype = substr( $repath_errtype, 0, 5000 );
 136          }
 137          $Settings->set( 'repath_errtype', $repath_errtype );
 138  
 139          if( ! $Messages->has_errors() )
 140          {
 141              $Settings->dbupdate();
 142              $Messages->add( T_('Settings updated.'), 'success' );
 143              // Redirect so that a reload doesn't write to the DB twice:

 144              header_redirect( '?ctrl=email&tab=settings', 303 ); // Will EXIT

 145              // We have EXITed already at this point!!

 146          }
 147          break;
 148  
 149      case 'test_1':
 150      case 'test_2':
 151      case 'test_3':
 152          // Check that this action request is not a CSRF hacked request:

 153          $Session->assert_received_crumb( 'emailsettings' );
 154  
 155          // Check permission:

 156          $current_User->check_perm( 'emails', 'edit', true );
 157  
 158          load_funcs( 'cron/model/_decode_returned_emails.funcs.php');
 159          load_class( '_ext/mime_parser/rfc822_addresses.php', 'rfc822_addresses_class' );
 160          load_class( '_ext/mime_parser/mime_parser.php', 'mime_parser_class' );
 161  
 162          if( isset($GLOBALS['files_Module']) )
 163          {
 164              load_funcs( 'files/model/_file.funcs.php');
 165          }
 166  
 167          global $dre_messages;
 168  
 169          switch( $action )
 170          {
 171              case 'test_1':
 172                  if( $mbox = dre_connect() )
 173                  {    // Close opened connection
 174                      imap_close( $mbox );
 175                  }
 176                  break;
 177  
 178              case 'test_2':
 179                  if( $mbox = dre_connect() )
 180                  {
 181                      // Read messages from server

 182                      dre_msg('Reading messages from server');
 183                      $imap_obj = imap_check( $mbox );
 184                      dre_msg('Found '.$imap_obj->Nmsgs.' messages');
 185  
 186                      if( $imap_obj->Nmsgs > 0 )
 187                      {    // We will read only 1 message from server in test mode
 188                          dre_process_messages( $mbox, 1 );
 189                      }
 190                      else
 191                      {
 192                          dre_msg( T_('There are no messages in the mailbox') );
 193                      }
 194                      imap_close( $mbox );
 195                  }
 196                  break;
 197  
 198                  case 'test_3':
 199                      param( 'test_error_message', 'raw', '' );
 200                      if( !empty( $test_error_message ) )
 201                      {    // Simulate a message processing
 202                          dre_simulate_message( $test_error_message );
 203                          $repath_test_output = implode( "<br />\n", $dre_messages );
 204                      }
 205                      break;
 206          }
 207  
 208          $Messages->clear(); // Clear all messages

 209  
 210          if( !empty( $dre_messages ) )
 211          {    // We will display the output in a scrollable fieldset
 212              $repath_test_output = implode( "<br />\n", $dre_messages );
 213          }
 214          break;
 215  
 216      case 'blocked_new':
 217          // Init Email Blocked to show on the form

 218          $edited_EmailBlocked = new EmailBlocked();
 219          break;
 220  
 221      case 'blocked_save':
 222          // Update Email Blocked...

 223  
 224          // Check that this action request is not a CSRF hacked request:

 225          $Session->assert_received_crumb( 'email_blocked' );
 226  
 227          $action = 'blocked_edit';
 228          if( !isset( $edited_EmailBlocked ) )
 229          {    // Create a new address
 230              $edited_EmailBlocked = new EmailBlocked();
 231              $action = 'blocked_new';
 232          }
 233  
 234          // load data from request

 235          if( $edited_EmailBlocked->load_from_Request() )
 236          {    // We could load data from form without errors:
 237              // Save Email Blocked in DB:

 238              $edited_EmailBlocked->dbsave();
 239              $Messages->add( T_('The email address was updated.'), 'success' );
 240  
 241              // Redirect so that a reload doesn't write to the DB twice:

 242              header_redirect( '?ctrl=email&tab=blocked', 303 ); // Will EXIT

 243              // We have EXITed already at this point!!

 244          }
 245          break;
 246  
 247      case 'blocked_delete':
 248          // Delete Email Blocked...

 249  
 250          // Check that this action request is not a CSRF hacked request:

 251          $Session->assert_received_crumb( 'email_blocked' );
 252  
 253          // Make sure we got an iprange_ID:

 254          param( 'emblk_ID', 'integer', true );
 255  
 256          if( $edited_EmailBlocked->dbdelete() )
 257          {
 258              $Messages->add( T_('The email address was deleted.'), 'success' );
 259  
 260              // Redirect so that a reload doesn't write to the DB twice:

 261              header_redirect( '?ctrl=email&tab=blocked', 303 ); // Will EXIT

 262              // We have EXITed already at this point!!

 263          }
 264          break;
 265  }
 266  
 267  $AdminUI->breadcrumbpath_init( false );
 268  $AdminUI->breadcrumbpath_add( T_('Emails'), '?ctrl=email' );
 269  
 270  switch( $tab )
 271  {
 272      case 'sent':
 273          $AdminUI->breadcrumbpath_add( T_('Sent'), '?ctrl=email&amp;tab='.$tab );
 274  
 275          $emlog_ID = param( 'emlog_ID', 'integer', 0 );
 276          if( empty( $emlog_ID ) )
 277          { // Init datepicker css on list page
 278              require_css( 'ui.datepicker.css' );
 279          }
 280          else
 281          { // Require the styles for email content
 282              require_css( $emailskins_url.'_email_style.css' );
 283          }
 284          break;
 285  
 286      case 'blocked':
 287          $AdminUI->breadcrumbpath_add( T_('Addresses'), '?ctrl=email&amp;tab='.$tab );
 288          if( !isset( $edited_EmailBlocked ) )
 289          {    // List page
 290              // Init datepicker css

 291              require_css( 'ui.datepicker.css' );
 292              // Init js to edit status field

 293              require_js( 'jquery/jquery.jeditable.js', 'rsc_url' );
 294          }
 295          break;
 296  
 297      case 'return':
 298          $AdminUI->breadcrumbpath_add( T_('Returned'), '?ctrl=email&amp;tab='.$tab );
 299          if( empty( $emret_ID ) )
 300          {    // Init datepicker css on list page
 301              require_css( 'ui.datepicker.css' );
 302          }
 303          break;
 304  
 305      case 'settings':
 306          $AdminUI->breadcrumbpath_add( T_('Settings'), '?ctrl=email&amp;tab='.$tab );
 307          break;
 308  }
 309  
 310  $AdminUI->set_path( 'email', $tab );
 311  
 312  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)

 313  $AdminUI->disp_html_head();
 314  
 315  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)

 316  $AdminUI->disp_body_top();
 317  
 318  // Begin payload block:

 319  $AdminUI->disp_payload_begin();
 320  
 321  evo_flush();
 322  
 323  switch( $tab )
 324  {
 325      case 'sent':
 326          if( $emlog_ID > 0 )
 327          {    // Display a details of selected email log
 328              $MailLog = $DB->get_row( '
 329                  SELECT *
 330                    FROM T_email__log
 331                   WHERE emlog_ID = '.$DB->quote( $emlog_ID ) );
 332              if( $MailLog )
 333              {    // The mail log exists with selected ID
 334                  $AdminUI->disp_view( 'tools/views/_email_sent_details.view.php' );
 335                  break;
 336              }
 337          }
 338          // Display a list of email logs:

 339          $AdminUI->disp_view( 'tools/views/_email_sent.view.php' );
 340          break;
 341  
 342      case 'blocked':
 343          if( isset( $edited_EmailBlocked ) )
 344          {    // Display form to create/edit an email address
 345              $AdminUI->disp_view( 'tools/views/_email_blocked.form.php' );
 346              break;
 347          }
 348          // Display a list of email logs:

 349          $AdminUI->disp_view( 'tools/views/_email_blocked.view.php' );
 350          break;
 351  
 352      case 'return':
 353          load_funcs('cron/model/_decode_returned_emails.funcs.php');
 354          $emret_ID = param( 'emret_ID', 'integer', 0 );
 355          if( $emret_ID > 0 )
 356          {    // Display a details of selected email
 357              $MailReturn = $DB->get_row( '
 358                  SELECT *
 359                    FROM T_email__returns
 360                   WHERE emret_ID = '.$DB->quote( $emret_ID ) );
 361              if( $MailReturn )
 362              {    // The returned email exists with selected ID
 363                  $AdminUI->disp_view( 'tools/views/_email_return_details.view.php' );
 364                  break;
 365              }
 366          }
 367          // Display a list of email logs:

 368          $AdminUI->disp_view( 'tools/views/_email_return.view.php' );
 369          break;
 370  
 371      case 'settings':
 372          $AdminUI->disp_view( 'tools/views/_email_settings.form.php' );
 373          break;
 374  
 375  }
 376  
 377  // End payload block:

 378  $AdminUI->disp_payload_end();
 379  
 380  // Display body bottom, debug info and close </html>:

 381  $AdminUI->disp_global_footer();
 382  
 383  ?>

title

Description

title

Description

title

Description

title

title

Body