mail.inc.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. private $processed = NULL;
  9. public function __construct($id, $mailSender, $subject, $mailboxFolderID, $mailUID, $processed) {
  10. $this->id = $id;
  11. $this->mailSender = $mailSender;
  12. $this->subject = $subject;
  13. $this->mailboxFolderID = $mailboxFolderID;
  14. $this->mailUID = $mailUID;
  15. $this->processed = $processed;
  16. }
  17. /**
  18. * Get the value of ID
  19. *
  20. *
  21. * @return int
  22. *
  23. */
  24. public function getID() {
  25. return $this->id;
  26. }
  27. /**
  28. * Set the value of ID
  29. *
  30. *
  31. * @param int id
  32. *
  33. */
  34. public function setID($id) {
  35. $this->id = $id;
  36. }
  37. /**
  38. * Get the value of Mail Sender
  39. *
  40. *
  41. * @return string
  42. *
  43. */
  44. public function getMailSender() {
  45. return $this->mailSender;
  46. }
  47. /**
  48. * Set the value of Mail Sender
  49. *
  50. *
  51. * @param string mailSender
  52. *
  53. */
  54. public function setMailSender($mailSender) {
  55. $this->mailSender = $mailSender;
  56. }
  57. /**
  58. * Get the value of Subject
  59. *
  60. *
  61. * @return string
  62. *
  63. */
  64. public function getSubject() {
  65. return $this->subject;
  66. }
  67. /**
  68. * Set the value of Subject
  69. *
  70. *
  71. * @param string subject
  72. *
  73. */
  74. public function setSubject($subject) {
  75. $this->subject = $subject;
  76. }
  77. /**
  78. * Get the value of Mailbox Folder ID
  79. *
  80. *
  81. * @return int
  82. *
  83. */
  84. public function getMailboxFolderID() {
  85. return $this->mailboxFolderID;
  86. }
  87. /**
  88. * Set the value of Mailbox Folder ID
  89. *
  90. *
  91. * @param int mailboxFolderID
  92. *
  93. */
  94. public function setMailboxFolderID($mailboxFolderID) {
  95. $this->mailboxFolderID = $mailboxFolderID;
  96. }
  97. /**
  98. * Get the value of Mail UID
  99. *
  100. *
  101. * @return int
  102. *
  103. */
  104. public function getMailUID() {
  105. return $this->mailUID;
  106. }
  107. /**
  108. * Set the value of Mail
  109. *
  110. *
  111. * @param int mailUID
  112. *
  113. */
  114. public function setMailUID($mailUID) {
  115. $this->mailUID = $mailUID;
  116. }
  117. /**
  118. * Get the value of processed
  119. *
  120. *
  121. * @return int
  122. *
  123. */
  124. public function getProcessed() {
  125. return $this->processed;
  126. }
  127. /**
  128. * Set the value of processed
  129. *
  130. *
  131. * @param int mailUID
  132. *
  133. */
  134. public function setProcessed($processed) {
  135. $this->processed = $processed;
  136. }
  137. public function getMailRecipient() {
  138. global $db;
  139. 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() . "));");
  140. }
  141. /**
  142. * Save Mail to DB
  143. *
  144. *
  145. * @return void
  146. *
  147. */
  148. public function save() {
  149. global $db;
  150. if($this->getID() == NULL) {
  151. $this->setID("'NULL'");
  152. }
  153. $db->insertQuery("INSERT INTO `mails` (`id`, `mail_sender`, `subject`, `mailbox_folder_id`, `mail_uid`, `processed`) VALUES (" . $this->getID() . ", '" . $this->getMailSender() . "', '" . $this->getSubject() . "', " . $this->getMailboxFolderID() . ", " . $this->getMailUID() . ", " . $this->getProcessed() . ") ON DUPLICATE KEY UPDATE `mail_sender` = '" . $this->getMailSender() . "', `subject` = '" . $this->getSubject() . "', `mailbox_folder_id` = " . $this->getMailboxFolderID() . ", `mail_uid` = " . $this->getMailUID() . ", `processed` = " . $this->getProcessed() . ";");
  154. if($this->getID() == "'NULL'") {
  155. $this->setID(NULL);
  156. }
  157. }
  158. /**
  159. * Get Mail by Mail-ID
  160. *
  161. * @param int $mailID ID of Mail
  162. *
  163. * @return Mail
  164. *
  165. */
  166. public static function getMailByMailID($mailID) {
  167. global $db;
  168. $mails = $db->selectQuery("SELECT * FROM `mails` WHERE `id` = " . $mailID . ";");
  169. $return = array();
  170. if(!$mails) {
  171. return false;
  172. }
  173. foreach($mails as $mail) {
  174. $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid, $mail->processed);
  175. }
  176. return $return[0];
  177. }
  178. /**
  179. * Get Mail by Mail information
  180. *
  181. * @param int $mailboxFolder ID of mailbox-Folder
  182. * @param int $mailUID UID of Mail
  183. *
  184. * @return Mail/bool Selected Mail, or false if not found
  185. *
  186. */
  187. public static function getMailByMailInfo($mailboxFolder, $mailUID) {
  188. global $db;
  189. $mails = $db->selectQuery("SELECT * FROM `mails` WHERE `mailbox_folder_id` = " . $mailboxFolder . " AND `mail_uid` = " . $mailUID . ";");
  190. $return = array();
  191. if(!$mails) {
  192. return false;
  193. }
  194. foreach($mails as $mail) {
  195. $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid, $mail->processed);
  196. }
  197. return $return[0];
  198. }
  199. /**
  200. * Get Mails by Label ID
  201. *
  202. * @param int $labelID ID of Label
  203. *
  204. * @return Array(Mail) Array with selected Mails
  205. *
  206. */
  207. public static function getMailsByLabelID($labelID) {
  208. global $db;
  209. $mails = $db->selectQuery("SELECT `mails`.* FROM `mails` JOIN `mailbox-folders` ON `mailbox-folders`.id = `mails`.mailbox_folder_id WHERE `mailbox-folders`.label_id = " . $labelID . ";");
  210. if(!$mails) {
  211. return false;
  212. }
  213. $return = array();
  214. foreach($mails as $mail) {
  215. $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid, $mail->processed);
  216. }
  217. return $return;
  218. }
  219. }
  220. ?>