Core
4 days ago
Util
4 days ago
Check_Email_Encode_Tab.php
4 days ago
Check_Email_Notify_Tab.php
4 days ago
Check_Email_SMTP_Tab.php
4 days ago
class-check-email-header-parser.php
4 days ago
class-check-email-log-autoloader.php
4 days ago
class-check-email-newsletter.php
4 days ago
deactivate-feedback.php
4 days ago
helper-function.php
4 days ago
install.php
4 days ago
class-check-email-header-parser.php
90 lines
| 1 | <?php |
| 2 | |
| 3 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
| 4 | |
| 5 | /** |
| 6 | * Class Email Header Parser. |
| 7 | */ |
| 8 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound |
| 9 | class Check_Email_Header_Parser { |
| 10 | |
| 11 | public function join_headers( $data ) { |
| 12 | $headers = ''; |
| 13 | |
| 14 | if ( ! empty( $data['from'] ) ) { |
| 15 | $headers .= 'From: ' . $data['from'] . "\r\n"; |
| 16 | } |
| 17 | |
| 18 | if ( ! empty( $data['cc'] ) ) { |
| 19 | $headers .= 'CC: ' . $data['cc'] . "\r\n"; |
| 20 | } |
| 21 | |
| 22 | if ( ! empty( $data['bcc'] ) ) { |
| 23 | $headers .= 'BCC: ' . $data['bcc'] . "\r\n"; |
| 24 | } |
| 25 | |
| 26 | if ( ! empty( $data['reply_to'] ) ) { |
| 27 | $headers .= 'Reply-to: ' . $data['reply_to'] . "\r\n"; |
| 28 | } |
| 29 | |
| 30 | if ( ! empty( $data['content_type'] ) ) { |
| 31 | $headers .= 'Content-type: ' . $data['content_type'] . "\r\n"; |
| 32 | } |
| 33 | |
| 34 | return $headers; |
| 35 | } |
| 36 | |
| 37 | public function parse_headers( $headers ) { |
| 38 | return $this->parse( $headers ); |
| 39 | } |
| 40 | |
| 41 | private function parse( $headers ) { |
| 42 | $data = array(); |
| 43 | $arr_headers = explode( "\n", $headers ); |
| 44 | |
| 45 | foreach ( $arr_headers as $header ) { |
| 46 | $split_header = explode( ':', $header ); |
| 47 | $value = $this->parse_header_line( $split_header ); |
| 48 | |
| 49 | if ( trim( $value ) != '' ) { |
| 50 | switch ( strtolower( $split_header[0] ) ) { |
| 51 | case 'from': |
| 52 | $data['from'] = $value; |
| 53 | break; |
| 54 | |
| 55 | case 'cc': |
| 56 | $data['cc'] = $value; |
| 57 | break; |
| 58 | |
| 59 | case 'bcc': |
| 60 | $data['bcc'] = $value; |
| 61 | break; |
| 62 | |
| 63 | case 'reply-to': |
| 64 | $data['reply_to'] = $value; |
| 65 | break; |
| 66 | |
| 67 | case 'content-type': |
| 68 | $data['content_type'] = $value; |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return $data; |
| 75 | } |
| 76 | |
| 77 | private function parse_header_line( $header ) { |
| 78 | $value = ''; |
| 79 | if ( count( $header ) == 2 ) { |
| 80 | if ( is_array( $header[1] ) ) { |
| 81 | $value = trim( implode( ',', array_map( 'trim', $header[1] ) ) ); |
| 82 | } else { |
| 83 | $value = trim( $header[1] ); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return $value; |
| 88 | } |
| 89 | } |
| 90 |