Moritz Schmidt hace 10 años
padre
commit
0de3f9f3d2
Se han modificado 4 ficheros con 153 adiciones y 7 borrados
  1. 1 0
      cron.php
  2. 14 6
      includes/functions.inc.php
  3. 122 0
      includes/option.inc.php
  4. 16 1
      sql_structure.sql

+ 1 - 0
cron.php

@@ -10,6 +10,7 @@ include('includes/label.inc.php');
 include('includes/mailbox.inc.php');
 include('includes/mailboxfolder.inc.php');
 include('includes/mail.inc.php');
+include('includes/option.inc.php');
 
 $db = new Database($CONFIG['dbHost'], $CONFIG['dbUser'], $CONFIG['dbPassword'], $CONFIG['dbDatabase']);
 

+ 14 - 6
includes/functions.inc.php

@@ -107,6 +107,8 @@ function handleFile($filename, &$allDocuments) {
 function searchMails() {
 	global $user;
 	$mailboxes = Mailbox::getAllMailBoxes();
+	$lastMailOption = Option::getOptionByKey("lastMailSearch");
+	$date = date("d-M-Y", $lastMailOption->getValue());
 
 
 	foreach($mailboxes as $mailbox) {
@@ -116,20 +118,26 @@ function searchMails() {
 			if($mbFolder != false) {
 				$mailbox->changeFolder($mbFolder->getFolderName());
 
-				$messageCount = imap_num_msg($mailbox->getMailbox());
+				$search = imap_search($mailbox->getMailbox(), 'SINCE "' . $date . '"');
 
-				for($i = 1; $i <= $messageCount; ++$i) {
-				    $headers = imap_header($mailbox->getMailbox(), $i);
+				if($search) {
+					foreach($search as $message) {
+						$headers = imap_header($mailbox->getMailbox(), $message);
 
-					if(!Mail::getMailByMessageID($headers->message_id)) {
-						$mail = new Mail(NULL, imap_utf8($headers->from[0]->mailbox . '@' . $headers->from[0]->host), imap_utf8($headers->subject), $mbFolder->getID(), $headers->Msgno, $headers->message_id, 0);
+						if(!Mail::getMailByMessageID($headers->message_id)) {
+							$mail = new Mail(NULL, imap_utf8($headers->from[0]->mailbox . '@' . $headers->from[0]->host), imap_utf8($headers->subject), $mbFolder->getID(), $headers->Msgno, $headers->message_id, 0);
+
+							$mail->save();
+						}
 
-						$mail->save();
 					}
 				}
 			}
 		}
 	}
+
+	$lastMailOption->setValue(time());
+	$lastMailOption->save();
 }
 
 

+ 122 - 0
includes/option.inc.php

@@ -0,0 +1,122 @@
+<?php
+
+class Option {
+    private $id     = NULL;
+    private $key    = NULL;
+    private $value  = NULL;
+
+    public function __construct($id, $key, $value) {
+        $this->id       = $id;
+        $this->key      = $key;
+        $this->value    = $value;
+    }
+
+    /**
+     * Get the value of Id
+     *
+     *
+     * @return int
+     *
+     */
+
+    public function getID() {
+        return $this->id;
+    }
+
+    /**
+     * Set the value of Id
+     *
+     *
+     * @param int id
+     *
+     */
+
+    public function setID($id) {
+        $this->id = $id;
+     }
+
+    /**
+     * Get the value of Key
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getKey() {
+        return $this->key;
+    }
+
+    /**
+     * Set the value of Key
+     *
+     *
+     * @param string key
+     *
+     */
+
+    public function setKey($key) {
+        $this->key = $key;
+     }
+
+    /**
+     * Get the value of Value
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getValue() {
+        return $this->value;
+    }
+
+    /**
+     * Set the value of Value
+     *
+     *
+     * @param string value
+     *
+     */
+
+    public function setValue($value) {
+        $this->value = $value;
+     }
+
+     /*
+      *
+      * Save current option
+      *
+      */
+
+     public function save() {
+         global $db;
+
+         $db->insertQuery("INSERT INTO `options` (`id`, `key`, `value`) VALUES (" . $this->id . ", '" . $this->key . "', '" . $this->value . "') ON DUPLICATE KEY UPDATE `id` = " . $this->id . ", `key` = '" . $this->key . "', `value` = '" . $this->value . "';");
+     }
+
+     /**
+     * Get Option by Key
+     *
+     * @param string $key  Key
+     *
+     * @return Option Selected Option
+     *
+     */
+
+     public static function getOptionByKey($key) {
+         global $db;
+
+         $option = $db->selectQuery("SELECT * FROM `options` WHERE `key` = '" . $key . "';");
+
+         if(!$option) {
+             return false;
+         }
+
+         return new Option($option[0]->id, $option[0]->key, $option[0]->value);
+
+     }
+
+}
+
+?>

+ 16 - 1
sql_structure.sql

@@ -143,7 +143,22 @@ CREATE TABLE `mails` (
   `message_id` varchar(256) COLLATE utf8_bin NOT NULL,
   `processed` tinyint(1) NOT NULL,
   PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `options`
+--
+
+DROP TABLE IF EXISTS `options`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `options` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `key` varchar(64) COLLATE utf8_bin NOT NULL,
+  `value` varchar(256) COLLATE utf8_bin NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --