DMail Milestone 1.0
Drupal Mail Client
dmail.db.inc File Reference

Go to the source code of this file.

Functions

 mfn_dmail_db_identities_select ($user_id=NULL)
 mfn_dmail_db_identities_with_counts ()
 mfn_dmail_db_identity_update ($id, $values)
 mfn_dmail_db_identity_update_counts ($id, $messages, $recent)
 mfn_dmail_db_identity_add ($values)
 mfn_dmail_db_identity_delete ($id)
 mfn_dmail_db_identity_select ($id)
 mfn_dmail_db_identity_update_lastchkd ($id, $lastchkd)
 mfn_dmail_db_mbox_select_by_name ($identity_id, $mbox)
 mfn_dmail_db_mbox_select ($id)
 mfn_dmail_db_mbox_delete ($id)
 mfn_dmail_db_mboxes_select ($identity_id)
 mfn_dmail_db_mboxes_add ($identity, $mbox_data)
 mfn_dmail_db_mboxes_update ($id, $mbox_data)
 mfn_dmail_db_message_header_select ($msgid)
 mfn_dmail_db_message_header_add ($message_header)
 mfn_dmail_db_message_header_update ($message_header)
 mfn_dmail_db_mbox_message_header_select ($mbox_id, $msgid=NULL)
 mfn_dmail_db_mbox_message_headers_select_ordered ($mbox_id)
 mfn_dmail_db_mbox_message_header_add ($mbox_message_header)
 mfn_dmail_db_mbox_message_header_update ($mbox_message_header)
 mfn_dmail_db_mbox_message_headers_select ($mbox_id)
 mfn_dmail_db_mbox_message_headers_count ($mbox_id)
 mfn_dmail_db_junk_message_select ($msgid)
 mfn_dmail_db_junk_message_add ($msgid)
 mfn_dmali_db_junk_message_del ($msgid)
 mfn_dmail_db_headerinfo_select ($msgid)
 mfn_dmail_db_headerinfo_add ($headerinfo)
 mfn_dmail_db_headerinfo_delete ($msgid)
 mfn_dmail_db_addrmap_select ($address)
 mfn_dmail_db_signatures_select ()
 mfn_dmail_db_signature_select ($name_or_id)
 mfn_dmail_db_signatures_add ($values)

Detailed Description

Database routines.

Definition in file dmail.db.inc.


Function Documentation

mfn_dmail_db_addrmap_select ( address)

Select an individual email address map record.

Parameters:
$address
  • The email address to map.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 882 of file dmail.db.inc.

Referenced by mfn_dmail_addrmap().

                                               {
  global $user;
  $ns = array('db', 'addrmap', 'single');
  $cache = dcache_get($ns);
  if (isset($cache['row']) &&
      $cache['uid'] == $user->uid &&
      $cache['address'] == $address &&
      !dcache_expired($cache)
     ) {
    return $cache['row'];
  }
  $sql = "SELECT * FROM `{dmail_addrmap}` WHERE `user_id` = %d AND `address` = '%s'";
  $ret = db_fetch_object(db_query($sql, $user->uid, $address));
  dcache_set($ns, array('uid' => $user->uid, 'address' => $address, 'row' => $ret));
  return $ret;
}
mfn_dmail_db_headerinfo_add ( headerinfo)

Add a mail box header item information record.

Parameters:
$headerinfo
  • An object filled with the column data.
Returns:
  • The result of the database action.

Definition at line 850 of file dmail.db.inc.

Referenced by mfn_dmail_get_headerinfo().

                                                  {
  $sql = "INSERT INTO `{dmail_headerinfo}` (`msgid`, `headers`) VALUES ('%s', '%s') ON DUPLICATE KEY UPDATE `headers` = VALUES(`headers`)";
  $msgid = $headerinfo->msgid;
  unset($headerinfo->msgid);
  dcache_del(array('db', 'headerinfo'), DCACHE_ALL);
  return db_query($sql, $msgid, base64_encode(gzcompress(serialize($headerinfo))));
}
mfn_dmail_db_headerinfo_delete ( msgid)

Delete a mail box header item information record.

Parameters:
$msgid
  • The msgid column value.
Returns:
  • The result of the database action.

Definition at line 867 of file dmail.db.inc.

                                                {
  $sql = "DELETE FROM `{dmail_headerinfo}` WHERE `msgid` = '%s'";
  dcache_del(array('db', 'headerinfo'), DCACHE_ALL);
  return db_query($sql, $msgid);
}
mfn_dmail_db_headerinfo_select ( msgid)

Select an individual mail box header item information record.

Parameters:
$msgid
  • The msgid column value.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 823 of file dmail.db.inc.

Referenced by mfn_dmail_get_headerinfo().

                                                {
  $ns = array('db', 'headerinfo', 'single');
  $cache = dcache_get($ns);
  if (isset($cache['row']) &&
      $cache['msgid'] == $msgid &&
      !dcache_expired($cache)
     ) {
    return $cache['row'];
  }
  $sql = "SELECT * FROM `{dmail_headerinfo}` WHERE `msgid` = '%s'";
  $ret = db_fetch_object(db_query($sql, $msgid));
  if ($ret !== FALSE) {
    $ret->headers = unserialize(gzuncompress(base64_decode($ret->headers)));
  }
  dcache_set($ns, array('msgid' => $msgid, 'row' => $ret));
  return $ret;
}
mfn_dmail_db_identities_select ( user_id = NULL)

Identities for specified or current user.

