Source for file spamcop.php

Documentation is available at spamcop.php

  1. <?php
  2.    /** 
  3.     **  spamcop.php -- SpamCop plugin
  4.     *
  5.     **  Copyright (c) 1999-2006 The SquirrelMail Project Team
  6.     **  Licensed under the GNU GPL. For full terms see the file COPYING.
  7.     *
  8.     **  $Id: spamcop.php,v 1.14.2.11 2006/07/13 10:13:23 tokul Exp $
  9.     **/
  10.  
  11.  
  12. define('SM_PATH','../../');
  13.  
  14.  /* SquirrelMail required files. */
  15. require_once(SM_PATH 'include/validate.php');
  16. require_once(SM_PATH 'functions/imap.php');
  17.  
  18. function getMessage_RFC822_Attachment($message$composeMessage$passed_id
  19.                                       $passed_ent_id=''$imapConnection{
  20.     global $attachments$attachment_dir$username$data_dir$uid_support;
  21.     
  22.     $hashed_attachment_dir getHashedDir($username$attachment_dir);
  23.     if (!$passed_ent_id{
  24.         $body_a sqimap_run_command($imapConnection
  25.                                     'FETCH '.$passed_id.' RFC822',
  26.                                     TRUE$response$readmessage
  27.                                     $uid_support);
  28.     else {
  29.         $body_a sqimap_run_command($imapConnection
  30.                                      'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
  31.                                      TRUE$response$readmessage$uid_support);
  32.         $message $message->parent;
  33.     }
  34.     if ($response == 'OK'{
  35.         $subject encodeHeader($message->rfc822_header->subject);
  36.         array_shift($body_a);
  37.         $body implode(''$body_a"\r\n";
  38.                 
  39.         $localfilename GenerateRandomString(32'FILE'7);
  40.         $full_localfilename "$hashed_attachment_dir/$localfilename";
  41.         $fp fopen$full_localfilename'w');
  42.         fwrite ($fp$body);
  43.         fclose($fp);
  44.     
  45.         /* dirty relative dir fix */
  46.         if (substr($attachment_dir,0,3== '../'{
  47.        $attachment_dir substr($attachment_dir,3);
  48.        $hashed_attachment_dir getHashedDir($username$attachment_dir);
  49.         }
  50.     $full_localfilename "$hashed_attachment_dir/$localfilename";
  51.  
  52.     $composeMessage->initAttachment('message/rfc822','email.txt'
  53.                      $full_localfilename);
  54.     }
  55.     return $composeMessage;
  56. }
  57.  
  58.  
  59. /* GLOBALS */
  60.  
  61. sqgetGlobalVar('username'$usernameSQ_SESSION);
  62. sqgetGlobalVar('key',      $key,      SQ_COOKIE);
  63. sqgetGlobalVar('onetimepad'$onetimepadSQ_SESSION);
  64.  
  65. sqgetGlobalVar('mailbox'$mailboxSQ_GET);
  66. sqgetGlobalVar('passed_id'$passed_idSQ_GET);
  67.  
  68. if (sqgetGlobalVar('startMessage'$startMessageSQ_GET) ) {
  69.     $startMessage 1;
  70. }
  71. if (sqgetGlobalVar('passed_ent_id'$passed_ent_idSQ_GET) ) {
  72.     $passed_ent_id 0;
  73. }
  74.  
  75. sqgetGlobalVar('compose_messages'$compose_messagesSQ_SESSION);
  76.  
  77. if(sqgetGlobalVar('composesession'$composesessionSQ_SESSION) ) {
  78.     $composesession 0;
  79.     sqsession_register($composesession'composesession');
  80. }
  81. /* END GLOBALS */
  82.  
  83.     
  84.     displayPageHeader($color$mailbox);
  85.  
  86.     $imap_stream sqimap_login($username$key$imapServerAddress
  87.        $imapPort0);
  88.     sqimap_mailbox_select($imap_stream$mailbox);
  89.  
  90.     if ($spamcop_method == 'quick_email' || 
  91.         $spamcop_method == 'thorough_email'{
  92.        // Use email-based reporting -- save as an attachment
  93.               $session "$composesession"+1;
  94.        $composesession $session;
  95.        sqsession_register($composesession,'composesession');
  96.        if (!isset($compose_messages)) {
  97.           $compose_messages array();
  98.        }
  99.        if (!isset($compose_messages[$session]|| ($compose_messages[$session== NULL)) {
  100.           $composeMessage new Message();
  101.           $rfc822_header new Rfc822Header();
  102.           $composeMessage->rfc822_header $rfc822_header;
  103.           $composeMessage->reply_rfc822_header '';
  104.           $compose_messages[$session$composeMessage;
  105.           sqsession_register($compose_messages,'compose_messages');  
  106.        else {
  107.           $composeMessage=$compose_messages[$session];
  108.        }
  109.  
  110.  
  111.         $message sqimap_get_message($imap_stream$passed_id$mailbox);
  112.         $composeMessage getMessage_RFC822_Attachment($message$composeMessage$passed_id
  113.                                       $passed_ent_id$imap_stream);
  114.  
  115.         $compose_messages[$session$composeMessage;
  116.     sqsession_register($compose_messages'compose_messages');
  117.  
  118.         $fn getPref($data_dir$username'full_name');
  119.         $em getPref($data_dir$username'email_address');
  120.  
  121.         $HowItLooks $fn ' ';
  122.         if ($em != '')
  123.           $HowItLooks .= '<' $em '>';
  124.      }
  125.  
  126.  
  127. echo "<p>";
  128. echo _("Sending this spam report will give you back a reply with URLs that you can click on to properly report this spam message to the proper authorities. This is a free service. By pressing the \"Send Spam Report\" button, you agree to follow SpamCop's rules/terms of service/etc.");
  129. echo "</p>";
  130.  
  131. ?>
  132.  
  133. <table align="center" width="75%" border="0" cellpadding="0" cellspacing="0">
  134. <tr>
  135. <td align="left" valign="top">
  136. <?PHP if (isset($js_web&& $js_web{
  137.   echo "<form method=\"post\" action=\"javascript:return false\">\n";
  138.   echo '<input type="button" value="' _("Close Window""\" onClick=\"window.close(); return true;\" />\n";
  139. else {
  140.    ?><form method="post" action="../../src/right_main.php">
  141.   <input type="hidden" name="mailbox" value="<?PHP echo htmlspecialchars($mailbox?>" />
  142.   <input type="hidden" name="startMessage" value="<?PHP echo htmlspecialchars($startMessage?>" />
  143.    <?PHP
  144.   echo '<input type="submit" value="' _("Cancel / Done""\" />\n";
  145. }
  146.   ?></form>
  147. </td>
  148. <td align="right" valign="top">
  149. <?PHP if ($spamcop_method == 'thorough_email' ||
  150.           $spamcop_method == 'quick_email'{
  151.    if ($spamcop_method == 'thorough_email')
  152.       $report_email 'submit.' $spamcop_id '@spam.spamcop.net';
  153.    else
  154.       $report_email 'quick.' $spamcop_id '@spam.spamcop.net';
  155.    $form_action SM_PATH 'src/compose.php';
  156. ?>  <form method="post" action="<?PHP echo $form_action?>">
  157.   <input type="hidden" name="mailbox" value="<?PHP echo htmlspecialchars($mailbox?>" />
  158.   <input type="hidden" name="spamcop_is_composing" value="<?PHP echo htmlspecialchars($passed_id?>" />
  159.   <input type="hidden" name="send_to" value="<?PHP echo htmlspecialchars($report_email)?>" />
  160.   <input type="hidden" name="subject" value="reply anyway" />
  161.   <input type="hidden" name="identity" value="0" />
  162.   <input type="hidden" name="session" value="<?PHP echo $session?>" />
  163. <?PHP  
  164.   echo '<input type="submit" name="send" value="' _("Send Spam Report""\" />\n";
  165.  else {
  166.    $spam_message mime_fetch_body ($imap_stream$passed_id$passed_ent_id50000);
  167.  
  168.    if (strlen($spam_message== 50000{
  169.       $Warning "\n[truncated by SpamCop]\n";
  170.       $spam_message substr($spam_message050000 strlen($Warning)) $Warning;
  171.    }
  172.    if (isset($js_web&& $js_web{
  173. ?>  <form method="post" action="http://members.spamcop.net/sc" name="submitspam"
  174.     enctype="multipart/form-data"><?PHP
  175.    else {
  176. ?>  <form method="post" action="http://members.spamcop.net/sc" name="submitspam"
  177.     enctype="multipart/form-data" target="_top"><?PHP
  178.    ?>
  179.   <input type="hidden" name="action" value="submit" />
  180.   <input type="hidden" name="oldverbose" value="1" />
  181.   <input type="hidden" name="spam" value="<?PHP echo htmlspecialchars($spam_message)?>" />
  182. <?PHP
  183.   echo '<input type="submit" name="x1" value="' _("Send Spam Report""\" />";
  184.  }
  185. ?>
  186. </form>
  187. </td></tr>
  188. </table>
  189. </body></html>

Documentation generated on Sat, 07 Oct 2006 16:33:44 +0300 by phpDocumentor 1.3.0RC6