Source for file spamcop.php

Documentation is available at spamcop.php

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

Documentation generated on Mon, 13 Jan 2020 04:25:21 +0100 by phpDocumentor 1.4.3