Parameters:
$user_id
  • Optional uid.
Returns:
  • Array selected row objects or empty array on selection failure.

Definition at line 21 of file dmail.db.inc.

Referenced by mfn_dmail_block_identities(), mfn_dmail_refresh(), and mfn_dmail_reply_from().

                                                         {
  global $user;
  $ns = array('db', 'identities', 'full');
  $cmode = DCACHE_DRUPAL;
  $cache = dcache_get($ns, $cmode);
  if (isset($cache['rows']) && !dcache_expired($cache)) {
    return $cache['rows'];
  }
  if ($user_id === NULL) {
    $user_id = $user->uid;
  }
  $sql = "SELECT * FROM `{dmail_identities}` WHERE `user_id` = %d";
  $result = db_query($sql, $user_id);
  $rows = array();
  while ($row = db_fetch_object($result)) {
    $rows[] = $row;
  }
  dcache_set($ns, array('rows' => $rows), $cmode);
  return $rows;
}
mfn_dmail_db_identities_with_counts ( )

Identities with message counts.

Returns:
  • Array selected row objects or empty array on selection failure.

Definition at line 48 of file dmail.db.inc.

Referenced by mfm_dmail_identities().

                                               {
  global $user;
  $ns = array('db', 'identities', 'counts');
  $cmode = DCACHE_DRUPAL;
  $cache = dcache_get($ns, $cmode);
  if (isset($cache['rows']) && !dcache_expired($cache)) {
    return $cache['rows'];
  }
  $select = "
    SELECT 
      `dmail_identities`.`id` AS 'id', 
      `dmail_identities`.`name` AS 'name', 
      `dmail_identities`.`lastchkd` AS 'lastchkd',
      `dmail_identities`.`inbox` AS 'inbox',
      `dmail_identities`.`messages` AS 'messages',
      `dmail_identities`.`recent` AS 'recent'
    FROM
      `{dmail_identities}` AS `dmail_identities`
    WHERE
      `dmail_identities`.`user_id` = %d
    ORDER BY
      `dmail_identities`.`id`
  ";
  $resource = db_query($select, $user->uid);
  $return = array();
  while ($row = db_fetch_object($resource)) {
    $return[] = $row;
  }
  dcache_set($ns, array('rows' => $return), $cmode);
  return $return;
}
mfn_dmail_db_identity_add ( values)

Store identity data in database.

The dmail_mboxes record for the named inbox will also be added.

Parameters:
$values
  • An associative array of all the values for the columns to be updated.
  • The user_id column is always added as the global $user->uid value.
Returns:
  • An array of database action results.

Definition at line 173 of file dmail.db.inc.

References mfn_dmail_encrypt().

Referenced by mfm_dmail_identities_add_submit().

                                            {
  global $user;
  $sql = "INSERT INTO {dmail_identities} (`user_id`, `name`, `created`, `lastchkd`, `host`, `service`, `port`, `inbox`, `delimiter`, `encryption`, `vld8cert`, `expunge`, `readonly`, `movedel`, `user`, `pass`, `smtpport`, `sanitizedeleted`, `deletefolder`, `draftfolder`, `sentfolder`, `junkfolder`, `toplevel`, `messages`, `recent`) VALUES (%d, '%s', NOW(), '0000-00-00 00:00:00', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', %d, %d, %d )";
  $ret[] = db_query(
    $sql,
    $user->uid,
    $values['name'],
    $values['host'],
    $values['service'],
    $values['port'],
    $values['inbox'],
    $values['delimiter'],
    $values['encrypt'],
    $values['validate_cert'] == 'yes',
    $values['expunge'] == 'yes',
    $values['readonly'] == 'yes',
    $values['move_deleted'] == 'yes',
    $values['user'],
    mfn_dmail_encrypt($values['pass']),
    $values['smtp_port'],
    $values['sanitize_deleted'] == 'yes',
    $values['delete_folder'],
    $values['draft_folder'],
    $values['sent_folder'],
    $values['junk_folder'],
    $values['toplevel'],
    0,
    0
  );
  $identity_id = db_last_insert_id('dmail_identities', 'id');
  $ret[] = $identity_id;
  if ($values['inbox']) {
    $sql = "INSERT INTO {dmail_mboxes} (`identity_id`, `name`, `created`) VALUES (%d, '%s', NOW())";
    $ret[] = db_query($sql, $identity_id, $values['inbox']);
  }
  dcache_del(array('db', 'identities'), DCACHE_ALL);
  dcache_del(array('db', 'mboxes'), DCACHE_ALL);
  return $ret;
}
mfn_dmail_db_identity_delete ( id)

Delete an individual identity from the database.

Parameters:
$id
  • The primary key for the identity.
Returns:
  • The result of the database action.
Todo:
Use $user->uid in the selection parameters to ensure only the authenticated user can remove his records.

Definition at line 225 of file dmail.db.inc.

Referenced by mfn_dmail_remove_identity().

                                           {
  $sql = "DELETE FROM `{dmail_identities}` WHERE `id` = %d";
  dcache_del(array('db', 'identities'), DCACHE_ALL);
  return db_query($sql, $id);
}
mfn_dmail_db_identity_select ( id)

Select an individual identity record.

Parameters:
$id
  • The primary key for the identity.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 240 of file dmail.db.inc.

