/**
  * Get all the fetchmail account configured (can specify a user id to retrieve only account for a single user)
  * @param MDB2 $dbm database connection
  * @param int $user_id
  */
 public function __construct($dbm, $user_id = -1)
 {
     $this->dbm = $dbm;
     $this->position = 0;
     // Retrieve the accounts list
     if ($user_id != -1) {
         $sql_result = $this->dbm->query("SELECT * FROM " . get_table_name('fetchmail_rc') . " WHERE fk_user=?", $user_id);
     } else {
         $sql_result = $this->dbm->query("SELECT * FROM " . get_table_name('fetchmail_rc'));
     }
     while ($account = $this->dbm->fetch_assoc($sql_result)) {
         $fetchmailRc = new fetchMailRc();
         $fetchmailRc->from_array($account);
         $this->datas[] = $fetchmailRc;
     }
 }
Esempio n. 2
0
 /**
  * Deletes given saved search record
  *
  * @param  int  $sid  Search ID
  *
  * @return boolean True if deleted successfully, false if nothing changed
  */
 function delete_search($sid)
 {
     if (!$this->ID) {
         return false;
     }
     $this->db->query("DELETE FROM " . $this->db->table_name('searches') . " WHERE user_id = ?" . " AND search_id = ?", (int) $this->ID, $sid);
     return $this->db->affected_rows();
 }
Esempio n. 3
0
 /**
  * Check for existing groups with the same name
  *
  * @param string Name to check
  * @return string A group name which is unique for the current use
  */
 private function unique_groupname($name)
 {
     $checkname = $name;
     $num = 2;
     $hit = false;
     do {
         $sql_result = $this->db->query("SELECT 1 FROM " . $this->db->table_name($this->db_groups) . " WHERE del<>1" . " AND user_id=?" . " AND name=?", $this->user_id, $checkname);
         // append number to make name unique
         if ($hit = $this->db->num_rows($sql_result)) {
             $checkname = $name . ' ' . $num++;
         }
     } while ($hit > 0);
     return $checkname;
 }
Esempio n. 4
0
 /**
  * @param string $key Cache key
  * @param int    $uid Message UID
  * @return int Message (sequence) ID
  * @access private
  */
 private function get_cache_uid2id($key, $uid)
 {
     if (!$this->caching_enabled) {
         return null;
     }
     if (array_key_exists('index', $this->icache) && $this->icache['index']['key'] == $key) {
         return array_search($uid, $this->icache['index']['result']);
     }
     $sql_result = $this->db->query("SELECT idx" . " FROM " . get_table_name('messages') . " WHERE user_id=?" . " AND cache_key=?" . " AND uid=?", $_SESSION['user_id'], $key, $uid);
     if ($sql_arr = $this->db->fetch_assoc($sql_result)) {
         return intval($sql_arr['idx']);
     }
     return null;
 }
