Skip to content

Commit

Permalink
Request: 14122 Support sending MDM via ActiveSync access.
Browse files Browse the repository at this point in the history
Honors IMP's mdn_send pref and/or hooks.
  • Loading branch information
mrubinsk committed Dec 10, 2015
1 parent 4610152 commit 2c538ff
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 2 deletions.
18 changes: 18 additions & 0 deletions framework/Core/lib/Horde/Core/ActiveSync/Connector.php
Expand Up @@ -832,6 +832,19 @@ public function horde_hasInterface($api)
return $this->_registry->hasInterface($api);
}

/**
* Wrapper around Horde_Registry::hasMethod.
*
* @param string $api The API to check.
* @param string $method The method name.
*
* @return boolean
*/
public function horde_hasMethod($method, $api)
{
return $this->_registry->hasMethod($method, $this->_registry->hasInterface($api));
}

/**
* Return the currently set vacation message details.
*
Expand Down Expand Up @@ -1392,4 +1405,9 @@ public function clearAuth()
$this->_registry->clearAuth(true);
}

public function mdnSend($mdn)
{
return $this->_registry->mail->mdnSend($mdn->headers(), $mdn->mailbox(), $mdn->uid());
}

}
18 changes: 18 additions & 0 deletions framework/Core/lib/Horde/Core/ActiveSync/Driver.php
Expand Up @@ -1916,10 +1916,28 @@ public function changeMessage($folderid, $id, Horde_ActiveSync_Message_Base $mes
'flags' => array(),
'categories' => false
);

if ($message->read !== '') {
$this->setReadFlag($folderid, $id, $message->read);
$stat['flags'] = array_merge($stat['flags'], array('read' => $message->read));

// Do RFC 3798 MDN checks. If $message->read is being set to
// FLAG_READ_SEEN, then we *might* be able to send one.
if ($message->read == Horde_ActiveSync_Message_Mail::FLAG_READ_SEEN) {
$this->_logger->info(sprintf(
"[%s] Checking for MDN",
$this->_pid)
);
$mdn = new Horde_Core_ActiveSync_Mdn($folderid, $id, $this->_imap, $this->_connector);
if ($mdn->mdnCheck()) {
$this->_logger->info(sprintf(
"[%s] Sending MDN",
$this->_pid)
);
}
}
}

if ($message->propertyExists('flag')) {
if (!$message->flag) {
$message->flag = Horde_ActiveSync::messageFactory('Flag');
Expand Down
121 changes: 121 additions & 0 deletions framework/Core/lib/Horde/Core/ActiveSync/Mdn.php
@@ -0,0 +1,121 @@
<?php
/**
*
*/
class Horde_Core_ActiveSync_Mdn
{
/**
* @var Horde_Core_ActiveSync_Connector
*/
protected $_connector;

/**
* @var string
*/
protected $_mailbox;

/**
* @var integer
*/
protected $_uid;

/**
* @var Horde_ActiveSync_Imap_Adapter
*/
protected $_imap;

/**
* @var Horde_ActiveSync_Imap_Message
*/
protected $_msg;

/**
* Const'r
*
* @param string $mailbox
* @param integer $uid
* @param Horde_ActiveSync_Imap_Adapter $imap
* @param Horde_Core_ActiveSync_Connector $connector
*/
public function __construct(
$mailbox, $uid, Horde_ActiveSync_Imap_Adapter $imap,
Horde_Core_ActiveSync_Connector $connector)
{
$this->_imap = $imap;
$this->_mailbox = $mailbox;
$this->_uid = $uid;
$this->_connector = $connector;
}

public function __call($method, $args)
{
switch ($method) {
case 'headers':
if (empty($this->_msg)) {
return false;
}
return $this->_msg->getHeaders();
case 'mailbox':
return $this->_mailbox;
case 'uid':
return $this->_uid;
}
}

/**
* Check if we should and are able to send an MDN.
*
* @boolean
*/
public function mdnCheck()
{
if (!$this->_sysCheck() || !$this->_msgCheck()) {
return false;
}

return $this->_connector->mdnSend($this);
}

/**
* Check to see if we are able to send an unconfirmed MDN based on the
* message data.
*
* @param string $mailbox The IMAP mailbox name.
* @param integer $uid The IMAP UID of the message.
*
* @return boolean True if able to send, otherwise false.
*/
protected function _msgCheck($mailbox, $uid)
{
$msgs = $this->_imap->getImapMessage($this->_mailbox, $this->_uid, array('headers' => true));
if (!count($msgs)) {
return false;
}
$imap_msg = array_pop($msgs);
$mdn = new Horde_Mime_Mdn($imap_msg->getHeaders());
if ($mdn->getMdnReturnAddr() && !$mdn->userConfirmationNeeded()) {
$this->_msg = $imap_msg;
return true;
}

return false;
}

/**
* Check system prefs and/or hooks to determine if we are allowed to send.
*
* @return boolean True if able to send otherwise false.
*/
protected function _sysCheck()
{
// Check existence of API method needed.
if (!$this->_connector->horde_hasMethod('mdnSend', 'mail')) {
return false;
}

// @todo Other checks?
return true;
}

}
6 changes: 4 additions & 2 deletions framework/Core/package.xml
Expand Up @@ -28,7 +28,7 @@
<email>mrubinsk@horde.org</email>
<active>yes</active>
</developer>
<date>2015-12-04</date>
<date>2015-12-10</date>
<version>
<release>2.22.4</release>
<api>2.22.0</api>
Expand Down Expand Up @@ -305,6 +305,7 @@
<file name="Connector.php" role="php" />
<file name="Driver.php" role="php" />
<file name="Mail.php" role="php" />
<file name="Mdn.php" role="php" />
</dir> <!-- /lib/Horde/Core/ActiveSync -->
<dir name="Ajax">
<dir name="Application">
Expand Down Expand Up @@ -1759,6 +1760,7 @@
<install as="Horde/Core/ActiveSync/Connector.php" name="lib/Horde/Core/ActiveSync/Connector.php" />
<install as="Horde/Core/ActiveSync/Driver.php" name="lib/Horde/Core/ActiveSync/Driver.php" />
<install as="Horde/Core/ActiveSync/Mail.php" name="lib/Horde/Core/ActiveSync/Mail.php" />
<install as="Horde/Core/ActiveSync/Mdn.php" name="lib/Horde/Core/ActiveSync/Mdn.php" />
<install as="Horde/Core/ActiveSync/Imap/Factory.php" name="lib/Horde/Core/ActiveSync/Imap/Factory.php" />
<install as="Horde/Core/ActiveSync/Logger/Factory.php" name="lib/Horde/Core/ActiveSync/Logger/Factory.php" />
<install as="Horde/Core/Ajax/Application.php" name="lib/Horde/Core/Ajax/Application.php" />
Expand Down Expand Up @@ -4085,7 +4087,7 @@
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2015-12-04</date>
<date>2015-12-10</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
Expand Down

0 comments on commit 2c538ff

Please sign in to comment.