+/** @ignore */
+define('SM_PATH','../../');
+
+ /* SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/imap.php');
+
+/**
+ * Stores message in attachment directory, when email based reports are used
+ * @access private
+ */
+function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
+ $passed_ent_id='', $imapConnection) {
+ global $attachments, $attachment_dir, $username, $data_dir;
+
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+ if (!$passed_ent_id) {
+ $body_a = sqimap_run_command($imapConnection,
+ 'FETCH '.$passed_id.' RFC822',
+ TRUE, $response, $readmessage,
+ TRUE);
+ } else {
+ $body_a = sqimap_run_command($imapConnection,
+ 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
+ TRUE, $response, $readmessage,TRUE);
+ $message = $message->parent;
+ }
+ if ($response == 'OK') {
+ $subject = encodeHeader($message->rfc822_header->subject);
+ array_shift($body_a);
+ $body = implode('', $body_a) . "\r\n";
+
+ $localfilename = GenerateRandomString(32, 'FILE', 7);
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+ $fp = fopen( $full_localfilename, 'w');
+ fwrite ($fp, $body);
+ fclose($fp);
+
+ /* dirty relative dir fix */
+ if (substr($attachment_dir,0,3) == '../') {
+ $attachment_dir = substr($attachment_dir,3);
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+ }
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+
+ $composeMessage->initAttachment('message/rfc822','email.txt',
+ $full_localfilename);
+ }
+ return $composeMessage;
+}
+
+
+/* GLOBALS */
+
+sqgetGlobalVar('username', $username, SQ_SESSION);
+sqgetGlobalVar('key', $key, SQ_COOKIE);
+sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
+
+sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
+sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
+sqgetGlobalVar('js_web', $js_web, SQ_GET);
+
+if (! sqgetGlobalVar('startMessage', $startMessage, SQ_GET) ) {
+ $startMessage = 1;
+}
+if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
+ $passed_ent_id = 0;
+}
+if (! sqgetGlobalVar('js_web', $js_web, SQ_GET) ) {
+ $js_web = 0;
+}
+
+sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
+
+if(! sqgetGlobalVar('composesession', $composesession, SQ_SESSION) ) {
+ $composesession = 0;
+ sqsession_register($composesession, 'composesession');
+}
+/* END GLOBALS */
+
+// js_web variable is 1 only when link opens web based report page in new window
+// and in new window menu line or extra javascript code is not needed.
+if ($js_web) {
+ displayHTMLHeader(_("SpamCop reporting"));
+ echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
+} else {
+ displayPageHeader($color,$mailbox);
+}