Esempio n. 5
0
 /**
  * Update user's last_login timestamp
  */
 function touch()
 {
     if ($this->ID) {
         $this->db->query("UPDATE " . get_table_name('users') . " SET last_login = "******" WHERE user_id = ?", $this->ID);
     }
 }
 private function read_squirrel_prefs($uname)
 {
     $rcmail = rcmail::get_instance();
     /**** File based backend ****/
     if ($rcmail->config->get('squirrelmail_driver') == 'file' && ($srcdir = $rcmail->config->get('squirrelmail_data_dir'))) {
         if (($hash_level = $rcmail->config->get('squirrelmail_data_dir_hash_level')) > 0) {
             $srcdir = slashify($srcdir) . chunk_split(substr(base_convert(crc32($uname), 10, 16), 0, $hash_level), 1, '/');
         }
         $prefsfile = slashify($srcdir) . $uname . '.pref';
         $abookfile = slashify($srcdir) . $uname . '.abook';
         $sigfile = slashify($srcdir) . $uname . '.sig';
         $sigbase = slashify($srcdir) . $uname . '.si';
         if (is_readable($prefsfile)) {
             $this->prefs = array();
             foreach (file($prefsfile) as $line) {
                 list($key, $value) = explode('=', $line);
                 $this->prefs[$key] = utf8_encode(rtrim($value));
             }
             // also read signature file if exists
             if (is_readable($sigfile)) {
                 $this->prefs['___signature___'] = utf8_encode(file_get_contents($sigfile));
             }
             if (isset($this->prefs['identities']) && $this->prefs['identities'] > 1) {
                 for ($i = 1; $i < $this->prefs['identities']; $i++) {
                     // read signature file if exists
                     if (is_readable($sigbase . $i)) {
                         $this->prefs['___sig' . $i . '___'] = utf8_encode(file_get_contents($sigbase . $i));
                     }
                 }
             }
             // parse addres book file
             if (filesize($abookfile)) {
                 foreach (file($abookfile) as $line) {
                     list($rec['name'], $rec['firstname'], $rec['surname'], $rec['email']) = explode('|', utf8_encode(rtrim($line)));
                     if ($rec['name'] && $rec['email']) {
                         $this->abook[] = $rec;
                     }
                 }
             }
         }
     } else {
         if ($rcmail->config->get('squirrelmail_driver') == 'sql') {
             $this->prefs = array();
             /* connect to squirrelmail database */
             $db = new rcube_mdb2($rcmail->config->get('squirrelmail_dsn'));
             $db->db_connect('r');
             // connect in read mode
             // $db->set_debug(true);
             /* retrieve prefs */
             $userprefs_table = $rcmail->config->get('squirrelmail_userprefs_table');
             $address_table = $rcmail->config->get('squirrelmail_address_table');
             $db_charset = $rcmail->config->get('squirrelmail_db_charset');
             if ($db_charset) {
                 $db->query('SET NAMES ' . $db_charset);
             }
             $sql_result = $db->query('SELECT * FROM ' . $userprefs_table . ' WHERE user=?', $uname);
             // ? is replaced with emailaddress
             while ($sql_array = $db->fetch_assoc($sql_result)) {
                 // fetch one row from result
                 $this->prefs[$sql_array['prefkey']] = rcube_charset_convert(rtrim($sql_array['prefval']), $db_charset);
             }
             /* retrieve address table data */
             $sql_result = $db->query('SELECT * FROM ' . $address_table . ' WHERE owner=?', $uname);
             // ? is replaced with emailaddress
             // parse addres book
             while ($sql_array = $db->fetch_assoc($sql_result)) {
                 // fetch one row from result
                 $rec['name'] = rcube_charset_convert(rtrim($sql_array['nickname']), $db_charset);
                 $rec['firstname'] = rcube_charset_convert(rtrim($sql_array['firstname']), $db_charset);
                 $rec['surname'] = rcube_charset_convert(rtrim($sql_array['lastname']), $db_charset);
                 $rec['email'] = rcube_charset_convert(rtrim($sql_array['email']), $db_charset);
                 $rec['note'] = rcube_charset_convert(rtrim($sql_array['label']), $db_charset);
                 if ($rec['name'] && $rec['email']) {
                     $this->abook[] = $rec;
                 }
             }
         }
     }
     // end if 'sql'-driver
 }
