postmark.module in Postmark 6
Same filename and directory in other branches
This module allows for the inclusion of Postmark as the native Drupal mail handler, and uses drupal_mail_wrapper to send emails from Drupal using Postmark
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, and uses drupal_mail_wrapper to send emails
* from Drupal using Postmark
*
* 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/settings/postmark'] = array(
'title' => t('Postmark Settings'),
'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_perm().
*/
function postmark_perm() {
return array(
'administer postmark',
);
}
// Taken from PHPMailer to add the Postmark library as the native email handler
if (strpos(variable_get('smtp_library', ''), 'postmark') && !function_exists('drupal_mail_wrapper')) {
/**
* Implementation of drupal_mail_wrapper().
*/
function drupal_mail_wrapper($message) {
module_load_include('inc', 'postmark', 'includes/postmark.drupal');
return postmark_send($message);
}
}
/**
* Implementation of hook_mailengine().
*/
function postmark_mailengine($op, $message = array()) {
switch ($op) {
case 'name':
return t('Postmark');
case 'description':
return t('Mailing engine using the Postmark library.');
case 'settings':
module_load_include('inc', 'postmark', 'postmark.admin');
return postmark_settings_form();
}
}
/**
* 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_mailengine | Implementation of hook_mailengine(). |
postmark_menu | Implementation of hook_menu(). |
postmark_parse_address | Extract address and optional display name of an e-mail address. |
postmark_perm | Implementation of hook_perm(). |
postmark_settings_access | Allow access to Postmark settings form |