Browse Source

Added date translation to local time

Luke Ehresman 25 years ago
parent
commit
c2c8e62961
4 changed files with 57 additions and 44 deletions
  1. 12 0
      ChangeLog
  2. 37 40
      functions/date.php
  3. 1 1
      functions/mailbox_display.php
  4. 7 3
      functions/mime.php

+ 12 - 0
ChangeLog

@@ -1,3 +1,15 @@
+Version 0.1.2  -- 
+----------------------------------
+- Date translation to local time
+
+Version 0.1.1  -- December 16, 1999
+-----------------------------------
+- Reworked all the IMAP functions to make them RFC 2060 compliant
+  (should work with all IMAP servers)
+- Added color customization
+- Sorted folder list (on left bar)
+- Added MUCH better error correction and notification
+
 Version 0.1 -- December 14, 1999
 --------------------------------
 - Message composing (with to, cc, bcc)

+ 37 - 40
functions/date.php

@@ -36,6 +36,32 @@
       return $date;
    }
 
+   // corrects a time stamp to be the local time
+   function getGMTSeconds($stamp, $gmt) {
+      if (substr($gmt, 0, 1) == "-") {
+         $neg = true;
+         $gmt = substr($gmt, 1, strlen($gmt));
+      } else if (substr($gmt, 0, 1) == "+") {
+         $neg = false;
+         $gmt = substr($gmt, 1, strlen($gmt));
+      } else
+         $neg = false;
+
+      $gmt = substr($gmt, 0, 2);
+      $gmt = $gmt * 3600;
+      if ($neg == true)
+         $gmt = "-$gmt";
+      else
+         $gmt = "+$gmt";
+
+      /** now find what the server is at **/
+      $current = date("Z", time());
+
+      $stamp = (int)$stamp - (int)$gmt + (int)$current;
+
+      return $stamp;
+   }
+
    function getHour($hour) {
       $time = explode(":", $hour);
       return $time[0];
@@ -139,7 +165,15 @@
       return $year;
    }
 
-   function getDateString($dateParts) {
+   function getLongDateString($stamp) {
+      return date("D, F j, Y g:i a", $stamp);
+   }
+
+   function getDateString($stamp) {
+      return date("M j, Y", $stamp);
+   }
+
+   function getTimeStamp($dateParts) {
       /** $dateParts[0] == <day of week>   Mon, Tue, Wed
        ** $dateParts[1] == <day of month>  23
        ** $dateParts[2] == <month>         Jan, Feb, Mar
@@ -153,21 +187,6 @@
        **        and everything would be bumped up one.
        **/
 
-      /* if the first part is a day */
-      if (eregi("mon|tue|wed|thu|fri|sat|sun", trim($dateParts[0]), $tmp)) {
-         $dateParts[0] = getDayOfWeek(trim($dateParts[0]));
-         $dateParts[1] = getDayOfMonth(trim($dateParts[1]));
-         $dateParts[2] = getMonth(trim($dateParts[2]));
-         $dateParts[3] = getYear(trim($dateParts[3]));
-         return "$dateParts[2] $dateParts[1], $dateParts[3]";
-      }
-      $dateParts[0] = getDayOfMonth(trim($dateParts[0]));
-      $dateParts[1] = getMonth(trim($dateParts[1]));
-      $dateParts[2] = getYear(trim($dateParts[2]));
-      return "$dateParts[1] $dateParts[0], $dateParts[2]";
-   }
-
-   function getTimeStamp($dateParts) {
       if (eregi("mon|tue|wed|thu|fri|sat|sun", $dateParts[0], $tmp)) {
          $d[0] = getHour(trim($dateParts[4]));
          $d[1] = getMinute(trim($dateParts[4]));
@@ -175,7 +194,7 @@
          $d[3] = getMonthNum(trim($dateParts[2]));
          $d[4] = getDayOfMonth(trim($dateParts[1]));
          $d[5] = getYear(trim($dateParts[3]));
-         return mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
+         return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[5]);
       }
       $d[0] = getHour(trim($dateParts[3]));
       $d[1] = getMinute(trim($dateParts[3]));
@@ -183,28 +202,6 @@
       $d[3] = getMonthNum(trim($dateParts[1]));
       $d[4] = getDayOfMonth(trim($dateParts[0]));
       $d[5] = getYear(trim($dateParts[2]));
-      return mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
-   }
-
-   function getLongDateString($stamp) {
-      $dateArray = getDate($stamp);
-
-      if ($dateArray["hours"] >= 12) {
-         $am_pm = "p.m.";
-      } else {
-         $am_pm = "a.m.";
-      }
-
-      if ($dateArray["hours"] >= 13) {
-         $dateArray["hours"] = $dateArray["hours"] - 12;
-      }
-
-      $dateParts[0] = getDayOfMonth($dateArray["mday"]);
-      $dateParts[1] = getMonth($dateArray["month"]);
-      $dateParts[2] = getYear($dateArray["year"]);
-      $dateParts[3] = $dateArray["hours"]; // hour
-      $dateParts[4] = getMinutes($dateArray["minutes"]); // minute
-
-      return "$dateParts[1] $dateParts[0], $dateParts[2] at $dateParts[3]:$dateParts[4] $am_pm";
+      return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[4]);
    }
 ?>

+ 1 - 1
functions/mailbox_display.php

@@ -45,7 +45,7 @@
          $tmpdate = explode(" ", trim($date[$j]));
 
          $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
-         $messages[$j]["DATE_STRING"] = getDateString($tmpdate);
+         $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
          $messages[$j]["ID"] = $j+1;
          $messages[$j]["FROM"] = getSenderName($from[$j]);
          $messages[$j]["SUBJECT"] = $subject[$j];

+ 7 - 3
functions/mime.php

@@ -6,7 +6,7 @@
 
 
    function decodeMime($body, $bound, $type0, $type1) {
-//      echo "$type0/$type1<BR>";
+      echo "$type0/$type1<BR>";
       if ($type0 == "multipart") {
          if ($body[0] == "")
             $i = 1;
@@ -42,7 +42,7 @@
 
    /** This gets one entity's properties **/
    function getEntity($body, $bound, $type0, $type1, $encoding, $charset) {
-//      echo "$type0/$type1<BR>";
+      echo "$type0/$type1<BR>";
       $msg[0]["TYPE0"] = $type0;
       $msg[0]["TYPE1"] = $type1;
       $msg[0]["ENCODING"] = $encoding;
@@ -59,7 +59,11 @@
             $msg[0]["BODY"] = $body;
          } else {
             $msg[0]["PRIORITY"] = 1;
-            $msg[0]["BODY"][0] = "<B><FONT COLOR=DD0000>This attachment is an unknown text format:  $type0/$type1</FONT></B>";
+            $msg[0]["BODY"][0] = "This entity is of an unknown format.  Doing my best to display anyway...<BR><BR>";
+            for ($p = 1;$p < count($body);$p++) {
+               $q = $p - 1;
+               $msg[0]["BODY"][$p] = $body[$q];
+            }
          }
       } else if ($type0 == "image") {
          $msg[0]["BODY"][0] = "<B><FONT COLOR=DD0000>This is an image.  Squirrelmail currently cannot decode images.</FONT></B>";