- fixed and improved wordWrap
authorlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 10 Aug 2000 08:24:55 +0000 (08:24 +0000)
committerlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 10 Aug 2000 08:24:55 +0000 (08:24 +0000)
- added sqStripSlashes() function

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@695 7612ce4b-ef26-0410-bec9-ea0150e637f0

16 files changed:
functions/imap_messages.php
functions/mailbox_display.php
functions/page_header.php
functions/prefs.php
functions/smtp.php
functions/strings.php
src/addrbook_search_html.php
src/compose.php
src/download.php
src/folders_create.php
src/folders_delete.php
src/folders_rename_do.php
src/folders_rename_getname.php
src/load_prefs.php
src/options.php
src/read_body.php

index 4aecad1..32ab26e 100755 (executable)
@@ -5,7 +5,7 @@
     **  This implements functions that manipulate messages 
     **/
 
-   if (!$mime_php) include "../functions/mime.php";
+   if (!isset($mime_php)) include "../functions/mime.php";
 
    /******************************************************************************
     **  Copies specified messages to specified folder
index 8613c2b..488da05 100644 (file)
@@ -19,7 +19,7 @@
 
       $senderName = sqimap_find_displayable_name($msg["FROM"]);
       $urlMailbox = urlencode($mailbox);
-      $subject = trim(stripslashes($msg["SUBJECT"]));
+      $subject = trim($msg["SUBJECT"]);
       echo "<TR>\n";
       
       if ($msg["FLAG_FLAGGED"] == true) { $flag = "<font color=$color[2]>"; $flag_end = "</font>"; }
index 22a8e0b..8b1d1d9 100644 (file)
@@ -75,7 +75,7 @@
 
       /** Here is the header and wrapping table **/
       $shortBoxName = readShortMailboxName($mailbox, ".");
-      $shortBoxName = stripslashes($shortBoxName);
+      $shortBoxName = sqStripSlashes($shortBoxName);
       echo "<A NAME=pagetop></A>\n";
       echo "<TABLE BGCOLOR=\"$color[4]\" BORDER=0 WIDTH=\"100%\" CELLSPACING=0 CELLPADDING=2>\n";
       echo "   <TR BGCOLOR=\"$color[9]\">\n";