Referenced by mfm_dmail_display_folders(), mfm_dmail_display_headers(), mfm_dmail_display_item(), mfm_dmail_identities_add_validate(), mfm_dmail_identities_edit(), mfm_dmail_identities_edit_submit(), mfm_dmail_send_action(), mfn_dmail_block_item_link(), mfn_dmail_db_identity_update(), mfn_dmail_db_identity_update_counts(), mfn_dmail_db_mbox_delete(), mfn_dmail_db_mboxes_update(), mfn_dmail_expunge_mailboxes(), mfn_dmail_get_headers(), mfn_dmail_get_mail(), mfn_dmail_get_mailboxes(), mfn_dmail_imap_open(), mfn_dmail_readonly_check(), mfn_dmail_remove_identity(), mfn_dmail_sanitize_mailboxes(), and mfn_dmail_signature().

                                           {
  global $user;
  $ns = array('db', 'identities', 'single');
  $cache = dcache_get($ns);
  if (isset($cache['row']) &&
      isset($cache['id']) &&
      $cache['id'] == $id &&
      !dcache_expired($cache)
     ) {
    return $cache['row'];
  }
  $sql = "SELECT * FROM `{dmail_identities}` WHERE `id` = %d and `user_id` = %d";
  $return = db_fetch_object(db_query($sql, $id, $user->uid));
  dcache_set($ns, array('id' => $id, 'row' => $return));
  return $return;
}
mfn_dmail_db_identity_update ( id,
values 
)

Updated the identity data stored in the database.

If the inbox changes then the dmail_mboxes record for the inbox will also be updated. The messages and recent columns are not updated here and are updated with mfn_dmail_db_identity_update_counts() instead.

Parameters:
$id
  • The primary key for the identity.
$values
  • An associative array of all the values for the columns to be updated.
Returns:
  • An array of database action results.

Definition at line 96 of file dmail.db.inc.

References mfn_dmail_db_identity_select(), mfn_dmail_db_mbox_select_by_name(), and mfn_dmail_encrypt().

Referenced by mfm_dmail_identities_edit_submit().

                                                    {
  global $user;
  $identity = mfn_dmail_db_identity_select($id);
  $sql = "UPDATE {dmail_identities} SET `name` = '%s', `host` = '%s', `service` = '%s', `port` = %d, `inbox` = '%s', `delimiter` = '%s', `encryption` = '%s', `vld8cert` = %d, `expunge` = %d, `readonly` = %d, `movedel` = %d, `user` = '%s', `pass` = '%s', `smtpport` = %d, `sanitizedeleted` = %d, `deletefolder` = '%s', `draftfolder` = '%s', `sentfolder` = '%s', `junkfolder` = '%s', `toplevel` = %d WHERE id = %d";
  $ret[] = db_query(
    $sql,
    $values['name'],
    $values['host'],
    $values['service'],
    $values['port'],
    $values['inbox'],
    $values['delimiter'],
    $values['encrypt'],
    $values['validate_cert'] == 'yes',
    $values['expunge'] == 'yes',
    $values['readonly'] == 'yes',
    $values['move_deleted'] == 'yes',
    $values['user'],
    mfn_dmail_encrypt($values['pass']),
    $values['smtp_port'],
    $values['sanitize_deleted'] == 'yes',
    $values['delete_folder'],
    $values['draft_folder'],
    $values['sent_folder'],
    $values['junk_folder'],
    $values['toplevel'],
    $id
  );
  if ($values['inbox'] !== $identity->inbox) {
    $inbox = mfn_dmail_db_mbox_select_by_name($id, $identity->inbox);
    $sql = "UPDATE {dmail_mboxes} SET `name` = '%s' WHERE `id` = %d";
    $ret[] = db_query($sql, $values['inbox'], $inbox->id);
    dcache_del(array('db', 'mboxes'), DCACHE_ALL);
  }
  dcache_del(array('db', 'identities'), DCACHE_ALL);
  return $ret;
}
mfn_dmail_db_identity_update_counts ( id,
messages,
recent 
)

Updated the identity data stored in the database.

Parameters:
$id
  • The primary key for the identity.
$messages
  • The total number of messages in all mailboxes.
$recent
  • The total of recent messages in all mailboxes.
Returns:
  • The database action results.

Definition at line 149 of file dmail.db.inc.

References mfn_dmail_db_identity_select().

Referenced by mfn_dmail_db_mbox_delete(), mfn_dmail_db_mboxes_add(), and mfn_dmail_db_mboxes_update().

                                                                      {
  $sql = "UPDATE {dmail_identities} SET `messages` = %d, `recent` = %d WHERE id = %d";
  $identity = mfn_dmail_db_identity_select($id);
  $messages = ($messages < 0) ? 0 : $messages;
  $recent = ($recent < 0) ? 0 : $recent;
  if ($identity->messages != $messages ||
      $identity->recent != $recent) {
    dcache_del(array('db', 'identities'), DCACHE_ALL);
    return db_query($sql, $messages, $recent, $id);
  }
}
mfn_dmail_db_identity_update_lastchkd ( id,
lastchkd 
)

Update lastchkd column of specified identity row.

Parameters:
$id
  • The primary key for the identity.
$lastchkd
  • A date string in the form of Y-m-d H:i:s.
Returns:
  • The result of the database action.

Definition at line 269 of file dmail.db.inc.

Referenced by mfn_dmail_get_mail(), and mfn_dmail_get_newmail().

                                                               {
  $sql = "UPDATE `{dmail_identities}` SET `lastchkd` = '%s' WHERE `id` = %d";
  dcache_del(array('db', 'identities'), DCACHE_ALL);
  return db_query($sql, $lastchkd, $id);
}
mfn_dmail_db_junk_message_add ( msgid)

