-
Notifications
You must be signed in to change notification settings - Fork 0
/
postmark.module
76 lines (70 loc) · 2.02 KB
/
postmark.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
<?php
/**
* @file
*
* This module allows for the inclusion of Emailmanager as the native
* Drupal mail handler using the new Drupal mail system interface.
*
* The Emailmanager PHP5 library include must be available for this module
* to work correctly.
*
* Credit to the phpmailer module on which this is heavily based.
*/
/**
* Implementation of hook_menu().
*/
function emailmanager_menu() {
$items['admin/config/system/emailmanager'] = array(
'title' => t('Emailmanager'),
'description' => 'Configure Emailmanager settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('emailmanager_settings_form'),
'access callback' => 'emailmanager_settings_access',
'file' => 'emailmanager.admin.inc',
);
return $items;
}
/**
* Implementation of hook_permission().
*/
function emailmanager_permission() {
return array(
'administer emailmanager' => array(
'title' => t('Administer Emailmanager'),
'description' => t('Perform administration tasks for Emailmanager.'),
),
);
}
/**
* Extract address and optional display name of an e-mail address.
*
* @param $address
* A string containing one or more valid e-mail address(es) separated with
* commas.
*
* @return
* An array containing all found e-mail addresses split into mail and name.
*
* @see http://tools.ietf.org/html/rfc5322#section-3.4
*/
function emailmanager_parse_address($address) {
$parsed = array();
$regexp = "/^(.*) <([a-z0-9]+(?:[_\\.-][a-z0-9]+)*@(?:[a-z0-9]+(?:[\.-][a-z0-9]+)*)+\\.[a-z]{2,})>$/i";
// Split multiple addresses and process each.
foreach (explode(',', $address) as $email) {
$email = trim($email);
if (preg_match($regexp, $email, $matches)) {
$parsed[] = array('mail' => $matches[2], 'name' => trim($matches[1], '"'));
}
else {
$parsed[] = array('mail' => $email, 'name' => '');
}
}
return $parsed;
}
/**
* Allow access to Emailmanager settings form
*/
function emailmanager_settings_access() {
return user_access('administer emailmanager');
}