-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailauthfail.module
67 lines (64 loc) · 1.89 KB
/
mailauthfail.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
<?php
/**
* Respond to a parsed message failing authentification.
*
* @param array $message
* The mail message Feeds was trying to parse.
*/
function mailauthfail_mailhandler_auth_failed($message) {
global $base_url;
$link = $base_url;
// Send mail on fail
mailauthfail_drupal_mail('default_from', get_toaddress($message), 'Ukendt bruger ved Digital Formidling', 'Hej<br><br>Du er ikke oprettet som bruger ved <a href=' . $link . '>' . $link . '</a><br>');
}
/**
* Return the "to address" from the headers. Note: will not return "toad dress".
*
* @param $message
* the message retrieved by Mailhandler
*/
function get_toaddress($message) {
$toaddress = '';
if (isset($message['header'])) {
$header = $message['header'];
if (isset($header->fromaddress)) {
$toaddress = $header->fromaddress;
}
}
preg_match('/\<(.+?\@.+?)\>/', $toaddress, $matches);
if (isset($matches[1])) {
$toaddress = $matches[1];
}
return strtolower($toaddress);
}
/**
* Simple wrapper function for drupal_mail() to avoid extraneous code.
*/
function mailauthfail_drupal_mail($from = 'default_from', $to, $subject, $message) {
$my_module = 'mailhandler';
$my_mail_token = microtime();
if ($from == 'default_from') {
// Change this to your own default 'from' email address.
$from = variable_get('site_mail', 'My Email Address <it-udvikling@fynbib.dk>');
}
$message = array(
'id' => $my_module . '_' . $my_mail_token,
'to' => $to,
'subject' => $subject,
'body' => array($message),
'headers' => array(
'From' => $from,
'Sender' => $from,
'Return-Path' => $from,
'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
),
);
$system = drupal_mail_system($my_module, $my_mail_token);
$message = $system->format($message);
if ($system->mail($message)) {
return TRUE;
}
else {
return FALSE;
}
}