index e43d180..558d11b 100644 (file)
       $filename = "$data_dir$username.sig";
       if (file_exists($filename)) {
          $file = fopen($filename, "r");
+         $sig = "";
          while (!feof($file)) {
             $sig .= fgets($file, 1024);
          }
index 868c262..397f07f 100644 (file)
          $bcc_list = getLineOfAddrs($bcc);
          
          /* Encoding 8-bit characters and making from line */
-         $subject = stripslashes(encodeHeader($subject));
+         $subject = sqStripSlashes(encodeHeader($subject));
          if ($from == "")
             $from = "<$from_addr>";
          else
             $body .= "Content-Type: text/plain\r\n";
 
          $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
-         $body .= stripslashes($passedBody) . "\r\n";
+         $body .= sqStripSlashes($passedBody) . "\r\n";
          fputs ($fp, $body);
 
          $attachmentlength = attachFiles($fp);
          $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n";
          fputs ($fp, $postbody);
       } else {
-         $body = stripslashes($passedBody) . "\r\n";
+         $body = sqStripSlashes($passedBody) . "\r\n";
          fputs ($fp, $body);
          $postbody = "\r\n";
          fputs ($fp, $postbody);
index 3dde660..c94ffdc 100644 (file)
 
    // Wraps text at $wrap characters
    function sqWordWrap($passed, $wrap) {
-      $passed = str_replace("&gt;", ">", $passed);
       $passed = str_replace("&lt;", "<", $passed);
+      $passed = str_replace("&gt;", ">", $passed);
 
-      $words = explode(" ", trim($passed));
-      $i = 0;
-      $line_len = strlen($words[$i])+1;
+      preg_match("/^(\s|>)+/", $passed, $regs);
+      $beginning_spaces = $regs[0];
+
+      $words = explode(" ", $passed);
+      $i = -1;
+      $line_len = strlen($words[0])+1;
       $line = "";
       if (count($words) > 1) {   
-         while ($i < count($words)) {
+         while ($i++ < count($words)) {
             while ($line_len < $wrap) {
                $line = "$line$words[$i] ";
                $i++;
-               $line_len = $line_len + strlen($words[$i])+1;
+               $line_len = $line_len + strlen($words[$i]) + 1;
             }
             $line_len = strlen($words[$i])+1;
-            if ($line_len < $wrap) {
-               if ($i < count($words)) // don't <BR> the last line
-                  $line = "$line\n";
+            if ($line_len <= $wrap) {
+               if (strlen($beginning_spaces) +2 >= $wrap)
+                  $beginning_spaces = "";
+               if ($i < count($words)) { // don't <BR> the last line
+                  $line = "$line\n$beginning_spaces";
+               }   
+               $line = "$line$words[$i] ";
+               $line_len = strlen($beginning_spaces) + strlen($words[$i]) + 1;
             } else {
+               /*
                $endline = $words[$i];
                while ($line_len >= $wrap) {
                   $bigline = substr($endline, 0, $wrap);
                   $line_len = strlen($endline);
                   $line = "$line$bigline<BR>";
                }
-               $line = "$line$endline<BR>";
-               $i++;
+               */
+               if (strlen($line) > $wrap)
+                  $line = "$line\n$words[$i]";
+               else
+                  $line = "$line$words[$i]";
+               $line_len = strlen($words[$i]);
             }
          }
       } else {
       for ($i=0; $i < count($body_ary); $i++) {
          $line = $body_ary[$i];
          $line = charset_decode($charset, $line);
+         $line = str_replace("\t", "        ", $line);
          
          if (strlen($line) - 2 >= $wrap_at) {
             $line = sqWordWrap($line, $wrap_at);  
          }
          
          $line = str_replace(" ", "&nbsp;", $line);
-         $line = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $line);
          $line = nl2br($line);
 
          $line = parseEmail ($line);
       }
       return $location;
    }   
+
+   function sqStripSlashes($string) {
+      if (get_magic_quotes_gpc()) {
+         $string = stripslashes($string);
+      }
+      return $string;
+   }
 ?>
index cbbfa93..cd8fb2c 100644 (file)
    // Initialize addressbook
    $abook = addressbook_init();
 
-   $body = stripslashes($body);
-   $send_to = stripslashes($send_to);
-   $send_to_cc = stripslashes($send_to_cc);
-   $send_to_bcc = stripslashes($send_to_bcc);
-   $subject = stripslashes($subject);
+   $body = sqStripSlashes($body);
+   $send_to = sqStripSlashes($send_to);
+   $send_to_cc = sqStripSlashes($send_to_cc);
+   $send_to_bcc = sqStripSlashes($send_to_bcc);
+   $subject = sqStripSlashes($subject);
 
 
    // Header
index a1e43f7..f9b4219 100644 (file)
@@ -43,8 +43,8 @@
       global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
          $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc;
 
-      $send_to = stripslashes(decodeHeader($send_to));
-      $send_to_cc = stripslashes(decodeHeader($send_to_cc));
+      $send_to = sqStripSlashes(decodeHeader($send_to));
+      $send_to_cc = sqStripSlashes(decodeHeader($send_to_cc));
 
       if ($forward_id)
          $id = $forward_id;
@@ -96,7 +96,7 @@
          return $body;   
       }
 
-      $send_to = stripslashes($send_to);
+      $send_to = sqStripSlashes($send_to);
       
       if (!$send_to) {
          $send_to = sqimap_find_email($send_to);
       echo "      </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
       if ($reply_subj) {
          $reply_subj = str_replace("\"", "'", $reply_subj);
-         $reply_subj = stripslashes($reply_subj);
+         $reply_subj = sqStripSlashes($reply_subj);
          $reply_subj = trim($reply_subj);
          if (substr(strtolower($reply_subj), 0, 3) != "re:")
             $reply_subj = "Re: $reply_subj";
                htmlspecialchars($reply_subj));
       } else if ($forward_subj) {
          $forward_subj = str_replace("\"", "'", $forward_subj);
-         $forward_subj = stripslashes($forward_subj);
+         $forward_subj = sqStripSlashes($forward_subj);
          $forward_subj = trim($forward_subj);
          if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") &&
              (substr(strtolower($forward_subj), 0, 5) != "[fwd:") &&
       is_logged_in();
       displayPageHeader($color, $mailbox);
 
-      $body = stripslashes($body);
-      $send_to = stripslashes($send_to);
-      $send_to_cc = stripslashes($send_to_cc);
-      $send_to_bcc = stripslashes($send_to_bcc);
-      $subject = stripslashes($subject);
+      $body = sqStripSlashes($body);
+      $send_to = sqStripSlashes($send_to);
+      $send_to_cc = sqStripSlashes($send_to_cc);
+      $send_to_bcc = sqStripSlashes($send_to_bcc);
+      $subject = sqStripSlashes($subject);
       
       for ($i=0; $i < count($send_to_search); $i++) {
          if ($send_to)
index 7c92975..a796ea5 100644 (file)
             header("Content-Disposition: attachment; filename=\"$filename\"");
             header("Content-type: application/octet-stream; name=\"$filename\"");
             if ($type1 == "plain") {
-               echo _("Subject") . ": " . decodeHeader(stripslashes($top_header->subject)) . "\n";
-               echo "   " . _("From") . ": " . decodeHeader(stripslashes($top_header->from)) . "\n";
-               echo "     " . _("To") . ": " . decodeHeader(stripslashes(getLineOfAddrs($top_header->to))) . "\n";
+               echo _("Subject") . ": " . decodeHeader(sqStripSlashes($top_header->subject)) . "\n";
+               echo "   " . _("From") . ": " . decodeHeader(sqStripSlashes($top_header->from)) . "\n";
+               echo "     " . _("To") . ": " . decodeHeader(sqStripSlashes(getLineOfAddrs($top_header->to))) . "\n";
                echo "   " . _("Date") . ": " . getLongDateString($top_header->date) . "\n\n";
             }
             echo trim($body);
index 9b200a9..7d09033 100644 (file)
@@ -47,7 +47,7 @@
       $subfolder_orig = $subfolder;
    }
 
-   if ((trim($subfolder_orig) == "[ None ]") || (trim(stripslashes($subfolder_orig)) == "[ None ]")) {
+   if ((trim($subfolder_orig) == "[ None ]") || (trim(sqStripSlashes($subfolder_orig)) == "[ None ]")) {
       sqimap_mailbox_create ($imapConnection, $folder_prefix.$folder_name, "");
    } else {
       sqimap_mailbox_create ($imapConnection, $subfolder.$dm.$folder_name, "");
index e98794b..e6d945e 100644 (file)
@@ -35,7 +35,7 @@
    $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
    $boxes = sqimap_mailbox_list ($imap_stream);
    $dm = sqimap_get_delimiter($imap_stream);
-   $mailbox = stripslashes($mailbox);
+   $mailbox = sqStripSlashes($mailbox);
    
    if (substr($mailbox, -1) == $dm)
       $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1); 
index 5368600..549f2c1 100644 (file)
@@ -35,8 +35,8 @@
    else
       $newone = "$new_name";
 
-   $orig = stripslashes($orig);
-   $newone = stripslashes($newone);
+   $orig = sqStripSlashes($orig);
+   $newone = sqStripSlashes($newone);
 
    fputs ($imapConnection, ". RENAME \"$orig\" \"$newone\"\r\n");
    $data = sqimap_read_data($imapConnection, ".", true, $a, $b);
index f16f057..67759ec 100644 (file)
@@ -38,7 +38,7 @@
       $old_parent = "";
    }
 
-   $old_name = stripslashes($old_name);
+   $old_name = sqStripSlashes($old_name);
 
    displayPageHeader($color, "None");
    echo "<br><TABLE align=center border=0 WIDTH=95% COLS=1>";
index 415dc0d..a8a76b8 100644 (file)
    $wrap_at = getPref($data_dir, $username, "wrap_at");
    if ($wrap_at == "")
       $wrap_at = 86;
+   if ($wrap_at < 15)
+      $wrap_at = 15;
 
    $left_size = getPref($data_dir, $username, "left_size");
    if ($left_size == "") {
index 769a48c..3ad5e4b 100644 (file)
@@ -29,7 +29,7 @@
    if (!isset($auth_php))
       include ("../functions/auth.php"); 
 
-   if ($language) {
+   if (isset($language)) {
       setcookie("squirrelmail_language", $language, time()+2592000);
       $squirrelmail_language = $language;
    }   
 <?php
    if ($submit_personal) {
       # Save personal information
-      if (isset($full_name)) setPref($data_dir, $username, "full_name", stripslashes($full_name));
-      if (isset($email_address)) setPref($data_dir, $username, "email_address", stripslashes($email_address));
-      if (isset($reply_to)) setPref($data_dir, $username, "reply_to", stripslashes($reply_to));  
-      setPref($data_dir, $username, "use_signature", stripslashes($usesignature));  
-      if (isset($signature_edit)) setSig($data_dir, $username, stripslashes($signature_edit)); 
+      if (isset($full_name)) setPref($data_dir, $username, "full_name", sqStripSlashes($full_name));
+      if (isset($email_address)) setPref($data_dir, $username, "email_address", sqStripSlashes($email_address));
+      if (isset($reply_to)) setPref($data_dir, $username, "reply_to", sqStripSlashes($reply_to));  
+      setPref($data_dir, $username, "use_signature", sqStripSlashes($usesignature));  
+      if (isset($signature_edit)) setSig($data_dir, $username, sqStripSlashes($signature_edit)); 
       
       echo "<br><center><b>"._("Successfully saved personal information!")."</b></center><br>";
    } else if ($submit_display) {  
index b1041c6..4925d87 100644 (file)
    $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
 
    /** translate the subject and mailbox into url-able text **/
-   $url_subj = urlencode(trim(stripslashes($message->header->subject)));
+   $url_subj = urlencode(trim(sqStripSlashes($message->header->subject)));
    $urlMailbox = urlencode($mailbox);
    $url_replyto = urlencode($message->header->replyto);
 
 
    /** make sure everything will display in HTML format **/
    $from_name = decodeHeader(htmlspecialchars($message->header->from));
-   $subject = decodeHeader(htmlspecialchars(stripslashes($message->header->subject)));
+   $subject = decodeHeader(htmlspecialchars($message->header->subject));
 
    do_hook("read_body_top");
    echo "<BR>";