From f0621c2dd59dfa99a8787b94fa019b6d7407a217 Mon Sep 17 00:00:00 2001 From: graf25 Date: Fri, 9 Feb 2001 17:08:21 +0000 Subject: [PATCH] Fixes the problem of subjects with entities getting trimmed too short. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1095 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mailbox_display.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index e534c936..ddbb6129 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -112,11 +112,32 @@ echo "$flag"; - if (strlen($subject) > 55) - echo substr($subject, 0, 50) . '...'; - else - echo $subject; - echo "$flag_end$bold_end\n"; + if (strlen($subject) > 55){ + $ent_strlen=strlen($subject); + $trim_val=50; + // see if this is entities-encoded string + if (is_int(strpos($subject, "&#"))){ + // Yes. Iterate through the whole string, find out + // the real number of characters, and if more + // than 55, substr with an updated trim value. + $ent_offset=0; + $ent_count=0; + do { + $ent_loc = strpos($subject, "&#", $ent_offset); + $ent_loc_end = strpos($subject, ";", $ent_offset); + if ($ent_loc_end){ + $trim_val += ($ent_loc_end-$ent_loc)+1; + $ent_strlen -= $ent_loc_end-$ent_loc; + $ent_offset = $ent_loc_end+1; + $ent_count++; + } else $ent_loc=false; + } while (is_int($ent_loc)); + } + if ($ent_strlen>55) echo substr($subject, 0, $trim_val) . '...'; + else echo $subject; + } else echo $subject; + + echo "$flag_end$bold_end\n"; break; case 5: # flags $stuff = false; -- 2.25.1