/**
* Check if we need to send a MDN, and send if needed.
*
* @param IMP_Indices $indices Indices object of the message.
* @param Horde_Mime_Headers $headers The headers of the message.
* @param boolean $confirmed Has the MDN request been confirmed?
*
* @return boolean True if the MDN request needs to be confirmed.
*/
public function MDNCheck(IMP_Indices $indices, $headers, $confirmed = false)
{
global $conf, $injector, $prefs;
$maillog = $injector->getInstance('IMP_Maillog');
$pref_val = $prefs->getValue('send_mdn');
list($mbox, ) = $indices->getSingle();
if (!$pref_val || $mbox->readonly) {
return false;
}
/* Check to see if an MDN has been requested. */
$mdn = new Horde_Mime_Mdn($headers);
if (!($return_addr = $mdn->getMdnReturnAddr())) {
return false;
}
$log_msg = new IMP_Maillog_Message($indices);
if (count($maillog->getLog($log_msg, array('forward', 'redirect', 'reply_all', 'reply_list', 'reply')))) {
return false;
}
/* See if we need to query the user. */
if (!$confirmed && (intval($pref_val) == 1 || $mdn->userConfirmationNeeded())) {
try {
if ($injector->getInstance('Horde_Core_Hooks')->callHook('mdn_check', 'imp', array($headers))) {
return true;
}
} catch (Horde_Exception_HookNotSet $e) {
return true;
}
}
/* Send out the MDN now. */
$success = false;
try {
$mdn->generate(false, $confirmed, 'displayed', $conf['server']['name'], $injector->getInstance('IMP_Mail'), array('charset' => 'UTF-8', 'from_addr' => $injector->getInstance('Horde_Core_Factory_Identity')->create()->getDefaultFromAddress()));
$maillog->log($log_msg, new IMP_Maillog_Log_Mdn());
$success = true;
} catch (Exception $e) {
}
$injector->getInstance('IMP_Sentmail')->log(IMP_Sentmail::MDN, '', $return_addr, $success);
return false;
}