/**
  * Starts the download of the specified messages.
  * 
  * @param	string		$pmIDs
  */
 public static function downloadAll($pmIDs)
 {
     // count messages
     $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_pm\n\t\t\tWHERE\tpmID IN (" . $pmIDs . ")";
     $row = WCF::getDB()->getFirstRow($sql);
     $count = $row['count'];
     // get recipients
     $recpients = array();
     $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_pm_to_user\n\t\t\tWHERE\t\tpmID IN (" . $pmIDs . ")\n\t\t\t\t\tAND isBlindCopy = 0\n\t\t\tORDER BY\trecipient";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (!isset($recpients[$row['pmID']])) {
             $recpients[$row['pmID']] = array();
         }
         $recpients[$row['pmID']][] = new PMRecipient(null, null, $row);
     }
     // get messages
     if ($count > 1) {
         $zip = new ZipWriter();
     }
     $sql = "SELECT\t\trecipient.*,\n\t\t\t\t\tpm.*\n\t\t\tFROM\t\twcf" . WCF_N . "_pm pm\n\t\t\tLEFT JOIN \twcf" . WCF_N . "_pm_to_user recipient\n\t\t\tON \t\t(recipient.pmID = pm.pmID\n\t\t\t\t\tAND recipient.recipientID = " . WCF::getUser()->userID . "\n\t\t\t\t\tAND recipient.isDeleted < 2)\n\t\t\tWHERE\t\tpm.pmID IN (" . $pmIDs . ")\n\t\t\tGROUP BY\tpm.pmID\n\t\t\tORDER BY\tpm.time DESC";
     $result = WCF::getDB()->sendQuery($sql);
     $messageNo = 1;
     while ($row = WCF::getDB()->fetchArray($result)) {
         $pm = new PM(null, $row);
         $pm->setRecipients(isset($recpients[$row['pmID']]) ? $recpients[$row['pmID']] : array());
         // get parsed text
         require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php';
         $parser = MessageParser::getInstance();
         $parser->setOutputType('text/plain');
         $parsedText = $parser->parse($pm->message, $pm->enableSmilies, $pm->enableHtml, $pm->enableBBCodes, false);
         $data = array('$author' => $pm->username ? $pm->username : WCF::getLanguage()->get('wcf.pm.author.system'), '$date' => DateUtil::formatTime(null, $pm->time), '$recipient' => implode(', ', $pm->getRecipients()), '$subject' => $pm->subject, '$text' => $parsedText);
         if ($count == 1) {
             // send headers
             // file type
             @header('Content-Type: text/plain');
             // file name
             @header('Content-disposition: attachment; filename="' . $pm->pmID . '-' . preg_replace('~[^a-z0-9_ -]+~i', '', $pm->subject) . '.txt"');
             // no cache headers
             @header('Pragma: no-cache');
             @header('Expires: 0');
             // output message
             echo (CHARSET == 'UTF-8' ? "" : '') . WCF::getLanguage()->get('wcf.pm.download.message', $data);
             exit;
         } else {
             $zip->addFile((CHARSET == 'UTF-8' ? "" : '') . WCF::getLanguage()->get('wcf.pm.download.message', $data), $pm->pmID . '-' . preg_replace('~[^a-z0-9_ -]+~i', '', $pm->subject) . '.txt', $pm->time);
         }
         $messageNo++;
     }
     if ($messageNo > 1) {
         // send headers
         // file type
         @header('Content-Type: application/octet-stream');
         // file name
         @header('Content-disposition: attachment; filename="messages-' . ($messageNo - 1) . '.zip"');
         // no cache headers
         @header('Pragma: no-cache');
         @header('Expires: 0');
         // output file
         echo $zip->getFile();
         exit;
     }
 }