- Timestamp:
- 03/24/2023 05:40:23 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/helpscout/common.php
r12484 r12493 80 80 $subject = $request->ticket->subject ?? ''; 81 81 $user = get_user_by( 'email', $email ); 82 83 // Ignore @wordpress.org "users", unless it's literally the only match (The ?? $email fallback at the end).84 if ( $user && str_ends_with( $user->user_email, '@wordpress.org' ) ) {85 $user = false;86 }87 82 88 83 // If this is related to a slack user, fetch their details instead. … … 96 91 // If the customer object has alternative emails listed, check to see if they have a profile. 97 92 if ( ! $user && ! empty( $request->customer->emails ) ) { 98 foreach ( $request->customer->emails as $alt_email ) {99 $user = get_user_by( 'email', $alt_email );100 if ( $user ) { 101 break;102 }103 }93 $user = get_user_from_emails( $request->customer->emails ); 94 } 95 96 // Ignore @wordpress.org "users", unless it's literally the only match (The ?? $email fallback at the end). 97 if ( $user && str_ends_with( $user->user_email, '@wordpress.org' ) ) { 98 $user = false; 104 99 } 105 100 … … 185 180 // Extract `To:`, `X-Orig-To:`, and fallback to all emails. 186 181 $emails = []; 187 if ( preg_match( '!^(x-orig-to:|to:|Final-Recipient:(\s*rfc\d+;)?)\s*(?P<email>.+@.+)$!im', $text, $m ) ) { 188 $m['email'] = str_replace( [ '<', '>' ], '', $m['email'] ); 189 $m['email'] = trim( $m['email'], '<> ' ); 190 191 $emails = [ $m['email'] ]; 192 } else { 182 if ( preg_match_all( '!^(x-orig-to:|to:|(Final|Original)-Recipient:(\s*rfc\d+;)?)\s*(?P<email>.+@.+)$!im', $text, $m ) ) { 183 $emails = $m['email']; 184 } elseif ( 193 185 // Ugly regex for emails, but it's good for mailer-daemon emails. 194 if ( preg_match_all( '![^\s;"]+@[^\s;&"]+\.[^\s;&"]+[a-z]!', $text, $m ) ) { 195 $emails = array_unique( array_diff( $m[0], [ $request->mailbox->email ] ) ); 196 } 197 } 186 preg_match_all( '![^\s;"]+@[^\s;&"]+\.[^\s;&"]+[a-z]!', $text, $m ) 187 ) { 188 $emails = $m[0]; 189 } 190 191 // Clean them up. 192 foreach ( $emails as &$email ) { 193 $email = str_replace( [ '<', '>' ], '', $email ); 194 $email = trim( $email, '<> ' ); 195 } 196 $emails = array_unique( $emails ); 197 198 // Remove any internal emails. 199 $emails = array_filter( $emails, function( $email ) use( $request ) { 200 return ! str_ends_with( $email, '@wordpress.org' ) && 201 $email != $request->mailbox->email; 202 } ); 198 203 199 204 return $emails;
Note: See TracChangeset
for help on using the changeset viewer.