From 7aaa81fcf8383ee72ee0e4fd3cb2fd8d5f9708b5 Mon Sep 17 00:00:00 2001 From: lkehresman Date: Thu, 10 Aug 2000 08:24:55 +0000 Subject: [PATCH] - fixed and improved wordWrap - added sqStripSlashes() function git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@695 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_messages.php | 2 +- functions/mailbox_display.php | 2 +- functions/page_header.php | 2 +- functions/prefs.php | 1 + functions/smtp.php | 6 ++--- functions/strings.php | 44 ++++++++++++++++++++++++---------- src/addrbook_search_html.php | 10 ++++---- src/compose.php | 20 ++++++++-------- src/download.php | 6 ++--- src/folders_create.php | 2 +- src/folders_delete.php | 2 +- src/folders_rename_do.php | 4 ++-- src/folders_rename_getname.php | 2 +- src/load_prefs.php | 2 ++ src/options.php | 12 +++++----- src/read_body.php | 4 ++-- 16 files changed, 72 insertions(+), 49 deletions(-) diff --git a/functions/imap_messages.php b/functions/imap_messages.php index 4aecad1b..32ab26e9 100755 --- a/functions/imap_messages.php +++ b/functions/imap_messages.php @@ -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 diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 8613c2b5..488da052 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -19,7 +19,7 @@ $senderName = sqimap_find_displayable_name($msg["FROM"]); $urlMailbox = urlencode($mailbox); - $subject = trim(stripslashes($msg["SUBJECT"])); + $subject = trim($msg["SUBJECT"]); echo "\n"; if ($msg["FLAG_FLAGGED"] == true) { $flag = ""; $flag_end = ""; } diff --git a/functions/page_header.php b/functions/page_header.php index 22a8e0b1..8b1d1d9e 100644 --- a/functions/page_header.php +++ b/functions/page_header.php @@ -75,7 +75,7 @@ /** Here is the header and wrapping table **/ $shortBoxName = readShortMailboxName($mailbox, "."); - $shortBoxName = stripslashes($shortBoxName); + $shortBoxName = sqStripSlashes($shortBoxName); echo "\n"; echo "\n"; echo " \n"; diff --git a/functions/prefs.php b/functions/prefs.php index e43d1807..558d11b6 100644 --- a/functions/prefs.php +++ b/functions/prefs.php @@ -137,6 +137,7 @@ $filename = "$data_dir$username.sig"; if (file_exists($filename)) { $file = fopen($filename, "r"); + $sig = ""; while (!feof($file)) { $sig .= fgets($file, 1024); } diff --git a/functions/smtp.php b/functions/smtp.php index 868c2620..397f07fe 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -132,7 +132,7 @@ $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 @@ -233,7 +233,7 @@ $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); @@ -241,7 +241,7 @@ $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); diff --git a/functions/strings.php b/functions/strings.php index 3dde6608..c94ffdcd 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -46,25 +46,34 @@ // Wraps text at $wrap characters function sqWordWrap($passed, $wrap) { - $passed = str_replace(">", ">", $passed); $passed = str_replace("<", "<", $passed); + $passed = str_replace(">", ">", $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
the last line - $line = "$line\n"; + if ($line_len <= $wrap) { + if (strlen($beginning_spaces) +2 >= $wrap) + $beginning_spaces = ""; + if ($i < count($words)) { // don't
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); @@ -72,8 +81,12 @@ $line_len = strlen($endline); $line = "$line$bigline
"; } - $line = "$line$endline
"; - $i++; + */ + if (strlen($line) > $wrap) + $line = "$line\n$words[$i]"; + else + $line = "$line$words[$i]"; + $line_len = strlen($words[$i]); } } } else { @@ -123,13 +136,13 @@ 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(" ", " ", $line); - $line = str_replace("\t", "        ", $line); $line = nl2br($line); $line = parseEmail ($line); @@ -211,4 +224,11 @@ } return $location; } + + function sqStripSlashes($string) { + if (get_magic_quotes_gpc()) { + $string = stripslashes($string); + } + return $string; + } ?> diff --git a/src/addrbook_search_html.php b/src/addrbook_search_html.php index cbbfa933..cd8fb2ca 100644 --- a/src/addrbook_search_html.php +++ b/src/addrbook_search_html.php @@ -107,11 +107,11 @@ // 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 diff --git a/src/compose.php b/src/compose.php index a1e43f78..f9b4219a 100644 --- a/src/compose.php +++ b/src/compose.php @@ -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); @@ -189,7 +189,7 @@ echo "
\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"; @@ -197,7 +197,7 @@ 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:") && @@ -317,11 +317,11 @@ 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) diff --git a/src/download.php b/src/download.php index 7c92975b..a796ea55 100644 --- a/src/download.php +++ b/src/download.php @@ -109,9 +109,9 @@ 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); diff --git a/src/folders_create.php b/src/folders_create.php index 9b200a97..7d090337 100644 --- a/src/folders_create.php +++ b/src/folders_create.php @@ -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, ""); diff --git a/src/folders_delete.php b/src/folders_delete.php index e98794b7..e6d945ef 100644 --- a/src/folders_delete.php +++ b/src/folders_delete.php @@ -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); diff --git a/src/folders_rename_do.php b/src/folders_rename_do.php index 53686009..549f2c13 100644 --- a/src/folders_rename_do.php +++ b/src/folders_rename_do.php @@ -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); diff --git a/src/folders_rename_getname.php b/src/folders_rename_getname.php index f16f0573..67759ec3 100644 --- a/src/folders_rename_getname.php +++ b/src/folders_rename_getname.php @@ -38,7 +38,7 @@ $old_parent = ""; } - $old_name = stripslashes($old_name); + $old_name = sqStripSlashes($old_name); displayPageHeader($color, "None"); echo "
"; diff --git a/src/load_prefs.php b/src/load_prefs.php index 415dc0dd..a8a76b8f 100644 --- a/src/load_prefs.php +++ b/src/load_prefs.php @@ -109,6 +109,8 @@ $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 == "") { diff --git a/src/options.php b/src/options.php index 769a48c2..3ad5e4ba 100644 --- a/src/options.php +++ b/src/options.php @@ -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; } @@ -48,11 +48,11 @@
"._("Successfully saved personal information!")."

"; } else if ($submit_display) { diff --git a/src/read_body.php b/src/read_body.php index b1041c61..4925d876 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -117,7 +117,7 @@ $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); @@ -215,7 +215,7 @@ /** 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 "
"; -- 2.25.1