Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Mail / Storage / AbstractStorage.php
blob5da0c19e814b9c1fc287f2a68fd0ea20f7680138
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Mail\Storage;
12 use ArrayAccess;
13 use Countable;
14 use SeekableIterator;
16 abstract class AbstractStorage implements
17 ArrayAccess,
18 Countable,
19 SeekableIterator
21 /**
22 * class capabilities with default values
23 * @var array
25 protected $has = array('uniqueid' => true,
26 'delete' => false,
27 'create' => false,
28 'top' => false,
29 'fetchPart' => true,
30 'flags' => false);
32 /**
33 * current iteration position
34 * @var int
36 protected $iterationPos = 0;
38 /**
39 * maximum iteration position (= message count)
40 * @var null|int
42 protected $iterationMax = null;
44 /**
45 * used message class, change it in an extended class to extend the returned message class
46 * @var string
48 protected $messageClass = 'Zend\Mail\Storage\Message';
50 /**
51 * Getter for has-properties. The standard has properties
52 * are: hasFolder, hasUniqueid, hasDelete, hasCreate, hasTop
54 * The valid values for the has-properties are:
55 * - true if a feature is supported
56 * - false if a feature is not supported
57 * - null is it's not yet known or it can't be know if a feature is supported
59 * @param string $var property name
60 * @throws Exception\InvalidArgumentException
61 * @return bool supported or not
63 public function __get($var)
65 if (strpos($var, 'has') === 0) {
66 $var = strtolower(substr($var, 3));
67 return isset($this->has[$var]) ? $this->has[$var] : null;
70 throw new Exception\InvalidArgumentException($var . ' not found');
74 /**
75 * Get a full list of features supported by the specific mail lib and the server
77 * @return array list of features as array(feature_name => true|false[|null])
79 public function getCapabilities()
81 return $this->has;
85 /**
86 * Count messages messages in current box/folder
88 * @return int number of messages
89 * @throws Exception\ExceptionInterface
91 abstract public function countMessages();
94 /**
95 * Get a list of messages with number and size
97 * @param int $id number of message
98 * @return int|array size of given message of list with all messages as array(num => size)
100 abstract public function getSize($id = 0);
104 * Get a message with headers and body
106 * @param $id int number of message
107 * @return Message
109 abstract public function getMessage($id);
113 * Get raw header of message or part
115 * @param int $id number of message
116 * @param null|array|string $part path to part or null for message header
117 * @param int $topLines include this many lines with header (after an empty line)
118 * @return string raw header
120 abstract public function getRawHeader($id, $part = null, $topLines = 0);
123 * Get raw content of message or part
125 * @param int $id number of message
126 * @param null|array|string $part path to part or null for message content
127 * @return string raw content
129 abstract public function getRawContent($id, $part = null);
132 * Create instance with parameters
134 * @param array $params mail reader specific parameters
135 * @throws Exception\ExceptionInterface
137 abstract public function __construct($params);
141 * Destructor calls close() and therefore closes the resource.
143 public function __destruct()
145 $this->close();
150 * Close resource for mail lib. If you need to control, when the resource
151 * is closed. Otherwise the destructor would call this.
153 abstract public function close();
157 * Keep the resource alive.
159 abstract public function noop();
162 * delete a message from current box/folder
164 * @param $id
166 abstract public function removeMessage($id);
169 * get unique id for one or all messages
171 * if storage does not support unique ids it's the same as the message number
173 * @param int|null $id message number
174 * @return array|string message number for given message or all messages as array
175 * @throws Exception\ExceptionInterface
177 abstract public function getUniqueId($id = null);
180 * get a message number from a unique id
182 * I.e. if you have a webmailer that supports deleting messages you should use unique ids
183 * as parameter and use this method to translate it to message number right before calling removeMessage()
185 * @param string $id unique id
186 * @return int message number
187 * @throws Exception\ExceptionInterface
189 abstract public function getNumberByUniqueId($id);
191 // interface implementations follows
194 * Countable::count()
196 * @return int
198 public function count()
200 return $this->countMessages();
205 * ArrayAccess::offsetExists()
207 * @param int $id
208 * @return bool
210 public function offsetExists($id)
212 try {
213 if ($this->getMessage($id)) {
214 return true;
216 } catch (Exception\ExceptionInterface $e) {}
218 return false;
223 * ArrayAccess::offsetGet()
225 * @param int $id
226 * @return \Zend\Mail\Storage\Message message object
228 public function offsetGet($id)
230 return $this->getMessage($id);
235 * ArrayAccess::offsetSet()
237 * @param mixed $id
238 * @param mixed $value
239 * @throws Exception\RuntimeException
241 public function offsetSet($id, $value)
243 throw new Exception\RuntimeException('cannot write mail messages via array access');
248 * ArrayAccess::offsetUnset()
250 * @param int $id
251 * @return bool success
253 public function offsetUnset($id)
255 return $this->removeMessage($id);
260 * Iterator::rewind()
262 * Rewind always gets the new count from the storage. Thus if you use
263 * the interfaces and your scripts take long you should use reset()
264 * from time to time.
266 public function rewind()
268 $this->iterationMax = $this->countMessages();
269 $this->iterationPos = 1;
274 * Iterator::current()
276 * @return Message current message
278 public function current()
280 return $this->getMessage($this->iterationPos);
285 * Iterator::key()
287 * @return int id of current position
289 public function key()
291 return $this->iterationPos;
296 * Iterator::next()
298 public function next()
300 ++$this->iterationPos;
305 * Iterator::valid()
307 * @return bool
309 public function valid()
311 if ($this->iterationMax === null) {
312 $this->iterationMax = $this->countMessages();
314 return $this->iterationPos && $this->iterationPos <= $this->iterationMax;
319 * SeekableIterator::seek()
321 * @param int $pos
322 * @throws Exception\OutOfBoundsException
324 public function seek($pos)
326 if ($this->iterationMax === null) {
327 $this->iterationMax = $this->countMessages();
330 if ($pos > $this->iterationMax) {
331 throw new Exception\OutOfBoundsException('this position does not exist');
333 $this->iterationPos = $pos;