--- /dev/null
+<?
+ /**
+ ** array.php3
+ **
+ ** This contains functions that work with array manipulation. They
+ ** will help sort, and do other types of things with arrays
+ **
+ **/
+
+ function ary_sort($ary,$col, $dir = 1){
+ // The globals are used because USORT determines what is passed to comp2
+ // These should be $this->col and $this->dir in a class
+ // Would beat using globals
+ if(!is_array($col)){
+ $col = array("$col");
+ }
+ $GLOBALS["col"] = $col; // Column or Columns as an array
+ $GLOBALS["dir"] = $dir; // Direction, a positive number for ascending a negative for descending
+
+ function comp2($a,$b,$i = 0) {
+ global $col;
+ global $dir;
+ $c = count($col) -1;
+ if ($a["$col[$i]"] == $b["$col[$i]"]){
+ $r = 0;
+ while($i < $c && $r == 0){
+ $i++;
+ $r = comp2($a,$b,$i);
+ }
+ } elseif($a["$col[$i]"] < $b["$col[$i]"]){
+ $r = -1 * $dir; // Im not sure why you must * dir here, but it wont work just before the return...
+ } else {
+ $r = 1 * $dir;
+ }
+ return $r;
+ }
+
+ usort($ary,comp2);
+ return $ary;
+ }
+?>
--- /dev/null
+<?
+ /**
+ ** date.php3
+ **
+ ** Takes a date and parses it into a usable format. The form that a
+ ** date SHOULD arrive in is:
+ ** Tue, 29 Jun 1999 09:52:11 -0500 (EDT)
+ ** (as specified in RFC 822)
+ **
+ **/
+
+ function getHour($hour) {
+ $time = explode(":", $hour);
+ return $time[0];
+ }
+
+ function getMinute($min) {
+ $time = explode(":", $min);
+ return $time[1];
+ }
+
+ function getSecond($sec) {
+ $time = explode(":", $sec);
+ return $time[2];
+ }
+
+ function getMonthNum($month) {
+ if (eregi("jan|january", $month, $tmp))
+ $date = "01";
+ else if (eregi("feb|february|febuary", $month, $tmp))
+ $date = "02";
+ else if (eregi("mar|march", $month, $tmp))
+ $date = "03";
+ else if (eregi("apr|april", $month, $tmp))
+ $date = "04";
+ else if (eregi("may", $month, $tmp))
+ $date = "05";
+ else if (eregi("jun|june", $month, $tmp))
+ $date = "06";
+ else if (eregi("jul|july", $month, $tmp))
+ $date = "07";
+ else if (eregi("aug|august", $month, $tmp))
+ $date = "08";
+ else if (eregi("sep|sept|september", $month, $tmp))
+ $date = "09";
+ else if (eregi("oct|october", $month, $tmp))
+ $date = "10";
+ else if (eregi("nov|november", $month, $tmp))
+ $date = "11";
+ else if (eregi("dec|december", $month, $tmp))
+ $date = "12";
+
+ return $date;
+ }
+
+ function getDayOfWeek($day) {
+ $date = "{WEEKDAY}";
+
+ if (eregi("(mon|monday)", $day, $tmp))
+ $date = "Mon";
+ else if (eregi("(tue|tuesday)", $day, $tmp))
+ $date = "Tue";
+ else if (eregi("(wed|wednesday)", $day, $tmp))
+ $date = "Wed";
+ else if (eregi("(thurs|thu|thursday)", $day, $tmp))
+ $date = "Thu";
+ else if (eregi("(fri|friday)", $day, $tmp))
+ $date = "Fri";
+ else if (eregi("(sat|saturday)", $day, $tmp))
+ $date = "Sat";
+ else if (eregi("(sun|sunday)", $day, $tmp))
+ $date = "Sun";
+
+ return $date;
+ }
+
+ function getDayOfMonth($day) {
+ return ereg_replace("^0", "", $day); /* remove a preceeding 0 */
+ }
+
+ function getMonth($month) {
+ $date = "{MONTH}";
+ if (eregi("jan|january", $month, $tmp))
+ $date = "Jan";
+ else if (eregi("feb|february|febuary", $month, $tmp))
+ $date = "Feb";
+ else if (eregi("mar|march", $month, $tmp))
+ $date = "Mar";
+ else if (eregi("apr|april", $month, $tmp))
+ $date = "Apr";
+ else if (eregi("may", $month, $tmp))
+ $date = "May";
+ else if (eregi("jun|june", $month, $tmp))
+ $date = "Jun";
+ else if (eregi("jul|july", $month, $tmp))
+ $date = "Jul";
+ else if (eregi("aug|august", $month, $tmp))
+ $date = "Aug";
+ else if (eregi("sep|sept|september", $month, $tmp))
+ $date = "Sep";
+ else if (eregi("oct|october", $month, $tmp))
+ $date = "Oct";
+ else if (eregi("nov|november", $month, $tmp))
+ $date = "Nov";
+ else if (eregi("dec|december", $month, $tmp))
+ $date = "Dec";
+
+ return $date;
+ }
+
+ function getYear($year) {
+ return $year;
+ }
+
+ function getDateString($dateParts) {
+ /** $dateParts[0] == <day of week> Mon, Tue, Wed
+ ** $dateParts[1] == <day of month> 23
+ ** $dateParts[2] == <month> Jan, Feb, Mar
+ ** $dateParts[3] == <year> 1999
+ ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
+ ** $dateParts[5] == <from GMT> +0100
+ ** $dateParts[6] == <zone> (EDT)
+ **
+ ** NOTE: In RFC 822, it states that <day of week> is optional.
+ ** In that case, dateParts[0] would be the <day of month>
+ ** and everything would be bumped up one.
+ **/
+
+ /* if the first part is a day */
+ if (eregi("mon|tue|wed|thu|fri|sat|sun", $dateParts[0], $tmp)) {
+ $dateParts[0] = getDayOfWeek($dateParts[0]);
+ $dateParts[1] = getDayOfMonth($dateParts[1]);
+ $dateParts[2] = getMonth($dateParts[2]);
+ $dateParts[3] = getYear($dateParts[3]);
+ return "$dateParts[2] $dateParts[1], $dateParts[3]";
+ }
+ $dateParts[0] = getDayOfMonth($dateParts[0]);
+ $dateParts[1] = getMonth($dateParts[1]);
+ $dateParts[2] = getYear($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($dateParts[4]);
+ $d[1] = getMinute($dateParts[4]);
+ $d[2] = getSecond($dateParts[4]);
+ $d[3] = getMonthNum($dateParts[2]);
+ $d[4] = getDayOfMonth($dateParts[1]);
+ $d[5] = getYear($dateParts[3]);
+ return mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
+ }
+ $d[0] = getHour($dateParts[3]);
+ $d[1] = getMinute($dateParts[3]);
+ $d[2] = getSecond($dateParts[3]);
+ $d[3] = getMonthNum($dateParts[1]);
+ $d[4] = getDayOfMonth($dateParts[0]);
+ $d[5] = getYear($dateParts[2]);
+ return mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
+ }
+?>
--- /dev/null
+<?
+ /**
+ ** display_messages.php3
+ **
+ ** This contains all messages, including information, error, and just
+ ** about any other message you can think of.
+ **
+ **/
+
+ function error_username_password_incorrect() {
+ echo "<BR>";
+ echo "<TABLE COLS=1 WIDTH=70% NOBORDER BGCOLOR=FFFFFF ALIGN=CENTER>";
+ echo " <TR>";
+ echo " <TD BGCOLOR=DCDCDC>";
+ echo " <FONT FACE=\"Arial,Helvetica\"><B><CENTER>ERROR</CENTER></B></FONT>";
+ echo " </TD></TR><TR><TD>";
+ echo " <CENTER><FONT FACE=\"Arial,Helvetica\"><BR>Unknown user or password incorrect.<BR><A HREF=\"login.php3\" TARGET=_top>Click here to try again</A>.</FONT></CENTER>";
+ echo " </TD></TR>";
+ echo "</TABLE>";
+ echo "</BODY></HTML>";
+ }
+
+ function general_info($motd, $org_logo, $version, $org_name) {
+ echo "<BR>";
+ echo "<TABLE COLS=1 WIDTH=70% NOBORDER BGCOLOR=FFFFFF ALIGN=CENTER>";
+ echo " <TR>";
+ echo " <TD BGCOLOR=DCDCDC>";
+ echo " <FONT FACE=\"Arial,Helvetica\"><B><CENTER>Welcome to $org_name's WebMail system</CENTER></B></FONT>";
+ echo " </TD></TR><TR><TD>";
+ echo " <TR><TD BGCOLOR=FFFFFF>";
+ echo " <FONT FACE=\"Arial,Helvetica\" SIZE=-1><CENTER>Running SquirrelMail version $version (c) 1999 by Nathan and Luke Ehresman.</CENTER></FONT>";
+ echo " </TD></TR><TR><TD>";
+ echo " <TABLE COLS=2 WIDTH=75% NOBORDER align=\"center\">";
+ echo " <TR>";
+ echo " <TD BGCOLOR=FFFFFF><CENTER>";
+ if (strlen($org_logo) > 3)
+ echo " <IMG SRC=\"$org_logo\">";
+ else
+ echo " <B><FONT FACE=\"Arial,Helvetica\">$org_name</FONT></B>";
+ echo " </CENTER></TD></TR><TR>";
+ echo " <TD BGCOLOR=FFFFFF>";
+ echo " <FONT FACE=\"Arial,Helvetica\">$motd</FONT>";
+ echo " </TD>";
+ echo " </TR>";
+ echo " </TABLE>";
+ echo " </TD></TR>";
+ echo "</TABLE>";
+ echo "</BODY></HTML>";
+ }
+?>
\ No newline at end of file
--- /dev/null
+<?
+ /**
+ ** imap.php3
+ **
+ ** Functions for the IMAP connection
+ **
+ **/
+
+ /** Read from the connection until we get either an OK or BAD message. **/
+ function imapReadData($connection) {
+ $read = fgets($connection, 1024);
+ $counter = 0;
+ while ((substr($read, strpos($read, " ") + 1, 2) != "OK") && (substr($read, strpos($read, " ") + 1, 3) != "BAD")) {
+ $data[$counter] = $read;
+ $read = fgets($connection, 1024);
+ $counter++;
+ }
+ return $data;
+ }
+?>
--- /dev/null
+<?
+ /**
+ ** mailbox.php3
+ **
+ ** This contains functions that request information about a mailbox. Including
+ ** reading and parsing headers, getting folder information, etc.
+ **
+ **/
+
+ function selectMailbox($imapConnection, $mailbox, &$numberOfMessages) {
+ // select mailbox
+ fputs($imapConnection, "mailboxSelect SELECT \"$mailbox\"\n");
+ $read = fgets($imapConnection, 1024);
+ while ((substr($read, 0, 16) != "mailboxSelect OK") && (substr($read, 0, 17) != "mailboxSelect BAD")) {
+ if (substr(Chop($read), -6) == "EXISTS") {
+ $array = explode(" ", $read);
+ $numberOfMessages = $array[1];
+ }
+ $read = fgets($imapConnection, 1024);
+ }
+ }
+
+ function getMessageHeaders($imapConnection, $i, &$from, &$subject, &$date) {
+ fputs($imapConnection, "messageFetch FETCH $i:$i RFC822.HEADER.LINES (From Subject Date)\n");
+ $read = fgets($imapConnection, 1024);
+ /* I have to replace <> with [] because HTML uses <> as tags, thus not printing what's in <> */
+ $read = ereg_replace("<", "[", $read);
+ $read = ereg_replace(">", "]", $read);
+
+ while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
+ if (substr($read, 0, 5) == "From:") {
+ $read = ereg_replace("<", "EMAILSTART--", $read);
+ $read = ereg_replace(">", "--EMAILEND", $read);
+ $from = substr($read, 5, strlen($read) - 6);
+ }
+ else if (substr($read, 0, 5) == "Date:") {
+ $read = ereg_replace("<", "[", $read);
+ $read = ereg_replace(">", "]", $read);
+ $date = substr($read, 5, strlen($read) - 6);
+ }
+ else if (substr($read, 0, 8) == "Subject:") {
+ $read = ereg_replace("<", "[", $read);
+ $read = ereg_replace(">", "]", $read);
+ $subject = substr($read, 8, strlen($read) - 9);
+ }
+
+ $read = fgets($imapConnection, 1024);
+ }
+ }
+
+ function getMessageFlags($imapConnection, $i, &$flags) {
+ /** * 2 FETCH (FLAGS (\Answered \Seen)) */
+ fputs($imapConnection, "messageFetch FETCH $i:$i FLAGS\n");
+ while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
+ if (strpos($read, "FLAGS")) {
+ $read = ereg_replace("\(", "", $read);
+ $read = ereg_replace("\)", "", $read);
+ $read = substr($read, strpos($read, "FLAGS")+6, strlen($read));
+ $read = trim($read);
+ $flags = explode(" ", $read);;
+ $i = 0;
+ while ($i < count($flags)) {
+ $flags[$i] = substr($flags[$i], 1, strlen($flags[$i]));
+ $i++;
+ }
+ } else {
+ $flags[0] = "None";
+ }
+ $read = fgets($imapConnection, 1024);
+ }
+ }
+
+ function getEmailAddr($sender) {
+ if (strpos($sender, "EMAILSTART--") == false)
+ return "";
+
+ $start = strpos($sender, "EMAILSTART--");
+ $emailAddr = substr($sender, $start, strlen($sender));
+
+ return $emailAddr;
+ }
+
+ function getSender($sender) {
+ if (strpos($sender, "EMAILSTART--") == false)
+ return "";
+
+ $first = substr($sender, 0, strpos($sender, "EMAILSTART--"));
+ $second = substr($sender, strpos($sender, "--EMAILEND") +10, strlen($sender));
+ return "$first$second";
+ }
+
+ function getSenderName($sender) {
+ $name = getSender($sender);
+ $emailAddr = getEmailAddr($sender);
+ $emailStart = strpos($emailAddr, "EMAILSTART--");
+ $emailEnd = strpos($emailAddr, "--EMAILEND") - 10;
+
+ if (($emailAddr == "") && ($name == "")) {
+ $from = $sender;
+ }
+ else if ((strstr($name, "?") != false) || (strstr($name, "$") != false) || (strstr($name, "%") != false)){
+ $emailAddr = ereg_replace("EMAILSTART--", "", $emailAddr);
+ $emailAddr = ereg_replace("--EMAILEND", "", $emailAddr);
+ $from = $emailAddr;
+ }
+ else if (strlen($name) > 0) {
+ $from = $name;
+ }
+ else if (strlen($emailAddr > 0)) {
+ $emailAddr = ereg_replace("EMAILSTART--", "", $emailAddr);
+ $emailAddr = ereg_replace("--EMAILEND", "", $emailAddr);
+ $from = $emailAddr;
+ }
+
+ $from = trim($from);
+
+ // strip out any quotes if they exist
+ if ((strlen($from) > 0) && ($from[0] == "\"") && ($from[strlen($from) - 1] == "\""))
+ $from = substr($from, 1, strlen($from) - 2);
+
+ return $from;
+ }
+?>
\ No newline at end of file
--- /dev/null
+<?
+ /**
+ ** mailbox_display.php3
+ **
+ ** This contains functions that display mailbox information, such as the
+ ** table row that has sender, date, subject, etc...
+ **
+ **/
+
+ function printMessageInfo($imapConnection, $i, $from, $subject, $date) {
+ getMessageHeaders($imapConnection, $i, $from, $subject, $date);
+ getMessageFlags($imapConnection, $i, $flags);
+ $dateParts = explode(" ", trim($date));
+ $dateString = getDateString($dateParts); // this will reformat the date string into a good format for us.
+ $senderName = getSenderName($from);
+ if (strlen(Chop($subject)) == 0)
+ $subject = "(no subject)";
+
+ $j = 0;
+ $deleted = false;
+ $seen = false;
+ $answered = false;
+ while ($j < count($flags)) {
+ if ($flags[$j] == "Deleted") {
+ $deleted = true;
+ } else if ($flags[$j] == "Answered") {
+ $answered = true;
+ } else if ($flags[$j] == "Seen") {
+ $seen = true;
+ }
+ $j++;
+ }
+
+ if ($deleted == false) {
+ echo "<TR>\n";
+ if ($seen == false) {
+ echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$i</B></FONT></TD>\n";
+ echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$senderName</B></FONT></TD>\n";
+ echo " <TD><CENTER><B><FONT FACE=\"Arial,Helvetica\">$dateString</FONT></B></CENTER></TD>\n";
+ echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$subject</B></FONT></TD>\n";
+ } else {
+ echo " <TD><FONT FACE=\"Arial,Helvetica\">$i</FONT></TD>\n";
+ echo " <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
+ echo " <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
+ echo " <TD><FONT FACE=\"Arial,Helvetica\">$subject</FONT></TD>\n";
+ }
+ echo "</TR>\n";
+ }
+ }
+?>
\ No newline at end of file
--- /dev/null
+<?
+ /**
+ ** page_header.php3
+ **
+ ** Prints the page header (duh)
+ **
+ **/
+
+ function displayPageHeader($mailbox) {
+ /** Here is the header and wrapping table **/
+ $shortBoxName = readShortMailboxName($mailbox, ".");
+ echo "<TABLE BGCOLOR=FFFFFF BORDER=0 COLS=2 WIDTH=100% CELLSPACING=0 CELLPADDING=2>";
+ echo " <TR BGCOLOR=A0B8C8 WIDTH=50%>";
+ echo " <TD ALIGN=left>";
+ echo " <FONT FACE=\"Arial,Helvetica\" SIZE=-1><A HREF=\"signout.php3\" TARGET=_top><B>Sign Out</B></A></FONT>";
+ echo " </TD><TD ALIGN=right WIDTH=50%>";
+ echo " <FONT FACE=\"Arial,Helvetica\"><div align=right>Current Folder: <B>$shortBoxName</div></B></FONT>";
+ echo " </TD>";
+ echo " </TR><TR>";
+ echo " <TD ALIGN=left WIDTH=50%>";
+ echo " <FONT FACE=\"Arial,Helvetica\">Compose</FONT>  ";
+ echo " <FONT FACE=\"Arial,Helvetica\">Addresses</FONT>  ";
+ echo " <FONT FACE=\"Arial,Helvetica\">Options</FONT>  ";
+ echo " </TD><TD ALIGN=right WIDTH=50%>";
+ echo " <FONT FACE=\"Arial,Helvetica\"><A HREF=\"http://adam.usa.om.org/~luke/main.php3\" TARGET=_top>Todos & Bugs</A></FONT>  ";
+ echo " <FONT FACE=\"Arial,Helvetica\">Help!</FONT>";
+ echo " </TD>";
+ echo "</TABLE>";
+ }
+?>
--- /dev/null
+<?
+ //*************************************************************************
+ // Count the number of occurances of $needle are in $haystack.
+ //*************************************************************************
+ function countCharInString($haystack, $needle) {
+ $len = strlen($haystack);
+ for ($i = 0; $i < $len; $i++) {
+ if ($haystack[$i] == $needle)
+ $count++;
+ }
+ return $count;
+ }
+
+ //*************************************************************************
+ // Read from the back of $haystack until $needle is found, or the begining
+ // of the $haystack is reached.
+ //*************************************************************************
+ function readShortMailboxName($haystack, $needle) {
+ $len = strlen($haystack);
+ for ($i = $len - 1; ($i >= 0) && (!$found);$i--) {
+ $char = $haystack[$i];
+ if ($char == $needle)
+ $found = 1;
+ else
+ $data .= $char;
+ }
+ return strrev($data);
+ }
+
+?>