Add a junk message record.

Parameters:
$msgid
  • The msgid column value.
Returns:
  • The result of the database action.

Definition at line 791 of file dmail.db.inc.

                                               {
  global $user;
  $sql = "INSERT INTO `{dmail_junk_messages}` (`user_id`, `msgid`) VALUES (%d, '%s')";
  dcache_del(array('db', 'junk_messages'), DCACHE_ALL);
  return db_query($sql, $user->uid, $msgid);
}
mfn_dmail_db_junk_message_select ( msgid)

Select an individual junk message record.

Parameters:
$msgid
  • The msgid column value.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 765 of file dmail.db.inc.

Referenced by mfn_dmail_is_junk().

                                                  {
  global $user;
  $ns = array('db', 'junk_messages', 'single');
  $cache = dcache_get($ns);
  if (isset($cache['row']) &&
      $cache['uid'] == $user->uid &&
      $cache['msgid'] == $msgid &&
      !dcache_expired($cache)
     ) {
    return $cache['row'];
  }
  $sql = "SELECT * FROM `{dmail_junk_messages}` WHERE `user_id` = %d AND `msgid` = '%s'";
  $row = db_fetch_object(db_query($sql, $user->uid, $msgid));
  dcache_set($ns, array('uid' => $user->uid, 'msgid' => $msgid, 'row' => $row));
  return $row;
}
mfn_dmail_db_mbox_delete ( id)

Delete an individual mail box from the database.

Parameters:
$id
  • The primary key for the mail box.
Returns:
  • The result of the database action.

Definition at line 336 of file dmail.db.inc.

References mfn_dmail_db_identity_select(), mfn_dmail_db_identity_update_counts(), and mfn_dmail_db_mbox_select().

Referenced by mfn_dmail_preprocess_mboxes(), and mfn_dmail_remove_identity().

                                       {
  $sql = "DELETE FROM `{dmail_mboxes}` WHERE `id` = %d";
  $mbox = mfn_dmail_db_mbox_select($id);
  $identity = mfn_dmail_db_identity_select($mbox->identity_id);
  $identity->messages -= $mbox->messages;
  $identity->recent -= $mbox->recent;
  mfn_dmail_db_identity_update_counts($identity->id, $identity->messages, $identity->recent);
  dcache_del(array('db', 'mboxes'), DCACHE_ALL);
  return db_query($sql, $id);
}
mfn_dmail_db_mbox_message_header_add ( mbox_message_header)

Add the mbox message header.

Parameters:
$mbox_message_header
  • An object of mbox_message_header parameters.
Returns:
  • The result of the query, FALSE on error.

Definition at line 677 of file dmail.db.inc.

References mfn_dmail_db_mbox_message_header_select().

Referenced by mfn_dmail_process_header().

                                                                    {
  $mmh =& $mbox_message_header;
  $mh = mfn_dmail_db_mbox_message_header_select($mmh->mbox_id, $mmh->msgid);
  if ($mh !== FALSE) {
    return FALSE;
  }
  $sql = "INSERT INTO `{dmail_mbox_message_headers}` (`mbox_id`, `msgid`, `uid`, `msgno`, `recent`, `flagged`, `answered`, `deleted`, `seen`, `draft`, `display`, `created`, `updated`) VALUES (%d, '%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, NOW(), NOW())";
  $result = db_query($sql, $mmh->mbox_id, $mmh->msgid, $mmh->uid, $mmh->msgno, $mmh->recent, $mmh->flagged, $mmh->answered, $mmh->deleted, $mmh->seen, $mmh->draft, $mmh->display);
  dcache_del(array('db', 'mbox_message_headers'), DCACHE_ALL);
  return $result;
}
mfn_dmail_db_mbox_message_header_select ( mbox_id,
msgid = NULL 
)

Select a mbox message header row.

Parameters:
$mbox_id
  • The primary key for the mail box or the primary key of the mbox_message_header.
$msgid
  • The unique message identification string
  • md5 of from and md5 of message_id in mail header.
  • Optional if the primary key of the mbox_message_header is given.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 549 of file dmail.db.inc.

References mfn_dmail_db_message_header_select().

Referenced by mfm_dmail_reply_item(), mfm_dmail_replyall_item(), mfm_dmail_replylist_item(), mfm_dmail_replyto_item(), mfn_dmail_db_mbox_message_header_add(), mfn_dmail_db_mbox_message_header_update(), and mfn_dmail_process_header().

                                                                          {
  $ns = array('db', 'mbox_message_headers', 'single');
  $cmode = DCACHE_DRUPAL;
  $cache = dcache_get($ns, $cmode);
  if ($msgid === NULL) {
    if ($cache['row'] && $cache['row']->id == $mbox_id && !dcache_expired($cache)) {
      return $cache['row'];
    }
    $sql = "SELECT * from `{dmail_mbox_message_headers}` WHERE `id` = %d";
    $mbox_header = db_fetch_object(db_query($sql, $mbox_id));
    if ($mbox_header !== FALSE) {
      $header = mfn_dmail_db_message_header_select($mbox_header->msgid);
      foreach((array)$header as $key => $param) {
        if (!isset($mbox_header->$key)) {
          $mbox_header->$key = $header->$key;
        }
      }
      $cache['row'] = $mbox_header;
    }
    else {
      $cache['row'] = FALSE;
    }
  }
  else {
    if ($cache['row'] && $cache['row']->mbox_id == $mbox_id && $cache['row']->msgid == $msgid && !dcache_expired($cache)) {
      return $cache['row'];
    }
    $sql = "SELECT * from `{dmail_mbox_message_headers}` WHERE `mbox_id` = %d AND `msgid` = '%s'";
    $cache['row'] = db_fetch_object(db_query($sql, $mbox_id, $msgid));
  }
  $row =& $cache['row'];
  $row = $row === NULL ? FALSE : $row;
  dcache_set($ns, $cache, $cmode);
  return $row;
}
mfn_dmail_db_mbox_message_header_update ( mbox_message_header)

