mail.inc.php 6.7 KB

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