+ // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
+ // return the index. used for finding the next and previous messages
+
+ // returns the index of the next valid message from the array
+ function findNextMessage() {
+ global $currentArrayIndex, $msgs;
+ if ($currentArrayIndex < (count($msgs)-1))
+ return $msgs[$currentArrayIndex+1]["ID"];
+ return -1;
+ }
+
+ // returns the index of the previous message from the array
+ function findPreviousMessage() {
+ global $currentArrayIndex, $msgs;
+ if ($currentArrayIndex > 0)
+ return $msgs[$currentArrayIndex-1]["ID"];
+ return -1;
+ }
+
+ if (isset($msgs)) {
+ for ($i=0; $i < count($msgs); $i++) {
+ if ($msgs[$i]["ID"] == $passed_id) {
+ $currentArrayIndex = $i;
+ break;
+ }
+ }
+ } else {
+ $currentArrayIndex = -1;
+ }
+