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