| | |
| | | /* |
| | | +-------------------------------------------------------------------------+ |
| | | | RoundCube Webmail IMAP Client | |
| | | | Version 0.1-20080506 | |
| | | | Version 0.2-20080614 | |
| | | | | |
| | | | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland | |
| | | | | |
| | |
| | | // define global vars |
| | | $OUTPUT_TYPE = 'html'; |
| | | |
| | | // init application and start session with requested task |
| | | $RCMAIL = rcmail::get_instance(); |
| | | |
| | | // init output class |
| | | $OUTPUT = !empty($_REQUEST['_remote']) ? $RCMAIL->init_json() : $RCMAIL->load_gui(!empty($_REQUEST['_framed'])); |
| | | |
| | | // set output buffering |
| | | if ($RCMAIL->action != 'get' && $RCMAIL->action != 'viewsource') { |
| | | // use gzip compression if supported |
| | |
| | | ob_start(); |
| | | } |
| | | } |
| | | |
| | | |
| | | // init application and start session with requested task |
| | | $RCMAIL = rcmail::get_instance(); |
| | | |
| | | // init output class |
| | | $OUTPUT = (!empty($_GET['_remote']) || !empty($_POST['_remote'])) ? $RCMAIL->init_json() : $RCMAIL->load_gui((!empty($_GET['_framed']) || !empty($_POST['_framed']))); |
| | | |
| | | |
| | | // check DB connections and exit on failure |
| | | if ($err_str = $DB->is_error()) { |
| | |
| | | } |
| | | |
| | | |
| | | // not logged in -> set task to 'login |
| | | if (empty($RCMAIL->user->ID)) { |
| | | if ($OUTPUT->ajax_call) |
| | | $OUTPUT->remote_response("setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);"); |
| | | |
| | | $RCMAIL->set_task('login'); |
| | | } |
| | | |
| | | |
| | | // check client X-header to verify request origin |
| | | if ($OUTPUT->ajax_call) { |
| | | if (empty($CONFIG['devel_mode']) && !rc_request_header('X-RoundCube-Referer')) { |
| | | if ($RCMAIL->config->get('devel_mode') && !rc_request_header('X-RoundCube-Referer')) { |
| | | header('HTTP/1.1 404 Not Found'); |
| | | die("Invalid Request"); |
| | | } |
| | |
| | | |
| | | // not logged in -> show login page |
| | | if (empty($RCMAIL->user->ID)) { |
| | | |
| | | if ($OUTPUT->ajax_call) |
| | | $OUTPUT->remote_response("setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);"); |
| | | |
| | | // check if installer is still active |
| | | if ($CONFIG['enable_installer'] && is_readable('./installer/index.php')) { |
| | | if ($RCMAIL->config->get('enable_installer') && is_readable('./installer/index.php')) { |
| | | $OUTPUT->add_footer(html::div(array('style' => "background:#ef9398; border:2px solid #dc5757; padding:0.5em; margin:2em auto; width:50em"), |
| | | html::tag('h2', array('style' => "margin-top:0.2em"), "Installer script is still accessible") . |
| | | html::p(null, "The install script of your RoundCube installation is still stored in its default location!") . |
| | |
| | | } |
| | | |
| | | $OUTPUT->set_env('task', 'login'); |
| | | $OUTPUT->task = 'login'; |
| | | $OUTPUT->send('login'); |
| | | exit; |
| | | } |
| | | |
| | | |
| | | // handle keep-alive signal |
| | | if ($RCMAIL->action=='keep-alive') { |
| | | $OUTPUT->reset(); |
| | | $OUTPUT->send(''); |
| | | exit; |
| | | $OUTPUT->send(); |
| | | } |
| | | |
| | | // include task specific files |
| | |
| | | * @param array Cell attributes |
| | | * @param string Cell content |
| | | */ |
| | | private function add_header($attr, $cont) |
| | | public function add_header($attr, $cont) |
| | | { |
| | | if (is_string($attr)) |
| | | $attr = array('class' => $attr); |
| | |
| | | * |
| | | * @param array Row attributes |
| | | */ |
| | | private function add_row($attr = array()) |
| | | public function add_row($attr = array()) |
| | | { |
| | | $this->rowindex++; |
| | | $this->colindex = 0; |
| | |
| | | if (!empty($this->header)) { |
| | | $rowcontent = ''; |
| | | foreach ($this->header as $c => $col) { |
| | | $rowcontent .= self::tag('th', $col->attrib, $col->content); |
| | | $rowcontent .= self::tag('td', $col->attrib, $col->content); |
| | | } |
| | | $thead = self::tag('thead', null, self::tag('tr', null, $rowcontent)); |
| | | } |
| | |
| | | } |
| | | |
| | | if ($r < $this->rowindex || count($row->cells)) { |
| | | $tbody .= self::tag('tr', $rows->attrib, $rowcontent); |
| | | $tbody .= self::tag('tr', $row->attrib, $rowcontent); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | // application constants |
| | | define('RCMAIL_VERSION', '0.1-trunk'); |
| | | define('RCMAIL_VERSION', '0.2-trunk'); |
| | | define('RCMAIL_CHARSET', 'UTF-8'); |
| | | define('JS_OBJECT_NAME', 'rcmail'); |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Load virtuser table in array |
| | | * |
| | | * @return array Virtuser table entries |
| | | */ |
| | | function rcmail_getvirtualfile() |
| | | { |
| | | global $CONFIG; |
| | | if (empty($CONFIG['virtuser_file']) || !is_file($CONFIG['virtuser_file'])) |
| | | return FALSE; |
| | | |
| | | // read file |
| | | $a_lines = file($CONFIG['virtuser_file']); |
| | | return $a_lines; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Find matches of the given pattern in virtuser table |
| | | * |
| | | * @param string Regular expression to search for |
| | | * @return array Matching entries |
| | | */ |
| | | function rcmail_findinvirtual($pattern) |
| | | { |
| | | $result = array(); |
| | | $virtual = rcmail_getvirtualfile(); |
| | | if ($virtual==FALSE) |
| | | return $result; |
| | | |
| | | // check each line for matches |
| | | foreach ($virtual as $line) |
| | | { |
| | | $line = trim($line); |
| | | if (empty($line) || $line{0}=='#') |
| | | continue; |
| | | |
| | | if (eregi($pattern, $line)) |
| | | $result[] = $line; |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Overwrite action variable |
| | | * |
| | | * @param string New action value |
| | |
| | | */ |
| | | function rcube_table_output($attrib, $table_data, $a_show_cols, $id_col) |
| | | { |
| | | global $DB; |
| | | global $RCMAIL; |
| | | |
| | | // allow the following attributes to be added to the <table> tag |
| | | $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary')); |
| | | $table = new html_table(/*array('cols' => count($a_show_cols))*/); |
| | | |
| | | $table = '<table' . $attrib_str . ">\n"; |
| | | |
| | | // add table title |
| | | $table .= "<thead><tr>\n"; |
| | | |
| | | // add table header |
| | | foreach ($a_show_cols as $col) |
| | | $table .= '<td class="'.$col.'">' . Q(rcube_label($col)) . "</td>\n"; |
| | | |
| | | $table .= "</tr></thead>\n<tbody>\n"; |
| | | $table->add_header($col, Q(rcube_label($col))); |
| | | |
| | | $c = 0; |
| | | if (!is_array($table_data)) |
| | | { |
| | | while ($table_data && ($sql_arr = $DB->fetch_assoc($table_data))) |
| | | $db = $RCMAIL->get_dbh(); |
| | | while ($table_data && ($sql_arr = $db->fetch_assoc($table_data))) |
| | | { |
| | | $zebra_class = $c%2 ? 'even' : 'odd'; |
| | | |
| | | $table .= sprintf('<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", $sql_arr[$id_col]); |
| | | $table->add_row(array('id' => 'rcmrow' . $sql_arr[$id_col], 'class' => "contact $zebra_class")); |
| | | |
| | | // format each col |
| | | foreach ($a_show_cols as $col) |
| | | { |
| | | $cont = Q($sql_arr[$col]); |
| | | $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; |
| | | } |
| | | $table->add($col, Q($sql_arr[$col])); |
| | | |
| | | $table .= "</tr>\n"; |
| | | $c++; |
| | | } |
| | | } |
| | |
| | | foreach ($table_data as $row_data) |
| | | { |
| | | $zebra_class = $c%2 ? 'even' : 'odd'; |
| | | |
| | | $table .= sprintf('<tr id="rcmrow%s" class="contact '.$zebra_class.'">'."\n", $row_data[$id_col]); |
| | | $table->add_row(array('id' => 'rcmrow' . $row_data[$id_col], 'class' => "contact $zebra_class")); |
| | | |
| | | // format each col |
| | | foreach ($a_show_cols as $col) |
| | | { |
| | | $cont = Q($row_data[$col]); |
| | | $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; |
| | | } |
| | | $table->add($col, Q($row_data[$col])); |
| | | |
| | | $table .= "</tr>\n"; |
| | | $c++; |
| | | } |
| | | } |
| | | |
| | | // complete message table |
| | | $table .= "</tbody></table>\n"; |
| | | |
| | | return $table; |
| | | return $table->show($attrib); |
| | | } |
| | | |
| | | |
| | |
| | | $out = $input->show($value); |
| | | |
| | | return $out; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return the mail domain configured for the given host |
| | | * |
| | | * @param string IMAP host |
| | | * @return string Resolved SMTP host |
| | | */ |
| | | function rcmail_mail_domain($host) |
| | | { |
| | | global $CONFIG; |
| | | |
| | | $domain = $host; |
| | | if (is_array($CONFIG['mail_domain'])) |
| | | { |
| | | if (isset($CONFIG['mail_domain'][$host])) |
| | | $domain = $CONFIG['mail_domain'][$host]; |
| | | } |
| | | else if (!empty($CONFIG['mail_domain'])) |
| | | $domain = $CONFIG['mail_domain']; |
| | | |
| | | return $domain; |
| | | } |
| | | |
| | | |
| | |
| | | $source); |
| | | |
| | | return $styles; |
| | | } |
| | | |
| | | /** |
| | | * Try to autodetect operating system and find the correct line endings |
| | | * |
| | | * @return string The appropriate mail header delimiter |
| | | */ |
| | | function rcmail_header_delm() |
| | | { |
| | | global $CONFIG; |
| | | |
| | | // use the configured delimiter for headers |
| | | if (!empty($CONFIG['mail_header_delimiter'])) |
| | | return $CONFIG['mail_header_delimiter']; |
| | | else if (strtolower(substr(PHP_OS, 0, 3)=='win')) |
| | | return "\r\n"; |
| | | else if (strtolower(substr(PHP_OS, 0, 3)=='mac')) |
| | | return "\r\n"; |
| | | else |
| | | return "\n"; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Try to autodetect operating system and find the correct line endings |
| | | * |
| | | * @return string The appropriate mail header delimiter |
| | | */ |
| | | public function header_delimiter() |
| | | { |
| | | // use the configured delimiter for headers |
| | | if (!empty($this->prop['mail_header_delimiter'])) |
| | | return $this->prop['mail_header_delimiter']; |
| | | else if (strtolower(substr(PHP_OS, 0, 3) == 'win')) |
| | | return "\r\n"; |
| | | else if (strtolower(substr(PHP_OS, 0, 3) == 'mac')) |
| | | return "\r\n"; |
| | | else |
| | | return "\n"; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Return the mail domain configured for the given host |
| | | * |
| | | * @param string IMAP host |
| | | * @return string Resolved SMTP host |
| | | */ |
| | | public function mail_domain($host) |
| | | { |
| | | $domain = $host; |
| | | |
| | | if (is_array($this->prop['mail_domain'])) { |
| | | if (isset($this->prop['mail_domain'][$host])) |
| | | $domain = $this->prop['mail_domain'][$host]; |
| | | } |
| | | else if (!empty($this->prop['mail_domain'])) |
| | | $domain = $this->prop['mail_domain']; |
| | | |
| | | return $domain; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | private $texts = array(); |
| | | private $commands = array(); |
| | | |
| | | public $task = ''; |
| | | public $ajax_call = true; |
| | | |
| | | |
| | |
| | | */ |
| | | public function __construct($task) |
| | | { |
| | | $this->task = $task; |
| | | $this->config = rcmail::get_instance()->config; |
| | | } |
| | | |
| | |
| | | { |
| | | var $app; |
| | | var $config; |
| | | var $task = ''; |
| | | var $framed = false; |
| | | var $pagetitle = ''; |
| | | var $env = array(); |
| | |
| | | $this->config = $this->app->config->all(); |
| | | |
| | | //$this->framed = $framed; |
| | | $this->task = $task; |
| | | $this->set_env('task', $task); |
| | | |
| | | // add common javascripts |
| | | $javascript = 'var '.JS_OBJECT_NAME.' = new rcube_webmail();'; |
| | |
| | | return $ver; |
| | | } |
| | | if ($object=='pagetitle') { |
| | | $task = $this->task; |
| | | $task = $this->env['task']; |
| | | $title = !empty($this->config['product_name']) ? $this->config['product_name'].' :: ' : ''; |
| | | |
| | | if (!empty($this->pagetitle)) { |
| | |
| | | |
| | | if ($user_id = $dbh->insert_id(get_sequence_name('users'))) |
| | | { |
| | | $mail_domain = rcmail_mail_domain($host); |
| | | $mail_domain = $rcmail->config->mail_domain($host); |
| | | |
| | | if ($user_email=='') |
| | | $user_email = strpos($user, '@') ? $user : sprintf('%s@%s', $user, $mail_domain); |
| | |
| | | static function email2user($email) |
| | | { |
| | | $user = $email; |
| | | $r = rcmail_findinvirtual("^$email"); |
| | | $r = self::findinvirtual("^$email"); |
| | | |
| | | for ($i=0; $i<count($r); $i++) |
| | | { |
| | |
| | | static function user2email($user) |
| | | { |
| | | $email = ""; |
| | | $r = rcmail_findinvirtual("$user$"); |
| | | $r = self::findinvirtual("$user$"); |
| | | |
| | | for ($i=0; $i<count($r); $i++) |
| | | { |
| | |
| | | return $email; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Find matches of the given pattern in virtuser table |
| | | * |
| | | * @param string Regular expression to search for |
| | | * @return array Matching entries |
| | | */ |
| | | private static function findinvirtual($pattern) |
| | | { |
| | | $result = array(); |
| | | $virtual = null; |
| | | |
| | | if ($virtuser_file = rcmail::get_instance()->config->get('virtuser_file')) |
| | | $virtual = file($virtuser_file); |
| | | |
| | | if (empty($virtual)) |
| | | return $result; |
| | | |
| | | // check each line for matches |
| | | foreach ($virtual as $line) |
| | | { |
| | | $line = trim($line); |
| | | if (empty($line) || $line{0}=='#') |
| | | continue; |
| | | |
| | | if (eregi($pattern, $line)) |
| | | $result[] = $line; |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | function rcmail_send_mdn($uid) |
| | | { |
| | | global $CONFIG, $USER, $IMAP; |
| | | global $RCMAIL, $IMAP; |
| | | |
| | | $message = new rcube_message($uid); |
| | | |
| | | if ($message->headers->mdn_to && !$message->headers->mdn_sent) |
| | | { |
| | | $identity = $USER->get_identity(); |
| | | $identity = $RCMAIL->user->get_identity(); |
| | | $sender = format_email_recipient($identity['email'], $identity['name']); |
| | | $recipient = array_shift($IMAP->decode_address_list($message->headers->mdn_to)); |
| | | $mailto = $recipient['mailto']; |
| | | |
| | | $compose = new rcube_mail_mime(rcmail_header_delm()); |
| | | $compose = new rcube_mail_mime($RCMAIL->config->header_delimiter()); |
| | | $compose->setParam(array( |
| | | 'text_encoding' => 'quoted-printable', |
| | | 'html_encoding' => 'quoted-printable', |
| | |
| | | 'From' => $sender, |
| | | 'To' => $message->headers->mdn_to, |
| | | 'Subject' => rcube_label('receiptread') . ': ' . $message->subject, |
| | | 'Message-ID' => sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), rcmail_mail_domain($_SESSION['imap_host'])), |
| | | 'Message-ID' => sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host'])), |
| | | 'X-Sender' => $identity['email'], |
| | | 'Content-Type' => 'multipart/report; report-type=disposition-notification', |
| | | ); |
| | | |
| | | if (!empty($CONFIG['useragent'])) |
| | | $headers['User-Agent'] = $CONFIG['useragent']; |
| | | if ($agent = $RCMAIL->config->get('useragent')) |
| | | $headers['User-Agent'] = $agent; |
| | | |
| | | $body = rcube_label("yourmessage") . "\r\n\r\n" . |
| | | "\t" . rcube_label("to") . ': ' . rcube_imap::decode_mime_string($message->headers->to, $message->headers->charset) . "\r\n" . |
| | | "\t" . rcube_label("subject") . ': ' . $message->subject . "\r\n" . |
| | | "\t" . rcube_label("sent") . ': ' . format_date($message->headers->date, $CONFIG['date_long']) . "\r\n" . |
| | | "\t" . rcube_label("sent") . ': ' . format_date($message->headers->date, $RCMAIL->config->get('date_long')) . "\r\n" . |
| | | "\r\n" . rcube_label("receiptnote") . "\r\n"; |
| | | |
| | | $ua = !empty($CONFIG['useragent']) ? $CONFIG['useragent'] : "RoundCube Webmail (Version ".RCMAIL_VERSION.")"; |
| | | $ua = $RCMAIL->config->get('useragent', "RoundCube Webmail (Version ".RCMAIL_VERSION.")"); |
| | | $report = "Reporting-UA: $ua\r\n"; |
| | | |
| | | if ($message->headers->to) |
| | |
| | | if (strlen($_POST['_draft_saveid']) > 3) |
| | | $olddraftmessageid = get_input_value('_draft_saveid', RCUBE_INPUT_POST); |
| | | |
| | | $message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), rcmail_mail_domain($_SESSION['imap_host'])); |
| | | $message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host'])); |
| | | $savedraft = !empty($_POST['_draft']) ? TRUE : FALSE; |
| | | |
| | | // remove all scripts and act as called in frame |
| | |
| | | // additional headers |
| | | if ($CONFIG['http_received_header']) |
| | | { |
| | | $nldlm = rcmail_header_delm() . "\t"; |
| | | $nldlm = $RCMAIL->config->header_delimiter() . "\t"; |
| | | $headers['Received'] = wordwrap('from ' . (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? |
| | | gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']).' ['.$_SERVER['HTTP_X_FORWARDED_FOR'].']'.$nldlm.' via ' : '') . |
| | | gethostbyaddr($_SERVER['REMOTE_ADDR']).' ['.$_SERVER['REMOTE_ADDR'].']'.$nldlm.'with ' . |
| | |
| | | $isHtml = ($isHtmlVal == "1"); |
| | | |
| | | // create extended PEAR::Mail_mime instance |
| | | $MAIL_MIME = new rcube_mail_mime(rcmail_header_delm()); |
| | | $MAIL_MIME = new rcube_mail_mime($RCMAIL->config->header_delimiter()); |
| | | |
| | | // For HTML-formatted messages, construct the MIME message with both |
| | | // the HTML part and the plain-text part |