Welcome to Geeklog Thursday, November 21 2019 @ 11:13 am EST

Geeklog Forums

Feature Request: Allow mail to be handled by plugins


Status: offline

jmucchiello

Forum User
Full Member
Registered: 29/08/05
Posts: 985
It would be nice if plugins could take over sendmail duty. This would allow a plugin (ultimately, only one plugin could do this) to save/retain outgoing emails, throttle email for webhosts that have extremely low hourly mail requirements, and similar duties.

First task is to split the existing COM_mail into public interface and actual functionality since the actual functionality of COM_mail is very good, it just lacks hooks.

As for the hooks, create a $_CONF['sendmail_plugin'] which can be none (send no mail), internal (use normal internal mailer), custom (call CUSTOM_email) or the name of a plugin (calling plugin_sendmailhandler_$plugin). For backwards compatibility, if the $_CONF is not set, it uses CUSTOM_email if exists or the internal mailer otherwise.

Here is the code:[code] // adapted from CVS
function COM_mail( $to, $subject, $message, $from = '', $html = false, $priority = 0, $cc = '' )
{
global $_CONF, $_PLUGINS;
static $mail_func = null;

if ($mail_func === null) {
if (isset($_CONF['sendmail_plugin'])) {
$pi_name = $_CONF['sendmail_plugin'];
if ($pi_name == 'none'Wink {
$mail_func = 'none';
} else if ($pi_name == 'internal'Wink {
$mail_func = 'INTERNAL_sendmail';
} else if ($pi_name == 'custom' && function_exists('CUSTOM_mail'Wink) {
$mail_func = 'CUSTOM_mail';
} else {
$function = 'plugin_sendmailhandler_'.$pi_name;
if (in_array($pi_name, $_PLUGINS) && function_exists($function)) {
$mail_func = $function;
}
}
} else if (function_exists('CUSTOM_mail'Wink) {
$mail_func = 'CUSTOM_mail';
}

if ($mail_func === null) {
foreach ($_PLUGINS as $pi_name) {
$function = 'plugin_sendmailhandler_'.$pi_name;
if (function_exists($function)) {
$mail_func = $function;
break; // first found, first used.
}
}
}
if ($mail_func === null) {
$mail_func = 'INTERNAL_sendmail';
}
}

if ($mail_func == 'none'Wink {
return true; // success
}

if( empty( $from ))
{
$from = COM_formatEmailAddress( $_CONF['site_name'], $_CONF['site_mail']);
}

$to = substr( $to, 0, strcspn( $to, "\r\n" ));
$cc = substr( $cc, 0, strcspn( $cc, "\r\n" ));
$from = substr( $from, 0, strcspn( $from, "\r\n" ));
$subject = substr( $subject, 0, strcspn( $subject, "\r\n" ));
$subject = COM_emailEscape( $subject );

return $mail_func($to, $subject, $message, $from, $html, $priority, $cc);
}

function INTERNAL_sendMail( $to, $subject, $message, $from, $html, $priority, $cc)
{
global $_CONF;
static $mailobj;

include_once( 'Mail.php' );
include_once( 'Mail/RFC822.php' );
// as existing COM_mail() from here[/code]
 Quote

All times are EST. The time is now 11:13 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content