PluginProbe ʕ •ᴥ•ʔ
Check & Log Email – Easy Email Testing & Mail logging / 1.0.13
Check & Log Email – Easy Email Testing & Mail logging v1.0.13
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 / helper-function.php
check-email / include Last commit date
Core 2 years ago Util 2 years ago class-check-email-header-parser.php 2 years ago class-check-email-log-autoloader.php 2 years ago class-check-email-newsletter.php 2 years ago deactivate-feedback.php 2 years ago helper-function.php 2 years ago install.php 2 years ago
helper-function.php
445 lines
1 <?php
2
3 /**
4 * Helper Functions
5 *
6 * @package check-mail
7 * @subpackage Helper/Templates
8 * @copyright Copyright (c) 2016, René Hermenau
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 * @since 1.4.0
11 */
12 // Exit if accessed directly
13 if( !defined( 'ABSPATH' ) )
14 exit;
15
16 /**
17 * Helper method to check if user is in the plugins page.
18 *
19 * @author René Hermenau
20 * @since 1.4.0
21 *
22 * @return bool
23 */
24
25 /**
26 * display deactivation logic on plugins page
27 *
28 * @since 1.4.0
29 */
30 function ck_mail_is_plugins_page() {
31
32 if(function_exists('get_current_screen')){
33 $screen = get_current_screen();
34 if(is_object($screen)){
35 if($screen->id == 'plugins' || $screen->id == 'plugins-network'){
36 return true;
37 }
38 }
39 }
40 return false;
41 }
42
43 add_filter('admin_footer', 'ck_mail_add_deactivation_feedback_modal');
44 function ck_mail_add_deactivation_feedback_modal() {
45
46 if( !is_admin() && !ck_mail_is_plugins_page()) {
47 return;
48 }
49
50 require_once CK_MAIL_PATH ."/include/deactivate-feedback.php";
51
52 }
53
54 /**
55 * send feedback via email
56 *
57 * @since 1.4.0
58 */
59 function ck_mail_send_feedback() {
60
61 if( isset( $_POST['data'] ) ) {
62 parse_str( $_POST['data'], $form );
63 }
64
65 if( !isset( $form['ck_mail_security_nonce'] ) || isset( $form['ck_mail_security_nonce'] ) && !wp_verify_nonce( sanitize_text_field( $form['ck_mail_security_nonce'] ), 'ck_mail_ajax_check_nonce' ) ) {
66 echo 'security_nonce_not_verified';
67 die();
68 }
69 if ( !current_user_can( 'manage_options' ) ) {
70 die();
71 }
72
73 $text = '';
74 if( isset( $form['ck_mail_disable_text'] ) ) {
75 $text = implode( " ", $form['ck_mail_disable_text'] );
76 }
77
78 $headers = array();
79
80 $from = isset( $form['ck_mail_disable_from'] ) ? $form['ck_mail_disable_from'] : '';
81 if( $from ) {
82 $headers[] = "From: $from";
83 $headers[] = "Reply-To: $from";
84 }
85
86 $subject = isset( $form['ck_mail_disable_reason'] ) ? $form['ck_mail_disable_reason'] : '(no reason given)';
87
88 if($subject == 'technical issue'){
89
90 $subject = 'Check & Log Email '.$subject;
91 $text = trim($text);
92
93 if(!empty($text)){
94
95 $text = 'technical issue description: '.$text;
96
97 }else{
98
99 $text = 'no description: '.$text;
100 }
101
102 }else{
103 $subject = 'Check & Log Email';
104 }
105
106 $success = wp_mail( 'team@magazine3.in', $subject, $text, $headers );
107
108 echo 'sent';
109 die();
110 }
111 add_action( 'wp_ajax_ck_mail_send_feedback', 'ck_mail_send_feedback' );
112
113 function ck_mail_enqueue_makebetter_email_js(){
114
115 if( !is_admin() && !ck_mail_is_plugins_page()) {
116 return;
117 }
118
119 wp_enqueue_script( 'ck_mail_make_better_js', CK_MAIL_URL . 'assets/js/admin/feedback.js', array( 'jquery' ));
120 $data = array(
121 'ajax_url' => admin_url( 'admin-ajax.php' ),
122 'ck_mail_security_nonce' => wp_create_nonce('ck_mail_ajax_check_nonce'),
123 );
124
125 $data = apply_filters( 'ck_mail_localize_filter', $data, 'eztoc_admin_data' );
126
127 wp_localize_script( 'ck_mail_make_better_js', 'cn_ck_mail_admin_data', $data );
128
129 wp_enqueue_style( 'ck_mail_make_better_css', CK_MAIL_URL . 'assets/css/admin/feedback.css', false );
130
131
132 }
133 add_action( 'admin_enqueue_scripts', 'ck_mail_enqueue_makebetter_email_js' );
134
135
136 add_action('wp_ajax_ck_mail_subscribe_newsletter','ck_mail_subscribe_for_newsletter');
137 function ck_mail_subscribe_for_newsletter(){
138 if( !wp_verify_nonce( sanitize_text_field( $_POST['ck_mail_security_nonce'] ), 'ck_mail_ajax_check_nonce' ) ) {
139 echo 'security_nonce_not_verified';
140 die();
141 }
142 if ( !current_user_can( 'manage_options' ) ) {
143 die();
144 }
145 $api_url = 'http://magazine3.company/wp-json/api/central/email/subscribe';
146 $api_params = array(
147 'name' => sanitize_text_field($_POST['name']),
148 'email'=> sanitize_email($_POST['email']),
149 'website'=> sanitize_text_field($_POST['website']),
150 'type'=> 'checkmail'
151 );
152 $response = wp_remote_post( $api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
153 $response = wp_remote_retrieve_body( $response );
154 echo $response;
155 die;
156 }
157
158 function check_mail_forward_mail($atts) {
159 if ( isset( $atts['to'] ) ) {
160 $to = $atts['to'];
161 if ( ! is_array( $to ) ) {
162 $to = explode( ',', $to );
163 }
164 }
165
166
167 if ( isset( $atts['subject'] ) ) {
168 $subject = $atts['subject'];
169 }
170
171 if ( isset( $atts['message'] ) ) {
172 $message = $atts['message'];
173 }
174
175 if ( isset( $atts['headers'] ) ) {
176 $headers = $atts['headers'];
177 }
178
179 if ( isset( $atts['attachments'] ) ) {
180 $attachments = $atts['attachments'];
181 }
182
183
184 $subject = esc_html('Forward Email Check & Log ', 'check-email').$subject;
185
186 if ( ! is_array( $attachments ) ) {
187 $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
188 }
189 global $phpmailer;
190 if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
191 require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
192 require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
193 require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
194 $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
195
196 $phpmailer::$validator = static function ( $email ) {
197 return (bool) is_email( $email );
198 };
199 }
200
201 // Headers.
202 $cc = array();
203 $bcc = array();
204 $reply_to = array();
205
206 if ( empty( $headers ) ) {
207 $headers = array();
208 } else {
209 if ( ! is_array( $headers ) ) {
210 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
211 } else {
212 $tempheaders = $headers;
213 }
214 $headers = array();
215
216 // If it's actually got contents.
217 if ( ! empty( $tempheaders ) ) {
218 // Iterate through the raw headers.
219 foreach ( (array) $tempheaders as $header ) {
220 if ( ! str_contains( $header, ':' ) ) {
221 if ( false !== stripos( $header, 'boundary=' ) ) {
222 $parts = preg_split( '/boundary=/i', trim( $header ) );
223 $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
224 }
225 continue;
226 }
227 // Explode them out.
228 list( $name, $content ) = explode( ':', trim( $header ), 2 );
229
230 // Cleanup crew.
231 $name = trim( $name );
232 $content = trim( $content );
233
234 switch ( strtolower( $name ) ) {
235 // Mainly for legacy -- process a "From:" header if it's there.
236 case 'from':
237 $bracket_pos = strpos( $content, '<' );
238 if ( false !== $bracket_pos ) {
239 // Text before the bracketed email is the "From" name.
240 if ( $bracket_pos > 0 ) {
241 $from_name = substr( $content, 0, $bracket_pos );
242 $from_name = str_replace( '"', '', $from_name );
243 $from_name = trim( $from_name );
244 }
245
246 $from_email = substr( $content, $bracket_pos + 1 );
247 $from_email = str_replace( '>', '', $from_email );
248 $from_email = trim( $from_email );
249
250 // Avoid setting an empty $from_email.
251 } elseif ( '' !== trim( $content ) ) {
252 $from_email = trim( $content );
253 }
254 break;
255 case 'content-type':
256 if ( str_contains( $content, ';' ) ) {
257 list( $type, $charset_content ) = explode( ';', $content );
258 $content_type = trim( $type );
259 if ( false !== stripos( $charset_content, 'charset=' ) ) {
260 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) );
261 } elseif ( false !== stripos( $charset_content, 'boundary=' ) ) {
262 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
263 $charset = '';
264 }
265
266 // Avoid setting an empty $content_type.
267 } elseif ( '' !== trim( $content ) ) {
268 $content_type = trim( $content );
269 }
270 break;
271 case 'cc':
272 $cc = array_merge( (array) $cc, explode( ',', $content ) );
273 break;
274 case 'bcc':
275 $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
276 break;
277 case 'reply-to':
278 $reply_to = array_merge( (array) $reply_to, explode( ',', $content ) );
279 break;
280 default:
281 // Add it to our grand headers array.
282 $headers[ trim( $name ) ] = trim( $content );
283 break;
284 }
285 }
286 }
287 }
288
289 // Empty out the values that may be set.
290 $phpmailer->clearAllRecipients();
291 $phpmailer->clearAttachments();
292 $phpmailer->clearCustomHeaders();
293 $phpmailer->clearReplyTos();
294 $phpmailer->Body = '';
295 $phpmailer->AltBody = '';
296
297 // Set "From" name and email.
298
299 // If we don't have a name from the input headers.
300 if ( ! isset( $from_name ) ) {
301 $from_name = 'WordPress';
302 }
303 if ( ! isset( $from_email ) ) {
304 // Get the site domain and get rid of www.
305 $sitename = wp_parse_url( network_home_url(), PHP_URL_HOST );
306 $from_email = 'wordpress@';
307
308 if ( null !== $sitename ) {
309 if ( str_starts_with( $sitename, 'www.' ) ) {
310 $sitename = substr( $sitename, 4 );
311 }
312
313 $from_email .= $sitename;
314 }
315 }
316
317 try {
318 $phpmailer->setFrom( $from_email, $from_name, false );
319 } catch ( PHPMailer\PHPMailer\Exception $e ) {
320 error_log('Error in forwar email check & log : '.$e->getMessage());
321 return false;
322 }
323
324 // Set mail's subject and body.
325 $phpmailer->Subject = $subject;
326 $phpmailer->Body = $message;
327
328 // Set destination addresses, using appropriate methods for handling addresses.
329 $address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
330
331 foreach ( $address_headers as $address_header => $addresses ) {
332 if ( empty( $addresses ) ) {
333 continue;
334 }
335
336 foreach ( (array) $addresses as $address ) {
337 try {
338 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>".
339 $recipient_name = '';
340
341 if ( preg_match( '/(.*)<(.+)>/', $address, $matches ) ) {
342 if ( count( $matches ) === 3 ) {
343 $recipient_name = $matches[1];
344 $address = $matches[2];
345 }
346 }
347
348 switch ( $address_header ) {
349 case 'to':
350 $phpmailer->addAddress( $address, $recipient_name );
351 break;
352 case 'cc':
353 $phpmailer->addCc( $address, $recipient_name );
354 break;
355 case 'bcc':
356 $phpmailer->addBcc( $address, $recipient_name );
357 break;
358 case 'reply_to':
359 $phpmailer->addReplyTo( $address, $recipient_name );
360 break;
361 }
362 } catch ( PHPMailer\PHPMailer\Exception $e ) {
363 continue;
364 }
365 }
366 }
367
368 // Set to use PHP's mail().
369 $phpmailer->isMail();
370
371 // Set Content-Type and charset.
372
373 // If we don't have a Content-Type from the input headers.
374 if ( ! isset( $content_type ) ) {
375 $content_type = 'text/plain';
376 }
377
378
379 $content_type = apply_filters( 'wp_mail_content_type', $content_type );
380
381 $phpmailer->ContentType = $content_type;
382
383 // Set whether it's plaintext, depending on $content_type.
384 if ( 'text/html' === $content_type ) {
385 $phpmailer->isHTML( true );
386 }
387
388 // If we don't have a charset from the input headers.
389 if ( ! isset( $charset ) ) {
390 $charset = get_bloginfo( 'charset' );
391 }
392
393
394 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
395
396 // Set custom headers.
397 if ( ! empty( $headers ) ) {
398 foreach ( (array) $headers as $name => $content ) {
399 // Only add custom headers not added automatically by PHPMailer.
400 if ( ! in_array( $name, array( 'MIME-Version', 'X-Mailer' ), true ) ) {
401 try {
402 $phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
403 } catch ( PHPMailer\PHPMailer\Exception $e ) {
404 continue;
405 }
406 }
407 }
408
409 if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
410 $phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) );
411 }
412 }
413
414 if ( ! empty( $attachments ) ) {
415 foreach ( $attachments as $filename => $attachment ) {
416 $filename = is_string( $filename ) ? $filename : '';
417
418 try {
419 $phpmailer->addAttachment( $attachment, $filename );
420 } catch ( PHPMailer\PHPMailer\Exception $e ) {
421 continue;
422 }
423 }
424 }
425
426 /**
427 * Fires after PHPMailer is initialized.
428 *
429 * @since 2.2.0
430 *
431 * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference).
432 */
433 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
434
435 $mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
436
437 // Send!
438 try {
439 $send = $phpmailer->send();
440 return $send;
441 } catch ( PHPMailer\PHPMailer\Exception $e ) {
442 error_log('Error in forwar email send check & log : '.$e->getMessage());
443 return false;
444 }
445 }