adapt spamcop to make use of the new way we send mail
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 6 Oct 2002 17:06:24 +0000 (17:06 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 6 Oct 2002 17:06:24 +0000 (17:06 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3769 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/spamcop/spamcop.php

index 511ca33e856dbd09ea51954d18b9e68564ba4f9b..90ad526adae07b8a090a502c6aa5a301eaaffa34 100644 (file)
@@ -14,24 +14,84 @@ define('SM_PATH','../../');
 require_once(SM_PATH . 'include/validate.php');
 require_once(SM_PATH . 'functions/imap.php');
 
 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'];
     $username = $_SESSION['username'];
     $key  = $_COOKIE['key'];
     $onetimepad = $_SESSION['onetimepad'];
-
     $mailbox = $_GET['mailbox'];
     $passed_id = $_GET['passed_id'];
     $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 */
     /* END GLOBALS */
+
     
     displayPageHeader($color, $mailbox);
 
     $imap_stream = sqimap_login($username, $key, $imapServerAddress, 
        $imapPort, 0);
     sqimap_mailbox_select($imap_stream, $mailbox);
     
     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);
     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 ($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 . '>';
           $HowItLooks .= '<' . $em . '>';
-    }
+     }
 
 ?>
 
 
 ?>
 
@@ -116,12 +166,13 @@ agree to follow SpamCop's rules/terms of service/etc.</p>
       $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net';
    else
       $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net';
       $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net';
    else
       $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net';
-?>  <form method=post action="../../src/compose.php">
+   $form_action = SM_PATH . 'src/compose.php';
+?>  <form method=post action="<?PHP echo $form_action?>">
   <input type=hidden name="mailbox" value="<?PHP echo
      htmlspecialchars($mailbox) ?>">
   <input type=hidden name="spamcop_is_composing" value="<?PHP echo
      htmlspecialchars($passed_id) ?>">
   <input type=hidden name="mailbox" value="<?PHP echo
      htmlspecialchars($mailbox) ?>">
   <input type=hidden name="spamcop_is_composing" value="<?PHP echo
      htmlspecialchars($passed_id) ?>">
-  <input type=hidden name="send_to" value="<?PHP echo $report_email ?>">
+  <input type=hidden name="send_to" value="<?PHP echo $report_email?>">
   <input type=hidden name="send_to_cc" value="">
   <input type=hidden name="send_to_bcc" value="">
   <input type=hidden name="subject" value="reply anyway">
   <input type=hidden name="send_to_cc" value="">
   <input type=hidden name="send_to_bcc" value="">
   <input type=hidden name="subject" value="reply anyway">