1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
|
<?php
use FluentMail\App\Services\Mailer\Manager; use FluentMail\App\Services\Mailer\Providers\AmazonSes\SimpleEmailService; use FluentMail\App\Services\Mailer\Providers\Factory;
if (!function_exists('fluentMail')) { /** * Returns an instance of the FluentMail\App\App class. * * @param string|null $module The module name (optional). * @return FluentMail\App\App The instance of the FluentMail\App\App class. */ function fluentMail($module = null) { return FluentMail\App\App::getInstance($module); } }
if (!function_exists('fluentMailMix')) { /** * Generate the mixed URL for the given asset path. * * @param string $path The asset path. * @param string $manifestDirectory The directory where the manifest file is located (optional). * @return string The mixed URL for the asset. */ function fluentMailMix($path, $manifestDirectory = '') { return fluentMail('url.assets') . ltrim($path, '/'); } }
if (!function_exists('fluentMailAssetUrl')) { /** * Returns the URL for the assets of the Fluent Mail plugin. * * @param string|null $path The path to the asset file (optional). * @return string The URL for the assets of the Fluent Mail plugin. */ function fluentMailAssetUrl($path = null) { $assetUrl = fluentMail('url.assets'); return $path ? ($assetUrl . $path) : $assetUrl; } }
if (!function_exists('fluentMailIsListedSenderEmail')) { /** * Check if the given email is listed as a sender email in the Fluent SMTP plugin settings. * * @param string $email The email address to check. * @return bool Returns true if the email is listed as a sender email, false otherwise. */ function fluentMailIsListedSenderEmail($email) { static $settings;
if (!$settings) { $settings = fluentMailGetSettings(); }
if (!$settings) { return false; } return !empty($settings['mappings'][$email]); } }
if (!function_exists('fluentMailDefaultConnection')) { /** * Retrieves the default mail connection settings. * * @return array The default mail connection settings. */ function fluentMailDefaultConnection() { static $defaultConnection;
if ($defaultConnection) { return $defaultConnection; }
$settings = fluentMailGetSettings();
if (!$settings) { return []; }
if ( isset($settings['misc']['default_connection']) && isset($settings['connections'][$settings['misc']['default_connection']]) ) { $default = $settings['misc']['default_connection']; $defaultConnection = $settings['connections'][$default]['provider_settings']; } else if (count($settings['connections'])) { $connection = reset($settings['connections']); $defaultConnection = $connection['provider_settings']; } else { $defaultConnection = []; }
return $defaultConnection; } }
if (!function_exists('fluentMailgetConnection')) { /** * Get the connection for the given email address. * * @param string $email The email address. * @return Connection The connection object. */ function fluentMailgetConnection($email) { $factory = fluentMail(Factory::class); if (!($connection = $factory->get($email))) { $connection = fluentMailDefaultConnection(); }
return $connection; } }
if (!function_exists('fluentMailGetProvider')) { /** * Get the FluentMail provider for the given email address. * * @param string $fromEmail The email address to get the provider for. * @param bool $cacheClear Whether to clear the provider cache. * @return \FluentMail\App\Services\Mailer\Providers\Simulator\Handler|false The FluentMail provider for the given email address, or false if no provider is found. */ function fluentMailGetProvider($fromEmail, $cacheClear = false) { static $providers = [];
if (isset($providers[$fromEmail]) && !$cacheClear) { return $providers[$fromEmail]; }
$manager = fluentMail(Manager::class);
$misc = $manager->getSettings('misc');
if ((!empty($misc['simulate_emails']) && $misc['simulate_emails'] == 'yes') || (defined('FLUENTMAIL_SIMULATE_EMAILS') && FLUENTMAIL_SIMULATE_EMAILS)) { $providers[$fromEmail] = new FluentMail\App\Services\Mailer\Providers\Simulator\Handler(); return $providers[$fromEmail]; }
$mappings = $manager->getSettings('mappings');
$connection = false;
if (isset($mappings[$fromEmail])) { $connectionId = $mappings[$fromEmail]; $connections = $manager->getSettings('connections'); if (isset($connections[$connectionId])) { $connection = $connections[$connectionId]['provider_settings']; } }
if (!$connection) { $connection = fluentMailDefaultConnection(); if ($connection && \FluentMail\Includes\Support\Arr::get($connection, 'force_from_email') != 'no') { $connection['force_from_email_id'] = $connection['sender_email']; } }
if ($connection) { $factory = fluentMail(Factory::class); $driver = $factory->make($connection['provider']); $driver->setSettings($connection); $providers[$fromEmail] = $driver; } else { $providers[$fromEmail] = false; }
return $providers[$fromEmail]; } }
if (!function_exists('fluentMailSesConnection')) { /** * Establishes a connection to the Fluent SMTP service using the Amazon Simple Email Service (SES). * * @param array $connection The connection details including sender email, access key, secret key, and region. * @return SimpleEmailService The SES driver instance for the specified sender email. */ function fluentMailSesConnection($connection) { static $drivers = [];
if (isset($drivers[$connection['sender_email']])) { return $drivers[$connection['sender_email']]; }
$region = 'email.' . $connection['region'] . '.amazonaws.com';
$ses = new SimpleEmailService( $connection['access_key'], $connection['secret_key'], $region, false );
$drivers[$connection['sender_email']] = $ses;
return $drivers[$connection['sender_email']]; } }
if (!function_exists('fluentMailSend')) { /** * Sends an email using the wp_mail() function with additional filters and pre-send checks. * * @param string|array $to Array or comma-separated list of email addresses to send the message to. * @param string $subject The subject of the email. * @param string $message The message content of the email. * @param string|array $headers Additional headers for the email. * @param array $attachments Paths to files to attach to the email. * * @return bool|null Returns true if the email was successfully sent, false if sending was preempted, or null if there was an error. * * * @filter wp_mail * @filter pre_wp_mail */ function fluentMailSend($to, $subject, $message, $headers = '', $attachments = array()) { // Compact the input, apply the filters, and extract them back out. /** * Filters the wp_mail() arguments. * * @param array $args A compacted array of wp_mail() arguments, including the "to" email, * subject, message, headers, and attachments values. * @since 2.2.0 * */ $atts = apply_filters( 'wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments') );
/** * Filters whether to preempt sending an email. * * Returning a non-null value will short-circuit {@see wp_mail()}, returning * that value instead. A boolean return value should be used to indicate whether * the email was successfully sent. * * @param null|bool $return Short-circuit return value. * @param array $atts { * Array of the `wp_mail()` arguments. * * @type string|string[] $to Array or comma-separated list of email addresses to send message. * @type string $subject Email subject. * @type string $message Message contents. * @type string|string[] $headers Additional headers. * @type string|string[] $attachments Paths to files to attach. * } * @since 5.7.0 * */ $pre_wp_mail = apply_filters('pre_wp_mail', null, $atts);
if (null !== $pre_wp_mail) { return $pre_wp_mail; }
if (isset($atts['to'])) { $to = $atts['to']; }
if (!is_array($to)) { $to = explode(',', $to); }
if (isset($atts['subject'])) { $subject = $atts['subject']; }
if (isset($atts['message'])) { $message = $atts['message']; }
if (isset($atts['headers'])) { $headers = $atts['headers']; }
if (isset($atts['attachments'])) { $attachments = $atts['attachments']; }
if (!is_array($attachments)) { $attachments = explode("\n", str_replace("\r\n", "\n", $attachments)); }
global $phpmailer;
// (Re)create it, if it's gone missing. if (!($phpmailer instanceof PHPMailer\PHPMailer\PHPMailer)) { require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php'; require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; $phpmailer = new PHPMailer\PHPMailer\PHPMailer(true);
$phpmailer::$validator = static function ($email) { return (bool) is_email($email); }; }
// Headers. $cc = array(); $bcc = array(); $reply_to = array();
if (empty($headers)) { $headers = array(); } else { if (!is_array($headers)) { // Explode the headers out, so this function can take // both string headers and an array of headers. $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers)); } else { $tempheaders = $headers; } $headers = array();
// If it's actually got contents. if (!empty($tempheaders)) { // Iterate through the raw headers. foreach ((array) $tempheaders as $header) { if (strpos($header, ':') === false) { if (false !== stripos($header, 'boundary=')) { $parts = preg_split('/boundary=/i', trim($header)); $boundary = trim(str_replace(array("'", '"'), '', $parts[1])); } continue; } // Explode them out. list($name, $content) = explode(':', trim($header), 2);
// Cleanup crew. $name = trim($name); $content = trim($content);
switch (strtolower($name)) { // Mainly for legacy -- process a "From:" header if it's there. case 'from': $bracket_pos = strpos($content, '<'); if (false !== $bracket_pos) { // Text before the bracketed email is the "From" name. if ($bracket_pos > 0) { $from_name = substr($content, 0, $bracket_pos - 1); $from_name = str_replace('"', '', $from_name); $from_name = trim($from_name); }
$from_email = substr($content, $bracket_pos + 1); $from_email = str_replace('>', '', $from_email); $from_email = trim($from_email);
// Avoid setting an empty $from_email. } elseif ('' !== trim($content)) { $from_email = trim($content); } break; case 'content-type': if (strpos($content, ';') !== false) { list($type, $charset_content) = explode(';', $content); $content_type = trim($type); if (false !== stripos($charset_content, 'charset=')) { $charset = trim(str_replace(array('charset=', '"'), '', $charset_content)); } elseif (false !== stripos($charset_content, 'boundary=')) { $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset_content)); $charset = ''; }
// Avoid setting an empty $content_type. } elseif ('' !== trim($content)) { $content_type = trim($content); } break; case 'cc': $cc = array_merge((array) $cc, explode(',', $content)); break; case 'bcc': $bcc = array_merge((array) $bcc, explode(',', $content)); break; case 'reply-to': $reply_to = array_merge((array) $reply_to, explode(',', $content)); break; default: // Add it to our grand headers array. $headers[trim($name)] = trim($content); break; } } } }
// Empty out the values that may be set. $phpmailer->clearAllRecipients(); $phpmailer->clearAttachments(); $phpmailer->clearCustomHeaders(); $phpmailer->clearReplyTos(); $phpmailer->Body = ''; $phpmailer->AltBody = '';
/* * If we don't have an email from the input headers, default to wordpress@$sitename * Some hosts will block outgoing mail from this address if it doesn't exist, * but there's no easy alternative. Defaulting to admin_email might appear to be * another option, but some hosts may refuse to relay mail from an unknown domain. * See https://core.trac.wordpress.org/ticket/5007. */ $defaultConnection = false; if (!isset($from_email)) { $defaultConnection = fluentMailDefaultConnection();
if (!empty($defaultConnection['sender_email'])) { $from_email = $defaultConnection['sender_email']; } else { // Get the site domain and get rid of www. $sitename = wp_parse_url(network_home_url(), PHP_URL_HOST); if ('www.' === substr($sitename, 0, 4)) { $sitename = substr($sitename, 4); } $from_email = 'wordpress@' . $sitename; } }
// Set "From" name and email. // If we don't have a name from the input headers. if (!isset($from_name)) { if ($defaultConnection && !empty($defaultConnection['sender_name'])) { $from_name = $defaultConnection['sender_name']; } else { $provider = fluentMailGetProvider($from_email); if ($provider && !empty($provider->getSetting('sender_name'))) { $from_name = $provider->getSetting('sender_name'); } else { $from_name = 'WordPress'; } } }
if (!apply_filters('fluentsmtp_disable_from_name_email', false)) { /** * Filters the email address to send from. * * @param string $from_email Email address to send from. * @since 2.2.0 * */ $from_email = apply_filters('wp_mail_from', $from_email); }
/** * Filters the name to associate with the "from" email address. * * @param string $from_name Name associated with the "from" email address. * @since 2.3.0 * */ $from_name = apply_filters('wp_mail_from_name', $from_name);
try { $phpmailer->setFrom($from_email, $from_name, false); } catch (PHPMailer\PHPMailer\Exception $e) { $mail_error_data = compact('to', 'subject', 'message', 'headers', 'attachments'); $mail_error_data['phpmailer_exception_code'] = $e->getCode();
/** * This filter is documented in wp-includes/pluggable.php * * @param WP_Error $error A WP_Error object containing the error message. * @param array $mail_error_data An array of additional error data. * @return void */ do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) ); return false; }
// Set mail's subject and body. $phpmailer->Subject = $subject; $phpmailer->Body = $message;
// Set destination addresses, using appropriate methods for handling addresses. $address_headers = compact('to', 'cc', 'bcc', 'reply_to');
foreach ($address_headers as $address_header => $addresses) { if (empty($addresses)) { continue; }
foreach ((array) $addresses as $address) { try { // Break $recipient into name and address parts if in the format "Foo <[email protected]>". $recipient_name = '';
if (preg_match('/(.*)<(.+)>/', $address, $matches)) { if (count($matches) == 3) { $recipient_name = $matches[1]; $address = $matches[2]; } }
switch ($address_header) { case 'to': $phpmailer->addAddress($address, $recipient_name); break; case 'cc': $phpmailer->addCc($address, $recipient_name); break; case 'bcc': $phpmailer->addBcc($address, $recipient_name); break; case 'reply_to': $phpmailer->addReplyTo($address, $recipient_name); break; } } catch (PHPMailer\PHPMailer\Exception $e) { continue; } } }
// Set to use PHP's mail(). $phpmailer->isMail();
// Set Content-Type and charset.
// If we don't have a content-type from the input headers. if (!isset($content_type)) { $content_type = 'text/plain'; }
/** * Filters the wp_mail() content type. * * @param string $content_type Default wp_mail() content type. * @since 2.3.0 * */ $content_type = apply_filters('wp_mail_content_type', $content_type);
$phpmailer->ContentType = $content_type;
// If we don't have a charset from the input headers. if (!isset($charset)) { $charset = get_bloginfo('charset'); }
/** * Filters the default wp_mail() charset. * * @param string $charset Default email charset. * @since 2.3.0 * */ $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset);
// Set custom headers. if (!empty($headers)) { foreach ((array) $headers as $name => $content) { // Only add custom headers not added automatically by PHPMailer. if (!in_array($name, array('MIME-Version', 'X-Mailer'), true)) { try { $phpmailer->addCustomHeader(sprintf('%1$s: %2$s', $name, $content)); } catch (PHPMailer\PHPMailer\Exception $e) { continue; } } }
if (false !== stripos($content_type, 'multipart') && !empty($boundary)) { $phpmailer->addCustomHeader(sprintf('Content-Type: %s; boundary="%s"', $content_type, $boundary)); } }
if ( ! empty( $attachments ) ) { foreach ( $attachments as $filename => $attachment ) { $filename = is_string( $filename ) ? $filename : ''; try { $phpmailer->addAttachment( $attachment, $filename ); } catch ( PHPMailer\PHPMailer\Exception $e ) { continue; } } }
/** * Fires after PHPMailer is initialized. * * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference). * @since 2.2.0 * */ do_action_ref_array('phpmailer_init', array(&$phpmailer));
// Set whether it's plaintext, depending on $content_type. if ('text/html' === $phpmailer->ContentType) { $phpmailer->isHTML(true); if (fluentMailSendMultiPartText() && !$phpmailer->AltBody) { $phpmailer->AltBody = (new \FluentMail\App\Services\Html2Text($message))->getText(); if ($phpmailer->AltBody) { // Set multipart $phpmailer->ContentType = 'multipart/alternative'; } } }
$mail_data = compact('to', 'subject', 'message', 'headers', 'attachments');
// Send! try { // Trap the fluentSMTPMail mailer here $phpmailer = new FluentMail\App\Services\Mailer\FluentPHPMailer($phpmailer); $send = $phpmailer->send();
/** * Fires after a successful email is sent using the wp_mail() function. * * @param array $mail_data The data of the sent email. */ do_action('wp_mail_succeeded', $mail_data);
return $send;
} catch (PHPMailer\PHPMailer\Exception $e) {
$mail_data['phpmailer_exception_code'] = $e->getCode();
/** * Fires after a PHPMailer\PHPMailer\Exception is caught. * * @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array * containing the mail recipient, subject, message, headers, and attachments. * @since 4.4.0 * */ do_action('wp_mail_failed', new WP_Error('wp_mail_failed', $e->getMessage(), $mail_data)); return false; } } }
if (!function_exists('fluentMailGetSettings')) { /** * Retrieves the Fluent Mail settings. * * This function retrieves the Fluent Mail settings from the WordPress options. * If the settings are not found, it returns the default settings provided. * If the settings are found and the 'use_encrypt' option is enabled, it decrypts * the secret fields for each connection provider. * * @param array $defaults The default settings to return if the Fluent Mail settings are not found. * @param bool $cached Whether to use the cached settings or not. * @return array The Fluent Mail settings. */ function fluentMailGetSettings($defaults = [], $cached = true) { static $cachedSettings; if ($cached && $cachedSettings) { return $cachedSettings; }
$settings = get_option('fluentmail-settings');
if (!$settings) { return $defaults; }
if (!empty($settings['use_encrypt'])) { $providerKeyMaps = [ 'smtp' => 'password', 'ses' => 'secret_key', 'mailgun' => 'api_key', 'sendgrid' => 'api_key', 'sendinblue' => 'api_key', 'sparkpost' => 'api_key', 'pepipost' => 'api_key', 'postmark' => 'api_key', 'elasticmail' => 'api_key', 'gmail' => 'client_secret', 'outlook' => 'client_secret' ]; if (!empty($settings['connections']) && is_array($settings['connections'])) { foreach ($settings['connections'] as $key => $connection) { $providerKey = $connection['provider_settings']['provider']; if (empty($providerKeyMaps[$providerKey])) { continue; }
$secretFieldKey = $providerKeyMaps[$providerKey];
if (empty($connection['provider_settings'][$secretFieldKey])) { continue; }
$settings['connections'][$key]['provider_settings'][$secretFieldKey] = fluentMailEncryptDecrypt($connection['provider_settings'][$secretFieldKey], 'd'); } } }
$cachedSettings = $settings;
return $settings; } }
if (!function_exists('fluentMailSetSettings')) { /** * Sets the Fluent Mail settings and encrypts sensitive fields. * * @param array $settings The Fluent Mail settings. * * @return bool Returns Result of the Settings.. */ function fluentMailSetSettings($settings) { /** * Get the value of the 'use_encrypt' setting. * * This function applies the 'fluentsmtp_use_encrypt' filter to the 'yes' default value. * * @param string $default The default value for the 'use_encrypt' setting. * @return string The filtered value of the 'use_encrypt' setting. */ $settings['use_encrypt'] = apply_filters('fluentsmtp_use_encrypt', 'yes');
$hasSecretField = false;
if (!empty($settings['use_encrypt'])) { $providerKeyMaps = [ 'smtp' => 'password', 'ses' => 'secret_key', 'mailgun' => 'api_key', 'sendgrid' => 'api_key', 'sendinblue' => 'api_key', 'sparkpost' => 'api_key', 'pepipost' => 'api_key', 'postmark' => 'api_key', 'elasticmail' => 'api_key', 'gmail' => 'client_secret', 'outlook' => 'client_secret' ]; if (!empty($settings['connections']) && is_array($settings['connections'])) { foreach ($settings['connections'] as $key => $connection) { $providerKey = $connection['provider_settings']['provider']; if (empty($providerKeyMaps[$providerKey])) { continue; }
$secretFieldKey = $providerKeyMaps[$providerKey];
if (empty($connection['provider_settings'][$secretFieldKey])) { continue; }
$hasSecretField = true;
$settings['connections'][$key]['provider_settings'][$secretFieldKey] = fluentMailEncryptDecrypt($connection['provider_settings'][$secretFieldKey], 'e'); } } }
if ($hasSecretField) { $settings['test'] = fluentMailEncryptDecrypt('test', 'e'); } else { $settings['test'] = ''; $settings['use_encrypt'] = ''; }
$result = update_option('fluentmail-settings', $settings);
fluentMailGetSettings([], false);
return $result; } }
if (!function_exists('fluentMailEncryptDecrypt')) { /** * Encrypts or decrypts a value using AES-256-CTR encryption. * * @param string $value The value to be encrypted or decrypted. * @param string $type The type of operation to perform. Defaults to 'e' for encryption. * * @return string|false The encrypted or decrypted value, or false on failure. */ function fluentMailEncryptDecrypt($value, $type = 'e') { if (!$value) { return $value; }
if (!extension_loaded('openssl')) { return $value; }
if (defined('FLUENTMAIL_ENCRYPT_SALT')) { $salt = FLUENTMAIL_ENCRYPT_SALT; } else { $salt = (defined('LOGGED_IN_SALT') && '' !== LOGGED_IN_SALT) ? LOGGED_IN_SALT : 'this-is-a-fallback-salt-but-not-secure'; }
if (defined('FLUENTMAIL_ENCRYPT_KEY')) { $key = FLUENTMAIL_ENCRYPT_KEY; } else { $key = (defined('LOGGED_IN_KEY') && '' !== LOGGED_IN_KEY) ? LOGGED_IN_KEY : 'this-is-a-fallback-key-but-not-secure'; }
if ($type == 'e') { $method = 'aes-256-ctr'; $ivlen = openssl_cipher_iv_length($method); $iv = openssl_random_pseudo_bytes($ivlen);
$raw_value = openssl_encrypt($value . $salt, $method, $key, 0, $iv); if (!$raw_value) { return false; }
return base64_encode($iv . $raw_value); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode }
$raw_value = base64_decode($value, true); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
$method = 'aes-256-ctr'; $ivlen = openssl_cipher_iv_length($method); $iv = substr($raw_value, 0, $ivlen); if (strlen($iv) < 16) { $iv = str_pad($iv, 16, "\0"); // Pad with null bytes if it's shorter }
$raw_value = substr($raw_value, $ivlen);
$newValue = openssl_decrypt($raw_value, $method, $key, 0, $iv); if (!$newValue || substr($newValue, -strlen($salt)) !== $salt) { return false; }
return substr($newValue, 0, -strlen($salt)); } }
/** * Returns the FluentSmtpDb instance. * * If the function `FluentSmtpDb` exists, it will be called and the result will be returned. * Otherwise, the file `wpfluent.php` will be required and the `FluentSmtpDb` function will be called and returned. * * @return FluentSmtpDb The FluentSmtpDb instance. */ function fluentMailDb() { if (function_exists('FluentSmtpDb')) { return FluentSmtpDb(); }
require_once FLUENTMAIL_PLUGIN_PATH . 'app/Services/DB/wpfluent.php'; return FluentSmtpDb(); }
function fluentMailFuncCouldNotBeLoadedRecheckPluginsLoad() { add_action('admin_notices', function () { if (!current_user_can('manage_options')) { return; } $details = new ReflectionFunction('wp_mail'); $hints = $details->getFileName() . ':' . $details->getStartLine(); ?> <div class="notice notice-warning fluentsmtp_urgent is-dismissible"> <p>The <strong>FluentSMTP</strong> plugin depends on <a target="_blank" href="https://developer.wordpress.org/reference/functions/wp_mail/">wp_mail</a> pluggable function and plugin is not able to extend it. Please check if another plugin is using this and disable it for <strong>FluentSMTP</strong> to work!</p> <p style="color: red;"> <?php esc_html_e('Possible Conflict: ', 'fluent-smtp');?> <?php echo $hints; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> </p> </div> <?php });
$activePlugins = get_option('active_plugins'); $index = array_search('fluent-smtp/fluent-smtp.php', $activePlugins); if ($index !== false) { if ($index === 0) { return; } unset($activePlugins[$index]); array_unshift($activePlugins, 'fluent-smtp/fluent-smtp.php'); update_option('active_plugins', $activePlugins, true); } }
/** * Check if the email should be sent as multi-part text. * * @return bool Returns true if the email should be sent as multi-part text, false otherwise. */ function fluentMailSendMultiPartText() { $settings = fluentMailGetSettings(); return isset($settings['misc']['send_as_text']) && $settings['misc']['send_as_text'] == 'yes'; }
|