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