From: kink Date: Mon, 21 Jul 2003 15:01:23 +0000 (+0000) Subject: Fetching the subject for the messages-to-be-attached went wrong. $i X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=a2388eb782bc8b1a2543adac15b745ecb55d9fbc;ds=sidebyside Fetching the subject for the messages-to-be-attached went wrong. $i and $start_message have no relation to the indices of the $msg array. Fix this by looping the $msgs array until we find the message with the right id and take that subject. Closes #772371. Is it possible given an ID to fetch the subject of a message in a more efficient way? git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@5370 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/src/move_messages.php b/src/move_messages.php index 43b89e56..5e17ac60 100644 --- a/src/move_messages.php +++ b/src/move_messages.php @@ -67,26 +67,34 @@ function attachSelectedMessages($msg, $imapConnection) { 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']; - array_shift($body_a); - $body = implode('', $body_a); - $body .= "\r\n"; + // 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; + } + } + + array_shift($body_a); + $body = implode('', $body_a); + $body .= "\r\n"; - $localfilename = GenerateRandomString(32, 'FILE', 7); - $full_localfilename = "$hashed_attachment_dir/$localfilename"; + $localfilename = GenerateRandomString(32, 'FILE', 7); + $full_localfilename = "$hashed_attachment_dir/$localfilename"; - $fp = fopen( $full_localfilename, 'wb'); - fwrite ($fp, $body); - fclose($fp); - $composeMessage->initAttachment('message/rfc822',$subject.'.eml', + $fp = fopen( $full_localfilename, 'wb'); + fwrite ($fp, $body); + fclose($fp); + $composeMessage->initAttachment('message/rfc822',$subject.'.eml', $full_localfilename); } - $j++; - } - $i++; + $j++; + } + $i++; } $compose_messages[$composesession] = $composeMessage; sqsession_register($compose_messages,'compose_messages');