Skip to content

Commit

Permalink
[mms] Sent-mail maillog entries are now linked to a viewable represen…
Browse files Browse the repository at this point in the history
…tation of the sent message, if it still exists on the server.

Further optimizations could include:
  - Adding preference to indicate what mailboxes should be searched
  • Loading branch information
slusarz committed Mar 9, 2015
1 parent 03f373c commit 6dfea09
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 22 deletions.
2 changes: 2 additions & 0 deletions imp/docs/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
v7.0.0-git
----------

[mms] Sent-mail maillog entries are now linked to a viewable representation of
the sent message, if it still exists on the server.
[mms] Store message ID of the sent message when saving maillog history.
[mms] Add backend configuration option to use body structure data to more
accurately determine whether a message contains attachments.
Expand Down
15 changes: 13 additions & 2 deletions imp/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ var ImpCore = {
/* Mouse click handler. */
clickHandler: function(e)
{
var args, tmp, text,
var args, cnames, text, tmp,
elt = e.element();

if (!elt.match('A')) {
Expand Down Expand Up @@ -454,7 +454,9 @@ var ImpCore = {
return;
}

if (elt.hasClassName('largeaddrspan_active') &&
cnames = $w(elt.className);

if ((cnames.indexOf('largeaddrspan_active') !== -1) &&
!e.memo.element().hasClassName('horde-button')) {
if (e.memo.element().hasClassName('largeaddrlistlimit')) {
e.memo.element().hide();
Expand All @@ -463,6 +465,15 @@ var ImpCore = {
tmp = elt.down();
[ tmp.down(), tmp.down(1), tmp.next() ].invoke('toggle');
}
} else if (cnames.indexOf('imp-maillog-sent') !== -1) {
HordeCore.popupWindow(this.conf.URI_MAILLOG, {
msgid: elt.retrieve('msgid'),
type: elt.retrieve('type')
}, {
height: Math.min(1000, HordeCore.conf.popup_height),
name: 'maillog' + new Date().getTime()
});
e.memo.stop();
}
},

Expand Down
29 changes: 29 additions & 0 deletions imp/js/maillog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Maillog display for dynamic view.
*
* @author Michael Slusarz <slusarz@horde.org>
* @copyright 2015 Horde LLC
* @license GPL-2 (http://www.horde.org/licenses/gpl)
*/

var ImpMaillog = {

// Vars set by calling code:
// error_msg

onDomLoad: function()
{
var base;

if (base = ImpCore.baseAvailable()) {
base.HordeCore.notify(this.error_msg, 'horde.error');
window.close();
} else {
document.body.insert(this.error_msg.escapeHTML());
}
}

};

/* Initialize onload handler. */
document.observe('dom:loaded', ImpMaillog.onDomLoad.bind(ImpMaillog));
1 change: 1 addition & 0 deletions imp/lib/Dynamic/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ protected function _addBaseVars()
$this->js_conf = array_filter(array(
// URL variables
'URI_COMPOSE' => strval(IMP_Dynamic_Compose::url()->setRaw(true)),
'URI_MAILLOG' => strval(IMP_Dynamic_Maillog::url()->setRaw(true)),
'URI_VIEW' => strval(Horde::url('view.php')->add(IMP_Contents_View::addToken())),

// Other variables
Expand Down
69 changes: 69 additions & 0 deletions imp/lib/Dynamic/Maillog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright 2015 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @copyright 2015 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/

/**
* Maillog message ID lookup page for dynamic view.
*
* Expects two URL parameters:
* - msgid: Message-ID
* - type: Maillog type
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2015 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
class IMP_Dynamic_Maillog extends IMP_Dynamic_Base
{
/**
* @throws IMP_Exception
*/
protected function _init()
{
global $notification, $page_output;

if (isset($this->vars->msgid) &&
isset($this->vars->type) &&
isset(IMP_Maillog_Storage_History::$drivers[$this->vars->type])) {
$log = new IMP_Maillog_Storage_History::$drivers[$this->vars->type](array(
'msgid' => $this->vars->msgid
));

$query = $log->searchQuery();

foreach ($log->searchMailboxes() as $val) {
if ($indices = $val->runSearchQuery($query)) {
list($mbox, $uid) = $indices->getSingle();
$url = IMP_Dynamic_Message::url();
$url->add($mbox->urlParams($uid));
$url->redirect();
}
}
}

$page_output->addScriptFile('maillog.js');

$page_output->addInlineJsVars(array(
'ImpMaillog.error_msg' => _("Could not load message.")
));
}

/**
*/
public static function url(array $opts = array())
{
return Horde::url('dynamic.php')->add('page', 'maillog');
}

}
7 changes: 7 additions & 0 deletions imp/lib/Maillog/Log/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class IMP_Maillog_Log_Redirect
*/
protected $_action = 'redirect';

/**
* Message ID header label.
*
* @var string
*/
protected $_msgidHeader = 'Resent-Message-ID';

/**
* List of recipients.
*
Expand Down
30 changes: 22 additions & 8 deletions imp/lib/Maillog/Log/Sentmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ abstract class IMP_Maillog_Log_Sentmail
*/
protected $_msgId;

/**
* Message ID header label.
*
* @var string
*/
protected $_msgidHeader = 'Message-ID';

/**
* Constructor.
*
Expand Down Expand Up @@ -73,27 +80,34 @@ public function addData()
/**
* Return the mailboxes that can be searched to find the sent message.
*
* @return array Array of arrays; each array is a group of mailboxes to
* search in order of priority.
* @return array Array of mailboxes to search in order of priority.
*/
public function searchMailboxes()
{
$out = array();

$special = IMP_Mailbox::getSpecialMailboxes();

/* Check for sent-mail mailbox(es) first. */
if (!empty($special[IMP_Mailbox::SPECIAL_SENT])) {
$out[] = $special[IMP_Mailbox::SPECIAL_SENT];
}
$out = $special[IMP_Mailbox::SPECIAL_SENT];

/* Add trash mailbox as backup. */
if (!empty($special[IMP_Mailbox::SPECIAL_TRASH]) &&
!$special[IMP_Mailbox::SPECIAL_TRASH]->vtrash) {
$out[] = array($special[IMP_Mailbox::SPECIAL_TRASH]);
$out[] = $special[IMP_Mailbox::SPECIAL_TRASH];
}

return $out;
}

/**
* Return the search query to use to find the sent message.
*
* @return Horde_Imap_Client_Search_Query The query object.
*/
public function searchQuery()
{
$query = new Horde_Imap_Client_Search_Query();
$query->headerText($this->_msgidHeader, $this->msg_id);
return $query;
}

}
27 changes: 16 additions & 11 deletions imp/lib/Maillog/Storage/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
*/
class IMP_Maillog_Storage_History extends IMP_Maillog_Storage_Base
{
/**
* Mapping of driver actions -> class names.
*
* @var array
*/
public static $drivers = array(
'forward' => 'IMP_Maillog_Log_Forward',
'mdn' => 'IMP_Maillog_Log_Mdn',
'redirect' => 'IMP_Maillog_Log_Redirect',
'reply' => 'IMP_Maillog_Log_Reply',
'reply_all' => 'IMP_Maillog_Log_Replyall',
'reply_list' => 'IMP_Maillog_Log_Replylist'
);

/**
* History object.
*
Expand Down Expand Up @@ -109,21 +123,12 @@ public function getLog(IMP_Maillog_Message $msg, array $types = array())
return $out;
}

$drivers = array(
'forward' => 'IMP_Maillog_Log_Forward',
'mdn' => 'IMP_Maillog_Log_Mdn',
'redirect' => 'IMP_Maillog_Log_Redirect',
'reply' => 'IMP_Maillog_Log_Reply',
'reply_all' => 'IMP_Maillog_Log_Replyall',
'reply_list' => 'IMP_Maillog_Log_Replylist',
);

foreach ($history as $val) {
if (!isset($drivers[$val['action']])) {
if (!isset(static::$drivers[$val['action']])) {
continue;
}

$ob = new $drivers[$val['action']]($val);
$ob = new static::$drivers[$val['action']]($val);

if (!empty($types) && !in_array(get_class($ob), $types)) {
continue;
Expand Down
7 changes: 6 additions & 1 deletion imp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>no</active>
</lead>
<date>2015-03-06</date>
<date>2015-03-09</date>
<version>
<release>7.0.0</release>
<api>7.0.0</api>
Expand All @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mms] Sent-mail maillog entries are now linked to a viewable representation of the sent message, if it still exists on the server.
* [mms] Store message ID of the sent message when saving maillog history.
* [mms] Add backend configuration option to use body structure data to more accurately determine whether a message contains attachments.
* [jan] Show warning on S/MIME page if personal certificate has expired.
Expand Down Expand Up @@ -145,6 +146,7 @@
<file name="editor.js" role="horde" />
<file name="imp.js" role="horde" />
<file name="login.js" role="horde" />
<file name="maillog.js" role="horde" />
<file name="message.js" role="horde" />
<file name="passphrase.js" role="horde" />
<file name="search.js" role="horde" />
Expand Down Expand Up @@ -259,6 +261,7 @@
<file name="Base.php" role="horde" />
<file name="Compose.php" role="horde" />
<file name="Mailbox.php" role="horde" />
<file name="Maillog.php" role="horde" />
<file name="Message.php" role="horde" />
</dir> <!-- /lib/Dynamic -->
<dir name="Factory">
Expand Down Expand Up @@ -1540,6 +1543,7 @@
<install as="imp/js/editor.js" name="js/editor.js" />
<install as="imp/js/imp.js" name="js/imp.js" />
<install as="imp/js/login.js" name="js/login.js" />
<install as="imp/js/maillog.js" name="js/maillog.js" />
<install as="imp/js/message.js" name="js/message.js" />
<install as="imp/js/passphrase.js" name="js/passphrase.js" />
<install as="imp/js/search.js" name="js/search.js" />
Expand Down Expand Up @@ -1656,6 +1660,7 @@
<install as="imp/lib/Dynamic/Base.php" name="lib/Dynamic/Base.php" />
<install as="imp/lib/Dynamic/Compose.php" name="lib/Dynamic/Compose.php" />
<install as="imp/lib/Dynamic/Mailbox.php" name="lib/Dynamic/Mailbox.php" />
<install as="imp/lib/Dynamic/Maillog.php" name="lib/Dynamic/Maillog.php" />
<install as="imp/lib/Dynamic/Message.php" name="lib/Dynamic/Message.php" />
<install as="imp/lib/Dynamic/Compose/Common.php" name="lib/Dynamic/Compose/Common.php" />
<install as="imp/lib/Dynamic/Helper/Base.php" name="lib/Dynamic/Helper/Base.php" />
Expand Down

0 comments on commit 6dfea09

Please sign in to comment.