Browse Source

Enable addon using emailer hooks to skip default call to mail()

tags/2019.06^2
Hypolite Petovan 1 month ago
parent
commit
4e207ef786
2 changed files with 15 additions and 2 deletions
  1. 2
    0
      doc/Addons.md
  2. 13
    2
      src/Util/Emailer.php

+ 2
- 0
doc/Addons.md View File

@@ -358,6 +358,7 @@ Called from `Emailer::send()` before building the mime message.
358 358
 - **htmlVersion**: html version of the message
359 359
 - **textVersion**: text only version of the message
360 360
 - **additionalMailHeader**: additions to the smtp mail header
361
+- **sent**: default false, if set to true in the hook, the default mailer will be skipped.
361 362
 
362 363
 ### emailer_send
363 364
 Called before calling PHP's `mail()`.
@@ -367,6 +368,7 @@ Called before calling PHP's `mail()`.
367 368
 - **subject**
368 369
 - **body**
369 370
 - **headers**
371
+- **sent**: default false, if set to true in the hook, the default mailer will be skipped.
370 372
 
371 373
 ### load_config
372 374
 Called during `App` initialization to allow addons to load their own configuration file(s) with `App::loadConfigFile()`.

+ 13
- 2
src/Util/Emailer.php View File

@@ -32,10 +32,16 @@ class Emailer
32 32
 	 * @return bool
33 33
 	 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
34 34
 	 */
35
-	public static function send($params)
35
+	public static function send(array $params)
36 36
 	{
37
+		$params['sent'] = false;
38
+
37 39
 		Hook::callAll('emailer_send_prepare', $params);
38 40
 
41
+		if ($params['sent']) {
42
+			return true;
43
+		}
44
+
39 45
 		$email_textonly = false;
40 46
 		if (!empty($params['uid'])) {
41 47
 			$email_textonly = PConfig::get($params['uid'], "system", "email_textonly");
@@ -87,11 +93,16 @@ class Emailer
87 93
 			'subject' => $messageSubject,
88 94
 			'body' => $multipartMessageBody,
89 95
 			'headers' => $messageHeader,
90
-			'parameters' => $sendmail_params
96
+			'parameters' => $sendmail_params,
97
+			'sent' => false,
91 98
 		];
92 99
 
93 100
 		Hook::callAll("emailer_send", $hookdata);
94 101
 
102
+		if ($hookdata['sent']) {
103
+			return true;
104
+		}
105
+
95 106
 		$res = mail(
96 107
 			$hookdata['to'],
97 108
 			$hookdata['subject'],

Loading…
Cancel
Save