/usr/share/php/Horde/Imap/Client/Data/Fetch.php is in php-horde-imap-client 2.29.12-1.
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | <?php
/**
* Copyright 2011-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2011-2016 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
/**
* Object containing data returned by the Horde_Imap_Client_Base#fetch()
* command.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2011-2016 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
class Horde_Imap_Client_Data_Fetch
{
/** Header formatting constants. */
const HEADER_PARSE = 1;
const HEADER_STREAM = 2;
/**
* Internal data array.
*
* @var array
*/
protected $_data = array();
/**
*/
public function __clone()
{
$this->_data = unserialize(serialize($this->_data));
}
/**
* Set the full message property.
*
* @param mixed $msg The full message text, as either a string or stream
* resource.
*/
public function setFullMsg($msg)
{
$this->_data[Horde_Imap_Client::FETCH_FULLMSG] = $this->_setMixed($msg);
}
/**
* Returns the full message.
*
* @param boolean $stream Return as a stream?
*
* @return mixed The full text of the entire message.
*/
public function getFullMsg($stream = false)
{
return $this->_msgText(
$stream,
isset($this->_data[Horde_Imap_Client::FETCH_FULLMSG])
? $this->_data[Horde_Imap_Client::FETCH_FULLMSG]
: null
);
}
/**
* Set the message structure.
*
* @param Horde_Mime_Part $structure The base MIME part of the message.
*/
public function setStructure(Horde_Mime_Part $structure)
{
$this->_data[Horde_Imap_Client::FETCH_STRUCTURE] = $structure;
}
/**
* Get the message structure.
*
* @return Horde_Mime_Part $structure The base MIME part of the message.
*/
public function getStructure()
{
return isset($this->_data[Horde_Imap_Client::FETCH_STRUCTURE])
? clone $this->_data[Horde_Imap_Client::FETCH_STRUCTURE]
: new Horde_Mime_Part();
}
/**
* Set a header entry.
*
* @param string $label The search label.
* @param mixed $data Either a Horde_Mime_Headers object or the raw
* header text.
*/
public function setHeaders($label, $data)
{
if ($data instanceof Horde_Stream) {
$data = $data->stream;
}
$this->_data[Horde_Imap_Client::FETCH_HEADERS][$label] = $data;
}
/**
* Get a header entry.
*
* @param string $label The search label.
* @param integer $format The return format. If self::HEADER_PARSE,
* returns a Horde_Mime_Headers object. If
* self::HEADER_STREAM, returns a stream.
* Otherwise, returns header text.
*
* @return mixed See $format.
*/
public function getHeaders($label, $format = 0)
{
return $this->_getHeaders(
$label,
$format,
Horde_Imap_Client::FETCH_HEADERS
);
}
/**
* Set a header text entry.
*
* @param string $id The MIME ID.
* @param mixed $text The header text, as either a string or stream
* resource.
*/
public function setHeaderText($id, $text)
{
$this->_data[Horde_Imap_Client::FETCH_HEADERTEXT][$id] = $this->_setMixed($text);
}
/**
* Get a header text entry.
*
* @param string $id The MIME ID.
* @param integer $format The return format. If self::HEADER_PARSE,
* returns a Horde_Mime_Headers object. If
* self::HEADER_STREAM, returns a stream.
* Otherwise, returns header text.
*
* @return mixed See $format.
*/
public function getHeaderText($id = 0, $format = 0)
{
return $this->_getHeaders(
$id,
$format,
Horde_Imap_Client::FETCH_HEADERTEXT
);
}
/**
* Set a MIME header entry.
*
* @param string $id The MIME ID.
* @param mixed $text The header text, as either a string or stream
* resource.
*/
public function setMimeHeader($id, $text)
{
$this->_data[Horde_Imap_Client::FETCH_MIMEHEADER][$id] = $this->_setMixed($text);
}
/**
* Get a MIME header entry.
*
* @param string $id The MIME ID.
* @param integer $format The return format. If self::HEADER_PARSE,
* returns a Horde_Mime_Headers object. If
* self::HEADER_STREAM, returns a stream.
* Otherwise, returns header text.
*
* @return mixed See $format.
*/
public function getMimeHeader($id, $format = 0)
{
return $this->_getHeaders(
$id,
$format,
Horde_Imap_Client::FETCH_MIMEHEADER
);
}
/**
* Set a body part entry.
*
* @param string $id The MIME ID.
* @param mixed $text The body part text, as either a string or stream
* resource.
* @param string $decode Either '8bit', 'binary', or null.
*/
public function setBodyPart($id, $text, $decode = null)
{
$this->_data[Horde_Imap_Client::FETCH_BODYPART][$id] = array(
'd' => $decode,
't' => $this->_setMixed($text)
);
}
/**
* Get a body part entry.
*
* @param string $id The MIME ID.
* @param boolean $stream Return as a stream?
*
* @return mixed The full text of the body part.
*/
public function getBodyPart($id, $stream = false)
{
return $this->_msgText(
$stream,
isset($this->_data[Horde_Imap_Client::FETCH_BODYPART][$id])
? $this->_data[Horde_Imap_Client::FETCH_BODYPART][$id]['t']
: null
);
}
/**
* Determines if/how a body part was MIME decoded on the server.
*
* @param string $id The MIME ID.
*
* @return string Either '8bit', 'binary', or null.
*/
public function getBodyPartDecode($id)
{
return isset($this->_data[Horde_Imap_Client::FETCH_BODYPART][$id])
? $this->_data[Horde_Imap_Client::FETCH_BODYPART][$id]['d']
: null;
}
/**
* Set the body part size for a body part.
*
* @param string $id The MIME ID.
* @param integer $size The size (in bytes).
*/
public function setBodyPartSize($id, $size)
{
$this->_data[Horde_Imap_Client::FETCH_BODYPARTSIZE][$id] = intval($size);
}
/**
* Returns the body part size, if returned by the server.
*
* @param string $id The MIME ID.
*
* @return integer The body part size, in bytes.
*/
public function getBodyPartSize($id)
{
return isset($this->_data[Horde_Imap_Client::FETCH_BODYPARTSIZE][$id])
? $this->_data[Horde_Imap_Client::FETCH_BODYPARTSIZE][$id]
: null;
}
/**
* Set a body text entry.
*
* @param string $id The MIME ID.
* @param mixed $text The body part text, as either a string or stream
* resource.
*/
public function setBodyText($id, $text)
{
$this->_data[Horde_Imap_Client::FETCH_BODYTEXT][$id] = $this->_setMixed($text);
}
/**
* Get a body text entry.
*
* @param string $id The MIME ID.
* @param boolean $stream Return as a stream?
*
* @return mixed The full text of the body text.
*/
public function getBodyText($id = 0, $stream = false)
{
return $this->_msgText(
$stream,
isset($this->_data[Horde_Imap_Client::FETCH_BODYTEXT][$id])
? $this->_data[Horde_Imap_Client::FETCH_BODYTEXT][$id]
: null
);
}
/**
* Set envelope data.
*
* @param array $data The envelope data to pass to the Envelope object
* constructor, or an Envelope object.
*/
public function setEnvelope($data)
{
$this->_data[Horde_Imap_Client::FETCH_ENVELOPE] = is_array($data)
? new Horde_Imap_Client_Data_Envelope($data)
: $data;
}
/**
* Get envelope data.
*
* @return Horde_Imap_Client_Data_Envelope An envelope object.
*/
public function getEnvelope()
{
return isset($this->_data[Horde_Imap_Client::FETCH_ENVELOPE])
? clone $this->_data[Horde_Imap_Client::FETCH_ENVELOPE]
: new Horde_Imap_Client_Data_Envelope();
}
/**
* Set IMAP flags.
*
* @param array $flags An array of IMAP flags.
*/
public function setFlags(array $flags)
{
$this->_data[Horde_Imap_Client::FETCH_FLAGS] = array_map(
'Horde_String::lower',
array_map('trim', $flags)
);
}
/**
* Get IMAP flags.
*
* @return array An array of IMAP flags (all flags in lowercase).
*/
public function getFlags()
{
return isset($this->_data[Horde_Imap_Client::FETCH_FLAGS])
? $this->_data[Horde_Imap_Client::FETCH_FLAGS]
: array();
}
/**
* Set IMAP internal date.
*
* @param mixed $date Either a Horde_Imap_Client_DateTime object or a
* date string.
*/
public function setImapDate($date)
{
$this->_data[Horde_Imap_Client::FETCH_IMAPDATE] = is_object($date)
? $date
: new Horde_Imap_Client_DateTime($date);
}
/**
* Get internal IMAP date.
*
* @return Horde_Imap_Client_DateTime A date object.
*/
public function getImapDate()
{
return isset($this->_data[Horde_Imap_Client::FETCH_IMAPDATE])
? clone $this->_data[Horde_Imap_Client::FETCH_IMAPDATE]
: new Horde_Imap_Client_DateTime();
}
/**
* Set message size.
*
* @param integer $size The size of the message, in bytes.
*/
public function setSize($size)
{
$this->_data[Horde_Imap_Client::FETCH_SIZE] = intval($size);
}
/**
* Get message size.
*
* @return integer The size of the message, in bytes.
*/
public function getSize()
{
return isset($this->_data[Horde_Imap_Client::FETCH_SIZE])
? $this->_data[Horde_Imap_Client::FETCH_SIZE]
: 0;
}
/**
* Set UID.
*
* @param integer $uid The message UID.
*/
public function setUid($uid)
{
$this->_data[Horde_Imap_Client::FETCH_UID] = intval($uid);
}
/**
* Get UID.
*
* @return integer The message UID.
*/
public function getUid()
{
return isset($this->_data[Horde_Imap_Client::FETCH_UID])
? $this->_data[Horde_Imap_Client::FETCH_UID]
: null;
}
/**
* Set message sequence number.
*
* @param integer $seq The message sequence number.
*/
public function setSeq($seq)
{
$this->_data[Horde_Imap_Client::FETCH_SEQ] = intval($seq);
}
/**
* Get message sequence number.
*
* @return integer The message sequence number.
*/
public function getSeq()
{
return isset($this->_data[Horde_Imap_Client::FETCH_SEQ])
? $this->_data[Horde_Imap_Client::FETCH_SEQ]
: null;
}
/**
* Set the modified sequence value for the message.
*
* @param integer $modseq The modseq value.
*/
public function setModSeq($modseq)
{
$this->_data[Horde_Imap_Client::FETCH_MODSEQ] = intval($modseq);
}
/**
* Get the modified sequence value for the message.
*
* @return integer The modseq value.
*/
public function getModSeq()
{
return isset($this->_data[Horde_Imap_Client::FETCH_MODSEQ])
? $this->_data[Horde_Imap_Client::FETCH_MODSEQ]
: null;
}
/**
* Set the internationalized downgraded status for the message.
*
* @since 2.11.0
*
* @param boolean $downgraded True if at least one message component has
* been downgraded.
*/
public function setDowngraded($downgraded)
{
if ($downgraded) {
$this->_data[Horde_Imap_Client::FETCH_DOWNGRADED] = true;
} else {
unset($this->_data[Horde_Imap_Client::FETCH_DOWNGRADED]);
}
}
/**
* Does the message contain internationalized downgraded data (i.e. it
* is a "surrogate" message)?
*
* @since 2.11.0
*
* @return boolean True if at least one message components has been
* downgraded.
*/
public function isDowngraded()
{
return !empty($this->_data[Horde_Imap_Client::FETCH_DOWNGRADED]);
}
/**
* Return the internal representation of the data.
*
* @return array The data array.
*/
public function getRawData()
{
return $this->_data;
}
/**
* Merge a fetch object into this one.
*
* @param Horde_Imap_Client_Data_Fetch $data A fetch object.
*/
public function merge(Horde_Imap_Client_Data_Fetch $data)
{
$this->_data = array_replace_recursive(
$this->_data,
$data->getRawData()
);
}
/**
* Does this object containing cacheable data of the given type?
*
* @param integer $type The type to query.
*
* @return boolean True if the type is cacheable.
*/
public function exists($type)
{
return isset($this->_data[$type]);
}
/**
* Does this object contain only default values for all fields?
*
* @return boolean True if object contains default data.
*/
public function isDefault()
{
return empty($this->_data);
}
/**
* Return text representation of a field.
*
* @param boolean $stream Return as a stream?
* @param mixed $data The field data (string or resource) or null if
* field does not exist.
*
* @return mixed Requested text representation.
*/
protected function _msgText($stream, $data)
{
if ($data instanceof Horde_Stream) {
if ($stream) {
$data->rewind();
return $data->stream;
}
return strval($data);
}
if (is_resource($data)) {
rewind($data);
return $stream
? $data
: stream_get_contents($data);
}
if (!$stream) {
return strval($data);
}
$tmp = fopen('php://temp', 'w+');
if (!is_null($data)) {
fwrite($tmp, $data);
rewind($tmp);
}
return $tmp;
}
/**
* Return representation of a header field.
*
* @param string $id The header id.
* @param integer $format The return format. If self::HEADER_PARSE,
* returns a Horde_Mime_Headers object. If
* self::HEADER_STREAM, returns a stream.
* Otherwise, returns header text.
* @param integer $key The array key where the data is stored in the
* internal array.
*
* @return mixed The data in the format specified by $format.
*/
protected function _getHeaders($id, $format, $key)
{
switch ($format) {
case self::HEADER_STREAM:
if (!isset($this->_data[$key][$id])) {
$data = null;
} elseif (is_object($this->_data[$key][$id])) {
switch ($key) {
case Horde_Imap_Client::FETCH_HEADERS:
$data = $this->_getHeaders($id, 0, $key);
break;
case Horde_Imap_Client::FETCH_HEADERTEXT:
case Horde_Imap_Client::FETCH_MIMEHEADER:
$data = $this->_data[$key][$id];
break;
}
} else {
$data = $this->_data[$key][$id];
}
return $this->_msgText(true, $data);
case self::HEADER_PARSE:
if (!isset($this->_data[$key][$id])) {
return new Horde_Mime_Headers();
} elseif (is_object($this->_data[$key][$id])) {
switch ($key) {
case Horde_Imap_Client::FETCH_HEADERS:
return clone $this->_data[$key][$id];
case Horde_Imap_Client::FETCH_HEADERTEXT:
case Horde_Imap_Client::FETCH_MIMEHEADER:
$hdrs = $this->_data[$key][$id];
break;
}
} else {
$hdrs = $this->_getHeaders($id, self::HEADER_STREAM, $key);
}
return Horde_Mime_Headers::parseHeaders($hdrs);
}
if (!isset($this->_data[$key][$id])) {
return '';
}
if (is_object($this->_data[$key][$id])) {
switch ($key) {
case Horde_Imap_Client::FETCH_HEADERS:
return $this->_data[$key][$id]->toString(
array('nowrap' => true)
);
case Horde_Imap_Client::FETCH_HEADERTEXT:
case Horde_Imap_Client::FETCH_MIMEHEADER:
return strval($this->_data[$key][$id]);
}
}
return $this->_msgText(false, $this->_data[$key][$id]);
}
/**
* Converts mixed input (string or resource) to the correct internal
* representation.
*
* @param mixed $data Mixed data (string, resource, Horde_Stream object).
*
* @return mixed The internal representation of that data.
*/
protected function _setMixed($data)
{
return is_resource($data)
? new Horde_Stream_Existing(array('stream' => $data))
: $data;
}
}
|