public function testGenerate() { $h = new Horde_Mime_Headers(); $ob = new Horde_Mime_Mdn($h); try { $ob->generate(true, true, 'deleted', 'foo', null); $this->fail('Expected Exception'); } catch (RuntimeException $e) { } $date = 'Tue, 18 Nov 2014 20:14:17 -0700'; $mdn_addr = 'Aäb <*****@*****.**>'; $h->addHeader('Date', $date); $h->addHeader('Subject', 'Test'); $h->addHeader('To', '"BAR" <*****@*****.**>'); $ob->addMdnRequestHeaders($mdn_addr); $mailer = new Horde_Mail_Transport_Mock(); $ob->generate(true, true, 'displayed', 'test.example.com', $mailer, array('from_addr' => '*****@*****.**'), array('error'), array('error' => 'Foo')); $sent = str_replace("\r\n", "\n", $mailer->sentMessages[0]); $this->assertEquals('auto-replied', $sent['headers']['Auto-Submitted']); $this->assertEquals('*****@*****.**', $sent['headers']['From']); $this->assertEquals($mdn_addr, Horde_Mime::decode($sent['headers']['To'])); $this->assertEquals('Disposition Notification', $sent['headers']['Subject']); $this->assertStringMatchesFormat('This message is in MIME format. --=%s Content-Type: text/plain; format=flowed; DelSp=Yes The message sent on Tue, 18 Nov 2014 20:14:17 -0700 to BAR <*****@*****.**> with subject "Test" has been displayed. This is no guarantee that the message has been read or understood. --=%s Content-Type: message/disposition-notification Reporting-UA: test.example.com; Horde Application Framework 5 Final-Recipient: rfc822;bar@example.com Disposition: manual-action/MDN-sent-manually; displayed/error Error: Foo --=%s Content-Type: message/rfc822 Date: Tue, 18 Nov 2014 20:14:17 -0700 Subject: Test To: BAR <*****@*****.**> Disposition-Notification-To: =?utf-8?b?QcOkYg==?= <*****@*****.**> --=%s ', $sent['body']); }
/** * Check if we need to send a MDN, and send if needed. * * @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($headers, $confirmed = false) { global $conf, $injector, $prefs; if (!($pref_val = $prefs->getValue('send_mdn'))) { return false; } /* Check to see if an MDN has been requested. */ $mdn = new Horde_Mime_Mdn($headers); if (!($return_addr = $mdn->getMdnReturnAddr())) { return false; } /* Check to see if MDN information can be stored. */ $log_msg = new IMP_Maillog_Message($this); $log_ob = new IMP_Maillog_Log_Mdn(); $maillog = $injector->getInstance('IMP_Maillog'); if (!$maillog->storage->isAvailable($log_msg, $log_ob) || count($maillog->getLog($log_msg, array('IMP_Maillog_Log_Mdn')))) { 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; $identity = $injector->getInstance('IMP_Identity'); if (isset($headers['To']) && ($match = $identity->getMatchingIdentity($headers['To'], true)) !== null) { $from = $identity->getFromAddress($match); } else { $from = $identity->getDefaultFromAddress(); } try { $mdn->generate(false, $confirmed, 'displayed', $conf['server']['name'], $injector->getInstance('IMP_Mail'), array('charset' => 'UTF-8', 'from_addr' => $from)); $maillog->log($log_msg, $log_ob); $success = true; } catch (Exception $e) { } $injector->getInstance('IMP_Sentmail')->log(IMP_Sentmail::MDN, '', $return_addr, $success); return false; }
/** * 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; }