From 6e7468f6db00425d6e328476374caaba1d56f33a Mon Sep 17 00:00:00 2001 From: fidian Date: Wed, 11 Oct 2000 15:52:55 +0000 Subject: [PATCH] Changed size display: - Change to megs if over 1024 k - if x < 10, show first digit after decimal point Created new function (in strings.php) in case sizes should be shown elsewhere. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@790 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_messages.php | 3 +-- functions/mailbox_display.php | 2 +- functions/mime.php | 5 ++--- functions/strings.php | 28 ++++++++++++++++++++++++++-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/functions/imap_messages.php b/functions/imap_messages.php index 9f147d2d..c0850443 100755 --- a/functions/imap_messages.php +++ b/functions/imap_messages.php @@ -95,8 +95,7 @@ fputs ($imap_stream, "a003 FETCH $id RFC822.SIZE\r\n"); $read = sqimap_read_data($imap_stream, "a003", true, $r, $m); preg_match("/([0-9]+)\)\s*$/i", $read[0], $regs); - $size = $regs[1] / 1024; - settype($size, "integer"); + $size = $regs[1]; $header = new small_header; if ($sent == true) diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index e23eff6a..6d29d7c5 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -71,7 +71,7 @@ else echo "  \n"; break; case 6: # size - echo " $bold".$msg["SIZE"]."k$bold_end\n"; + echo " $bold".show_readable_size($msg['SIZE'])."$bold_end\n"; break; } } diff --git a/functions/mime.php b/functions/mime.php index ff5bf65b..dd4d0eb0 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -528,9 +528,8 @@ $body .= '  '; $body .= "$display_filename "; - $size = $message->header->size / 1024; - settype($size, "integer"); - $body .= "" . $size . "k  "; + $body .= '' . show_readable_size($message->header->size) . + '  '; $body .= "[ $type0/$type1 ] "; $body .= ''; if ($message->header->description) diff --git a/functions/strings.php b/functions/strings.php index 6d82b88d..b293a6c9 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -59,14 +59,14 @@ if (count($words) > 1) { while ($i < count($words)) { // Force one word to be on a line (minimum) - $line .= $words[$i] . ' '; + $line .= $words[$i]; $line_len = strlen($beginning_spaces) + strlen($words[$i]) + strlen($words[$i + 1]) + 2; $i ++; // Add more words (as long as they fit) while ($line_len < $wrap && $i < count($words)) { - $line .= $words[$i] . ' '; + $line .= ' ' . $words[$i]; $i++; $line_len += strlen($words[$i]) + 1; } @@ -392,5 +392,29 @@ return true; } + + /* Returns a string showing the size of the message/attachment */ + function show_readable_size($bytes) + { + $bytes /= 1024; + $type = 'k'; + + if ($bytes / 1024 > 1) + { + $bytes /= 1024; + $type = 'm'; + } + + if ($bytes < 10) + { + $bytes *= 10; + settype($bytes, "integer"); + $bytes /= 10; + } + else + settype($bytes, "integer"); + + return $bytes . ' ' . $type . ''; + } ?> -- 2.25.1