mail.inc.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. class Mail {
  3. private $id = NULL;
  4. private $mailSender = NULL;
  5. private $subject = NULL;
  6. private $mailboxFolderID = NULL;
  7. private $mailUID = NULL;
  8. public function __construct($id, $mailSender, $subject, $mailboxFolderID, $mailUID) {
  9. $this->id = $id;
  10. $this->mailSender = $mailSender;
  11. $this->subject = $subject;
  12. $this->mailboxFolderID = $mailboxFolderID;
  13. $this->mailUID = $mailUID;
  14. }
  15. /**
  16. * Get the value of ID
  17. *
  18. *
  19. * @return int
  20. *
  21. */
  22. public function getID() {
  23. return $this->id;
  24. }
  25. /**
  26. * Set the value of ID
  27. *
  28. *
  29. * @param int id
  30. *
  31. */
  32. public function setID($id) {
  33. $this->id = $id;
  34. }
  35. /**
  36. * Get the value of Mail Sender
  37. *
  38. *
  39. * @return string
  40. *
  41. */
  42. public function getMailSender() {
  43. return $this->mailSender;
  44. }
  45. /**
  46. * Set the value of Mail Sender
  47. *
  48. *
  49. * @param string mailSender
  50. *
  51. */
  52. public function setMailSender($mailSender) {
  53. $this->mailSender = $mailSender;
  54. }
  55. /**
  56. * Get the value of Subject
  57. *
  58. *
  59. * @return string
  60. *
  61. */
  62. public function getSubject() {
  63. return $this->subject;
  64. }
  65. /**
  66. * Set the value of Subject
  67. *
  68. *
  69. * @param string subject
  70. *
  71. */
  72. public function setSubject($subject) {
  73. $this->subject = $subject;
  74. }
  75. /**
  76. * Get the value of Mailbox Folder ID
  77. *
  78. *
  79. * @return int
  80. *
  81. */
  82. public function getMailboxFolderID() {
  83. return $this->mailboxFolderID;
  84. }
  85. /**
  86. * Set the value of Mailbox Folder ID
  87. *
  88. *
  89. * @param int mailboxFolderID
  90. *
  91. */
  92. public function setMailboxFolderID($mailboxFolderID) {
  93. $this->mailboxFolderID = $mailboxFolderID;
  94. }
  95. /**
  96. * Get the value of Mail UID
  97. *
  98. *
  99. * @return int
  100. *
  101. */
  102. public function getMailUID() {
  103. return $this->mailUID;
  104. }
  105. /**
  106. * Set the value of Mail
  107. *
  108. *
  109. * @param int mailUID
  110. *
  111. */
  112. public function setMailUID($mailUID) {
  113. $this->mailUID = $mailUID;
  114. }
  115. public function getMailRecipient() {
  116. global $db;
  117. return $db->selectStringQuery("SELECT `mailboxes`.`username` FROM `mailboxes` WHERE `mailboxes`.`id` = (SELECT `mailbox-folders`.`mailbox_id` FROM `mailbox-folders`WHERE `mailbox-folders`.`id` = (SELECT `mails`.`mailbox_folder_id` FROM `mails` WHERE `mails`.`id` = " . $this->getID() . "));");
  118. }
  119. /**
  120. * Save Mail to DB
  121. *
  122. *
  123. * @return void
  124. *
  125. */
  126. public function save() {
  127. global $db;
  128. if($this->getID() == NULL) {
  129. $this->setID("'NULL'");
  130. }
  131. $db->insertQuery("INSERT INTO `mails` (`id`, `mail_sender`, `subject`, `mailbox_folder_id`, `mail_uid`) VALUES (" . $this->getID() . ", '" . $this->getMailSender() . "', '" . $this->getSubject() . "', " . $this->getMailboxFolderID() . ", " . $this->getMailUID() . ") ON DUPLICATE KEY UPDATE `mail_sender` = '" . $this->getMailSender() . "', `subject` = '" . $this->getSubject() . "', `mailbox_folder_id` = " . $this->getMailboxFolderID() . ", `mail_uid` = " . $this->getMailUID() . ";");
  132. $this->setID(NULL); // get ID from DB
  133. echo "<br><br>";
  134. }
  135. /**
  136. * Get Mail by Mail information
  137. *
  138. * @param int $mailboxFolder ID of mailbox-Folder
  139. * @param int $mailUID UID of Mail
  140. *
  141. * @return Mail/bool Selected Mail, or false if not found
  142. *
  143. */
  144. public static function getMailByMailInfo($mailboxFolder, $mailUID) {
  145. global $db;
  146. $mails = $db->selectQuery("SELECT * FROM `mails` WHERE `mailbox_folder_id` = " . $mailboxFolder . " AND `mail_uid` = " . $mailUID . ";");
  147. $return = array();
  148. if(!$mails) {
  149. return false;
  150. }
  151. foreach($mails as $mail) {
  152. $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid);
  153. }
  154. return $return[0];
  155. }
  156. /**
  157. * Get Mails by Label ID
  158. *
  159. * @param int $labelID ID of Label
  160. *
  161. * @return Array(Mail) Array with selected Mails
  162. *
  163. */
  164. public static function getMailsByLabelID($labelID) {
  165. global $db;
  166. $mails = $db->selectQuery("SELECT `mails`.* FROM `mails` JOIN `mailbox-folders` ON `mailbox-folders`.id = `mails`.mailbox_folder_id WHERE `mailbox-folders`.label_id = " . $labelID . ";");
  167. if(!$mails) {
  168. return false;
  169. }
  170. $return = array();
  171. foreach($mails as $mail) {
  172. $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid);
  173. }
  174. return $return;
  175. }
  176. }
  177. ?>