function parse_ini($ini) { // split lines $ini = parse_lines($ini); if (count($ini) == 0) { return array(); } $result = array(); $sections = array(); $values = array(); $globals = array(); $i = 0; foreach ($ini as $line) { $line = trim($line); // Comments, do not parse line if ($line == '' || $line[0] == ';') { continue; } // Sections if ($line[0] == '[') { $sections[] = substr($line, 1, -1); $i++; continue; } // Key-value pair if (strpos($line, '=') === false) { $key = $line; $value = ''; } else { list($key, $value) = explode('=', $line, 2); } $key = strtolower(trim($key)); $value = trim($value); if ($i == 0) { // Array values if (substr($line, -1, 2) == '[]') { $globals[$key][] = $value; } else { $globals[$key] = $value; } } else { // Array values if (substr($line, -1, 2) == '[]') { $values[$i - 1][$key][] = $value; } else { $values[$i - 1][$key] = $value; } } } foreach ($values as $key => $value) { $result[$sections[$key]] = $value; } return $result + $globals; }
} else { array_push($curl_headers_array, $name . ': ' . $value); } } if (!curl_load($redirect_url . $query_string, $data, $curl_headers_array)) { header("HTTP/1.0 404 Not Found"); header("Status: 404 Not Found"); $_SERVER['REDIRECT_STATUS'] = 404; if (file_exists('404.html')) { echo file_get_contents('404.html'); } die; } $headers_end_pos = strpos($data, "\r\n\r\n"); $data_start_pos = $headers_end_pos + 4; if ($headers_end_pos === false) { $headers_end_pos = strpos($data, "\n\n"); $data_start_pos = $headers_end_pos + 2; } if ($headers_end_pos !== false) { $lines = parse_lines(substr($data, 0, $headers_end_pos)); foreach ($lines as $line) { // do not pass "Transfer-Encoding: chunked" header if (stripos($line, 'Transfer-Encoding') === false) { header($line . "\r\n"); } } die(substr($data, $data_start_pos)); } else { die($data); }
protected function process_conf($value) { if (!strlen($value)) { return; } $line_start = 'user_pref('; $line_end = ');'; $values = parse_lines($value); $conf_values = array(); foreach ($values as $line) { $line = Utf8ToWin(trim($line)); if (str_begins($line, $line_start) && str_ends($line, $line_end)) { $line = stripslashes(substr($line, strlen($line_start), -strlen($line_end))); if (strlen($line) < 2) { continue; } $name_end = strpos($line, '",'); if ($name_end !== false && $line[0] == '"') { $name = substr($line, 1, $name_end - 1); $value = trim(substr($line, $name_end + 2)); if (str_begins($value, '"') && str_ends($value, '"')) { $value = trim(substr($value, 1, -1)); } $name = strtolower($name); $conf_values[$name] = $value; } } } $accounts = assign($conf_values['mail.accountmanager.accounts']); $accounts = explode(',', $accounts); if (is_array($accounts) && count($accounts)) { foreach ($accounts as $account) { $server = assign($conf_values['mail.account.' . $account . '.server']); $host = assign($conf_values['mail.server.' . $server . '.hostname']); $port = assign($conf_values['mail.server.' . $server . '.port']); $user = assign($conf_values['mail.server.' . $server . '.username']); $protocol = assign($conf_values['mail.server.' . $server . '.type']); $pass = ''; if ($protocol == 'imap') { if (isset($this->mailboxes['imap://' . $host])) { $pass = $this->mailboxes['imap://' . $host][1]; } } elseif ($protocol == 'pop3') { if (isset($this->mailboxes['pop3://' . $host])) { $pass = $this->mailboxes['pop3://' . $host][1]; } } if (!strlen($pass)) { if (isset($this->mailboxes['mailbox://' . $host])) { $pass = $this->mailboxes['mailbox://' . $host][1]; } else { $pass = ''; } } $identities = assign($conf_values['mail.account.' . $account . '.identities']); $identities = explode(',', $identities); if (is_array($identities) && count($identities)) { foreach ($identities as $identity) { $email = assign($conf_values['mail.identity.' . $identity . '.useremail']); $smtp_name = assign($conf_values['mail.identity.' . $identity . '.smtpserver']); // find default server if (!strlen($smtp_name)) { $smtp_name = assign($conf_values['mail.smtp.defaultserver']); } if (!strlen($smtp_name)) { $smtp_names = assign($conf_values['mail.smtpservers']); $smtp_names = explode(',', $smtp_names); if (is_array($smtp_names) && count($smtp_names)) { $smtp_name = $smtp_names[0]; } } $smtp_host = assign($conf_values['mail.smtpserver.' . $smtp_name . '.hostname']); $smtp_user = assign($conf_values['mail.smtpserver.' . $smtp_name . '.username']); $smtp_port = assign($conf_values['mail.smtpserver.' . $smtp_name . '.port']); if (isset($this->mailboxes['smtp://' . $smtp_host])) { $smtp_pass = $this->mailboxes['smtp://' . $smtp_host][1]; } else { $smtp_pass = ''; } if (is_array($smtp_pass)) { $smtp_pass = $smtp_pass[1]; } // pop3/imap if ($protocol == 'pop3' || $protocol == 'imap') { $this->add_email($email, $protocol, $host, $port, $user, $pass); } $this->add_email($email, 'smtp', $smtp_host, $smtp_port, $smtp_user, $smtp_pass); } } } } }