From 90a2fc475dd393a6bc997ccdc6bdfe81dbd4d105 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Tue, 22 Sep 2009 15:09:45 +0000 Subject: [PATCH] E-mail attachments git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1128 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- changes.txt | 1 + editor/include/adminer.inc.php | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/changes.txt b/changes.txt index b0b7b44c..cad43e08 100644 --- a/changes.txt +++ b/changes.txt @@ -2,6 +2,7 @@ Adminer 2.1.1-dev: Display table links above table structure Fix removed default in ALTER Display whitespace in texts (bug #2858042) +E-mail attachments (Editor) Move

to $adminer->navigation (customization) Rename get_dbh to connection (customization) diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index e8bdec09..fb4923d3 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -192,6 +192,7 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5 echo lang('Subject') . ": \n"; echo "


\n"; echo " \n"; //! JavaScript + echo "

"; echo "

" . (count($emailFields) == 1 ? '' : ' '); echo "\n"; echo "\n"; @@ -263,9 +264,9 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5 if ($_POST["all"] || $_POST["check"]) { $field = idf_escape($_POST["email_field"]); $subject = $_POST["email_subject"]; - $message = $_POST["email_message"]; + $message = "$_POST[email_message]\n"; preg_match_all('~\\{\\$([a-z0-9_]+)\\}~i', "$subject.$message", $matches); // allows {$name} in subject or message - $result = $connection->query("SELECT DISTINCT $field, " . implode(", ", array_map('idf_escape', array_unique($matches[1]))) . " FROM " . idf_escape($_GET["select"]) + $result = $connection->query("SELECT DISTINCT $field" . ($matches[1] ? ", " . implode(", ", array_map('idf_escape', array_unique($matches[1]))) : "") . " FROM " . idf_escape($_GET["select"]) . " WHERE $field IS NOT NULL AND $field != ''" . ($where ? " AND " . implode(" AND ", $where) : "") . ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . "))") @@ -274,16 +275,34 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5 while ($row = $result->fetch_assoc()) { $rows[] = $row; } + $boundary = uniqid("boundary"); + $attachments = ""; + $email_files = $_FILES["email_files"]; + foreach ($email_files["error"] as $key => $val) { + if (!$val) { + $attachments .= "--$boundary\n" + . "Content-Type: " . str_replace("\n", "", $email_files["type"][$key]) . "\n" + . "Content-Disposition: attachment; filename=\"" . preg_replace('~["\\n]~', '', $email_files["name"][$key]) . "\"\n" + . "Content-Transfer-Encoding: base64\n" + . "\n" . chunk_split(base64_encode(file_get_contents($email_files["tmp_name"][$key])), 76, "\n") . "\n" + ; + } + } + $beginning = ""; + $headers = "Content-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit"; + if ($attachments) { + $attachments .= "--$boundary--\n"; + $beginning = "--$boundary\n$headers\n\n"; + $headers = "Content-Type: multipart/mixed; boundary=\"$boundary\""; + } + $headers .= "\nMIME-Version: 1.0" . ($_POST["email_from"] ? "\nFrom: " . str_replace("\n", "", $_POST["email_from"]) : ""); //! should escape display name foreach ($this->rowDescriptions($rows, $foreignKeys) as $row) { $replace = array(); foreach ($matches[1] as $val) { $replace['{$' . "$val}"] = $row[$val]; //! allow literal {$name} } $email = $row[$_POST["email_field"]]; - if (is_email($email) && mail($email, email_header(strtr($subject, $replace)), strtr($message, $replace), - "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit" - . (is_email($_POST["email_from"]) ? "\nFrom: $_POST[email_from]" : "") //! should allow address with a name but simple application of email_header() adds the default server domain - )) { + if (is_email($email) && mail($email, email_header(strtr($subject, $replace)), $beginning . strtr($message, $replace) . $attachments, $headers)) { //! replace \n by \r\n on Windows $sent++; } }