X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=plugins%2Fsquirrelspell%2Fmodules%2Fcheck_me.mod;h=370241f1621628dd66fc9c772496bae6dfb1415e;hb=5c325683cbdd9f91a91ed24078b2ffd1a0bc90ce;hp=f47dfd9e89dfc7c01e0610bb360e4e99429c7f83;hpb=fb0abd31769201a87860ec54c123e3a729a38518;p=squirrelmail.git
diff --git a/plugins/squirrelspell/modules/check_me.mod b/plugins/squirrelspell/modules/check_me.mod
index f47dfd9e..370241f1 100644
--- a/plugins/squirrelspell/modules/check_me.mod
+++ b/plugins/squirrelspell/modules/check_me.mod
@@ -1,288 +1,438 @@
$ln".
- '';
+/**
+ * check_me.mod
+ * -------------
+ * Squirrelspell module.
+ *
+ * Copyright (c) 1999-2002 The SquirrelMail development team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This module is the main workhorse of SquirrelSpell. It submits
+ * the message to the spell-checker, parses the output, and loads
+ * the interface window.
+ *
+ * $Id$
+ *
+ * @author Konstantin Riabitsev ($Author$)
+ * @version $Date$
+ */
+/**
+ * This function makes a javascript-powered link. Not sure why
+ * Philippe decided to move it outside the main code, but hey. ;)
+ * I bet for the i18n reasons.
+ *
+ * @param $jscode Javascript code to include in the link.
+ * @param $title A little pop-up title to provide for the links.
+ * @param $link The content of the link.
+ * @return void, since this just draws the content.
+ */
+function SpellLink($jscode, $title, $link) {
+ echo "
';
}
-// Declaring globals for E_ALL.
+/**
+ * Declaring globals for users with E_ALL set.
+ */
global $sqspell_text, $SQSPELL_APP, $sqspell_use_app, $attachment_dir,
- $username, $SQSPELL_EREG, $color;
+ $username, $SQSPELL_EREG, $color;
- // Now we explode the lines for three reasons:
- // 1) So we can ignore lines starting with ">" (reply's)
- // 2) So we can stop processing when we get to "--" on a single line,
- // which means that the signature is starting
- // 3) So we can add an extra space at the beginning of each line. This way
- // ispell/aspell don't treat these as command characters.
- $sqspell_raw_lines = explode("\n", $sqspell_text);
- for ($i=0; $i')
+/**
+ * Now we explode the lines for three reasons:
+ * 1) So we can ignore lines starting with ">" (reply's)
+ * 2) So we can stop processing when we get to "--" on a single line,
+ * which means that the signature is starting
+ * 3) So we can add an extra space at the beginning of each line. This way
+ * ispell/aspell don't treat these as command characters.
+ */
+$sqspell_raw_lines = explode("\n", $sqspell_text);
+for ($i=0; $i'){
$sqspell_new_lines[$i] = ' ' . $sqspell_raw_lines[$i];
- else $sqspell_new_lines[$i] = '';
- }
- $sqspell_new_text=implode("\n", $sqspell_new_lines);
+ } else {
+ $sqspell_new_lines[$i] = '';
+ }
+}
+/**
+ * $sqspell_new_lines array now contains the lines to submit to the
+ * spellchecker.
+ */
+$sqspell_new_text=implode("\n", $sqspell_new_lines);
+
+/**
+ * Define the command used to spellcheck the document.
+ */
+$sqspell_command=$SQSPELL_APP[$sqspell_use_app];
+/**
+ * For the simplicity's sake we'll put all text into a file in
+ * attachment_dir directory, then cat it and pipe it to
+ * sqspell_command. There are other ways to do it, including popen(),
+ * but it's unidirectional and no fun at all.
+ *
+ * The name of the file is an md5 hash of the message itself plus
+ * microtime. This prevents symlink attacks. The loop is here to
+ * further enhance this feature, and make sure we don't overwrite
+ * someone else's data, although the possibility of this happening is
+ * QUITE remote.
+ */
+do {
+ $floc = "$attachment_dir/" . md5($sqspell_new_text . microtime());
+} while (file_exists($floc));
+/**
+ * Write the contents to the file.
+ */
+$fp=fopen($floc, 'w');
+fwrite($fp, $sqspell_new_text);
+fclose($fp);
+/**
+ * Execute ispell/aspell and catch the output.
+ */
+exec("cat $floc | $sqspell_command 2>&1", $sqspell_output, $sqspell_exitcode);
+/**
+ * Remove the temp file.
+ */
+unlink($floc);
- // Define the command used to spellcheck the document.
- $sqspell_command=$SQSPELL_APP[$sqspell_use_app];
- // For the simplicity's sake we'll put all text into a file
- // in attachment_dir directory, then cat it and pipe it to sqspell_command.
- // There are other ways to do it, including popen(), but it's unidirectional
- // and no fun at all.
- // NOTE: This will probably change in future releases of squirrelspell
- // for privacy reasons.
- //
- $floc = "$attachment_dir/$username_sqspell_data.txt";
- $fp=fopen($floc, 'w');
- fwrite($fp, $sqspell_new_text);
- fclose($fp);
- exec("cat $floc | $sqspell_command", $sqspell_output);
- unlink($floc);
+/**
+ * Check if the execution was successful. Bail out if it wasn't.
+ */
+if ($sqspell_exitcode){
+ $msg= "
"
+ . sprintf(_("I tried to execute '%s', but it returned:"),
+ $sqspell_command) . "
"
+ . nl2br(join("\n", $sqspell_output)) . "
"
+ . "
";
+ sqspell_makeWindow(null, _("SquirrelSpell is misconfigured."), null, $msg);
+ exit;
+}
- // Load the user dictionary.
- $words=sqspell_getLang(sqspell_getWords(), $sqspell_use_app);
- // define some variables.
- $current_line=0;
- $missed_words=Array();
- $misses = Array();
- $locations = Array();
- $errors=0;
- // Now we process the output of sqspell_command (ispell or aspell
- // in ispell compatibility mode, whichever).
- for ($i=0; $i\n".
- "\n".
- '' . _("SquirrelSpell Results") . '';
- if ($theme_css != '') {
- echo "\n";
- }
- // Load the spelling errors into JavaScript arrays
- echo "\n".
- "\n".
- "\n";
+ /**
+ * Locations are where those misspellings are located, line:symbol
+ */
+ echo "var locations= new Array();\n";
+ $i=0;
+ while (list($word, $value) = each($locations)){
+ echo "locations[$i] = \"$value\";\n";
+ $i++;
+ }
- echo "\n".
- '