postmark.module in Postmark 7
Same filename and directory in other branches
This module allows for the inclusion of Postmark as the native Drupal mail handler using the new Drupal mail system interface.
The Postmark PHP5 library include must be available for this module to work correctly.
Credit to the phpmailer module on which this is heavily based.
File
postmark.moduleView source
<?php
/**
* @file
*
* This module allows for the inclusion of Postmark as the native
* Drupal mail handler using the new Drupal mail system interface.
*
* The Postmark 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 postmark_menu() {
$items['admin/config/system/postmark'] = array(
'title' => t('Postmark'),
'description' => 'Configure Postmark settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'postmark_settings_form',
),
'access callback' => 'postmark_settings_access',
'file' => 'postmark.admin.inc',
);
return $items;
}
/**
* Implementation of hook_permission().
*/
function postmark_permission() {
return array(
'administer postmark' => array(
'title' => t('Administer Postmark'),
'description' => t('Perform administration tasks for Postmark.'),
),
);
}
/**
* Implementation of hook_libraries_info().
*/
function postmark_libraries_info() {
$libraries['postmark-php'] = array(
'name' => 'Postmark PHP',
'vendor url' => 'http://www.mimmin.com/',
'download url' => 'https://github.com/Znarkus/postmark-php',
'version arguments' => array(
'file' => 'CHANGELOG.md',
'pattern' => '/## (.*)/',
'lines' => 5,
),
'versions' => array(
'0.4.5' => array(
'files' => array(
'php' => array(
'Postmark.php',
),
),
),
'0.5' => array(
'files' => array(
'php' => array(
'src/Postmark/Mail.php',
),
),
),
),
);
return $libraries;
}
/**
* 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 postmark_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 Postmark settings form
*/
function postmark_settings_access() {
return user_access('administer postmark');
}
Functions
Name | Description |
---|---|
postmark_libraries_info | Implementation of hook_libraries_info(). |
postmark_menu | Implementation of hook_menu(). |
postmark_parse_address | Extract address and optional display name of an e-mail address. |
postmark_permission | Implementation of hook_permission(). |
postmark_settings_access | Allow access to Postmark settings form |