ImapLib.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. <?php
  2. /**
  3. * LICENSE: The MIT License
  4. * Copyright (c) 2010 Chris Nizzardini (http://www.cnizz.com)
  5. */
  6. /**
  7. * basic idea from
  8. * http://www.phpclasses.org/package/6256-PHP-Retrieve-messages-from-an-IMAP-server.html
  9. * added enhancements
  10. *
  11. * @modified 2011-11-13 Mark Scherer
  12. * @php 5
  13. * @cakephp 2.0
  14. *
  15. * ImapLib for accessing IMAP and POP email accounts
  16. * 2011-10-11 ms
  17. */
  18. class ImapLib {
  19. const S_MAILBOX = 'mailbox';
  20. const S_SERVER = 'server';
  21. const S_PORT = 'port';
  22. const S_SERVICE = 'service';
  23. const S_USER = 'user';
  24. const S_PASSWORD = 'password';
  25. const S_AUTHUSER = 'authuser';
  26. const S_DEBUG = 'debug';
  27. const S_SECURE = 'secure';
  28. const S_NORSH = 'norsa';
  29. const S_SSL = 'ssl';
  30. const S_VALIDATECERT = 'validatecert';
  31. const S_TLS = 'tls';
  32. const S_NOTLS = 'notls';
  33. const S_READONLY = 'readonly';
  34. public $stream;
  35. public $settings = array(
  36. self::S_MAILBOX => 'INBOX',
  37. self::S_SERVER => '',
  38. self::S_PORT => '',
  39. self::S_SERVICE => 'imap',
  40. self::S_USER => false,
  41. self::S_PASSWORD => '',
  42. self::S_AUTHUSER => false,
  43. self::S_DEBUG => false,
  44. self::S_SECURE => false,
  45. self::S_NORSH => false,
  46. self::S_SSL => false,
  47. self::S_VALIDATECERT => false,
  48. self::S_TLS => false,
  49. self::S_NOTLS => false,
  50. self::S_READONLY => false
  51. );
  52. public $currentSettings = array();
  53. public $currentRef = '';
  54. public function buildConnector($data = array()) {
  55. $data = array_merge($this->settings, $data);
  56. $string = '{';
  57. $string .= $data[self::S_SERVER];
  58. if ($data[self::S_PORT]) {
  59. $string .= ':' . $data[self::S_PORT];
  60. }
  61. if ($data[self::S_SERVICE]) {
  62. $string .= '/service=' . $data[self::S_SERVICE];
  63. }
  64. if ($data[self::S_USER]) {
  65. $string .= '/user=' . $data[self::S_USER];
  66. } else {
  67. $string .= '/anonymous';
  68. }
  69. if ($data[self::S_AUTHUSER]) {
  70. $string .= '/authuser=' . $data[self::S_AUTHUSER];
  71. }
  72. if ($data[self::S_DEBUG]) {
  73. $string .= '/debug';
  74. }
  75. if ($data[self::S_SECURE]) {
  76. $string .= '/secure';
  77. }
  78. if ($data[self::S_NORSH]) {
  79. $string .= '/norsh';
  80. }
  81. if ($data[self::S_SSL]) {
  82. $string .= '/ssl';
  83. }
  84. if ($data[self::S_VALIDATECERT]) {
  85. $string .= '/validate-cert';
  86. } else {
  87. $string .= '/novalidate-cert';
  88. }
  89. if ($data[self::S_TLS]) {
  90. $string .= '/tls';
  91. }
  92. if ($data[self::S_NOTLS]) {
  93. $string .= '/notls';
  94. }
  95. if ($data[self::S_READONLY]) {
  96. $string .= '/readonly';
  97. }
  98. $string .= '}';
  99. $string .= $data[self::S_MAILBOX];
  100. $this->currentRef = $string;
  101. $this->currentSettings = $data;
  102. return $string;
  103. }
  104. public function set($key, $value) {
  105. return $this->settings[$key] = $value;
  106. }
  107. public function lastError() {
  108. return imap_last_error();
  109. }
  110. /**
  111. * @return bool $success
  112. * 2011-10-25 ms
  113. */
  114. public function connect($user, $pass, $server, $port = null) {
  115. if (!$this->dependenciesMatches()) {
  116. return false;
  117. }
  118. $this->settings[self::S_SERVER] = $server;
  119. if ($port || !$port && $this->settings[self::S_SERVICE] == 'imap') {
  120. $this->settings[self::S_PORT] = $port;
  121. }
  122. $this->settings[self::S_USER] = $user;
  123. $this->settings[self::S_PASSWORD] = $pass;
  124. $connector = $this->buildConnector();
  125. //die($connector);
  126. $this->stream = @imap_open($connector, $user, $pass);
  127. if (false === $this->stream) {
  128. return false;
  129. }
  130. return true;
  131. }
  132. public function checkConnection() {
  133. if ($this->stream) {
  134. return $this->lastError();
  135. }
  136. return false;
  137. }
  138. public function msgCount() {
  139. if ($error = $this->checkConnection()) {
  140. return $error;
  141. }
  142. return imap_num_msg($this->stream);
  143. }
  144. public function listMailboxes($current = true) {
  145. if ($error = $this->checkConnection()) {
  146. return $error;
  147. }
  148. if (is_bool($current)) {
  149. if ($current) {
  150. $current = '%';
  151. } else {
  152. $current = '*';
  153. }
  154. }
  155. return imap_list($this->stream, $this->currentRef, $current);
  156. }
  157. public function getFolder() {
  158. return new ImapFolderLib($this);
  159. }
  160. public function expunge() {
  161. if ($error = $this->checkConnection()) {
  162. return $error;
  163. }
  164. return imap_expunge($this->stream);
  165. }
  166. public function close($expunge = false) {
  167. if ($error = $this->checkConnection()) {
  168. return $error;
  169. }
  170. if ($expunge) {
  171. return @imap_close($this->stream, CL_EXPUNGE);
  172. } else {
  173. return @imap_close($this->stream);
  174. }
  175. }
  176. public function __destruct() {
  177. $this->close();
  178. }
  179. /**
  180. * main listing of messages
  181. * - body, structure, attachments
  182. * 2011-11-17 ms
  183. */
  184. public function msgList($msg_list = array()) {
  185. if ($this->stream) {
  186. $return = array();
  187. if (is_array($msg_list) or count($msg_list) == 0) {
  188. $count = $this->msgCount();
  189. for ($i = 1; $i <= $count; $i++) {
  190. $header = imap_headerinfo($this->stream, $i);
  191. foreach ($header as $id => $value) {
  192. // Simple array
  193. if (!is_array($value)) {
  194. $return[$header->Msgno][$id] = $value;
  195. } else {
  196. foreach ($value as $newid => $array_value) {
  197. foreach ($value[0] as $key => $aValue) {
  198. $return[$header->Msgno][$id][$key] = quoted_printable_decode($aValue);
  199. }
  200. }
  201. }
  202. // Let's add the body
  203. $return[$header->Msgno]['body'] = imap_fetchbody($this->stream, $header->Msgno, 1);
  204. //lets add attachments
  205. $return[$header->Msgno]['structure'] = imap_fetchstructure($this->stream, $header->Msgno, 1);
  206. $return[$header->Msgno]['attachments'] = $this->attachments($header);
  207. }
  208. }
  209. }
  210. // We want to search a specific array of messages
  211. else {
  212. foreach ($msg_list as $i) {
  213. $header = imap_headerinfo($this->stream, $i);
  214. foreach ($header as $id => $value) {
  215. // Simple array
  216. if (!is_array($value)) {
  217. $return[$header->Msgno][$id] = $value;
  218. } else {
  219. foreach ($value as $newid => $array_value) {
  220. foreach ($value[0] as $key => $aValue) {
  221. $return[$header->Msgno][$id][$key] = $this->_quoted_printable_encode($aValue);
  222. }
  223. }
  224. }
  225. // Let's add the body too!
  226. $return[$header->Msgno]['body'] = imap_fetchbody($this->stream, $header->Msgno, 0);
  227. $return[$header->Msgno]['structure'] = imap_fetchstructure($this->stream, $header->Msgno);
  228. $return[$header->Msgno]['attachments'] = $this->attachments($header);
  229. }
  230. }
  231. }
  232. #$return['num_of_msgs'] = count($return);
  233. return $return;
  234. }
  235. return imap_last_error();
  236. }
  237. /**
  238. * @see http://www.nerdydork.com/download-pop3imap-email-attachments-with-php.html
  239. * 2011-09-02 ms
  240. */
  241. public function attachments($header) {
  242. $structure = imap_fetchstructure($this->stream, $header->Msgno, FT_UID);
  243. $parts = $structure->parts;
  244. $fpos = 2;
  245. $message = array();
  246. $message["attachment"]["type"][0] = "text";
  247. $message["attachment"]["type"][1] = "multipart";
  248. $message["attachment"]["type"][2] = "message";
  249. $message["attachment"]["type"][3] = "application";
  250. $message["attachment"]["type"][4] = "audio";
  251. $message["attachment"]["type"][5] = "image";
  252. $message["attachment"]["type"][6] = "video";
  253. $message["attachment"]["type"][7] = "other";
  254. $attachments = array();
  255. for ($i = 1; $i < count($parts); $i++) {
  256. $attachment = array();
  257. $part = $parts[$i];
  258. if (isset($part->disposition) && $part->disposition == "ATTACHMENT") {
  259. $attachment["pid"] = $i;
  260. $attachment["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype);
  261. $attachment["subtype"][$i] = strtolower($part->subtype);
  262. $ext = $part->subtype;
  263. $params = $part->dparameters;
  264. $mege = "";
  265. $data = "";
  266. $mege = imap_fetchbody($this->stream, $header->Msgno, $fpos);
  267. $attachment['filename'] = $part->dparameters[0]->value;
  268. $attachment['data'] = $this->_getDecodedValue($mege, $part->type);
  269. $attachment['filesize'] = strlen($attachment['data']);
  270. $fpos++;
  271. $attachments[] = $attachment;
  272. }
  273. }
  274. return $attachments;
  275. }
  276. /**
  277. * @see http://www.nerdydork.com/download-pop3imap-email-attachments-with-php.html
  278. * 2011-09-02 ms
  279. */
  280. public function _getDecodedValue($message, $coding) {
  281. if ($coding == 0) {
  282. $message = imap_8bit($message);
  283. } elseif ($coding == 1) {
  284. $message = imap_8bit($message);
  285. } elseif ($coding == 2) {
  286. $message = imap_binary($message);
  287. } elseif ($coding == 3) {
  288. $message = imap_base64($message);
  289. } elseif ($coding == 4) {
  290. $message = imap_qprint($message);
  291. } elseif ($coding == 5) {
  292. $message = imap_base64($message);
  293. }
  294. return $message;
  295. }
  296. public function search($params) {
  297. if ($this->stream) {
  298. if (is_array($params)) {
  299. $search_string = '';
  300. foreach ($params as $field => $value) {
  301. if (is_numeric($field)) {
  302. // Make sure the value is uppercase
  303. $search_string .= strtoupper($value) . ' ';
  304. } else {
  305. $search_string .= strtoupper($field) . ' "' . $value . '" ';
  306. }
  307. }
  308. // Perform the search
  309. #echo "'$search_string'";
  310. return imap_search($this->stream, $search_string);
  311. } else {
  312. return imap_last_error();
  313. }
  314. }
  315. return imap_last_error();
  316. }
  317. public function flag($flag) {
  318. return imap_setflag_full($this->ImapFolder->Imap->stream, $this->uid, $flag, ST_UID);
  319. }
  320. /** testing only **/
  321. public function delete($emails, $delete = false) {
  322. $emails = (array )$emails;
  323. foreach ($emails as $email) {
  324. if ($delete) {
  325. imap_delete($this->stream, (int)$email);
  326. } else {
  327. imap_mail_move($this->stream, (int)$email, "Inbox/Trash");
  328. }
  329. }
  330. return imap_expunge($this->stream);
  331. }
  332. /**
  333. * deprecated
  334. */
  335. public function delx($emails, $delete = false) {
  336. if (!$this->stream) {
  337. return false;
  338. }
  339. $emails = (array )$emails;
  340. foreach ($emails as $key => $val) {
  341. $emails[$key] = (int)$val;
  342. }
  343. // Let's delete multiple emails
  344. if (count($emails) > 0) {
  345. $delete_string = '';
  346. $email_error = array();
  347. foreach ($emails as $email) {
  348. if ($delete) {
  349. if (!imap_delete($this->stream, $email)) {
  350. $email_error[] = $email;
  351. }
  352. }
  353. }
  354. if (!$delete) {
  355. // Need to take the last comma out!
  356. $delete_string = implode(',', $emails);
  357. echo $delete_string;
  358. imap_mail_move($this->stream, $delete_string, "Inbox/Trash");
  359. //imap_expunge($this->stream);
  360. } else {
  361. // NONE of the emails were deleted
  362. //imap_expunge($this->stream);
  363. if (count($email_error) === count($emails)) {
  364. return imap_last_error();
  365. } else {
  366. $return['status'] = false;
  367. $return['not_deleted'] = $email_error;
  368. return $return;
  369. }
  370. }
  371. }
  372. // Not connected
  373. return imap_last_error();
  374. }
  375. public function switch_mailbox($mailbox = '') {
  376. if ($this->stream) {
  377. $this->mbox = '{' . $this->server;
  378. if ($this->port) {
  379. $this->mbox .= ':' . $this->port;
  380. }
  381. if ($this->flags) {
  382. $this->mbox .= $this->flags;
  383. }
  384. $this->mbox .= '/user="' . $this->user . '"';
  385. $this->mbox .= '}';
  386. $this->mbox .= $this->default_mailbox;
  387. if ($mailbox) {
  388. $this->mbox .= '.' . $mailbox;
  389. }
  390. return @imap_reopen($this->stream, $this->mbox);
  391. }
  392. // Not connected
  393. return imap_last_error();
  394. }
  395. public function current_mailbox() {
  396. if ($this->stream) {
  397. $info = imap_mailboxmsginfo($this->stream);
  398. if ($info) {
  399. return $info->Mailbox;
  400. } else {
  401. // There was an error
  402. return imap_last_error();
  403. }
  404. }
  405. // Not connected
  406. return imap_last_error();
  407. }
  408. public function mailbox_info($type = 'obj') {
  409. if ($this->stream) {
  410. $info = imap_mailboxmsginfo($this->stream);
  411. if ($info) {
  412. if ($type == 'array') {
  413. $info_array = get_object_vars($info);
  414. return $info_array;
  415. } else {
  416. return $info;
  417. }
  418. } else {
  419. // There was an error
  420. return imap_last_error();
  421. }
  422. }
  423. // Not connected
  424. return imap_last_error();
  425. }
  426. /**
  427. * makes sure imap_open is available etc
  428. * @return bool $success
  429. * 2011-10-25 ms
  430. */
  431. public function dependenciesMatches() {
  432. if (!function_exists('imap_open')) {
  433. trigger_error('imap_open not available. Please install extension/module.');
  434. return false;
  435. }
  436. return true;
  437. }
  438. }
  439. /**
  440. * IMAP Postf�cher mit CakePHP abfragen
  441. * @see http://www.interaktionsdesigner.de/2009/05/11/imap-postfacher-mit-cakephp-abfragen/
  442. *
  443. * $this->Imap->connect();
  444. * Der R�ckgabewert dieser Funktion ist negativ wenn es nicht funktioniert hat.
  445. *
  446. * Eine gute Hilfe gegen verr�ckte Sonderzeichen und Kodierungen ist die Kombination von utf8_encode und quoted_printable_decode. Damit werden die meisten Umlaute richtig dargestellt.
  447. * F�r den Text der Mail w�re das dann innerhalb der foreach-Schleife:
  448. * debug(utf8_encode(quoted_printable_decode($message['body'])));
  449. *
  450. * fixes: pop3 connect etc
  451. * 2011-09-02 ms
  452. */
  453. class ImapMessageInfoLib {
  454. const BS = "\\";
  455. public $ImapFolder;
  456. public $ImapMessage;
  457. public $subject;
  458. public $from;
  459. public $to;
  460. public $date;
  461. public $message_id;
  462. public $references;
  463. public $in_reply_to;
  464. public $size;
  465. public $uid;
  466. public $msgno;
  467. public $recent;
  468. public $flagged;
  469. public $answered;
  470. public $deleted;
  471. public $seen;
  472. public $draft;
  473. public function __construct($ImapFolder, $data) {
  474. if (!is_object($data)) {
  475. $list = new ImapMessagesListLib($ImapFolder, array($data));
  476. $list = $list->overview(false);
  477. $data = $list[0];
  478. }
  479. foreach ($data as $key => $value) {
  480. $this->{$key} = $value;
  481. }
  482. $this->ImapFolder = $ImapFolder;
  483. }
  484. public function messageObject() {
  485. if (!isset($this->ImapMessage)) {
  486. return $this->ImapMessage = new ImapMessageLib($this->ImapFolder, $this->uid, $this);
  487. } else {
  488. return $this->ImapMessage;
  489. }
  490. }
  491. public function flag($flag) {
  492. return imap_setflag_full($this->ImapFolder->Imap->stream, $this->uid, $flag, ST_UID);
  493. }
  494. public function unFlag($flag) {
  495. return imap_clearflag_full($this->ImapFolder->Imap->stream, $this->uid, $flag, ST_UID);
  496. }
  497. public function seen($set = null) {
  498. if ($set === null) {
  499. return $this->seen;
  500. } elseif ($set) {
  501. return $this->flag(self::BS . 'Seen');
  502. } else {
  503. return $this->unFlag(self::BS . 'Seen');
  504. }
  505. }
  506. public function answered($set = null) {
  507. if ($set === null) {
  508. return $this->answered;
  509. } elseif ($set) {
  510. return $this->flag(self::BS . 'Answered');
  511. } else {
  512. return $this->unFlag(self::BS . 'Answered');
  513. }
  514. }
  515. public function flagged($set = null) {
  516. if ($set === null) {
  517. return $this->flagged;
  518. } elseif ($set) {
  519. return $this->flag(self::BS . 'Flagged');
  520. } else {
  521. return $this->unFlag(self::BS . 'Flagged');
  522. }
  523. }
  524. public function deleted($set = null) {
  525. if ($set === null) {
  526. return $this->deleted;
  527. } elseif ($set) {
  528. return $this->flag(self::BS . 'Deleted');
  529. } else {
  530. return $this->unFlag(self::BS . 'Deleted');
  531. }
  532. }
  533. public function draft($set = null) {
  534. if ($set === null) {
  535. return $this->draft;
  536. } elseif ($set) {
  537. return $this->flag(self::BS . 'Draft');
  538. } else {
  539. return $this->unFlag(self::BS . 'Draft');
  540. }
  541. }
  542. }
  543. class ImapMessageLib {
  544. public $ImapFolder;
  545. public $MessageInfo;
  546. public $uid;
  547. public function __construct($ImapFolder, $uid, $ImapMessageInfo = null) {
  548. $this->ImapFolder = $ImapFolder;
  549. if ($ImapMessageInfo === null) {
  550. $this->MessageInfo = new ImapMessageInfoLib($this->ImapFolder, $uid);
  551. } else {
  552. $this->MessageInfo = $ImapMessageInfo;
  553. }
  554. $this->MessageInfo->ImapMessage = $this;
  555. $this->uid = $uid;
  556. }
  557. public function move($folder) {
  558. }
  559. public function id() {
  560. //CHANGE DIR TO CURRENT
  561. return imap_msgno($this->ImapFolder->Imap->stream, $this->uid);
  562. }
  563. public function uid($ID) {
  564. return $this->uid;
  565. }
  566. public function fetchstructure() {
  567. return imap_fetchstructure($this->ImapFolder->Imap->stream, $this->uid, FT_UID);
  568. }
  569. public function fetchbody($section = 0) {
  570. return imap_fetchbody($this->ImapFolder->Imap->stream, $this->uid, $section, (FT_UID + FT_PEEK));
  571. }
  572. }
  573. class ImapMessagesListLib {
  574. public $ImapFolder;
  575. public $messageUIDs = array();
  576. public function __construct($ImapFolder, $messageUIDs) {
  577. $this->ImapFolder = $ImapFolder;
  578. $this->messageUIDs = $messageUIDs;
  579. }
  580. public function messgageObject($id) {
  581. if (isset($this->messageUIDs[$id])) {
  582. if (is_object($this->messageUIDs[$id])) {
  583. return $this->messageUIDs[$id];
  584. } else {
  585. return $this->messageUIDs[$id] = new ImapMessageLib($this->ImapFolder, $this->messageUIDs[$id]);
  586. }
  587. }
  588. return false;
  589. }
  590. public function count() {
  591. return count($this->messageUIDs);
  592. }
  593. public function overview($returnInfo = true) {
  594. //CHANGE DIR TO CURRENT
  595. $overview = imap_fetch_overview($this->ImapFolder->Imap->stream, implode(',', $this->messageUIDs), FT_UID);
  596. if ($returnInfo) {
  597. $msgObjs = array();
  598. foreach ($overview as $info) {
  599. $msgObjs[] = new ImapMessageInfoLib($this->ImapFolder, $info);
  600. }
  601. return $msgObjs;
  602. } else {
  603. return $overview;
  604. }
  605. }
  606. }
  607. class ImapFolderLib {
  608. const S_ALL = 'ALL';
  609. const S_ANSWERED = 'ANSWERED';
  610. const S_BCC = 'BCC';
  611. const S_BEFORE = 'BEFORE';
  612. const S_BODY = 'BODY';
  613. const S_CC = 'CC';
  614. const S_DELETED = 'DELETED';
  615. const S_FLAGGED = 'FLAGGED';
  616. const S_FROM = 'FROM';
  617. const S_KEYWORD = 'KEYWORD';
  618. const S_NEW = 'NEW';
  619. const S_OLD = 'OLD';
  620. const S_ON = 'ON';
  621. const S_RECENT = 'RECENT';
  622. const S_SEEN = 'SEEN';
  623. const S_SINCE = 'SINCE';
  624. const S_SUBJECT = 'SUBJECT';
  625. const S_TEXT = 'TEXT';
  626. const S_TO = 'TO';
  627. const S_UNANSWERED = 'UNANSWERED';
  628. const S_UNDELETED = 'UNDELETED';
  629. const S_UNFLAGGED = 'UNFLAGGED';
  630. const S_UNKEYWORD = 'UNKEYWORD';
  631. const S_UNSEEN = 'UNSEEN';
  632. public $Imap;
  633. public $currentRef = '';
  634. public function __construct($Imap) {
  635. $this->Imap = $Imap;
  636. $this->currentRef = $this->Imap->currentRef;
  637. }
  638. public function listFolder() {
  639. }
  640. public function searchMessages($options = array(self::ALL)) {
  641. $optionstring = '';
  642. foreach ($options as $key => $value) {
  643. if (is_int($key)) {
  644. $key = $value;
  645. $value = null;
  646. }
  647. switch ($key) {
  648. case self::S_FROM:
  649. $param = '"' . $value . '" ';
  650. break;
  651. default:
  652. $param = '';
  653. break;
  654. }
  655. $optionstring .= $key . ' ' . $param;
  656. }
  657. //CHANGE DIR TO CURRENT
  658. $msg = imap_search($this->Imap->stream, $optionstring, SE_UID);
  659. if ($msg !== false) {
  660. return new ImapMessagesListLib($this, $msg);
  661. }
  662. return false;
  663. }
  664. public function allMessages() {
  665. return $this->searchMessages();
  666. }
  667. }