/usr/share/horde/ingo/lib/Script/Imap/Mock.php is in php-horde-ingo 3.2.8-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <?php
/**
* Copyright 2012-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
/**
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
class Ingo_Script_Imap_Mock extends Ingo_Script_Imap_Api
{
/**
* TODO
*/
protected $_fixtures = array();
/**
* TODO
*/
protected $_folders = array();
/**
* TODO
*/
public function loadFixtures($dir)
{
$this->_fixtures = array();
$dh = opendir($dir);
while (($dent = readdir($dh)) !== false) {
if (!in_array($dent, array('.', '..'))) {
$this->_fixtures[$dent] = Horde_Mime_Headers::parseHeaders(file_get_contents($dir . '/' . $dent));
}
}
closedir($dh);
$i = 0;
foreach (array_keys($this->_fixtures) as $key) {
$this->_folders['INBOX'][] = array('uid' => ++$i,
'fixture' => $key,
'deleted' => false);
}
}
/**
* TODO
*/
public function hasMessage($fixture, $folder = 'INBOX')
{
if (empty($this->_folders[$folder])) {
return false;
}
foreach ($this->_folders[$folder] as $message) {
if ($message['fixture'] == $fixture) {
return !$message['deleted'];
}
}
return false;
}
/**
* @todo The new Horde_Imap library *only* does server-side searches now,
* so we can't use Horde_Imap_Client_Search_Query for mock searches
* anymore.
*/
public function search($query)
{
$result = array();
foreach ($this->_folders['INBOX'] as $message) {
if ($message['deleted']) {
continue;
}
if ($query->matches($this->_fixtures[$message['fixture']])) {
$result[] = $message['uid'];
}
}
return $result;
}
/**
* TODO
*/
public function deleteMessages($indices)
{
foreach (array_keys($this->_folders['INBOX']) as $i) {
if (in_array($this->_folders['INBOX'][$i]['uid'], $indices)) {
unset($this->_folders['INBOX'][$i]);
}
}
// Force renumbering
$this->_folders['INBOX'] = array_merge($this->_folders['INBOX'], array());
}
/**
* TODO
*/
public function moveMessages($indices, $folder)
{
foreach (array_keys($this->_folders['INBOX']) as $i) {
if (in_array($this->_folders['INBOX'][$i]['uid'], $indices)) {
$this->_folders[$folder][] = $this->_folders['INBOX'][$i];
}
}
return $this->deleteMessages($indices);
}
/**
* TODO
*/
public function fetchEnvelope($indices)
{
$result = array();
foreach ($indices as $uid) {
foreach (array_keys($this->_folders['INBOX']) as $i) {
if ($this->_folders['INBOX'][$i]['uid'] == $uid) {
$fetch = new Horde_Imap_Client_Data_Fetch();
$fetch->setEnvelope(array(
'from' => $this->_fixtures[$this->_folders['INBOX'][$i]['fixture']]->getValue('from')
));
$fetch->setUid = $uid;
$result[$uid] = $fetch;
}
}
}
return $result;
}
}
|