Update the mbox message header

Parameters:
$mbox_message_header
  • An object of mbox_message_header parameters.
Returns:
  • The result of the query, FALSE on error or NULL if not attempted.

Definition at line 698 of file dmail.db.inc.

References mfn_dmail_db_mbox_message_header_select().

Referenced by mfn_dmail_process_header().

                                                                       {
  $mmh =& $mbox_message_header;
  $mh = mfn_dmail_db_mbox_message_header_select($mmh->mbox_id, $mmh->msgid);
  if ($mh === FALSE) {
    return FALSE;
  }
  $result = NULL;
  if ($mh->uid != $mmh->uid ||
      $mh->msgno != $mmh->msgno ||
      $mh->recent != $mmh->recent ||
      $mh->flagged != $mmh->flagged ||
      $mh->answered != $mmh->answered ||
      $mh->deleted != $mmh->deleted ||
      $mh->seen != $mmh->seen ||
      $mh->draft != $mmh->draft ||
      $mh->display != $mmh->display) {
    $sql = "UPDATE `{dmail_mbox_message_headers}` SET `uid` = '%s', `msgno` = '%s', `recent` = %d, `flagged` = %d, `answered` = %d, `deleted` = %d, `seen` = %d, `draft` = %d, `display` = %d, `updated` = NOW() WHERE `mbox_id` = %d and `msgid` = '%s'";
    $result = db_query($sql, $mmh->uid, $mmh->msgno, $mmh->recent, $mmh->flagged, $mmh->answered, $mmh->deleted, $mmh->seen, $mmh->draft, $mmh->display, $mmh->mbox_id, $mmh->mbox_id);
  }
  return $result;
}
mfn_dmail_db_mbox_message_headers_count ( mbox_id)

Get a count of mail box item headers.

Definition at line 751 of file dmail.db.inc.

Referenced by mfm_dmail_display_headers().

                                                           {
  $sql = "SELECT COUNT(1) as \"count\" FROM `{dmail_mbox_message_headers}` WHERE `mbox_id` = %d";
  return db_result(db_query($sql, $mbox_id));
}
mfn_dmail_db_mbox_message_headers_select ( mbox_id)

Select a mbox message header row.

Parameters:
$mbox_id
  • The primary key for the mail box.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 729 of file dmail.db.inc.

                                                            {
  $ns = array('db', 'mbox_message_headers', 'full');
  $cmode = DCACHE_DRUPAL;
  $cache = dcache_get($ns, $cmode);
  if ($cache['rows'] && $cache['mbox_id'] == $mbox_id && !dcache_expired($cache)) {
    return $cache['rows'];
  }
  $sql = "SELECT * from `{dmail_mbox_message_headers}` WHERE `mbox_id` = %d";
  $result = db_query($sql, $mbox_id);
  $rows = array();
  while ($row = db_fetch_object($result)) {
    $rows = $row;
  }
  $cache['rows'] = $rows;
  $cache['mbox_id'] = $mbox_id;
  dcache_set($ns, $cache, $cmode);
  return $cache['rows'];
}
mfn_dmail_db_mbox_message_headers_select_ordered ( mbox_id)

Select all mbox message headers ordered by user request.

Parameters:
$mbox_id
  • The primary key for the mail box.

Definition at line 591 of file dmail.db.inc.

References mfn_dmail_items_list_header().

