[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 3 require_once 'Horde/History.php'; 4 5 /** 6 * The IMP_Maillog:: class contains all functions related to handling 7 * logging of responses to individual e-mail messages. 8 * 9 * $Horde: imp/lib/Maillog.php,v 1.15.10.13 2007/01/02 13:54:56 jan Exp $ 10 * 11 * Copyright 2003-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 12 * 13 * See the enclosed file COPYING for license information (GPL). If you 14 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 15 * 16 * @author Michael Slusarz <slusarz@bigworm.colorado.edu> 17 * @since IMP 4.0 18 * @package IMP 19 */ 20 class IMP_Maillog { 21 22 /** 23 * Create a log entry. 24 * 25 * @param string $type Either 'forward', 'redirect', 'reply', or 'mdn'. 26 * @param mixed $msg_ids Either a single Message-ID or an array of 27 * Message-IDs to log. 28 * @param string $data Any additional data to store. For 'forward' and 29 * 'redirect' this is the list of recipients the 30 * message was sent to. For 'mdn' this is the 31 * MDN-type of the message that was sent. 32 */ 33 function log($type, $msg_ids, $data = null) 34 { 35 $history = &Horde_History::singleton(); 36 37 if (!is_array($msg_ids)) { 38 $msg_ids = array($msg_ids); 39 } 40 41 foreach ($msg_ids as $val) { 42 $id = IMP_Maillog::_getUniqueHistoryId($val); 43 switch ($type) { 44 case 'forward': 45 $r = $history->log($id, array('recipients' => $data, 'action' => 'forward')); 46 break; 47 48 case 'mdn': 49 $r = $history->log($id, array('type' => $data, 'action' => 'mdn')); 50 break; 51 52 case 'redirect': 53 $r = $history->log($id, array('recipients' => $data, 'action' => 'redirect')); 54 break; 55 56 case 'reply': 57 $r = $history->log($id, array('action' => 'reply')); 58 break; 59 } 60 61 /* On error, log the error message only since informing the user 62 * is just a waste of time and a potential point of confusion, 63 * especially since they most likely don't even know the message 64 * is being logged. */ 65 if (is_a($r, 'PEAR_Error')) { 66 $entry = sprintf('Could not log message details to Horde_History. Error returned: %s', $r->getMessage()); 67 Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_ERR); 68 } 69 } 70 } 71 72 /** 73 * Retrieve any history for the given Message-ID. 74 * 75 * @param string $msg_id The Message-ID of the message. 76 * 77 * @return DataTreeObject The DataTreeObject object containing the log 78 * information, or PEAR_Error on error. 79 */ 80 function &getLog($msg_id) 81 { 82 $history = &Horde_History::singleton(); 83 $log = &$history->getHistory(IMP_Maillog::_getUniqueHistoryId($msg_id)); 84 return $log; 85 } 86 87 /** 88 * Determines if an MDN notification of a certain type has been sent 89 * previously for this message-ID. 90 * 91 * @param string $msg_id The Message-ID of the message. 92 * @param string $type The type of MDN. 93 * 94 * @return boolean True if a MDN has been sent for this message with 95 * the given type. 96 */ 97 function sentMDN($msg_id, $type) 98 { 99 $msg_history = IMP_Maillog::getLog($msg_id); 100 if ($msg_history && !is_a($msg_history, 'PEAR_Error')) { 101 foreach ($msg_history->getData() as $entry) { 102 if (($entry['action'] == 'mdn') && ($entry['type'] == $type)) { 103 return true; 104 } 105 } 106 } 107 108 return false; 109 } 110 111 /** 112 * Retrieve any history for the given Message-ID and display via the 113 * Horde notification system. 114 * 115 * @param string $msg_id The Message-ID of the message. 116 */ 117 function displayLog($msg_id) 118 { 119 global $notification, $prefs; 120 121 $msg_history = IMP_Maillog::getLog($msg_id); 122 if ($msg_history && !is_a($msg_history, 'PEAR_Error')) { 123 foreach ($msg_history->getData() as $entry) { 124 $msg = null; 125 if (isset($entry['desc'])) { 126 $msg = $entry['desc']; 127 } else { 128 switch ($entry['action']) { 129 case 'forward': 130 $msg = sprintf(_("You forwarded this message on %%s to the following recipients: %s."), $entry['recipients']); 131 break; 132 133 case 'mdn': 134 /* We don't display 'mdn' log entries. */ 135 break; 136 137 case 'redirect': 138 $msg = sprintf(_("You redirected this message to %s on %%s."), $entry['recipients']); 139 break; 140 141 case 'reply': 142 $msg = _("You replied to this message on %s."); 143 break; 144 } 145 } 146 if (!is_null($msg)) { 147 $notification->push(htmlspecialchars(@sprintf($msg, strftime($prefs->getValue('date_format') . ' ' . $prefs->getValue('time_format'), $entry['ts']))), 'imp.' . $entry['action']); 148 } 149 } 150 } 151 } 152 153 /** 154 * Delete the log entries for a given list of Message-IDs. 155 * 156 * @param mixed $msg_ids Either a single Message-ID or an array 157 * of Message-IDs to delete. 158 */ 159 function deleteLog($msg_ids) 160 { 161 if (!is_array($msg_ids)) { 162 $msg_ids = array(IMP_Maillog::_getUniqueHistoryId($msg_ids)); 163 } else { 164 foreach ($msg_ids as $key => $msg_id) { 165 $msg_ids[$key] = IMP_Maillog::_getUniqueHistoryId($msg_id); 166 } 167 } 168 169 $history = &Horde_History::singleton(); 170 return $history->removeByNames($msg_ids); 171 } 172 173 /** 174 * Generate the unique log ID for a forward/reply/redirect event. 175 * 176 * @access private 177 * 178 * @param string $msgid The Message-ID of the original message. 179 * 180 * @return string The unique log ID to use with Horde_History::. 181 */ 182 function _getUniqueHistoryId($msgid) 183 { 184 if (is_array($msgid)) { 185 return ''; 186 } 187 188 return implode('.', array('imp', str_replace('.', '*', Auth::getAuth()), $msgid)); 189 } 190 191 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:30:07 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |