imap.inc.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class Imap {
  3. private $server = NULL;
  4. private $username = NULL;
  5. private $password = NULL;
  6. private $mailbox = NULL;
  7. private $folders = NULL;
  8. public function __construct($server, $username, $password) {
  9. $this->server = $server;
  10. $this->username = $username;
  11. $this->password = $password;
  12. $this->mailbox = imap_open($this->server . 'INBOX', $this->username, $this->password) or error('Failed to connect to IMAP');
  13. }
  14. public function changeFolder($folder) {
  15. imap_reopen($this->mailbox, $this->server . $folder);
  16. }
  17. public function listFolders() {
  18. $newFolders = array();
  19. $folders = imap_list($this->mailbox, $this->server, "*");
  20. foreach($folders as $folder) {
  21. $newFolders[] = preg_replace('/(\{(.*)\})(.*)/', '${3}', $folder);
  22. }
  23. $this->folders = $newFolders;
  24. }
  25. public function getFolders() {
  26. return $this->folders;
  27. }
  28. public function getServer() {
  29. return $this->server;
  30. }
  31. public function getMailbox() {
  32. return $this->mailbox;
  33. }
  34. }