imap.inc.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, $connect) {
  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. if($connect) {
  26. $this->mailbox = imap_open($this->server . 'INBOX', $this->username, $this->password) or error('Failed to connect to IMAP: ' . $this->username . '@' . $this->hostname);
  27. }
  28. }
  29. public function changeFolder($folder) {
  30. imap_reopen($this->mailbox, $this->server . $folder);
  31. }
  32. public function listFolders() {
  33. $newFolders = array();
  34. $folders = imap_list($this->mailbox, $this->server, "*");
  35. foreach($folders as $folder) {
  36. $newFolders[] = preg_replace('/(\{(.*)\})(.*)/', '${3}', $folder);
  37. }
  38. $this->folders = $newFolders;
  39. }
  40. public function getId() {
  41. return $this->id;
  42. }
  43. public function getFolders() {
  44. return $this->folders;
  45. }
  46. public function getServer() {
  47. return $this->server;
  48. }
  49. public function getMailbox() {
  50. return $this->mailbox;
  51. }
  52. public function getHostname() {
  53. return $this->hostname;
  54. }
  55. public function getPort() {
  56. return $this->port;
  57. }
  58. public function getProtocol() {
  59. return $this->protocol;
  60. }
  61. public function getUseSsl() {
  62. return $this->useSsl;
  63. }
  64. public function getNoValidCert() {
  65. return $this->noValidCert;
  66. }
  67. public function getUsername() {
  68. return $this->username;
  69. }
  70. }