From 1e89ed4130b20730fa4d3715901ad5d3d8e1494e Mon Sep 17 00:00:00 2001 From: stekkel Date: Sun, 6 Oct 2002 17:06:24 +0000 Subject: [PATCH] adapt spamcop to make use of the new way we send mail git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3769 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- plugins/spamcop/spamcop.php | 137 +++++++++++++++++++++++++----------- 1 file changed, 94 insertions(+), 43 deletions(-) diff --git a/plugins/spamcop/spamcop.php b/plugins/spamcop/spamcop.php index 511ca33e..90ad526a 100644 --- a/plugins/spamcop/spamcop.php +++ b/plugins/spamcop/spamcop.php @@ -14,24 +14,84 @@ define('SM_PATH','../../'); require_once(SM_PATH . 'include/validate.php'); require_once(SM_PATH . 'functions/imap.php'); - /* GLOBALS */ +function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, + $passed_ent_id='', $imapConnection) { + global $attachments, $attachment_dir, $username, $data_dir, $uid_support; + + $hashed_attachment_dir = getHashedDir($username, $attachment_dir); + if (!$passed_ent_id) { + $body_a = sqimap_run_command($imapConnection, + 'FETCH '.$passed_id.' RFC822', + TRUE, $response, $readmessage, + $uid_support); + } else { + $body_a = sqimap_run_command($imapConnection, + 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']', + TRUE, $response, $readmessage, $uid_support); + $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 */ $username = $_SESSION['username']; $key = $_COOKIE['key']; $onetimepad = $_SESSION['onetimepad']; - $mailbox = $_GET['mailbox']; $passed_id = $_GET['passed_id']; - $startMessage = $_GET['startMessage']; + if (isset($_GET['startMessage'])) { + $startMessage = $_GET['startMessage']; + } else { + $startMessage = 1; + } + if (isset($_GET['passed_ent_id'])) { + $passed_ent_id = $_GET['passed_ent_id']; + } else { + $passed_ent_id = ''; + } + if ( isset($_SESSION['compose_messages']) ) { + $compose_messages = &$_SESSION['compose_messages']; + } + if ( isset($_SESSION['composesession']) ) { + $composesession = $_SESSION['composesession']; + } else { + $composesession = 0; + sqsession_register($composesession, 'composesession'); + } /* END GLOBALS */ + displayPageHeader($color, $mailbox); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imap_stream, $mailbox); - $sid = sqimap_session_id($uid_support) + + + $sid = sqimap_session_id($uid_support); fputs($imap_stream, $sid.' FETCH ' . $passed_id . ' RFC822' . "\r\n"); $read = sqimap_read_data($imap_stream, $sid, true, $response, $message); @@ -40,48 +100,38 @@ require_once(SM_PATH . 'functions/imap.php'); if ($spamcop_method == 'quick_email' || $spamcop_method == 'thorough_email') { // Use email-based reporting -- save as an attachment - if(!isset($composesession)) { - $composesession = 0; - sqsession_register($composesession, 'composesession'); + $session = "$composesession"+1; + $composesession = $session; + sqsession_register($composesession,'composesession'); + if (!isset($compose_messages)) { + $compose_messages = array(); } - if (!isset($session)) { - $session = "$composesession" +1; - $composesession = $session; + if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) { + $composeMessage = new Message(); + $rfc822_header = new Rfc822Header(); + $composeMessage->rfc822_header = $rfc822_header; + $composeMessage->reply_rfc822_header = ''; + $compose_messages[$session] = $composeMessage; + sqsession_register($compose_messages,'compose_messages'); + } else { + $composeMessage=$compose_messages[$session]; } - if (!isset($attachments)) { - $attachments = array(); - sqsession_register($attachments, 'attachments'); - } - - foreach ($attachments as $info) { - if (file_exists($attachment_dir . $info['localfilename'])) - unlink($attachment_dir . $info['localfilename']); - } - $attachments = array(); - - $file = GenerateRandomString(32, '', 7); - while (file_exists($attachment_dir . $file)) - $file = GenerateRandomString(32, '', 7); - $newAttachment['localfilename'] = $file; - $newAttachment['remotefilename'] = 'email.txt'; - $newAttachment['type'] = 'message/rfc822'; - $newAttachment['session'] = $session; - $fp = fopen($attachment_dir . $file, 'w'); - foreach ($read as $line) { - fputs($fp, $line); - } - sqsession_unregister('attachments'); - $attachments[] = $newAttachment; - sqsession_register($attachments , 'attachments'); - $fn = getPref($data_dir, $username, 'full_name'); - $em = getPref($data_dir, $username, 'email_address'); - - $HowItLooks = $fn . ' '; - if ($em != '') + $message = sqimap_get_message($imap_stream, $passed_id, $mailbox); + $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, + $passed_ent_id='', $imap_stream); + + $compose_messages[$session] = $composeMessage; + sqsession_register($compose_messages, 'compose_messages'); + + $fn = getPref($data_dir, $username, 'full_name'); + $em = getPref($data_dir, $username, 'email_address'); + + $HowItLooks = $fn . ' '; + if ($em != '') $HowItLooks .= '<' . $em . '>'; - } + } ?> @@ -116,12 +166,13 @@ agree to follow SpamCop's rules/terms of service/etc.

$report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net'; else $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net'; -?>
+ $form_action = SM_PATH . 'src/compose.php'; +?> - + -- 2.25.1