[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/ -> MP_process_pop3_.class.php (source)

   1  <?php
   2  abstract class MP_process_pop3_ extends MP_WP_db_connect_
   3  {
   4      public $bt = 132;
   5  
   6  	function __construct()
   7      {
   8          $this->config = get_option( $this->option_name );
   9          if ( !$this->config ) return;
  10  
  11          $this->trace = new MP_Log( $this->log_name, array( 'option_name' => $this->log_option_name ) );
  12  
  13          $this->trace->log( '!' . str_repeat( '-', $this->bt ) . '!' );
  14          $bm = $this->get_log_title();
  15          $this->trace->log( '!' . str_repeat( ' ', 5 ) . $bm . str_repeat( ' ', $this->bt - 5 - strlen( $bm ) ) . '!' );
  16          $this->trace->log( '!' . str_repeat( '-', $this->bt ) . '!' );
  17          $bm = " start      !";
  18          $this->trace->log( '!' . $bm . str_repeat( ' ', $this->bt - strlen( $bm ) ) . '!' );
  19  
  20          $return = $this->process();
  21  
  22          do_action( $this->cron_name );
  23  
  24          $this->trace->log( '!' . str_repeat( '-', $this->bt ) . '!' );
  25          $this->trace->end( $return );
  26      }
  27  
  28  	function get_pop3_config()
  29      {
  30          if ( isset( $this->config['pop3'] ) ) return $this->config['pop3'];
  31  
  32          $this->config['pop3'] = get_option( 'MailPress_connection_pop3' );
  33          update_option( $this->option_name, $this->config );
  34          return $this->config['pop3'];
  35      }
  36  
  37  // process
  38  	function process()
  39      {
  40          $return = true;
  41          $pop3 = $this->get_pop3_config();
  42  
  43          $this->pop3 = new MP_Swift_Pop3( $pop3['server'], $pop3['port'], $pop3['username'], $pop3['password'], $this->trace );
  44  
  45          $bm = ' connecting ! ' . $pop3['server'] . ':' . $pop3['port'];
  46          $this->trace->log( '!' . $bm . str_repeat( ' ', $this->bt - strlen( $bm ) ) . '!' );
  47  
  48          if ( $this->pop3->connect() )
  49          {
  50              if ( $this->pop3->get_list() )
  51              {
  52                  foreach( $this->pop3->messages as $this->message_id ) $this->process_message();
  53              }
  54              else
  55              {
  56                  $v = ' *** ALL DONE ***       *** ALL DONE ***       *** ALL DONE *** '; 
  57                  $this->trace->log( '!' . str_repeat( '-', $this->bt ) . '!' );
  58                  $this->trace->log( '!' . str_repeat( ' ', 15 ) . $v . str_repeat( ' ', $this->bt -15 - strlen( $v ) ) . '!' );
  59                  $this->trace->log( '!' . str_repeat( '-', $this->bt ) . '!' );
  60                  $return = false;
  61              }
  62              if ( !$this->pop3->disconnect() ) $return = false;
  63          }
  64          else $return = false;
  65  
  66          if ( $return )
  67          {
  68              $bm = " end        !";
  69              $this->trace->log( '!' . $bm . str_repeat( ' ', $this->bt - strlen( $bm ) ) . '!' );
  70          }
  71          return $return;
  72      }
  73  
  74  	function has_email()
  75      {
  76          $this->email_address = false;
  77          $this->name_address  = false;
  78  // from
  79          $from = $this->pop3->get_header( 'From' );
  80  
  81          if ( empty( $from ) )
  82          {
  83              $bm = '            ! ** ERROR ** empty header : From (?) ' . $this->tag;
  84              $this->local_log[] = '!' . $bm . str_repeat( ' ', $this->bt - strlen( $bm ) ) . '!';
  85              return;
  86          }
  87  
  88          $froms = explode( ' ', $from );
  89  
  90          if ( is_array( $froms ) && count( $froms ) )
  91          {
  92              $froms = array_map( 'trim', $froms );
  93              do {
  94                  $from = array_pop( $froms );
  95                  $beg = substr( $from,  0, 1 );
  96                  $end = substr( $from, -1, 1 );
  97                  if ( ( $beg == '<' ) && ( $end == '>' ) ) $from = substr( $from, 1, -1);
  98  
  99                  if ( MailPress::is_email( $from ) )
 100                  {
 101                      $this->email_address = $from;
 102                      break;
 103                  }
 104              }while( count( $froms ) );
 105  
 106              if ( !$this->email_address )
 107              {
 108                  $bm = ' From:      ! ??? cannot find email ' . $this->tag;
 109                  $this->local_log[] = '!' . $bm . str_repeat( ' ', $this->bt - strlen( $bm ) ) . '!';
 110                  return;
 111              }
 112          }
 113          else
 114          {
 115              $this->email_address = ( MailPress::is_email( $from ) ) ? $from : false;
 116  
 117              if ( !$this->email_address )
 118              {
 119                  $bm = ' From:      ! ??? cannot find email ' . $this->tag;
 120                  $this->local_log[] = '!' . $bm . str_repeat( ' ', $this->bt - strlen( $bm ) ) . '!';
 121                  return;
 122              }
 123          }
 124  
 125          if ( count( $froms ) )
 126          {
 127              $from = implode( ' ', $froms );
 128              $from = trim( $from );
 129              if ( !empty( $from ) )
 130              {
 131                  $beg = substr( $from,  0, 1 );
 132                  $end = substr( $from, -1, 1 );
 133                  if ( ( $beg == '"' ) && ( $end == '"' ) ) $from = substr( $from, 1, -1);
 134                  $this->name_address = $from;
 135              }
 136          }
 137      }
 138  
 139  	function compare( $a, $b )
 140      {
 141          foreach( array( 'a', 'b' ) as $arg )
 142          {
 143              $$arg = trim( $$arg );
 144              $$arg = strtolower( $$arg );
 145              $$arg = mb_convert_encoding( $$arg, 'utf-8', 'auto' );
 146          }
 147  
 148          return ( $a == $b );
 149      }
 150  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1