Example #1
0
 /**
  * @dataProvider UserConfirmationNeededProvider
  */
 public function testUserConfirmationNeeded($h, $expected)
 {
     $ob = new Horde_Mime_Mdn($h);
     if ($expected) {
         $this->assertTrue($ob->userConfirmationNeeded());
     } else {
         $this->assertFalse($ob->userConfirmationNeeded());
     }
 }
Example #2
0
    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']);
    }
Example #3
0
File: Mdn.php Project: horde/horde
 /**
  * Check to see if we are able to send an unconfirmed MDN based on the
  * message data.
  *
  * @return boolean  True if able to send, otherwise false.
  */
 protected function _msgCheck()
 {
     $msgs = $this->_imap->getImapMessage($this->_mailbox, $this->_uid, array('headers' => true));
     if (!count($msgs)) {
         return false;
     }
     $imap_msg = array_pop($msgs);
     $mdn = new Horde_Mime_Mdn($imap_msg->getHeaders());
     if ($mdn->getMdnReturnAddr() && !$mdn->userConfirmationNeeded()) {
         $this->_msg = $imap_msg;
         return true;
     }
     return false;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * Prepare header object with basic header fields and converts headers
  * to the current compose charset.
  *
  * @param array $headers  Array with 'from', 'to', 'cc', 'bcc', and
  *                        'subject' values.
  * @param array $opts     An array of options w/the following keys:
  *   - priority: (string) The message priority ('high', 'normal', 'low').
  *
  * @return Horde_Mime_Headers  Headers object with the appropriate headers
  *                             set.
  */
 protected function _prepareHeaders($headers, array $opts = array())
 {
     $ob = new Horde_Mime_Headers();
     $ob->addHeaderOb(Horde_Mime_Headers_Date::create());
     $ob->addHeaderOb(Horde_Mime_Headers_MessageId::create());
     $hdrs = array('From' => 'from', 'To' => 'to', 'Cc' => 'cc', 'Bcc' => 'bcc', 'Subject' => 'subject');
     foreach ($hdrs as $key => $val) {
         if (isset($headers[$val]) && (is_object($headers[$val]) || strlen($headers[$val]))) {
             $ob->addHeader($key, $headers[$val]);
         }
     }
     if ($this->replyType(true) == self::REPLY) {
         if ($refs = $this->getMetadata('references')) {
             $ob->addHeader('References', implode(' ', $refs));
         }
         if ($this->getMetadata('in_reply_to')) {
             $ob->addHeader('In-Reply-To', $this->getMetadata('in_reply_to'));
         }
     }
     /* Add priority header, if requested. */
     if (!empty($opts['priority'])) {
         switch ($opts['priority']) {
             case 'high':
                 $ob->addHeader('Importance', 'High');
                 $ob->addHeader('X-Priority', '1 (Highest)');
                 break;
             case 'low':
                 $ob->addHeader('Importance', 'Low');
                 $ob->addHeader('X-Priority', '5 (Lowest)');
                 break;
         }
     }
     /* Add Return Receipt Headers. */
     if (!empty($opts['readreceipt']) && ($h = $ob['from'])) {
         $from = $h->getAddressList(true);
         if (is_null($from->host)) {
             $from->host = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->config->maildomain;
         }
         $mdn = new Horde_Mime_Mdn($ob);
         $mdn->addMdnRequestHeaders($from);
     }
     return $ob;
 }
Example #7
0
 /**
  * Prepare header object with basic header fields and converts headers
  * to the current compose charset.
  *
  * @param array $headers  Array with 'from', 'to', 'cc', 'bcc', and
  *                        'subject' values.
  * @param array $opts     An array of options w/the following keys:
  *   - bcc: (boolean) Add BCC header to output.
  *   - priority: (string) The message priority ('high', 'normal', 'low').
  *
  * @return Horde_Mime_Headers  Headers object with the appropriate headers
  *                             set.
  */
 protected function _prepareHeaders($headers, array $opts = array())
 {
     $ob = new Horde_Mime_Headers();
     $ob->addHeader('Date', date('r'));
     $ob->addMessageIdHeader();
     if (isset($headers['from']) && strlen($headers['from'])) {
         $ob->addHeader('From', $headers['from']);
     }
     if (isset($headers['to']) && (is_object($headers['to']) || strlen($headers['to']))) {
         $ob->addHeader('To', $headers['to']);
     } elseif (!isset($headers['cc'])) {
         $ob->addHeader('To', 'undisclosed-recipients:;');
     }
     if (isset($headers['cc']) && (is_object($headers['cc']) || strlen($headers['cc']))) {
         $ob->addHeader('Cc', $headers['cc']);
     }
     if (!empty($opts['bcc']) && isset($headers['bcc']) && (is_object($headers['bcc']) || strlen($headers['bcc']))) {
         $ob->addHeader('Bcc', $headers['bcc']);
     }
     if (isset($headers['subject']) && strlen($headers['subject'])) {
         $ob->addHeader('Subject', $headers['subject']);
     }
     if ($this->replyType(true) == self::REPLY) {
         if ($refs = $this->getMetadata('references')) {
             $ob->addHeader('References', implode(' ', $refs));
         }
         if ($this->getMetadata('in_reply_to')) {
             $ob->addHeader('In-Reply-To', $this->getMetadata('in_reply_to'));
         }
     }
     /* Add priority header, if requested. */
     if (!empty($opts['priority'])) {
         switch ($opts['priority']) {
             case 'high':
                 $ob->addHeader('Importance', 'High');
                 $ob->addHeader('X-Priority', '1 (Highest)');
                 break;
             case 'low':
                 $ob->addHeader('Importance', 'Low');
                 $ob->addHeader('X-Priority', '5 (Lowest)');
                 break;
         }
     }
     /* Add Return Receipt Headers. */
     if (!empty($opts['readreceipt'])) {
         $from = $ob->getOb('from');
         $from = $from[0];
         if (is_null($from->host)) {
             $from->host = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->config->maildomain;
         }
         $mdn = new Horde_Mime_Mdn($ob);
         $mdn->addMdnRequestHeaders($from);
     }
     return $ob;
 }