View source
<?php
define('MANDRILL_TEST_API_KEY', 'undefined');
define('MANDRILL_QUEUE', 'mandrill_queue');
define('MANDRILL_EMAIL_REGEX', '/^\\s*(.+?)\\s*<\\s*([^>]+)\\s*>$/');
if (file_exists(drupal_get_path('module', 'mandrill') . '/lib/mandrill/src/Mandrill.php')) {
require drupal_get_path('module', 'mandrill') . '/lib/mandrill/src/Mandrill.php';
}
function mandrill_help($path, $arg) {
$output = '';
switch ($path) {
case 'admin/help#mandrill':
$output = t('Allow for site emails to be sent through Mandrill.');
}
return $output;
}
function mandrill_test_access() {
$has_permission = \Drupal::currentUser()
->hasPermission('administer mandrill');
$key = \Drupal::config('mandrill.settings')
->get('mandrill_api_key');
return $has_permission & !empty($key);
}
function mandrill_mail($key, &$message, $params) {
if ($key == 'test') {
$message['subject'] = $params['subject'];
$message['body'] = $params['body'];
if ($params['include_attachment']) {
$message['attachments'][] = \Drupal::service('file_system')
->realpath('misc/druplicon.png');
$message['body'] .= ' ' . t('The Drupal icon is included as an attachment to test the attachment functionality.');
}
}
}
function mandrill_mailsend($message, $function, $args = array()) {
throw new \Exception('Use send() method on MandrillService instead.');
}
function mandrill_sender_plain($message) {
$api = \Drupal::service('mandrill.api');
return $api
->send($message);
}
function mandrill_get_api_object($reset = FALSE) {
throw new \Exception('This method has moved to the API service class, and is private. Use one of the abstracts for whatever call you require.');
}
function mandrill_get_module_key_names() {
$name_array = array(
'' => '--none--',
'default-system' => "Site-wide default",
);
$descriptions = array();
foreach (\Drupal::service('extension.list.module')
->getList() as $item) {
if ($item->status && !empty($item->info['name'])) {
$descriptions[strtolower($item
->getName())] = (empty($item->info['package']) ? '' : $item->info['package']) . ' » ' . t(':module module', array(
':module' => $item->info['name'],
));
}
}
asort($descriptions);
$mailsystem_config = \Drupal::service('config.factory')
->get('mailsystem.settings');
$modules = $mailsystem_config
->get('modules');
if (!empty($modules)) {
foreach (array_keys($modules) as $module_name) {
foreach ($modules[$module_name] as $key => $options) {
$id = $module_name . '_' . $key;
$title = preg_replace('/^.* » /', '', $descriptions[$module_name]);
$title .= " ({$key} key)";
$name_array[$id] = $title;
}
}
}
return $name_array;
}
function mandrill_get_templates() {
throw new \Exception('Use the getTemplates() method on the API service class instead.');
}
function mandrill_get_subaccounts() {
throw new \Exception('Use the getSubAccounts() method on the API service class instead.');
}
function mandrill_get_webhooks() {
throw new \Exception('Use the getWebhooks() method on the API service class instead.');
}
function mandrill_get_inbound_domains() {
throw new \Exception('Use the getInboundDomains() method on the API service class instead.');
}
function mandrill_get_inbound_routes($domain) {
throw new \Exception('Use the getInboundRoutes() method on the API service class instead.');
}
function mandrill_add_inbound_domain($domain) {
throw new \Exception('Use the addInboundDomain() method on the API service class instead.');
}
function mandrill_add_webhook($path, $events, $description = 'Drupal Webhook') {
throw new \Exception('Use the addWebhook() method on the API service class instead.');
}
function mandrill_delete_inbound_domain($domain) {
throw new \Exception('Use the deleteInboundDomain() method on the API service class instead.');
}
function mandrill_add_inbound_route($domain, $pattern, $url) {
throw new \Exception('Use the addInboundRoute() method on the API service class instead.');
}
function mandrill_mail_key_blacklist() {
return \Drupal::config('mandrill.settings')
->get('mandrill_mail_key_blacklist');
}
function mandrill_get_to($to) {
$recipients = array();
$to_array = explode(',', $to);
foreach ($to_array as $email) {
if (preg_match(MANDRILL_EMAIL_REGEX, $email, $matches)) {
$recipients[] = array(
'email' => $matches[2],
'name' => $matches[1],
);
}
else {
$recipients[] = array(
'email' => $email,
);
}
}
return $recipients;
}
function mandrill_process_async() {
return \Drupal::config('mandrill.settings')
->get('mandrill_process_async');
}
function mandrill_from() {
$email = \Drupal::config('mandrill.settings')
->get('mandrill_from_email');
$name = \Drupal::config('mandrill.settings')
->get('mandrill_from_name');
return array(
'email' => $email,
'name' => $name,
);
}