FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Configuration settings page for sending MIME-encoded emails.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration form.
|
||||
*/
|
||||
function mimemail_admin_settings() {
|
||||
// Check for the existence of a mail.css file in the default theme folder.
|
||||
$theme = variable_get('theme_default', NULL);
|
||||
$mailstyle = drupal_get_path('theme', $theme) . '/mail.css';
|
||||
// Disable site style sheets including option if found.
|
||||
if (is_file($mailstyle)) {
|
||||
variable_set('mimemail_sitestyle', 0);
|
||||
$disable_sitestyle = TRUE;
|
||||
}
|
||||
else {
|
||||
$disable_sitestyle = FALSE;
|
||||
}
|
||||
|
||||
$form = array();
|
||||
$form['mimemail']['mimemail_name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Sender name'),
|
||||
'#default_value' => variable_get('mimemail_name', variable_get('site_name', 'Drupal')),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 128,
|
||||
'#description' => t('The name that all site emails will be from when using default engine.'),
|
||||
);
|
||||
$form['mimemail']['mimemail_mail'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Sender e-mail address'),
|
||||
'#default_value' => variable_get('mimemail_mail', variable_get('site_mail', ini_get('sendmail_from'))),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 128,
|
||||
'#description' => t('The email address that all site e-mails will be from when using default engine.'),
|
||||
);
|
||||
$form['mimemail']['mimemail_simple_address'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use simple address format'),
|
||||
'#default_value' => variable_get('mimemail_simple_address', FALSE),
|
||||
'#description' => t('Use the simple format of user@example.com for all recipient email addresses.'),
|
||||
);
|
||||
$form['mimemail']['mimemail_sitestyle'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Include site style sheets'),
|
||||
'#default_value' => variable_get('mimemail_sitestyle', TRUE),
|
||||
'#description' => t('Gather all style sheets when no mail.css found in the default theme directory.'),
|
||||
'#disabled' => $disable_sitestyle,
|
||||
);
|
||||
$form['mimemail']['mimemail_textonly'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Send plain text email only'),
|
||||
'#default_value' => variable_get('mimemail_textonly', FALSE),
|
||||
'#description' => t('This option disables the use of email messages with graphics and styles. All messages will be converted to plain text.'),
|
||||
);
|
||||
$form['mimemail']['mimemail_linkonly'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Link images only'),
|
||||
'#default_value' => variable_get('mimemail_linkonly', 0),
|
||||
'#description' => t('This option disables the embedding of images. All image will be available as external content. This can make email messages much smaller.'),
|
||||
);
|
||||
if (module_exists('mimemail_compress')) {
|
||||
$form['mimemail']['mimemail_preserve_class'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Preserve class attributes'),
|
||||
'#default_value' => variable_get('mimemail_preserve_class', 0),
|
||||
'#description' => t('This option disables the removing of class attributes from the message source. Useful for debugging the style of the message.'),
|
||||
);
|
||||
}
|
||||
|
||||
// Get a list of all formats.
|
||||
$formats = filter_formats();
|
||||
foreach ($formats as $format) {
|
||||
$format_options[$format->format] = $format->name;
|
||||
}
|
||||
$form['mimemail']['mimemail_format'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('E-mail format'),
|
||||
'#options' => $format_options,
|
||||
'#default_value' => variable_get('mimemail_format', filter_fallback_format()),
|
||||
'#access' => count($formats) > 1,
|
||||
'#attributes' => array('class' => array('filter-list')),
|
||||
);
|
||||
|
||||
$form['mimemail']['advanced'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Advanced settings'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['mimemail']['advanced']['mimemail_incoming'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Process incoming messages posted to this site'),
|
||||
'#default_value' => variable_get('mimemail_incoming', FALSE),
|
||||
'#description' => t('This is an advanced setting that should not be enabled unless you know what you are doing.'),
|
||||
);
|
||||
$form['mimemail']['advanced']['mimemail_key'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Message validation string'),
|
||||
'#default_value' => variable_get('mimemail_key', md5(rand())),
|
||||
'#required' => TRUE,
|
||||
'#description' => t('This string will be used to validate incoming messages. It can be anything, but must be used on both sides of the transfer.'),
|
||||
);
|
||||
|
||||
// Get the available mail engines.
|
||||
$engines = mimemail_get_engines();
|
||||
foreach ($engines as $module => $engine) {
|
||||
$engine_options[$module] = $engine['name'] . ': ' . $engine['description'];
|
||||
}
|
||||
// Hide the settings if only 1 engine is available.
|
||||
if (count($engines) == 1) {
|
||||
reset($engines);
|
||||
variable_set('mimemail_engine', key($engines));
|
||||
$form['mimemail']['mimemail_engine'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => variable_get('mimemail_engine', 'mimemail'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['mimemail']['mimemail_engine'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('E-mail engine'),
|
||||
'#default_value' => variable_get('mimemail_engine', 'mimemail'),
|
||||
'#options' => $engine_options,
|
||||
'#description' => t('Choose an engine for sending mails from your site.'),
|
||||
);
|
||||
}
|
||||
|
||||
if (variable_get('mimemail_engine', 'mail')) {
|
||||
$settings = module_invoke(variable_get('mimemail_engine', 'mimemail'), 'mailengine', 'settings');
|
||||
if ($settings) {
|
||||
$form['mimemail']['engine_settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Engine specific settings'),
|
||||
);
|
||||
foreach ($settings as $name => $value) {
|
||||
$form['mimemail']['engine_settings'][$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('Please choose a mail engine.'), 'error');
|
||||
}
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Functions that handle inbound messages to mimemail.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Receive messages POSTed from an external source.
|
||||
*
|
||||
* This function enables messages to be sent via POST or some other RFC822
|
||||
* source input (e.g. directly from a mail server).
|
||||
*
|
||||
* @return
|
||||
* The POSTed message.
|
||||
*/
|
||||
function mimemail_post() {
|
||||
$message = $_POST['message'];
|
||||
$token = $_POST['token'];
|
||||
$hash = md5(variable_get('mimemail_key', '**') . $message);
|
||||
|
||||
if ($hash != $token) {
|
||||
watchdog('access denied', 'Authentication error for POST e-mail', WATCHDOG_WARNING);
|
||||
return drupal_access_denied();
|
||||
}
|
||||
return mimemail_incoming($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an externally received message.
|
||||
*
|
||||
* @param $message
|
||||
* The message to parse.
|
||||
*/
|
||||
function mimemail_incoming($message) {
|
||||
$mail = mimemail_parse($message);
|
||||
|
||||
foreach (module_implements('mimemail_incoming_alter') as $module) {
|
||||
call_user_func_array($module . '_mimemail_incoming_alter', $mail);
|
||||
}
|
||||
|
||||
module_invoke_all('mimemail_incoming', $mail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a message into its parts.
|
||||
*
|
||||
* @param string $message
|
||||
* The message to parse.
|
||||
*
|
||||
* @return array
|
||||
* The parts of the message.
|
||||
*/
|
||||
function mimemail_parse($message) {
|
||||
// Provides a "headers", "content-type" and "body" element.
|
||||
$mail = mimemail_parse_headers($message);
|
||||
|
||||
// Get an address-only version of "From" (useful for user_load() and such).
|
||||
$mail['from'] = preg_replace('/.*\b([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4})\b.*/i', '\1', drupal_strtolower($mail['headers']['From']));
|
||||
|
||||
// Get a subject line, which may be cleaned up/modified later.
|
||||
$mail['subject'] = $mail['headers']['Subject'];
|
||||
|
||||
// Make an array to hold any non-content attachments.
|
||||
$mail['attachments'] = array();
|
||||
|
||||
// We're dealing with a multi-part message.
|
||||
$mail['parts'] = mimemail_parse_boundary($mail);
|
||||
|
||||
foreach ($mail['parts'] as $i => $part_body) {
|
||||
$part = mimemail_parse_headers($part_body);
|
||||
$sub_parts = mimemail_parse_boundary($part);
|
||||
|
||||
// Content is encoded in a multipart/alternative section.
|
||||
if (count($sub_parts) > 1) {
|
||||
foreach ($sub_parts as $j => $sub_part_body) {
|
||||
$sub_part = mimemail_parse_headers($sub_part_body);
|
||||
if ($sub_part['content-type'] == 'text/plain') {
|
||||
$mail['text'] = mimemail_parse_content($sub_part);
|
||||
}
|
||||
if ($sub_part['content-type'] == 'text/html') {
|
||||
$mail['html'] = mimemail_parse_content($sub_part);
|
||||
}
|
||||
else {
|
||||
$mail['attachments'][] = mimemail_parse_attachment($sub_part);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (($part['content-type'] == 'text/plain') && !isset($mail['text'])) {
|
||||
$mail['text'] = mimemail_parse_content($part);
|
||||
}
|
||||
elseif (($part['content-type'] == 'text/html') && !isset($mail['html'])) {
|
||||
$mail['html'] = mimemail_parse_content($part);
|
||||
}
|
||||
else {
|
||||
$mail['attachments'][] = mimemail_parse_attachment($part);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure our text and html parts are accounted for.
|
||||
if (isset($mail['html']) && !isset($mail['text'])) {
|
||||
$mail['text'] = preg_replace('|<style.*</style>|mis', '', $mail['html']);
|
||||
$mail['text'] = drupal_html_to_text($mail['text']);
|
||||
}
|
||||
elseif (isset($mail['text']) && !isset($mail['html'])) {
|
||||
$mail['html'] = check_markup($mail['text'], variable_get('mimemail_format', filter_fallback_format()));
|
||||
}
|
||||
|
||||
// Last ditch attempt - use the body as-is.
|
||||
if (!isset($mail['text'])) {
|
||||
$mail['text'] = mimemail_parse_content($mail);
|
||||
$mail['html'] = check_markup($mail['text'], variable_get('mimemail_format', filter_fallback_format()));
|
||||
}
|
||||
|
||||
return $mail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a multi-part message using MIME boundaries.
|
||||
*/
|
||||
function mimemail_parse_boundary($part) {
|
||||
$m = array();
|
||||
if (preg_match('/.*boundary="?([^";]+)"?.*/', $part['headers']['Content-Type'], $m)) {
|
||||
$boundary = "\n--" . $m[1];
|
||||
$body = str_replace("$boundary--", '', $part['body']);
|
||||
return array_slice(explode($boundary, $body), 1);
|
||||
}
|
||||
return array($part['body']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a message (or message part) into its headers and body section.
|
||||
*/
|
||||
function mimemail_parse_headers($message) {
|
||||
// Split out body and headers.
|
||||
if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $message, $match)) {
|
||||
list($hdr, $body) = array($match[1], $match[2]);
|
||||
}
|
||||
|
||||
// Un-fold the headers.
|
||||
$hdr = preg_replace(array("/\r/", "/\n(\t| )+/"), array('', ' '), $hdr);
|
||||
|
||||
$headers = array();
|
||||
foreach (explode("\n", trim($hdr)) as $row) {
|
||||
$split = strpos($row, ':');
|
||||
$name = trim(drupal_substr($row, 0, $split));
|
||||
$val = trim(drupal_substr($row, $split+1));
|
||||
$headers[$name] = $val;
|
||||
}
|
||||
|
||||
$type = (preg_replace('/\s*([^;]+).*/', '\1', $headers['Content-Type']));
|
||||
|
||||
return array('headers' => $headers, 'body' => $body, 'content-type' => $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a decoded MIME part in UTF-8.
|
||||
*/
|
||||
function mimemail_parse_content($part) {
|
||||
$content = $part['body'];
|
||||
|
||||
// Decode this part.
|
||||
if ($encoding = drupal_strtolower($part['headers']['Content-Transfer-Encoding'])) {
|
||||
switch ($encoding) {
|
||||
case 'base64':
|
||||
$content = base64_decode($content);
|
||||
break;
|
||||
case 'quoted-printable':
|
||||
$content = quoted_printable_decode($content);
|
||||
break;
|
||||
// 7bit is the RFC default.
|
||||
case '7bit':
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to convert character set to UTF-8.
|
||||
if (preg_match('/.*charset="?([^";]+)"?.*/', $part['headers']['Content-Type'], $m)) {
|
||||
$content = drupal_convert_to_utf8($content, $m[1]);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a MIME part into a file array.
|
||||
*/
|
||||
function mimemail_parse_attachment($part) {
|
||||
$m = array();
|
||||
if (preg_match('/.*filename="?([^";])"?.*/', $part['headers']['Content-Disposition'], $m)) {
|
||||
$name = $m[1];
|
||||
}
|
||||
elseif (preg_match('/.*name="?([^";])"?.*/', $part['headers']['Content-Type'], $m)) {
|
||||
$name = $m[1];
|
||||
}
|
||||
|
||||
return array(
|
||||
'filename' => $name,
|
||||
'filemime' => $part['content-type'],
|
||||
'content' => mimemail_parse_content($part),
|
||||
);
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Mime Mail implementations of MailSystemInterface.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Modify the Drupal mail system to send HTML emails.
|
||||
*/
|
||||
class MimeMailSystem implements MailSystemInterface {
|
||||
/**
|
||||
* Concatenate and wrap the e-mail body for HTML mails.
|
||||
*
|
||||
* @param array $message
|
||||
* A message array, as described in hook_mail_alter() with optional
|
||||
* parameters described in mimemail_prepare_message().
|
||||
*
|
||||
* @return array
|
||||
* The formatted $message.
|
||||
*/
|
||||
public function format(array $message) {
|
||||
if (is_array($message['body'])) {
|
||||
$message['body'] = implode("\n\n", $message['body']);
|
||||
}
|
||||
|
||||
if (preg_match('/plain/', $message['headers']['Content-Type'])) {
|
||||
$message['body'] = check_markup($message['body'], variable_get('mimemail_format', filter_fallback_format()));
|
||||
}
|
||||
|
||||
$engine = variable_get('mimemail_engine', 'mimemail');
|
||||
$mailengine = $engine . '_mailengine';
|
||||
$engine_prepare_message = $engine . '_prepare_message';
|
||||
|
||||
if (function_exists($engine_prepare_message)) {
|
||||
$message = $engine_prepare_message($message);
|
||||
}
|
||||
else {
|
||||
$message = mimemail_prepare_message($message);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
/**
|
||||
* Send an HTML e-mail message, using Drupal variables and default settings.
|
||||
*
|
||||
* @param array $message
|
||||
* A message array, as described in hook_mail_alter() with optional
|
||||
* parameters described in mimemail_prepare_message().
|
||||
*
|
||||
* @return boolean
|
||||
* TRUE if the mail was successfully accepted, otherwise FALSE.
|
||||
*/
|
||||
public function mail(array $message) {
|
||||
$engine = variable_get('mimemail_engine', 'mimemail');
|
||||
$mailengine = $engine . '_mailengine';
|
||||
|
||||
if (!$engine || !function_exists($mailengine)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $mailengine('send', $message);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user