-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail_intercept.module
86 lines (75 loc) · 2.31 KB
/
mail_intercept.module
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
<?php
/**
* @file
* Intercept sent emails and display their contents, either via dpm() if available or
* as a status message if not.
*/
/**
* Implements hook_menu().
*/
function mail_intercept_menu() {
$items['admin/config/development/mail_intercept'] = array(
'title' => 'Mail intercept',
'description' => 'Settings for intercepting Backdrop emails.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('mail_intercept_settings_form'),
'file' => 'mail_intercept.admin.inc',
'access arguments' => array('administer site configuration'),
);
return $items;
}
/**
* Implements hook_config_info().
*/
function mail_intercept_config_info() {
$prefixes['mail_intercept.settings'] = array(
'label' => t('Mail Intercept settings'),
'group' => t('Configuration'),
);
}
/**
* Implements hook_module_implements_alter().
*
* Move our hook to the end of the list so that the message is fully constructed
* by everyone else (e.g., attachments added) before we see it.
*/
function mail_intercept_module_implements_alter(&$implementations, $hook) {
if ($hook == 'mail_alter') {
$group = $implementations['mail_intercept'];
unset($implementations['mail_intercept']);
$implementations['mail_intercept'] = $group;
}
}
/**
* Implements hook_mail_alter().
*
* Send the email to the screen instead of trying to send it externally.
*/
function mail_intercept_mail_alter(&$message) {
$handler = config_get('mail_intercept.settings', 'mail_intercept_handler');
switch ($handler) {
case 1: // Write to screen
if (module_exists('devel')) {
dpm($message, 'Backdrop email');
}
else {
backdrop_set_message(t("Backdrop email:<ul><li>from => @from</li><li>to => @to</li><li>subject => @subject</li></ul>@body",
array(
'@from' => $message['from'],
'@to' => $message['to'],
'@subject' => $message['subject'],
'@body' => $message['body'],
)));
}
break;
case 2: // Write to a /tmp file
$tmp_file = '/tmp/mail_intercept-' . date('Ymd-H-i') . '.txt';
ob_start();
print_r($message);
$content .= ob_get_clean() . "\n";
file_put_contents($tmp_file, $content, FILE_APPEND);
break;
default: // case 0, no action
}
$message['send'] = FALSE;
}