Referenced by mfm_dmail_display_headers(), mfm_dmail_display_item(), and mfn_dmail_options_addr().

                                                                    {
  global $pager_page_array, $pager_total, $pager_total_items;
  $sortdir =& $_GET['sort'];
  $sortcol =& $_GET['order'];
  $ns = array('db', 'mbox_message_headers', 'ordered');
  $cmode = DCACHE_DRUPAL;
  $cache = dcache_get($ns, $cmode);
  if (isset($cache['rows']) &&
      $cache['mbox_id'] == $mbox_id &&
      $cache['sortcol'] == $sortcol &&
      $cache['sortdir'] == $sortdir &&
      !dcache_expired($cache)
     ) {
    $pager_page_array = $cache['pager_page_array'];
    $pager_total = $cache['pager_total'];
    $pager_total_items = $cache['pager_total_items'];
    return $cache['rows'];
  }
  $sql = "SELECT mmh.`id` AS \"id\",
                 mmh.`mbox_id` AS \"mbox_id\",
                 mmh.`msgid` AS \"msgid\",
                 mh.`from` AS \"from\",
                 mh.`to` AS \"to\",
                 mh.`subject` AS \"subject\",
                 mh.`re` AS \"re\",
                 mh.`date` AS \"date\",
                 mh.`size` AS \"size\",
                 mh.`message_id` AS \"message_id\",
                 mh.`created` AS \"header_created\",
                 mh.`updated` AS \"header_updated\",
                 mmh.`uid` AS \"uid\",
                 mmh.`msgno` AS \"msgno\",
                 mmh.`recent` AS \"recent\",
                 mmh.`flagged` AS \"flagged\",
                 mmh.`answered` AS \"answered\",
                 mmh.`deleted` AS \"deleted\",
                 mmh.`seen` AS \"seen\",
                 mmh.`draft` AS \"draft\",
                 mmh.`display` AS \"display\",
                 mmh.`created` AS \"mbox_header_created\",
                 mmh.`updated` as \"mbox_header_updated\"
          FROM `{dmail_mbox_message_headers}` AS mmh
          JOIN `{dmail_message_headers}` AS mh ON mh.`msgid` = mmh.`msgid`
          WHERE mmh.`mbox_id` = %d
         ";
  $sortby = $sortcol;
  foreach (mfn_dmail_items_list_header() as $data) {
    if ($data['data'] == $sortcol) {
      $sortby = $data['field'];
      break;
    }
  }
  $sql .= " ORDER BY `{$sortby}` {$sortdir}, `date` ASC ";
  $result = db_query($sql, $mbox_id);
  $rows = array();
  while ($row = db_fetch_object($result)) {
    $row->current_id = count($rows);
    $row->prev_id = $row->current_id ? $row->current_id - 1 : NULL;
    $row->next_id = $row->current_id + 1;
    $row->subject = $row->re ? "Re: {$row->subject}" : $row->subject;
    $rows[] = $row;
  }
  if (count($rows)) {
    $rows[count($rows) - 1]->next_id = NULL;
  }
  dcache_set($ns, array(
    'mbox_id' => $mbox_id,
    'sortdir' => $sortdir,
    'sortcol' => $sortcol,
    'rows' => $rows,
    'pager_page_array' => $pager_page_array,
    'pager_total' => $pager_total,
    'pager_total_items' => $pager_total_items,
  ), $cmode);
  return $rows;
}
mfn_dmail_db_mbox_select ( id)

Select an individual mail box record.

Parameters:
$id
  • The primary key for the mail box.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 312 of file dmail.db.inc.

Referenced by mfm_dmail_display_headers(), mfm_dmail_display_item(), mfn_dmail_block_item_link(), mfn_dmail_db_mbox_delete(), mfn_dmail_db_mboxes_update(), and mfn_dmail_get_headers().

                                       {
  $ns = array('db', 'mboxes', 'single');
  $cache = dcache_get($ns);
  if (isset($cache['row']) &&
      $cache['id'] == $id &&
      !dcache_expired($cache)
     ) {
    return $cache['row'];
  }
  $sql = "SELECT * FROM `{dmail_mboxes}` WHERE `id` = %d";
  $row = db_fetch_object(db_query($sql, $id));
  dcache_set($ns, array('id' => $id, 'row' => $row));
  return $row;
}
mfn_dmail_db_mbox_select_by_name ( identity_id,
mbox 
)

Select the named mail box for the given identity_id.

Parameters:
$identity_id
  • The primary key for the identity.
$mbox
  • A string representing the full path of the mail box.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 287 of file dmail.db.inc.

Referenced by mfn_dmail_db_identity_update(), mfn_dmail_get_newmail(), and mfn_dmail_process_mbox().

                                                               {
  $ns = array('db', 'mboxes', 'by_name');
  $cache = dcache_get($ns);
  if (isset($cache['row']) && 
      $cache['identity_id'] == $identity_id &&
      $cache['mbox_name'] == $mbox &&
      !dcache_expired($cache)
     ) {
    return $cache['row'];
  }
  $sql = "SELECT * FROM `{dmail_mboxes}` WHERE `identity_id` = %d and `name` = '%s'";
  $row = db_fetch_object(db_query($sql, $identity_id, $mbox));
  dcache_set($ns, array('identity_id' => $row->identity_id, 'mbox_name' => $row->name, 'row' => $row));
  return $row;
}
mfn_dmail_db_mboxes_add ( identity,
mbox_data 
)

Add a mbox record.

Parameters:
$identity
  • The identity object for the mail box being inserted.
$mbox_data
  • An object filled with the column data.
Returns:
  • The id of the inserted row or FALSE on failure.

Definition at line 388 of file dmail.db.inc.

References mfn_dmail_db_identity_update_counts().

Referenced by mfn_dmail_process_mbox().

                                                        {
  if ($mbox_data->no_server_in_name) {
    $name = $mbox_data->name;
  }
  else {
    list(, $name) = explode('}', $mbox_data->name);
  }
  $sql = "INSERT INTO `{dmail_mboxes}` (`identity_id`, `name`, `created`, `lastchkd`, `attributes`, `flags`, `messages`, `recent`, `unseen`) VALUES (%d, '%s', NOW(), NOW(), %d, %d, %d, %d, %d)";
  $result = db_query($sql, $identity->id, $name, $mbox_data->attributes, $mbox_data->flags, $mbox_data->messages, $mbox_data->recent, $mbox_data->unseen);
  if ($result) {
    $id = db_last_insert_id('dmail_mboxes', 'id');
  }
  else {
    $id = FALSE;
  }
  if ($id !== FALSE) {
    $identity->messages += $mbox_data->messages;
    $identity->recent += $mbox_data->recent;
    mfn_dmail_db_identity_update_counts($identity->id, $identity->messages, $identity->recent);
  }
  dcache_del(array('db', 'mboxes'), DCACHE_ALL);
  return $id;
}
mfn_dmail_db_mboxes_select ( identity_id)

