Skip to content

Commit

Permalink
Finalize rewrite of IMP_Maillog system
Browse files Browse the repository at this point in the history
+ Now based on Mailbox/UIDs, not message IDs
+ Don't use Horde_History_Log, since that is specific to a single driver
+ Move IMAP-flag based MDN checking into an IMP_Maillog driver
  • Loading branch information
slusarz committed Mar 12, 2014
1 parent af91533 commit cf64cc0
Show file tree
Hide file tree
Showing 25 changed files with 1,015 additions and 341 deletions.
6 changes: 4 additions & 2 deletions imp/lib/Ajax/Application/Handler/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function sendMessage()

if ($indices = $imp_compose->getMetadata('indices')) {
/* Update maillog information. */
$this->_base->queue->maillog($indices, $imp_compose->getMetadata('in_reply_to'));
$this->_base->queue->maillog($indices);
}

$imp_compose->destroy('send');
Expand Down Expand Up @@ -635,7 +635,9 @@ public function redirectMessage()
$subject = $val->headers->getValue('subject');
$GLOBALS['notification']->push(empty($subject) ? _("Message redirected successfully.") : sprintf(_("Message \"%s\" redirected successfully."), Horde_String::truncate($subject)), 'horde.success');

$this->_base->queue->maillog(new IMP_Indices($val->mbox, $val->uid), $val->headers->getValue('message-id'));
$this->_base->queue->maillog(
new IMP_Indices($val->mbox, $val->uid)
);
}
} catch (Horde_Exception $e) {
$GLOBALS['notification']->push($e);
Expand Down
12 changes: 9 additions & 3 deletions imp/lib/Ajax/Application/Handler/Dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -812,21 +812,27 @@ public function purgeDeleted()
*/
public function sendMDN()
{
global $injector, $notification;

if (count($this->_base->indices) != 1) {
return false;
}

try {
$contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create($this->_base->indices);
$contents = $injector->getInstance('IMP_Factory_Contents')->create($this->_base->indices);
} catch (IMP_Imap_Exception $e) {
$e->notify(_("The Message Disposition Notification was not sent. This is what the server said") . ': ' . $e->getMessage());
return false;
}

list($mbox, $uid) = $this->_base->indices->getSingle();
$GLOBALS['injector']->getInstance('IMP_Message_Ui')->MDNCheck($mbox, $uid, $contents->getHeaderAndMarkAsSeen(), true);
$injector->getInstance('IMP_Message_Ui')->MDNCheck(
new IMP_Indices($mbox, $uid),
$contents->getHeaderAndMarkAsSeen(),
true
);

$GLOBALS['notification']->push(_("The Message Disposition Notification was sent successfully."), 'horde.success');
$notification->push(_("The Message Disposition Notification was sent successfully."), 'horde.success');

$result = new stdClass;
$result->buid = $this->_base->vars->buid;
Expand Down
4 changes: 2 additions & 2 deletions imp/lib/Ajax/Application/ShowMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function showMessage($args)

/* Maillog information. */
$ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
$ajax_queue->maillog($this->_indices, $this->_envelope->message_id);
$ajax_queue->maillog($this->_indices);

if (!$preview) {
/* Display the user-specified headers for the current identity. */
Expand Down Expand Up @@ -276,7 +276,7 @@ public function showMessage($args)
/* Do MDN processing now. */
switch ($registry->getView()) {
case $registry::VIEW_DYNAMIC:
if ($imp_ui->MDNCheck($mbox, $uid, $mime_headers)) {
if ($imp_ui->MDNCheck(new IMP_Indices($mbox, $uid), $mime_headers)) {
$status = new IMP_Mime_Status(array(
_("The sender of this message is requesting notification from you when you have read this message."),
sprintf(_("Click %s to send the notification message."), Horde::link('#', '', '', '', '', '', '', array('id' => 'send_mdn_link')) . _("HERE") . '</a>')
Expand Down
42 changes: 20 additions & 22 deletions imp/lib/Ajax/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class IMP_Ajax_Queue
protected $_messages = array();

/**
* Mail log queue.
* Maillog queue.
*
* @var array
*/
Expand Down Expand Up @@ -235,25 +235,26 @@ public function add(IMP_Ajax_Application $ajax)
/* Add folder tree information. */
$this->_addFtreeInfo($ajax);

/* Add mail log information. */
/* Add maillog information. */
if (!empty($this->_maillog)) {
$imp_maillog = $injector->getInstance('IMP_Maillog');
$maillog = array();

foreach ($this->_maillog as $val) {
$tmp = array();
foreach ($imp_maillog->parseLog($val['msg_id']) as $val2) {
$ret[] = array(
'm' => $val2['msg'],
't' => $val2['action']
foreach ($imp_maillog->getLog($val, array('mdn')) as $val2) {
$tmp[] = array(
'm' => $val2->message,
't' => $val2->action
);
}

if ($tmp) {
list($mbox, $buid) = $val->indices->getSingle();
$log_ob = new stdClass;
$log_ob->buid = intval($val['buid']);
$log_ob->buid = intval($buid);
$log_ob->log = $tmp;
$log_ob->mbox = $val['mailbox']->form_to;
$log_ob->mbox = $mbox->form_to;
$maillog[] = $log_ob;
}
}
Expand Down Expand Up @@ -492,28 +493,25 @@ public function message(IMP_Indices $indices, $preview = false,
}

/**
* Add mail log data to output.
* Add maillog data to output.
*
* @param IMP_Indices $indices Indices object.
* @param string $msg_id The message ID of the original message.
*/
public function maillog(IMP_Indices $indices, $msg_id)
public function maillog(IMP_Indices $indices)
{
if (!$GLOBALS['injector']->getInstance('IMP_Maillog')) {
return;
}

if ($indices instanceof IMP_Indices_Mailbox) {
$indices = $indices->joinIndices();
}

foreach ($indices as $val) {
foreach ($val->uids as $val2) {
$this->_maillog[] = array(
'buid' => $val2,
'mailbox' => $val->mbox,
'msg_id' => $msg_id
);
if (count($indices) === 1) {
$this->_maillog[] = new IMP_Maillog_Message($indices);
} else {
foreach ($indices as $val) {
foreach ($val->uids as $val2) {
$this->_maillog[] = new IMP_Maillog_Message(
new IMP_Indices($val->mbox, $val2)
);
}
}
}
}
Expand Down
60 changes: 56 additions & 4 deletions imp/lib/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,30 +372,78 @@ public function getSpecialMailboxes()
* Obtain the Maillog for a given message.
*
* @since 6.1.0
* @todo This should not be returning a Horde_History_Log object.
*
* @param string $mid The Message-ID to obtain the log for.
*
* @return Horde_History_Log The log object.
*/
public function getMaillog($mid)
{
return $GLOBALS['injector']->getInstance('IMP_Maillog')->getLog($mid);
global $injector, $registry;

$log = $injector->getInstance('IMP_Maillog')->getLog(
new IMP_Maillog_Message($mid)
);

$history = array();
foreach ($log as $val) {
$history[] = array(
'history_action' => $val->action,
'history_desc' => '',
'history_id' => 0,
'history_modseq' => 0,
'history_ts' => $val->timestamp,
'history_who' => $registry->getAuth()
);
}

return new Horde_History_Log($mid, $history);
}

/**
* Log an entry in the Maillog.
*
* @since 6.1.0
* @todo Abstract '$action', since it is currently keyed to IMP constants.
* @todo Rewrite this. $action and $data are both IMP specific, so they
* aren't intended to be set from outside of IMP. And $mid should
* be replaced by mailbox/UID.
*
* @param string $action The action to log.
* @param string $mid The Message-ID.
* @param string $data Additional data.
*/
public function logMaillog($action, $mid, $data = null)
{
switch ($action) {
case 'forward':
$log = new IMP_Maillog_Log_Forward($data['recipients']);
break;

case 'mdn':
$log = new IMP_Maillog_Log_Mdn();
break;

case 'redirect':
$log = new IMP_Maillog_Log_Redirect($data['recipients']);
break;

case 'reply':
$log = new IMP_Maillog_Log_Reply();
break;

case 'reply_all':
$log = new IMP_Maillog_Log_Replyall();
break;

case 'reply_list':
$log = new IMP_Maillog_Log_Replylist();
break;
}

$GLOBALS['injector']->getInstance('IMP_Maillog')->log(
$action, $mid, $data
new IMP_Maillog_Message($mid),
$log
);
}

Expand All @@ -404,6 +452,7 @@ public function logMaillog($action, $mid, $data = null)
* the specified timestamp.
*
* @since 6.1.0
* @todo This should not be returning Message-IDs.
*
* @param integer $ts The timestamp to start searching from. Only entries
* after this timestamp will be returned.
Expand All @@ -412,7 +461,10 @@ public function logMaillog($action, $mid, $data = null)
*/
public function getMaillogChanges($ts)
{
return $GLOBALS['injector']->getInstance('IMP_Maillog')->getChanges($ts);
return array_map(
'strval',
$GLOBALS['injector']->getInstance('IMP_Maillog')->getChanges($ts)
);
}

}
12 changes: 5 additions & 7 deletions imp/lib/Basic/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ protected function _init()
IMP_Contents::SUMMARY_PRINT;

/* Do MDN processing now. */
$mdntext = $imp_ui->MDNCheck($msg_index['m'], $buid, $mime_headers, $this->vars->mdn_confirm)
$mdntext = $imp_ui->MDNCheck(new IMP_Indices($msg_index['m'], $buid), $mime_headers, $this->vars->mdn_confirm)
? strval(new IMP_Mime_Status(array(
_("The sender of this message is requesting a notification from you when you have read this message."),
sprintf(_("Click %s to send the notification message."), Horde::link($selfURL->copy()->add('mdn_confirm', 1)) . _("HERE") . '</a>')
Expand Down Expand Up @@ -909,13 +909,11 @@ protected function _init()

$page_output->noDnsPrefetch();

if ($maillog = $injector->getInstance('IMP_Maillog')) {
Horde::startBuffer();
foreach ($maillog->parseLog($msg_id) as $val) {
$notification->push($val['msg'], 'imp.' . $val['action']);
}
$this->output = Horde::endBuffer();
Horde::startBuffer();
foreach ($injector->getInstance('IMP_Maillog')->getLog(new IMP_Maillog_Message($this->indices, array('mdn'))) as $val) {
$notification->push($val->message, 'imp.' . $val->action);
}
$this->output = Horde::endBuffer();

$this->output .= $t_view->render('navbar_top') .
$n_view->render('navbar_navigate') .
Expand Down
36 changes: 30 additions & 6 deletions imp/lib/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,31 @@ public function buildAndSendMessage(
if ($this->_replytype) {
/* Log the reply. */
if ($this->getMetadata('in_reply_to')) {
switch ($this->_replytype) {
case self::FORWARD:
case self::FORWARD_ATTACH:
case self::FORWARD_BODY:
case self::FORWARD_BOTH:
$log = new IMP_Maillog_Log_Forward($recipients);
break;

case self::REPLY:
case self::REPLY_SENDER:
$log = new IMP_Maillog_Log_Reply();
break;

case IMP_Compose::REPLY_ALL:
$log = new IMP_Maillog_Log_Replyall();
break;

case IMP_Compose::REPLY_LIST:
$log = new IMP_Maillog_Log_Replylist();
break;
}

$injector->getInstance('IMP_Maillog')->log(
$this->_replytype,
$this->getMetadata('in_reply_to'),
$recipients
new IMP_Maillog_Message($this->getMetadata('in_reply_to')),
$log
);
}

Expand Down Expand Up @@ -2283,12 +2304,15 @@ public function sendRedirectMessage($to, $log = true)
if ($log) {
/* Store history information. */
$injector->getInstance('IMP_Maillog')->log(
self::REDIRECT,
new IMP_Maillog_Message($headers->getValue('message-id')),
new IMP_Maillog_Log_Redirect($recipients)
);

$injector->getInstance('IMP_Sentmail')->log(
IMP_Sentmail::REDIRECT,
$headers->getValue('message-id'),
$recipients
);

$injector->getInstance('IMP_Sentmail')->log(IMP_Sentmail::REDIRECT, $headers->getValue('message-id'), $recipients);
}

$tmp = new stdClass;
Expand Down
17 changes: 14 additions & 3 deletions imp/lib/Factory/Maillog.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,36 @@ public function create(Horde_Injector $injector)
{
global $conf, $injector, $registry;

$storage = array();

if ($injector->getInstance('IMP_Factory_Imap')->create()->isImap()) {
$storage[] = new IMP_Maillog_Storage_Mdnsent();
}

$driver = isset($conf['maillog']['driver'])
? $conf['maillog']['driver']
// @todo BC support for 'use_maillog'
: (empty($conf['maillog']['use_maillog']) ? 'none' : 'history');

switch ($driver) {
case 'history':
$storage = new IMP_Maillog_Storage_History(
$storage[] = new IMP_Maillog_Storage_History(
$injector->getInstance('Horde_History'),
$registry->getAuth()
);
break;

case 'none':
$storage = new IMP_Maillog_Storage_Null();
default:
$storage[] = new IMP_Maillog_Storage_Null();
break;
}

return new IMP_Maillog($storage);
return new IMP_Maillog(
(count($storage) > 1)
? new IMP_Maillog_Storage_Composite($storage)
: reset($storage)
);
}

}

0 comments on commit cf64cc0

Please sign in to comment.