- while ($j < count($msg)) {
- if (isset($msg[$i])) {
- $id = $msg[$i];
- $body_a = sqimap_run_command($imapConnection, "FETCH $id RFC822",true, $response, $readmessage, $uid_support);
- if ($response == 'OK') {
- $k = $i + $start_index;
- $subject = $msgs[$k]['SUBJECT'];
+ foreach($msg as $id) {
+ $body_a = sqimap_run_command($imapConnection, "FETCH $id RFC822", true, $response, $readmessage, $uid_support);
+
+ if ($response == 'OK') {
+
+ // fetch the subject for the message with $id from msgs.
+ // is there a more efficient way to do this?
+ foreach($msgs as $k => $vals) {
+ if($vals['ID'] == $id) {
+ $subject = $msgs[$k]['SUBJECT'];
+ break;
+ }
+ }