imap.inc.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. class Imap {
  3. private $id = NULL;
  4. private $server = NULL;
  5. private $hostname = NULL;
  6. private $port = NULL;
  7. private $protocol = NULL;
  8. private $useSsl = NULL;
  9. private $noValidCert = NULL;
  10. private $username = NULL;
  11. private $password = NULL;
  12. private $mailbox = NULL;
  13. private $folders = NULL;
  14. public function __construct($id, $hostname, $port, $protocol, $useSsl, $noValidCert, $username, $password) {
  15. $this->id = $id;
  16. $this->hostname = $hostname;
  17. $this->port = $port;
  18. $this->protocol = $protocol;
  19. $this->useSsl = $useSsl;
  20. $this->noValidCert = $noValidCert;
  21. $this->username = $username;
  22. $this->password = $password;
  23. // '{' . $mailbox->server . ':' . $mailbox->port . '/' . $mailbox->protocol . $useSsl . $noValidCert . '}'
  24. $this->server = '{' . $this->hostname . ':' . $this->port . '/' . $this->protocol . $this->useSsl . $this->noValidCert . '}';
  25. $this->mailbox = imap_open($this->server . 'INBOX', $this->username, $this->password) or error('Failed to connect to IMAP: ' . $this->username . '@' . $this->hostname);
  26. }
  27. public function changeFolder($folder) {
  28. imap_reopen($this->mailbox, $this->server . $folder);
  29. }
  30. public function listFolders() {
  31. $newFolders = array();
  32. $folders = imap_list($this->mailbox, $this->server, "*");
  33. foreach($folders as $folder) {
  34. $newFolders[] = preg_replace('/(\{(.*)\})(.*)/', '${3}', $folder);
  35. }
  36. $this->folders = $newFolders;
  37. }
  38. public function getId() {
  39. return $this->id;
  40. }
  41. public function getFolders() {
  42. return $this->folders;
  43. }
  44. public function getServer() {
  45. return $this->server;
  46. }
  47. public function getMailbox() {
  48. return $this->mailbox;
  49. }
  50. public function getHostname() {
  51. return $this->hostname;
  52. }
  53. public function getPort() {
  54. return $this->port;
  55. }
  56. public function getProtocol() {
  57. return $this->protocol;
  58. }
  59. public function getUseSsl() {
  60. return $this->useSsl;
  61. }
  62. public function getNoValidCert() {
  63. return $this->noValidCert;
  64. }
  65. public function getUsername() {
  66. return $this->username;
  67. }
  68. }