瀏覽代碼

Updated (again) how HTML tags render in plain text messages

Luke Ehresman 25 年之前
父節點
當前提交
ca0075e511
共有 4 個文件被更改,包括 75 次插入10 次删除
  1. 28 0
      functions/date.php
  2. 43 7
      functions/mailbox.php
  3. 0 1
      functions/mailbox_display.php
  4. 4 2
      src/read_body.php

+ 28 - 0
functions/date.php

@@ -158,4 +158,32 @@
       $d[5] = getYear(trim($dateParts[2]));
       return mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
    }
+
+   function getLongDateString($dateParts) {
+      if (eregi("mon|tue|wed|thu|fri|sat|sun", trim($dateParts[0]), $tmp)) {
+         $date[0] = getDayOfMonth(trim($dateParts[1]));
+         $date[1] = getMonth(trim($dateParts[2]));
+         $date[2] = getYear(trim($dateParts[3]));
+         $date[3] = getHour(trim($dateParts[4]));
+         $date[4] = getMinute(trim($dateParts[4]));
+      } else {
+         $date[0] = getDayOfMonth(trim($dateParts[0]));
+         $date[1] = getMonth(trim($dateParts[1]));
+         $date[2] = getYear(trim($dateParts[2]));
+         $date[3] = getHour(trim($dateParts[3]));
+         $date[4] = getMinute(trim($dateParts[4]));
+      }
+
+      if ($date[3] >= 12) {
+         $date[5] = "p.m.";
+         if ($date[3] >= 13)
+            $date[3] = $date[3] - 12;
+      } else {
+         $date[5] = "a.m.";
+         if ($date[3] < 1)
+            $date[3] = 12;
+      }
+
+      return "$date[1] $date[0], $date[2]&nbsp;&nbsp;&nbsp;$date[3]:$date[4] $date[5]";
+   }
 ?>

+ 43 - 7
functions/mailbox.php

@@ -282,6 +282,8 @@
 
       $line = str_replace(" ", "&nbsp;", $line);
       $line = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $line);
+      $line = str_replace("\n", "", $line);
+      $line = str_replace("\r", "", $line);
 
       /** if >> or > are found at the beginning of a line, I'll assume that was
           replied text, so make it different colors **/
@@ -299,24 +301,58 @@
       /** This translates "http://" into a link.  It could be made better to accept
           "www" and "mailto" also.  That should probably be added later. **/
       if (strpos(strtolower($line), "http://") != false) {
+         $line = ereg_replace("<BR>", "", $line);
          $start = strpos(strtolower($line), "http://");
-         $text = substr($line, $start, strlen($line));
-         $link = ereg_replace("<BR>", "", $text);
+         $link = substr($line, $start, strlen($line));
 
-         if (strpos($link, "&"))
-            $end = strpos($link, "&");
-         else if (strpos($link, "<"))
+         if (strpos($link, " ")) {
+            $end = strpos($link, " ")-1;
+         }
+         else if (strpos($link, "&nbsp;")) {
+            $end = strpos($link, "&nbsp;")-1;
+         }
+         else if (strpos($link, "<")) {
             $end = strpos($link, "<");
+         }
+         else if (strpos($link, ">")) {
+            $end = strpos($link, ">");
+         }
+         else if (strpos($link, "(")) {
+            $end = strpos($link, "(")-1;
+         }
+         else if (strpos($link, ")")) {
+            $end = strpos($link, ")")-1;
+         }
+         else if (strpos($link, "{")) {
+            $end = strpos($link, "{")-1;
+         }
+         else if (strpos($link, "}")) {
+            $end = strpos($link, "}")-1;
+         }
          else
             $end = strlen($link);
 
-         $link = substr($link, 0, $end);
-         $line = str_replace($text, "<A HREF=\"$link\" TARGET=_top>$text</A>", $line);
+         $link = substr($line, $start, $end);
+         $end = $end + $start;
+         $before = substr($line, 0, $start);
+         $after  = substr($line, $end, strlen($line));
+
+         $line = "$before<A HREF=\"$link\" TARGET=_top>$link</A>$after<BR>";
       }
 
       return $line;
    }
 
+/*
+         $start = strpos(strtolower($line), "http://");
+         $text = substr($line, $start, strlen($line));
+         $linktext = substr($link, 0, $end);
+         $link = trim(ereg_replace("<BR>", "", $linktext));
+
+
+//         $line = str_replace($text, "<A HREF=\"$link\" TARGET=_top>$link</A>", $line);
+*/
+
    function getMessageHeadersTo($imapConnection, $start, $end, &$to) {
       $rel_start = $start;
       if (($start > $end) || ($start < 1)) {

+ 0 - 1
functions/mailbox_display.php

@@ -38,7 +38,6 @@
 
       $j = 0;
       while ($j < $numMessages) {
-//         echo "$numMessages -- $j -- $subject[$j]<BR>";
          $date[$j] = ereg_replace("  ", " ", $date[$j]);
          $tmpdate = explode(" ", trim($date[$j]));
 

+ 4 - 2
src/read_body.php

@@ -19,7 +19,9 @@
    $url_subj = urlencode(trim($subject));
 
    $d[0] = ereg_replace("  ", " ", $d[0]);
-   $date = $d[0];
+   $dateParts = explode(" ", trim($d[0]));
+   $dateString = getLongDateString($dateParts);
+
    $from_name = getSenderName($f[0]);
    $urlMailbox = urlencode($mailbox);
 
@@ -101,7 +103,7 @@
    echo "         <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT>\n";
    echo "            <FONT FACE=\"Arial,Helvetica\">Date:</FONT>\n";
    echo "         </TD><TD BGCOLOR=FFFFFF WIDTH=85%>\n";
-   echo "            <FONT FACE=\"Arial,Helvetica\"><B>$date</B></FONT>\n";
+   echo "            <FONT FACE=\"Arial,Helvetica\"><B>$dateString</B></FONT>\n";
    echo "         </TD>\n";
    echo "      </TR>\n";
    /** to **/