All mail boxes for specified identity.

Parameters:
$identity_id
  • The primary key for the identity.
Returns:
  • Array selected row objects or empty array on selection failure.

Definition at line 356 of file dmail.db.inc.

Referenced by mfm_dmail_display_folders(), mfn_dmail_block_identities(), mfn_dmail_get_mail(), mfn_dmail_preprocess_mboxes(), mfn_dmail_remove_identity(), and mfn_dmail_sanitize_mailboxes().

                                                  {
  $ns = array('db', 'mboxes', 'full');
  $cmode = DCACHE_DRUPAL;
  $cache = dcache_get($ns, $cmode);
  if (isset($cache['rows']) &&
      $cache['identity_id'] == $identity_id &&
      !dcache_expired($cache)
     ) {
    return $cache['rows'];
  }
  $sql = "SELECT * FROM `{dmail_mboxes}` WHERE `identity_id` = %d ORDER BY `name`";
  $result = db_query($sql, $identity_id);
  $rows = array();
  while ($row = db_fetch_object($result)) {
    $rows[] = $row;
  }
  dcache_set($ns, array('identity_id' => $identity_id, 'rows' => $rows), $cmode);
  return $rows;
}
mfn_dmail_db_mboxes_update ( id,
mbox_data 
)

Update a mbox record.

Parameters:
$id
  • The primary key for the mail box.
$mbox_data
  • An object filled with the column data.
Returns:
  • The result of the database action.

Definition at line 424 of file dmail.db.inc.

References mfn_dmail_db_identity_select(), mfn_dmail_db_identity_update_counts(), and mfn_dmail_db_mbox_select().

Referenced by mfn_dmail_get_newmail(), and mfn_dmail_process_mbox().

                                                     {
  $sql = "UPDATE `{dmail_mboxes}` SET `attributes` = %d, `flags` = %d, `messages` = %d, `recent` = %d, `unseen` = %d, `lastchkd` = '%s' WHERE `id` = %d";
  $mbox = mfn_dmail_db_mbox_select($id);
  if ($mbox->messages != $mbox_data->messages &&
      $mbox->recent != $mbox_data->recent &&
      $mbox->unseen != $mbox_data->unseen &&
      $mbox->attributes != $mbox_data->attributes &&
      $mbox->flags != $mbox_data->flags) {
    $identity = mfn_dmail_db_identity_select($mbox->identity_id);
    if ($mbox->messages != $mbox_data->messages) {
      $identity->messages = ((($identity->messages -= $mbox->messages) < 0) ? 0 : $identity->messages) + $mbox_data->messages;
    }
    if ($mbox->recent != $mbox_data->recent) {
      $identity->recent = ((($identity->recent -= $mbox->recent) < 0) ? 0 : $identity->recent) + $mbox_data->recent;
    }
    $ret = db_query($sql, $mbox_data->attributes, $mbox_data->flags, $mbox_data->messages, $mbox_data->recent, $mbox_data->unseen, $mbox_data->lastchkd, $id);
    mfn_dmail_db_identity_update_counts($identity->id, $identity->messages, $identity->recent);
    dcache_del(array('db', 'mboxes'), DCACHE_ALL);
  }
  return $ret;
}
mfn_dmail_db_message_header_add ( message_header)

Add a message header row.

Parameters:
$message_header
  • An object of message header parameters.
Returns:
  • The result of the query, FALSE on error.

Definition at line 483 of file dmail.db.inc.

References mfn_dmail_datetime(), mfn_dmail_db_message_header_select(), and mfn_dmail_subject_re().

Referenced by mfn_dmail_process_header().

                                                          {
  $mmh =& $message_header;
  $mh = mfn_dmail_db_message_header_select($mmh->msgid);
  if ($mh !== FALSE) {
    return FALSE;
  }
  $mmh->date = mfn_dmail_datetime($mmh->date);
  $sql = "INSERT INTO `{dmail_message_headers}` (`msgid`, `subject`, `re`, `from`, `to`, `date`, `message_id`, `size`, `created`, `updated`) VALUES ('%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', NOW(), NOW())";
  $s = mfn_dmail_subject_re($mmh->subject);
  $mmh->subject = $s->subject;
  $mmh->re = $s->re;
  $result = db_query($sql, $mmh->msgid, $mmh->subject, $mmh->re, $mmh->from, $mmh->to, $mmh->date, $mmh->message_id, $mmh->size);
  dcache_del(array('db', 'message_header'), DCACHE_ALL);
  return $result;
}
mfn_dmail_db_message_header_select ( msgid)

Select a message header row.

Parameters:
$msgid
  • The unique message identification string
  • md5 of from and md5 of message_id in mail header.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 456 of file dmail.db.inc.

Referenced by mfn_dmail_db_mbox_message_header_select(), mfn_dmail_db_message_header_add(), mfn_dmail_db_message_header_update(), and mfn_dmail_process_header().

                                                    {
  $ns = array('db', 'message_headers', 'single');
  $cmode = DCACHE_DRUPAL;
  $cache = dcache_get($ns, $cmode);
  if ($cache['row'] && $cache['row']->msgid == $msgid && !dcache_expired($cache)) {
    return $cache['row'];
  }
  $sql = "SELECT * from `{dmail_message_headers}` WHERE `msgid` = '%s'";
  $cache['row'] = db_fetch_object(db_query($sql, $msgid));
  $cache['row'] = $cache['row'] === NULL ? FALSE : $cache['row'];
  $row =& $cache['row'];
  if ($row->re) {
    $row->subject = "Re: {$row->subject}";
  }
  dcache_set($ns, $cache, $cmode);
  return $cache['row'];
}
mfn_dmail_db_message_header_update ( message_header)

