Am 17.11.2009 17:25, schrieb Paul J Stevens: > Reindl Harald wrote: > >> I have no idea how i should do this with sieve in future because we >> switch here from mysql-database to a protocl and afaik there >> can be only one active sieve-script for each user > > I'm not sure I understand what you're saying here.
We have implemented thousands of lines oo-code for the adminpanel and most of the reply-features depends on the two reply-tables * "reply-groups" where we can define lists auf accounts getting the same reply * listing all active/inactive replies with dates * listing last sent replies from the replycache > Indeed, there can be only one active sieve script per user. But there is > nothing to prevent you from inserting sieve scripts directly through the > sql interface. No need to go through timsieved, unless you want to make > sure scripts are valid. A sample where this do not work or would not work really stable * I have a big sieve-script which puts mails in many folders on the server * This script is written with a thunderbird plugin * The rules should be active even when i have a holiday-reply * How do i handle this? * syntax-errors are a problem because timsieved hangs if theres a error I can send you some screenshots of our 100% self-written gui which contains 11855 LOC after some weeks working night and day which could explain my problem if we lost the explicit reply-tables and start mixing userdefinied sieve-scripts with webui-controlled autoreplies Sorry, i can not attach the screenshots public, but i attach the "dbmail_reply"-class as textfile (depends on our own CMS and many other libraries but should show what we do, even with german comments) Regards from vienna Harry
<?php /** CONTENT MANAGMENT SYSTEM BY REINDL HARALD ------------------------------------------------------------------ AENDERUNGEN UND WEITERGABE DIESER DATEI OHNE RUECKSPRACHE MIT DEM ENTWICKLER SIND LIZENZRECHTLICH NICHT GESTATTET! ------------------------------------------------------------------ * DBMail-Administration * Autoreply-Schnittstelle ------------------------------------------------------------------ the lounge interactive design WEB: http://www.thelounge.net MAIL: [email protected] TEL: +43 1 595 3 999 Hofmuehlgasse 17 1060 Wien -------------------------------------------------------------------- * @package dbmailadmin * @copyright 2009 Reindl Harald <[email protected]> * @license Commercial */ /** * Zentrale Kapselung aller Reply-Methoden * Zeitangaben erfolgen in der Library IMMER als Unix-Timestamps * * @uses mysql_class * @uses dbmail * * @package dbmailadmin * @copyright 2009 Reindl Harald <[email protected]> * @license Commercial */ class dbmail_reply { /** @property object An Instance of dbmail */ public $interface_ref; /** @property object An Instance of mysql_class */ public $db; /** @property integer Zeichenlimitierung */ public $max_message_length = 10000; /** * Liste aller Mailadressen mit einem Auto-Reply abrufen * Zeitangaben erfolgen in der Library IMMER als Unix-Timestamps * * @param integer $state -1/Alle, 0/Aktiv, 1/Abgelaufen * @return array (user_idnr, username, email, start_date, stop_date) * @access public */ public function liste($state=0) { /** Zwischenspeicher definieren */ $arr = array(); /** Query generieren und ausfuehren */ $sql = 'select user_idnr,start_date,stop_date from `dbmail_auto_replies`'; switch($state) { case 0: $sql .= ' where stop_date>now() and start_date<now()'; break; case 1: $sql .= ' where stop_date<now() or start_date>now()'; break; } $result = $this->db->query($sql . ';', 1, 0); /** Liste durchlaufen und mit ergaenzten Daten in Zielarray puffern */ while($row = $this->db->fetch_assoc($result)) { $user_idnr = $row['user_idnr']; $username = $this->interface_ref->user->get_username_by_id($row['user_idnr']); $email = $this->interface_ref->user->get_email_by_username($username); $arr[$email] = array ( 'user_idnr' => (int)$user_idnr, 'username' => $username, 'email' => $email, 'start_date' => strtotime($row['start_date']), 'stop_date' => strtotime($row['stop_date']) ); } /** Sortierte Liste zurueckgeben */ ksort($arr); return $arr; } /** * Kompletten Auto-Reply-Datensatz anhand des Usernamens abfragen * false wenn der Benutzer nicht existiert * Ansonsten immer Array mit allen Feldern egal ob ein Reply-Datensatz existiert * * * @param string $username * @return array (user_idnr, username, email, start_date, stop_date, body) */ public function get_by_username($username) { $user_idnr = $this->interface_ref->user->get_id_by_username($username); if(!$user_idnr) { return false; } else { $result = $this->db->query('select * from `dbmail_auto_replies` where user_idnr=' . (int)$user_idnr . ';', 1, 0); if($this->db->num_rows($result)) { $row = $this->db->fetch_assoc($result); $email = $this->interface_ref->user->get_email_by_username($username); return array ( 'user_idnr' => (int)$user_idnr, 'username' => $username, 'email' => $email, 'start_date' => strtotime($row['start_date']), 'stop_date' => strtotime($row['stop_date']), 'body' => $row['reply_body'] ); } else { $email = $this->interface_ref->user->get_email_by_username($username); return array ( 'user_idnr' => (int)$user_idnr, 'username' => $username, 'email' => $email, 'start_date' => 0, 'stop_date' => 0, 'body' => '' ); } } } /** * Auto-Reply setzen * Ggf. bestehender Datensatz fuer den Usernamen wird ggf. im Vorfeld entfernt * * username: Benutzername aus der Tabelle dbmail_users * start: Unix-Timestamp * stop: Unix-Timestamp * body: Mailbody als Plaintext * * @param array $data * @return boolean * @access public */ public function set_reply(array $data) { /** Sicherstellen dass sinnvolle Daten uebergeben werden */ if(!isset($data['username']) || !isset($data['start']) || !isset($data['stop']) || !isset($data['body'])) { return false; } /** Whitespaces filtern und Datumsangaben als Integer erzwingen */ $data['username'] = trim($data['username']); $data['body'] = trim($data['body']); $data['start'] = (int)$data['start']; $data['stop'] = (int)$data['stop']; /** Username und Mailbody erzwingen, sicherstellen dass Ende nicht vor dem Start liegt */ if(empty($data['username']) || empty($data['body']) || $data['stop'] <= $data['start']) { return false; } /** User-ID anhand des Usernamens ermitteln */ $user_idnr = $this->interface_ref->user->get_id_by_username($data['username']); if($user_idnr < 1) { return false; } /** Bestehenden Datensatz wenn vorhanden loeschen */ $this->db->query('delete from `dbmail_auto_replies` where user_idnr=' . (int)$user_idnr . ';', 1, 1); /** Datensatz in Reply-Tabelle schreiben */ $this->db->query("insert into `dbmail_auto_replies` (user_idnr, start_date, stop_date, reply_body) values (" . (int)$user_idnr . ", FROM_UNIXTIME(" . $data['start'] . "), FROM_UNIXTIME(" . $data['stop'] . "), '" . $this->db->addslashes($data['body']) . "');", 1, 1); /** Protokollieren */ $this->interface_ref->log('Reply for "' . $data['username'] . '" changed'); /** Erfolg zurueckgeben */ return true; } /** * Auto-Reply anhand des Usernamens loeschen * * @param string $username * @return boolean * @access public */ public function remove($username) { /** User-ID ermitteln und abbrechen wenn nicht aufloesbar */ $user_idnr = $this->interface_ref->user->get_id_by_username($username); /** Bei bekannter User-ID Datensatz entfernen oder Fehler zurueckgeben */ if($user_idnr < 1) { return false; } else { $this->db->query('delete from `dbmail_auto_replies` where user_idnr=' . (int)$user_idnr . ';', 1, 1); $this->interface_ref->log('Reply for "' . $username . '" removed'); return true; } } /** * Liste aller definierten Reply-Gruppen abrufen * "targets" wird als Array zureuckgegeben * Physische Speicherung erfolgt serialisiert * * @return array (email, targets) * @access public */ public function list_groups() { $arr = array(); /** Reply-Groups sortiert nach Eltern-Adresse auflisten */ $result = $this->db->query('select * from `dbma_reply_groups`;', 1, 0); while($row = $this->db->fetch_assoc($result)) { /** Textfeld deserialisieren */ $arr[] = array('email'=>$row['address'], 'targets'=>unserialize($row['targets'])); } $this->interface_ref->order_array($arr, 'email', 0); return $arr; } /** * Reply-Gruppe anlegen bzw. ersetzen wenn es bereits einen Eintrag fuer die Mailadresse gibt * * @param string $email Basis-Adresse * @param string $liste Sub-Adressen (1 Adresse pro Zeile) * @return boolean * @access public */ public function set_group($email, $liste) { /** Whitespaces filern und Liste auftrennen */ $email = trim($email); $zsp = explode(MY_LE, $liste . MY_LE); $liste = array(); /** Leere Werte und Ubereinstimmungen mit der Elternadresse filtern */ foreach($zsp as $key=>$value) { $value = trim($value); if(!empty($value) && $value != $email) { $liste[] = $value; } } sort($liste); /** Sicherstellen dass wir nur formal gueltige Adressen verarbeiten */ if(!CheckMail($email) || empty($liste)) { return false; } foreach($liste as $item) { if(!CheckMail($item)) { return false; break; } } /** Ggf. bestehende Datensaetze loeschen */ $this->db->query("delete from `dbma_reply_groups` where address='" . $this->db->addslashes($email) . "';", 1, 1); foreach($liste as $item) { $this->db->query("delete from `dbma_reply_groups` where address='" . $this->db->addslashes($item) . "';", 1, 1); $this->db->query("delete from `dbma_reply_groups` where targets like '%" . $this->db->addslashes($item) . "%';", 1, 1); } /** Neuen Eintrag speichern */ $this->db->query("insert into `dbma_reply_groups` (address, targets) values ('" . $this->db->addslashes($email) . "', '" . $this->db->addslashes(serialize($liste)) . "');", 1, 1); $this->interface_ref->log('Reply-Group for "' . $email . '" changed'); return true; } /** * Reply-Gruppe einer Mailadresse loeschen * * @param string $email Basis-Adresse * @return boolean * @access public */ public function remove_group($email) { /** Check ob es zur angegebenen Mailadresse eine Reply-Group gibt */ $row = $this->db->fetch_row($this->db->query("select count(*) from `dbma_reply_groups` where address='" . $this->db->addslashes($email) . "';", 1, 0)); if($row[0] < 1) { return false; } /** Wenn vorhanden entfernen */ else { $this->db->query("delete from `dbma_reply_groups` where address='" . $this->db->addslashes($email) . "';", 1, 1); $this->interface_ref->log('Reply-Group for "' . $email . '" removed'); return true; } } /** * Subadressen zu einer Hauptadresse falls konfiguriert abfragen und als Array zureuckgeben * * @param string $email * @return array * @access public */ public function get_group($email) { $result = $this->db->query("select targets from `dbma_reply_groups` where address='" . $this->db->addslashes($email) . "';", 1, 0); if($this->db->num_rows($result) > 0) { $row = $this->db->fetch_row($result); return unserialize($row[0]); } else { return array(); } } /** * Abfrage der zuletzt gesendeten Replies * * @param integer $limit Zeilen-Limit * @param string $email Filter auf bestimmten User * @return array (from_addr, to_addr, date) * @access public */ public function last_sent($limit=100, $email='') { $arr = array(); if($limit < 1) { $limit = 500; } $sql = 'select from_addr, to_addr, lastseen as date from `dbmail_replycache`'; if(!empty($email)) { $sql .= " where from_addr='" . $this->db->addslashes($email) . "'"; } $sql .= ' limit ' . (int)$limit . ';'; $result = $this->db->query($sql, 1, 0); while($row = $this->db->fetch_assoc($result)) { $row['date'] = strtotime($row['date']); $arr[] = $row; } /** Sortierung auf PHP-Ebene um Datenbank zu entlasten */ $this->interface_ref->order_array($arr, 'date', 1); return $arr; } } ?>
signature.asc
Description: OpenPGP digital signature
_______________________________________________ DBmail mailing list [email protected] http://mailman.fastxs.nl/cgi-bin/mailman/listinfo/dbmail
