diff options
author | thomascube <thomas@roundcube.net> | 2005-12-03 16:54:12 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2005-12-03 16:54:12 +0000 |
commit | 1cded85790206afe084e1baff371c543711b2b18 (patch) | |
tree | b050fb89707e048df5f30f500faad792962a1e81 /program/steps/mail | |
parent | 5bc8cb662fc3bcda9aa641b7a5e88c0b81dd63d6 (diff) |
Re-design of caching (new database table added\!); some bugfixes; Postgres support
Diffstat (limited to 'program/steps/mail')
-rw-r--r-- | program/steps/mail/addcontact.inc | 8 | ||||
-rw-r--r-- | program/steps/mail/compose.inc | 182 | ||||
-rw-r--r-- | program/steps/mail/func.inc | 121 | ||||
-rw-r--r-- | program/steps/mail/sendmail.inc | 15 |
4 files changed, 199 insertions, 127 deletions
diff --git a/program/steps/mail/addcontact.inc b/program/steps/mail/addcontact.inc index ad1544e71..b1129ec9d 100644 --- a/program/steps/mail/addcontact.inc +++ b/program/steps/mail/addcontact.inc @@ -32,7 +32,7 @@ if ($_GET['_address']) $sql_result = $DB->query("SELECT 1 FROM ".get_table_name('contacts')." WHERE user_id=? AND email=? - AND del<>'1'", + AND del<>1", $_SESSION['user_id'],$contact['mailto']); // contact entry with this mail address exists @@ -42,13 +42,13 @@ if ($_GET['_address']) else if ($contact['mailto']) { $DB->query("INSERT INTO ".get_table_name('contacts')." - (user_id, changed, name, email) - VALUES (?, now(), ?, ?)", + (user_id, changed, del, name, email) + VALUES (?, now(), 0, ?, ?)", $_SESSION['user_id'], $contact['name'], $contact['mailto']); - $added = $DB->insert_id(); + $added = $DB->insert_id(get_sequence_name('contacts')); } } diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 9509b492b..45f111263 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -88,50 +88,20 @@ function rcmail_compose_headers($attrib) switch ($part) { case 'from': - // pass the following attributes to the form class - $field_attrib = array('name' => '_from'); - foreach ($attrib as $attr => $value) - if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) - $field_attrib[$attr] = $value; - - // get this user's identities - $sql_result = $DB->query("SELECT identity_id, name, email - FROM ".get_table_name('identities')." WHERE user_id=? - AND del<>'1' - ORDER BY ".$DB->quoteIdentifier('default')." DESC, name ASC", - $_SESSION['user_id']); - - if ($DB->num_rows($sql_result)) - { - $select_from = new select($field_attrib); - while ($sql_arr = $DB->fetch_assoc($sql_result)) - $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $sql_arr['identity_id']); - - $out = $select_from->show($_POST['_from']); - } - else - { - $input_from = new textfield($field_attrib); - $out = $input_from->show($_POST['_from']); - } - - if ($form_start) - $out = $form_start.$out; - - return $out; - + return rcmail_compose_header_from($attrib); case 'to': $fname = '_to'; $header = 'to'; - + // we have contact id's as get parameters - if (!empty($_GET['_to']) && preg_match('/[0-9]+,?/', $_GET['_to'])) + if (!empty($_GET['_to']) && preg_match('/^([0-9]+,?)+$/', $_GET['_to'])) { $a_recipients = array(); $sql_result = $DB->query("SELECT name, email - FROM ".get_table_name('contacts')." WHERE user_id=? - AND del<>'1' + FROM ".get_table_name('contacts')." + WHERE user_id=? + AND del<>1 AND contact_id IN (".$_GET['_to'].")", $_SESSION['user_id']); @@ -229,71 +199,91 @@ function rcmail_compose_headers($attrib) } -/*function rcube_compose_headers($attrib) - { - global $CONFIG, $OUTPUT; - - list($form_start, $form_end) = get_form_tags($attrib); - - // allow the following attributes to be added to the headers table - $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border')); - - $labels = array(); - $labels['from'] = rcube_label('from'); - $labels['to'] = rcube_label('to'); - $labels['cc'] = rcube_label('cc'); - $labels['bcc'] = rcube_label('bcc'); - $labels['replyto'] = rcube_label('replyto'); - - $input_from = new textfield(array('name' => '_from', 'size' => 30)); - $input_to = new textfield(array('name' => '_to', 'size' => 30)); - $input_cc = new textfield(array('name' => '_cc', 'size' => 30)); - $input_bcc = new textfield(array('name' => '_bcc', 'size' => 30)); - $input_replyto = new textfield(array('name' => '_replyto', 'size' => 30)); - - $fields = array(); - $fields['from'] = $input_from->show($_POST['_from']); - $fields['to'] = $input_to->show($_POST['_to']); - $fields['cc'] = $input_cc->show($_POST['_cc']); - $fields['bcc'] = $input_bcc->show($_POST['_bcc']); - $fields['replyto'] = $input_replyto->show($_POST['_replyto']); - - - $out = <<<EOF -$form_start -<table$attrib_str><tr> - -<td class="title">$labels[from]</td> -<td>$fields[from]</td> - -</tr><tr> - -<td class="title">$labels[to]</td> -<td>$fields[to]</td> -</tr><tr> +function rcmail_compose_header_from($attrib) + { + global $IMAP, $REPLY_MESSAGE, $DB, $OUTPUT, $JS_OBJECT_NAME; + + // pass the following attributes to the form class + $field_attrib = array('name' => '_from'); + foreach ($attrib as $attr => $value) + if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) + $field_attrib[$attr] = $value; + + // extract all recipients of the reply-message + $a_recipients = array(); + if ($REPLY_MESSAGE && is_object($REPLY_MESSAGE['headers'])) + { + $a_to = $IMAP->decode_address_list($REPLY_MESSAGE['headers']->to); + foreach ($a_to as $addr) + { + if (!empty($addr['mailto'])) + $a_recipients[] = $addr['mailto']; + } -<td class="title">$labels[cc]</td> -<td>$fields[cc]</td> + if (!empty($REPLY_MESSAGE['headers']->cc)) + { + $a_cc = $IMAP->decode_address_list($REPLY_MESSAGE['headers']->cc); + foreach ($a_cc as $addr) + { + if (!empty($addr['mailto'])) + $a_recipients[] = $addr['mailto']; + } + } + } -</tr><tr> + // get this user's identities + $sql_result = $DB->query("SELECT identity_id, name, email, signature + FROM ".get_table_name('identities')." + WHERE user_id=? + AND del<>1 + ORDER BY ".$DB->quoteIdentifier('standard')." DESC, name ASC", + $_SESSION['user_id']); + + if ($DB->num_rows($sql_result)) + { + $from_id = 0; + $a_signatures = array(); + + $field_attrib['onchange'] = "$JS_OBJECT_NAME.change_identity(this)"; + $select_from = new select($field_attrib); + + while ($sql_arr = $DB->fetch_assoc($sql_result)) + { + $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $sql_arr['identity_id']); -<td class="title">$labels[bcc]</td> -<td>$fields[bcc]</td> + // add signature to array + if (!empty($sql_arr['signature'])) + $a_signatures[$sql_arr['identity_id']] = $sql_arr['signature']; + + // set identity if it's one of the reply-message recipients + if (in_array($sql_arr['email'], $a_recipients)) + $from_id = $sql_arr['identity_id']; + } -</tr><tr> + // overwrite identity selection with post parameter + if (isset($_POST['_from'])) + $from_id = $_POST['_from']; -<td class="title">$labels[replyto]</td> -<td>$fields[replyto]</td> + $out = $select_from->show($from_id); + -</tr></table> -$form_end -EOF; + // add signatures to client + $OUTPUT->add_script(sprintf("%s.set_env('signatures', %s);", $JS_OBJECT_NAME, array2js($a_signatures))); + } + else + { + $input_from = new textfield($field_attrib); + $out = $input_from->show($_POST['_from']); + } + + if ($form_start) + $out = $form_start.$out; - return $out; + return $out; } -*/ + function rcmail_compose_body($attrib) { @@ -360,6 +350,14 @@ function rcmail_create_reply_body($body) $pefix = sprintf("\n\n\nOn %s, %s wrote:\n", $REPLY_MESSAGE['headers']->date, $IMAP->decode_header($REPLY_MESSAGE['headers']->from)); + + + // try to remove the signature + if ($sp = strrpos($body, '--')) + { + if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r") + $body = substr($body, 0, $sp-1); + } return $pefix.$body; } @@ -596,7 +594,7 @@ function rcmail_charset_pulldown($selected='ISO-8859-1') $sql_result = $DB->query("SELECT name, email FROM ".get_table_name('contacts')." WHERE user_id=? - AND del<>'1'",$_SESSION['user_id']); + AND del<>1",$_SESSION['user_id']); if ($DB->num_rows($sql_result)) { diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index ca72f7437..c81dd2fd2 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -305,26 +305,41 @@ function rcmail_message_list($attrib) // make sort links $sort = ''; - if (in_array($col, $a_sort_cols) && (!empty($attrib['sortdescbutton']) || !empty($attrib['sortascbutton']))) + if ($IMAP->get_capability('sort') && in_array($col, $a_sort_cols)) { - $sort = ' '; - - // asc link - if (!empty($attrib['sortascbutton'])) + // have buttons configured + if (!empty($attrib['sortdescbutton']) || !empty($attrib['sortascbutton'])) { - $sort .= rcube_button(array('command' => 'sort', - 'prop' => $col.'_ASC', - 'image' => $attrib['sortascbutton'], - 'title' => 'sortasc')); - } + $sort = ' '; + + // asc link + if (!empty($attrib['sortascbutton'])) + { + $sort .= rcube_button(array('command' => 'sort', + 'prop' => $col.'_ASC', + 'image' => $attrib['sortascbutton'], + 'align' => 'absmiddle', + 'title' => 'sortasc')); + } - // desc link - if (!empty($attrib['sortdescbutton'])) + // desc link + if (!empty($attrib['sortdescbutton'])) + { + $sort .= rcube_button(array('command' => 'sort', + 'prop' => $col.'_DESC', + 'image' => $attrib['sortdescbutton'], + 'align' => 'absmiddle', + 'title' => 'sortdesc')); + } + } + // just add a link tag to the header + else { - $sort .= rcube_button(array('command' => 'sort', - 'prop' => $col.'_DESC', - 'image' => $attrib['sortdescbutton'], - 'title' => 'sortdesc')); + $col_name = sprintf('<a href="./#sort" onclick="return %s.command(\'sort\',\'%s\',this)" title="%s">%s</a>', + $JS_OBJECT_NAME, + $col, + rcube_label('sortby'), + $col_name); } } @@ -1128,20 +1143,76 @@ function rcmail_first_text_part($message_parts) // get source code of a specific message and cache it function rcmail_message_source($uid) { - global $IMAP, $DB; + global $IMAP, $DB, $CONFIG; + + // get message ID if uid is given + $cache_key = $IMAP->mailbox.'.msg'; + $cached = $IMAP->get_cached_message($cache_key, $uid, FALSE); + + // message is cached in database + if ($cached && !empty($cached->body)) + return $cached->body; + + if (!$cached) + $headers = $IMAP->get_headers($uid); + else + $headers = &$cached; + - // get message ID if uid is given - $headers = $IMAP->get_headers($uid); $message_id = $headers->messageID; - // get cached message source - $msg_source = rcube_read_cache($message_id); + $temp_dir = $CONFIG['temp_dir'].(!eregi('\/$', $CONFIG['temp_dir']) ? '/' : ''); + $cache_dir = $temp_dir.$_SESSION['client_id']; + $cache_path = $cache_dir.'/'.$message_id; + + // message is cached in temp dir + if (is_dir($cache_dir) && is_file($cache_path)) + { + if ($fp = fopen($cache_path, 'r')) + { + $msg_source = fread($fp, filesize($cache_path)); + fclose($fp); + return $msg_source; + } + } + + + // get message from server + $msg_source = $IMAP->get_raw_body($uid); + + // let's cache the message body within the database + if ($CONFIG['enable_caching'] && $cached && ($CONFIG['db_max_length'] -300) > $headers->size) + { + $DB->query("UPDATE ".get_table_name('messages')." + SET body=? + WHERE user_id=? + AND cache_key=? + AND uid=?", + $msg_source, + $_SESSION['user_id'], + $cache_key, + $uid); + + return $msg_source; + } + + + // create dir for caching + if (!is_dir($cache_dir)) + $dir = mkdir($cache_dir); + else + $dir = true; - // get message from server and cache it - if (!$msg_source) + // attempt to write a file with the message body + if ($dir && ($fp = fopen($cache_path, 'w'))) + { + fwrite($fp, $msg_source); + fclose($fp); + } + else { - $msg_source = $IMAP->get_raw_body($uid); - rcube_write_cache($message_id, $msg_source, TRUE); + raise_error(array('code' => 403, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__, + 'message' => "Failed to write to temp dir"), TRUE, FALSE); } return $msg_source; diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 11fb559dd..8ec30b0a7 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -46,7 +46,7 @@ function rcmail_get_identity($id) FROM ".get_table_name('identities')." WHERE identity_id=? AND user_id=? - AND del<>'1'", + AND del<>1", $id,$_SESSION['user_id']); if ($DB->num_rows($sql_result)) @@ -78,8 +78,8 @@ if (empty($CHARSET)) $CHARSET = 'ISO-8859-1'; -$mailto_regexp = array('/,\s*[\r\n]+/', '/[\r\n]+/', '/,\s*$/m'); -$mailto_replace = array(' ', ', ', ''); +$mailto_regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m'); +$mailto_replace = array(', ', ', ', ''); // repalce new lines and strip ending ', ' $mailto = preg_replace($mailto_regexp, $mailto_replace, stripslashes($_POST['_to'])); @@ -175,13 +175,16 @@ if (is_array($_FILES['_attachments']['tmp_name'])) foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) $MAIL_MIME->addAttachment($filepath, $files['type'][$i], $files['name'][$i], TRUE); + +$message_charset = isset($_POST['_charset']) ? $_POST['_charset'] : $CHARSET; + // encoding settings for mail composing $message_param = array('text_encoding' => '7bit', 'html_encoding' => 'quoted-printable', 'head_encoding' => 'quoted-printable', - 'head_charset' => $CHARSET, - 'html_charset' => $CHARSET, - 'text_charset' => $CHARSET); + 'head_charset' => $message_charset, + 'html_charset' => $message_charset, + 'text_charset' => $message_charset); // compose message body and get headers $msg_body = $MAIL_MIME->get($message_param); |