IMP_Indices::mdnCheck PHP Method

mdnCheck() public method

Check if we need to send a MDN, and send if needed.
public mdnCheck ( Horde_Mime_Headers $headers, boolean $confirmed = false ) : boolean
$headers Horde_Mime_Headers The headers of the message.
$confirmed boolean 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;
    }

Usage Example

Example #1
0
 /**
  * Create the object used to display the message.
  *
  * @return array  Array with the following keys:
  *   - atc: (object) Attachment information.
  *     - download: (string) The URL for the download all action.
  *     - label: (string) The attachment label.
  *     - list: (array) Attachment information.
  *   - md: (array) Metadata.
  *   - msgtext: (string) The text of the message.
  *   - onepart: (boolean) True if message only contains one part.
  *
  * @throws IMP_Exception
  */
 public function showMessage()
 {
     global $prefs, $registry, $session;
     $result = array();
     // Create message text and attachment list.
     $result['msgtext'] = '';
     $show_parts = $prefs->getValue('parts_display');
     /* Do MDN processing now. */
     switch ($registry->getView()) {
         case $registry::VIEW_DYNAMIC:
             if ($this->_indices->mdnCheck($this->_loadHeaders())) {
                 $status = new IMP_Mime_Status(null, array(_("The sender of this message is requesting notification from you when you have read this message."), Horde::link('#', '', '', '', '', '', '', array('id' => 'send_mdn_link')) . _("Click to send the notification message.") . '</a>'));
                 $status->domid('sendMdnMessage');
                 $result['msgtext'] .= strval($status);
             }
     }
     /* Build body text. This needs to be done before we build the
      * attachment list. */
     $session->close();
     $inlineout = $this->getInlineOutput();
     $session->start();
     $result['md'] = $inlineout['metadata'];
     $result['msgtext'] .= $inlineout['msgtext'];
     if ($inlineout['one_part']) {
         $result['onepart'] = true;
     }
     if (count($inlineout['atc_parts']) || $show_parts == 'all' && count($inlineout['display_ids']) > 2) {
         $result['atc']['label'] = $show_parts == 'all' ? _("Parts") : sprintf(ngettext("%d Attachment", "%d Attachments", count($inlineout['atc_parts'])), count($inlineout['atc_parts']));
         if (count($inlineout['atc_parts']) > 1) {
             $result['atc']['download'] = strval($this->contents->urlView($this->contents->getMIMEMessage(), 'download_all')->setRaw(true));
         }
     }
     /* Show attachment information in headers? */
     if (!empty($inlineout['atc_parts'])) {
         $partlist = array();
         $contents_mask = IMP_Contents::SUMMARY_DESCRIP | IMP_Contents::SUMMARY_DESCRIP_LINK | IMP_Contents::SUMMARY_DOWNLOAD | IMP_Contents::SUMMARY_ICON | IMP_Contents::SUMMARY_SIZE;
         $part_info = array('icon', 'description', 'size', 'download', 'description_raw', 'download_url');
         if ($show_parts == 'all') {
             array_unshift($part_info, 'id');
         }
         foreach ($inlineout['atc_parts'] as $id) {
             $summary = $this->contents->getSummary($id, $contents_mask);
             $tmp = array();
             foreach ($part_info as $val) {
                 if (isset($summary[$val])) {
                     $tmp[$val] = $summary[$val] instanceof Horde_Url ? strval($summary[$val]->setRaw(true)) : $summary[$val];
                 }
             }
             $partlist[] = array_filter($tmp);
         }
         $result['atc']['list'] = $partlist;
     }
     return $result;
 }
All Usage Examples Of IMP_Indices::mdnCheck