[ Index ] |
MailPress 7.2 |
[ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] |
[Summary view] [Print] [Text view]
1 <?php 2 abstract class MP_bounce_ extends MP_process_pop3_ 3 { 4 public static $count = array(); 5 6 function get_log_title() 7 { 8 $xmailboxstatus = array( 0 => 'no changes', 1 => 'mark as read', 2 => 'delete', ); 9 return sprintf( $this->log_title, $xmailboxstatus[$this->config['mailbox_status']] ); 10 } 11 12 function process_message() 13 { 14 $this->local_log = array(); 15 16 if ( !$this->is_bounce() ) 17 { 18 $sep = ( count( $this->local_log ) != 1 ); 19 if ( $sep ) $this->trace->log( '!' . str_repeat( '-', $this->bt ) . '!' ); 20 foreach( $this->local_log as $local_log ) $this->trace->log( $local_log ); 21 if ( $sep ) $this->trace->log( '!' . str_repeat( '-', $this->bt ) . '!' ); 22 23 return; 24 } 25 26 $user_logmess = $mail_logmess = ''; 27 $already_processed = $already_stored = false; 28 29 $bm = ' !'; 30 $bm .= str_repeat( '-', $this->bt - strlen( $bm ) ); 31 $this->trace->log( '!' . $bm . '!' ); 32 33 $this->mysql_disconnect( $this->class ); 34 $this->mysql_connect( $this->class ); 35 36 if ( !$mp_user = MP_User::get( $this->mp_user_id ) ) 37 { 38 $user_logmess = '** WARNING ** user not in database'; 39 $usermeta['bounce'] = 0; 40 } 41 else 42 { 43 $bounce = array( 'message' => $this->pop3->message ); 44 45 $usermeta = MP_User_meta::get( $this->mp_user_id, $this->meta_key ); 46 if ( !$usermeta ) 47 { 48 $usermeta = array(); 49 $usermeta['bounce'] = 1; 50 $usermeta['bounces'][$this->mail_id][] = $bounce; 51 MP_User_meta::add( $this->mp_user_id, $this->meta_key, $usermeta ); 52 } 53 else 54 { 55 if ( !is_array( $usermeta ) ) $usermeta = array(); 56 57 if ( !isset( $usermeta['bounces'][$this->mail_id] ) ) 58 { 59 $usermeta['bounces'][$this->mail_id] = array(); 60 61 if ( !isset( $usermeta['bounce'] ) ) $usermeta['bounce'] = 1; 62 elseif ( !is_numeric( $usermeta['bounce'] ) ) $usermeta['bounce'] = 1; 63 else $usermeta['bounce']++; 64 } 65 else 66 { 67 $already_processed = true; 68 foreach( $usermeta['bounces'][$this->mail_id] as $bounces ) 69 { 70 if ( $bounces['message'] == $bounce['message'] ) 71 { 72 $already_stored = true; 73 break; 74 } 75 } 76 } 77 78 if ( !$already_stored ) $usermeta['bounces'][$this->mail_id][] = $bounce; 79 80 if ( !MP_User_meta::add( $this->mp_user_id, $this->meta_key, $usermeta, true ) ) 81 MP_User_meta::update( $this->mp_user_id, $this->meta_key, $usermeta ); 82 } 83 84 switch ( true ) 85 { 86 case $already_processed : 87 $user_logmess = '-- notice -- bounce previously processed'; 88 break; 89 case ( 'bounced' == $mp_user->status ) : 90 $user_logmess = ' <' . $mp_user->email . '> already ** BOUNCED **'; 91 break; 92 case ( $usermeta['bounce'] >= $this->config['max_bounces'] ) : 93 MP_User::set_status( $this->mp_user_id, 'bounced' ); 94 $user_logmess = '** BOUNCED ** <' . $mp_user->email . '>'; 95 break; 96 default : 97 $user_logmess = 'new bounce for <' . $mp_user->email . '>'; 98 break; 99 } 100 } 101 102 $mailmeta = ''; 103 if ( !$already_processed ) 104 { 105 switch ( true ) 106 { 107 case ( -1 == $this->mail_id ) : 108 $mail_logmess = '** WARNING ** mail unknown'; 109 break; 110 case ( !$mail = MP_Mail::get( $this->mail_id ) ) : 111 $mail_logmess = '** WARNING ** mail not in database'; 112 break; 113 default : 114 if ( !isset( self::$count[$this->mail_id] ) ) self::$count[$this->mail_id] = MP_Mail_meta::get( $this->mail_id, $this->meta_key ); 115 self::$count[$this->mail_id] = ( is_numeric( self::$count[$this->mail_id] ) ) ? ( self::$count[$this->mail_id] + 1 ) : 1; 116 if ( !MP_Mail_meta::add( $this->mail_id, $this->meta_key, self::$count[$this->mail_id] , true ) ) 117 MP_Mail_meta::update( $this->mail_id, $this->meta_key, self::$count[$this->mail_id] ); 118 $mailmeta = self::$count[$this->mail_id]; 119 120 $metas = MP_Mail_meta::get( $this->mail_id, '_MailPress_replacements' ); 121 $mail_logmess = $mail->subject; 122 if ( $metas ) foreach( $metas as $k => $v ) $mail_logmess = str_replace( $k, $v, $mail_logmess ); 123 if ( strlen( $mail_logmess ) > 50 ) $mail_logmess = substr( $mail_logmess, 0, 49 ) . '...'; 124 break; 125 } 126 } 127 128 $this->trace->log( '!' . str_repeat( '-', $this->bt ) . '!' ); 129 130 $bm = ' ! id ! bounces ! '; 131 $this->trace->log( '!' . $bm . str_repeat( ' ', $this->bt - strlen( $bm ) ) . '!' ); 132 133 $bm = ' user ! '; 134 $bm .= str_repeat( ' ', 10 - strlen( $this->mp_user_id ) ) . $this->mp_user_id . ' !'; 135 $bm .= str_repeat( ' ', 10 - strlen( $usermeta['bounce'] ) ) . ( ( $usermeta['bounce'] ) ? $usermeta['bounce'] : '' ) . ' !'; 136 $bm .= " $user_logmess"; 137 $this->trace->log( '!' . $bm . str_repeat( ' ', $this->bt - strlen( $bm ) ) . '!' ); 138 139 $bm = ' mail ! '; 140 $bm .= str_repeat( ' ', 10 - strlen( $this->mail_id ) ) . $this->mail_id . ' !'; 141 $bm .= str_repeat( ' ', 10 - strlen( $mailmeta ) ) . $mailmeta . ' !'; 142 $bm .= " $mail_logmess"; 143 $this->trace->log( '!' . $bm . str_repeat( ' ', $this->bt - strlen( $bm ) ) . '!' ); 144 145 $bm = ' !------------+-----------+'; 146 $bm .= str_repeat( '-', $this->bt - strlen( $bm ) ); 147 $this->trace->log( '!' . $bm . '!' ); 148 149 switch ( $this->config['mailbox_status'] ) 150 { 151 case 1 : 152 $this->pop3->get_message( $this->message_id ); 153 break; 154 case 2 : 155 $this->pop3->delete( $this->message_id ); 156 break; 157 default : 158 break; 159 } 160 161 $this->trace->log( '!' . str_repeat( '-', $this->bt ) . '!' ); 162 } 163 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue May 19 15:55:14 2020 | Cross-referenced by PHPXref 0.7.1 |