PluginProbe ʕ •ᴥ•ʔ
Check & Log Email – Easy Email Testing & Mail logging / 2.0.15
Check & Log Email – Easy Email Testing & Mail logging v2.0.15
2.0.15 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 2.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.13.1 2.0.13.2 2.0.14 2.0.2 2.0.3 2.0.4 2.0.5 2.0.5.1 2.0.6 2.0.7 2.0.8 2.0.9 trunk 0.5.7 0.6.0 0.6.1 0.6.2 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.12.1 1.0.13 1.0.13.1 1.0.2 1.0.3
check-email / include / class-check-email-header-parser.php
check-email / include Last commit date
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