Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Windows support in e-mail attachments

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1129 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
commit 02046d692b20d25239f0735fea96ca916b128955 1 parent 90a2fc4
authored September 23, 2009
2  compile.php
@@ -133,7 +133,7 @@ function php_shrink($input) {
133 133
 				if ($tokens[$i+1][0] === T_ECHO) {
134 134
 					// join two consecutive echos
135 135
 					next($tokens);
136  
-					$token[1] = ','; // '.' would conflict with "a".1+2 and would use more memory //! remove ',' and ","
  136
+					$token[1] = ','; // '.' would conflict with "a".1+2 and would use more memory //! remove ',' and "," but not $var","
137 137
 				} else {
138 138
 					$in_echo = false;
139 139
 				}
25  editor/include/adminer.inc.php
@@ -264,7 +264,8 @@ function selectEmailProcess($where, $foreignKeys) {
264 264
 			if ($_POST["all"] || $_POST["check"]) {
265 265
 				$field = idf_escape($_POST["email_field"]);
266 266
 				$subject = $_POST["email_subject"];
267  
-				$message = "$_POST[email_message]\n";
  267
+				$eol = (strncasecmp(PHP_OS, "win", 3) ? "\n" : "\r\n");
  268
+				$message = str_replace("\n", $eol, str_replace("\r", "", "$_POST[email_message]\n"));
268 269
 				preg_match_all('~\\{\\$([a-z0-9_]+)\\}~i', "$subject.$message", $matches); // allows {$name} in subject or message
269 270
 				$result = $connection->query("SELECT DISTINCT $field" . ($matches[1] ? ", " . implode(", ", array_map('idf_escape', array_unique($matches[1]))) : "") . " FROM " . idf_escape($_GET["select"])
270 271
 					. " WHERE $field IS NOT NULL AND $field != ''"
@@ -280,29 +281,31 @@ function selectEmailProcess($where, $foreignKeys) {
280 281
 				$email_files = $_FILES["email_files"];
281 282
 				foreach ($email_files["error"] as $key => $val) {
282 283
 					if (!$val) {
283  
-						$attachments .= "--$boundary\n"
284  
-							. "Content-Type: " . str_replace("\n", "", $email_files["type"][$key]) . "\n"
285  
-							. "Content-Disposition: attachment; filename=\"" . preg_replace('~["\\n]~', '', $email_files["name"][$key]) . "\"\n"
286  
-							. "Content-Transfer-Encoding: base64\n"
287  
-							. "\n" . chunk_split(base64_encode(file_get_contents($email_files["tmp_name"][$key])), 76, "\n") . "\n"
  284
+						$attachments .= "--$boundary$eol"
  285
+							. "Content-Type: " . str_replace("\n", "", $email_files["type"][$key]) . $eol
  286
+							. "Content-Disposition: attachment; filename=\"" . preg_replace('~["\\n]~', '', $email_files["name"][$key]) . "\"$eol"
  287
+							. "Content-Transfer-Encoding: base64$eol"
  288
+							. $eol . chunk_split(base64_encode(file_get_contents($email_files["tmp_name"][$key])), 76, $eol) . $eol
288 289
 						;
289 290
 					}
290 291
 				}
291 292
 				$beginning = "";
292  
-				$headers = "Content-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit";
  293
+				$headers = "Content-Type: text/plain; charset=utf-8$eol" . "Content-Transfer-Encoding: 8bit";
293 294
 				if ($attachments) {
294  
-					$attachments .= "--$boundary--\n";
295  
-					$beginning = "--$boundary\n$headers\n\n";
  295
+					$attachments .= "--$boundary--$eol";
  296
+					$beginning = "--$boundary$eol$headers$eol$eol";
296 297
 					$headers = "Content-Type: multipart/mixed; boundary=\"$boundary\"";
297 298
 				}
298  
-				$headers .= "\nMIME-Version: 1.0" . ($_POST["email_from"] ? "\nFrom: " . str_replace("\n", "", $_POST["email_from"]) : ""); //! should escape display name
  299
+				$headers .= $eol . "MIME-Version: 1.0"
  300
+					. ($_POST["email_from"] ? $eol . "From: " . str_replace("\n", "", $_POST["email_from"]) : "") //! should escape display name
  301
+				;
299 302
 				foreach ($this->rowDescriptions($rows, $foreignKeys) as $row) {
300 303
 					$replace = array();
301 304
 					foreach ($matches[1] as $val) {
302 305
 						$replace['{$' . "$val}"] = $row[$val]; //! allow literal {$name}
303 306
 					}
304 307
 					$email = $row[$_POST["email_field"]];
305  
-					if (is_email($email) && mail($email, email_header(strtr($subject, $replace)), $beginning . strtr($message, $replace) . $attachments, $headers)) { //! replace \n by \r\n on Windows
  308
+					if (is_email($email) && mail($email, email_header(strtr($subject, $replace)), $beginning . strtr($message, $replace) . $attachments, $headers)) {
306 309
 						$sent++;
307 310
 					}
308 311
 				}

0 notes on commit 02046d6

Please sign in to comment.
Something went wrong with that request. Please try again.