Esempio n. 7
0
 /**
  * Synchronizes the mailbox.
  *
  * @param string $mailbox Folder name
  */
 function synchronize($mailbox)
 {
     // RFC4549: Synchronization Operations for Disconnected IMAP4 Clients
     // RFC4551: IMAP Extension for Conditional STORE Operation
     //          or Quick Flag Changes Resynchronization
     // RFC5162: IMAP Extensions for Quick Mailbox Resynchronization
     // @TODO: synchronize with other methods?
     $qresync = $this->imap->get_capability('QRESYNC');
     $condstore = $qresync ? true : $this->imap->get_capability('CONDSTORE');
     if (!$qresync && !$condstore) {
         return;
     }
     // Get stored index
     $index = $this->get_index_row($mailbox);
     // database is empty
     if (empty($index)) {
         // set the flag that DB was already queried for index
         // this way we'll be able to skip one SELECT in get_index()
         $this->icache[$mailbox]['index_queried'] = true;
         return;
     }
     $this->icache[$mailbox]['index'] = $index;
     // no last HIGHESTMODSEQ value
     if (empty($index['modseq'])) {
         return;
     }
     // NOTE: make sure the mailbox isn't selected, before
     // enabling QRESYNC and invoking SELECT
     if ($this->imap->conn->selected !== null) {
         $this->imap->conn->close();
     }
     // Enable QRESYNC
     $res = $this->imap->conn->enable($qresync ? 'QRESYNC' : 'CONDSTORE');
     if (!is_array($res)) {
         return;
     }
     // Get mailbox data (UIDVALIDITY, HIGHESTMODSEQ, counters, etc.)
     $mbox_data = $this->imap->mailbox_data($mailbox);
     if (empty($mbox_data)) {
         return;
     }
     // Check UIDVALIDITY
     if ($index['validity'] != $mbox_data['UIDVALIDITY']) {
         $this->clear($mailbox);
         return;
     }
     // QRESYNC not supported on specified mailbox
     if (!empty($mbox_data['NOMODSEQ']) || empty($mbox_data['HIGHESTMODSEQ'])) {
         return;
     }
     // Nothing new
     if ($mbox_data['HIGHESTMODSEQ'] == $index['modseq']) {
         return;
     }
     // Get known uids
     $uids = array();
     $sql_result = $this->db->query("SELECT uid" . " FROM " . get_table_name('cache_messages') . " WHERE user_id = ?" . " AND mailbox = ?", $this->userid, $mailbox);
     while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
         $uids[] = $sql_arr['uid'];
     }
     // No messages in database, nothing to sync
     if (empty($uids)) {
         return;
     }
     // Get modified flags and vanished messages
     // UID FETCH 1:* (FLAGS) (CHANGEDSINCE 0123456789 VANISHED)
     $result = $this->imap->conn->fetch($mailbox, !empty($uids) ? $uids : '1:*', true, array('FLAGS'), $index['modseq'], $qresync);
     $invalidated = false;
     if (!empty($result)) {
         foreach ($result as $id => $msg) {
             $uid = $msg->uid;
             // Remove deleted message
             if ($this->skip_deleted && !empty($msg->flags['DELETED'])) {
                 $this->remove_message($mailbox, $uid);
                 if (!$invalidated) {
                     $invalidated = true;
                     // Invalidate thread indexes (?)
                     $this->remove_thread($mailbox);
                     // Invalidate index
                     $index['valid'] = false;
                 }
                 continue;
             }
             $flags = 0;
             if (!empty($msg->flags)) {
                 foreach ($this->flags as $idx => $flag) {
                     if (!empty($msg->flags[$flag])) {
                         $flags += $idx;
                     }
                 }
             }
             $this->db->query("UPDATE " . get_table_name('cache_messages') . " SET flags = ?, changed = " . $this->db->now() . " WHERE user_id = ?" . " AND mailbox = ?" . " AND uid = ?" . " AND flags <> ?", $flags, $this->userid, $mailbox, $uid, $flags);
         }
     }
     // Get VANISHED
     if ($qresync) {
         $mbox_data = $this->imap->mailbox_data($mailbox);
         // Removed messages
         if (!empty($mbox_data['VANISHED'])) {
             $uids = rcube_imap_generic::uncompressMessageSet($mbox_data['VANISHED']);
             if (!empty($uids)) {
                 // remove messages from database
                 $this->remove_message($mailbox, $uids);
                 // Invalidate thread indexes (?)
                 $this->remove_thread($mailbox);
                 // Invalidate index
                 $index['valid'] = false;
             }
         }
     }
     $sort_field = $index['sort_field'];
     $sort_order = $index['sort_order'];
     $exists = true;
     // Validate index
     if (!$this->validate($mailbox, $index, $exists)) {
         // Update index
         $data = $this->get_index_data($mailbox, $sort_field, $sort_order, $mbox_data);
     } else {
         $data = array_combine($index['seq'], $index['uid']);
     }
     // update index and/or HIGHESTMODSEQ value
     $this->add_index_row($mailbox, $sort_field, $sort_order, $data, $mbox_data, $exists);
     // update internal cache for get_index()
     $this->icache[$mailbox]['index']['result'] = $data;
 }