Update the message header row.

Parameters:
$message_header
  • An object of message_header parameters.
Returns:
  • The result of the query, FALSE on error, or NULL if update wasn't attempted.

Definition at line 509 of file dmail.db.inc.

References mfn_dmail_datetime(), mfn_dmail_db_message_header_select(), and mfn_dmail_subject_re().

Referenced by mfn_dmail_process_header().

                                                             {
  $mmh =& $message_header;
  $sql = "UPDATE `{dmail_message_headers}` SET `subject` = '%s', `re` = %d, `from` = '%s', `to` = '%s', `date` = '%s', `message_id` = '%s', `size` = %d, `updated` = NOW() WHERE `msgid` = '%s'";
  $mh = mfn_dmail_db_message_header_select($message_header->msgid);
  if ($mh === FALSE) {
    return FALSE;
  }
  $result = NULL;
  $mmh->date = mfn_dmail_datetime($mmh->date);
  if ($mh->subject != $mmh->subject ||
      $mh->re != $mmh->re ||
      $mh->from != $mmh->from ||
      $mh->to != $mmh->to ||
      $mh->date != $mmh->date ||
      $mh->message_id != $mmh->message_id ||
      $mh->size != $mmh->size) {
    $s = mfn_dmail_subject_re($mmh->subject);
    $mmh->subject = $s->subject;
    $mmh->re = $s->re;
    $result = db_query($sql, $mmh->subject, $mmh->re, $mmh->from, $mmh->to, $mmh->date, $mmh->message->id, $mmh->size, $mmh->msgid);
    dcache_del(array('db', 'message_header'), DCACHE_ALL);
  }
  return $result;
}
mfn_dmail_db_signature_select ( name_or_id)

Select an individual signature record by name or id.

Parameters:
$name_or_id
  • The signature primary key or a specified signature name.
Returns:
  • The database row object or FALSE on selection error.

Definition at line 935 of file dmail.db.inc.

Referenced by mfm_dmail_signatures_add_validate(), mfn_dmail_form_default(), and mfn_dmail_signature().

                                                    {
  global $user;
  $ns = array('db', 'signatures', 'single');
  $cache = dcache_get($ns);
  if (isset($cache['row']) &&
      $cache['name'] == $name_or_id &&
      !dcache_expired($cache) 
     ) {
    return $cache['row'];
  }
  if (is_numeric($name_or_id)) {
    $sql = "SELECT * FROM `{dmail_signatures}` WHERE `user_id` = %d AND `id` = %d";
  }
  else {
    $sql = "SELECT * FROM `{dmail_signatures}` WHERE `user_id` = %d AND `name` = '%s'";
  }
  $row = db_fetch_object(db_query($sql, $user->uid, $name_or_id));
  dcache_set($ns, array('name' => $name_or_id, 'row' => $row));
  return $row;
}
mfn_dmail_db_signatures_add ( values)

Add a signature record.

Parameters:
$values
  • An array of user specified values.
Returns:
  • The id of the inserted row or FALSE on failure.

Definition at line 965 of file dmail.db.inc.

Referenced by mfm_dmail_signatures_add_submit().

                                              {
  global $user;
  $sql = "INSERT INTO `{dmail_signatures}` (`user_id`, `name`, `signature`, `created`, `updated`) VALUES (%d, '%s', '%s', NOW(), NOW())";
  $result = db_query($sql, $user->uid, $values['name'], $values['signature']);
  if ($result !== FALSE) {
    $result = db_last_insert_id('dmail_signatures', 'id');
  }
  dcache_del(array('db', 'signatures'), DCACHE_ALL);
  return $result;
}
mfn_dmail_db_signatures_select ( )

All signature records for the authenticated user.

Returns:
  • Array selected row objects or empty array on selection failure.

Definition at line 905 of file dmail.db.inc.

Referenced by mfm_dmail_signatures(), and mfn_dmail_form_options().

                                          {
  global $user;
  $ns = array('db', 'signatures', 'full');
  $cmode = DCACHE_DRUPAL;
  $cache = dcache_get($ns, $cmode);
  if (isset($cache['rows']) &&
      $cache['uid'] == $user->uid &&
      !dcache_expired($cache)
     ) {
    return $cache['rows'];
  }
  $sql = "SELECT * FROM `{dmail_signatures}` WHERE `user_id` = %d";
  $result = db_query($sql, $user->uid);
  $rows = array();
  while ($row = db_fetch_object($result)) {
    $rows[$row->id] = $row;
  }
  dcache_set($ns, array('uid' => $user->uid, 'rows' => $rows), $cmode);
  return $rows;
}
mfn_dmali_db_junk_message_del ( msgid)

Delete a junk message record.

Parameters:
$msgid
  • The msgid column value.
Returns:
  • The result of the database action.

Definition at line 807 of file dmail.db.inc.

                                               {
  global $user;
  $sql = "DELETE FROM `{dmail_junk_messages}` WHERE `user_id` = %d AND `msgid` = '%s'";
  dcache_del(array('db', 'junk_messages'), DCACHE_ALL);
  return db_query($sql, $user->uid, $msgid);
}
All Data Structures Files Functions Variables Enumerations