예제 #1
0
파일: MdnTest.php 프로젝트: raz0rsdge/horde
 /**
  * @dataProvider getMdnReturnAddrProvider
  */
 public function testGetMdnReturnAddr($email)
 {
     $h = new Horde_Mime_Headers();
     $ob = new Horde_Mime_Mdn($h);
     if (!is_null($email)) {
         $ob->addMdnRequestHeaders($email);
     }
     $this->assertEquals(strval($email), $ob->getMdnReturnAddr());
 }
예제 #2
0
파일: Mdn.php 프로젝트: 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;
 }
예제 #3
0
파일: Ui.php 프로젝트: DSNS-LAB/Dmail
 /**
  * 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;
 }
예제 #4
0
파일: Indices.php 프로젝트: horde/horde
 /**
  * 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;
 }
예제 #5
0
 /**
  * @dataProvider getMdnReturnAddrProvider
  */
 public function testGetMdnReturnAddr($h, $expected)
 {
     $ob = new Horde_Mime_Mdn($h);
     $this->assertEquals($expected, $ob->getMdnReturnAddr());
 }
예제 #6
0
파일: Compose.php 프로젝트: raz0rsdge/horde
 /**
  * Resumes a previously saved draft message.
  *
  * @param IMP_Indices $indices  See resumeDraft().
  * @param integer $type         Compose type.
  * @param array $opts           Additional options:
  *   - format: (string) Force to this format.
  *             DEFAULT: Auto-determine.
  *
  * @return mixed  See resumeDraft().
  *
  * @throws IMP_Compose_Exception
  */
 protected function _resumeDraft($indices, $type, $opts)
 {
     global $injector, $notification, $prefs;
     $contents_factory = $injector->getInstance('IMP_Factory_Contents');
     try {
         $contents = $contents_factory->create($indices);
     } catch (IMP_Exception $e) {
         throw new IMP_Compose_Exception($e);
     }
     $headers = $contents->getHeader();
     $imp_draft = false;
     if ($draft_url = $headers[self::DRAFT_REPLY]) {
         if (is_null($type) && !($type = $headers[self::DRAFT_REPLY_TYPE])) {
             $type = self::REPLY;
         }
         $imp_draft = self::REPLY;
     } elseif ($draft_url = $headers[self::DRAFT_FWD]) {
         $imp_draft = self::FORWARD;
         if (is_null($type)) {
             $type = self::FORWARD;
         }
     } elseif (isset($headers[self::DRAFT_HDR])) {
         $imp_draft = self::COMPOSE;
     }
     if (!empty($opts['format'])) {
         $compose_html = $opts['format'] == 'html';
     } elseif ($prefs->getValue('compose_html')) {
         $compose_html = true;
     } else {
         switch ($type) {
             case self::EDITASNEW:
             case self::FORWARD:
             case self::FORWARD_BODY:
             case self::FORWARD_BOTH:
                 $compose_html = $prefs->getValue('forward_format');
                 break;
             case self::REPLY:
             case self::REPLY_ALL:
             case self::REPLY_LIST:
             case self::REPLY_SENDER:
                 $compose_html = $prefs->getValue('reply_format');
                 break;
             case self::TEMPLATE:
                 $compose_html = true;
                 break;
             default:
                 /* If this is an draft saved by IMP, we know 100% for sure
                  * that if an HTML part exists, the user was composing in
                  * HTML. */
                 $compose_html = $imp_draft !== false;
                 break;
         }
     }
     $msg_text = $this->_getMessageText($contents, array('html' => $compose_html, 'imp_msg' => $imp_draft, 'toflowed' => false));
     if (empty($msg_text)) {
         $body = '';
         $format = 'text';
         $text_id = 0;
     } else {
         /* Use charset at time of initial composition if this is an IMP
          * draft. */
         if ($imp_draft !== false) {
             $this->charset = $msg_text['charset'];
         }
         $body = $msg_text['text'];
         $format = $msg_text['mode'];
         $text_id = $msg_text['id'];
     }
     $mime_message = $contents->getMIMEMessage();
     /* Add attachments. */
     $parts = array();
     if ($mime_message->getPrimaryType() == 'multipart' && $mime_message->getType() != 'multipart/alternative') {
         for ($i = 1;; ++$i) {
             if (intval($text_id) == $i) {
                 continue;
             }
             if ($part = $contents->getMimePart($i)) {
                 $parts[] = $part;
             } else {
                 break;
             }
         }
     } elseif ($mime_message->getDisposition() == 'attachment') {
         $parts[] = $contents->getMimePart('1');
     }
     foreach ($parts as $val) {
         try {
             $this->addAttachmentFromPart($val);
         } catch (IMP_Compose_Exception $e) {
             $notification->push($e, 'horde.warning');
         }
     }
     $alist = new Horde_Mail_Rfc822_List();
     $addr = array('to' => clone $alist, 'cc' => clone $alist, 'bcc' => clone $alist);
     if ($type != self::EDITASNEW) {
         foreach (array('to', 'cc', 'bcc') as $val) {
             if ($h = $headers[$val]) {
                 $addr[$val] = $h->getAddressList(true);
             }
         }
         if ($val = $headers['References']) {
             $this->_setMetadata('references', $val->getIdentificationOb()->ids);
             if ($val = $headers['In-Reply-To']) {
                 $this->_setMetadata('in_reply_to', $val);
             }
         }
         if ($draft_url) {
             $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
             $indices = new IMP_Indices();
             foreach (explode(',', $draft_url->value_single) as $val) {
                 $imap_url = new Horde_Imap_Client_Url(rtrim(ltrim($val, '<'), '>'));
                 try {
                     if ($imap_url->protocol == ($imp_imap->isImap() ? 'imap' : 'pop') && $imap_url->username == $imp_imap->getParam('username') && IMP_Mailbox::get($imap_url->mailbox)->uidvalid == $imap_url->uidvalidity && $contents_factory->create(new IMP_Indices($imap_url->mailbox, $imap_url->uid))) {
                         $indices->add($imap_url->mailbox, $imap_url->uid);
                     }
                 } catch (Exception $e) {
                 }
             }
             if (count($indices)) {
                 $this->_setMetadata('indices', $indices);
                 $this->_replytype = $type;
             }
         }
     }
     $mdn = new Horde_Mime_Mdn($headers);
     $readreceipt = (bool) $mdn->getMdnReturnAddr();
     $this->changed = 'changed';
     return array('addr' => $addr, 'body' => $body, 'format' => $format, 'identity' => $this->_getMatchingIdentity($headers, array('from')), 'priority' => $injector->getInstance('IMP_Mime_Headers')->getPriority($headers), 'readreceipt' => $readreceipt, 'subject' => strval($headers['Subject']), 'type' => $type);
 }