forked from makinacorpus/drupal-netsmtp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetsmtp.module
More file actions
executable file
·68 lines (58 loc) · 2.04 KB
/
netsmtp.module
File metadata and controls
executable file
·68 lines (58 loc) · 2.04 KB
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
<?php
/**
* @file
* Net SMTP module.
*/
define('NETSMTP_SETTINGS', 'netsmtp.settings');
use Drupal\Core\Url;
/**
* Implements hook_mail().
*/
function netsmtp_mail($key, &$message) {
switch ($key) {
case 'test_message':
$uuid = \Drupal\Component\Uuid\Php::generate();
$message['subject'] = 'uniq-mailtrap-id:' . $uuid;
\Drupal::state()->set('netsmtp.last_message_id', $message['subject']);
$message['body'][] = t('Testing Net Smtp mailer.');
break;
}
}
/**
* Implements hook_mail_alter().
*/
function netsmtp_mail_alter(&$message) {
$config = \Drupal::config(NETSMTP_SETTINGS);
if ($config->get('netsmtp_debug_trace')) {
$path = $config->get('netsmtp_debug_trace_path');
file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$filename = $path . '/netsmtp-trace-' . date('Y-m-d') . '.log';
$data = array();
$data[] = 'Sent at ' . date('Y_m_d-H_i_s');
$data[] = 'Module: ' . $message['module'] . ', key: ' . $message['key'];
$data[] = 'Recipient: ' . $message['to'];
$data[] = 'Subject: ' . $message['subject'];
$data[] = 'Stack trace:';
ob_start();
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$data[] = ob_get_clean();
$data[] = '';
file_put_contents($filename, implode("\n", $data), FILE_APPEND | LOCK_EX);
}
if ($recipient = $config->get('netsmtp_catch')) {
$front_page_url = Url::fromUri('base:/', ['absolute' => TRUE]);
$message['headers']['X-Catched-Mail-Key'] = isset($message['id']) ? $message['id'] : NULL;
$message['headers']['X-Catched-Website'] = $front_page_url->toString();
$message['headers']['X-Catched-Original-To'] = $message['to'];
$message['to'] = is_array($recipient) ? implode(',', $recipient) : $recipient;
foreach ($message['headers'] as $header => $value) {
switch (strtolower($header)) {
case 'cc':
case 'bcc':
unset($message['headers'][$header]);
$message['headers']['X-Rerouted-Original-' . $header] = $value;
break;
}
}
}
}