Adding support for spamcop member service.
authortokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 26 Dec 2003 08:39:17 +0000 (08:39 +0000)
committertokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 26 Dec 2003 08:39:17 +0000 (08:39 +0000)
Adding fix that allows submiting attached spams with web based reporting form
(thanks to Magnus Henoch <mange at freemail.hu>)

Removing page header display, when form is opened in new window.

Removing insertion of javascript, when javascript is disabled.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@6320 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/spamcop/options.php
plugins/spamcop/setup.php
plugins/spamcop/spamcop.php

index 8c4c1e0e070cd2cb52efc8ed6662475fb5389240..111903ffaa0e2e62de79492155223c21a601c238 100755 (executable)
 define('SM_PATH','../../');
 require_once(SM_PATH . 'include/validate.php');
 
 define('SM_PATH','../../');
 require_once(SM_PATH . 'include/validate.php');
 
+/**
+ * Internal spamcop plugin function.
+ *
+ * It is used to display similar action links.
+ */
 function spamcop_enable_disable($option,$disable_action,$enable_action) {
     if ($option) { 
        $ret= _("Enabled") . "(<a href=\"options.php?action=$disable_action\">" . _("Disable it") . "</a>)\n";
 function spamcop_enable_disable($option,$disable_action,$enable_action) {
     if ($option) { 
        $ret= _("Enabled") . "(<a href=\"options.php?action=$disable_action\">" . _("Disable it") . "</a>)\n";
@@ -29,6 +34,7 @@ displayPageHeader($color, 'None');
 /* globals */
 sqgetGlobalVar('action', $action);
 sqgetGlobalVar('meth', $meth);
 /* globals */
 sqgetGlobalVar('action', $action);
 sqgetGlobalVar('meth', $meth);
+sqgetGlobalVar('type', $type);
 sqgetGlobalVar('ID' , $ID);
 
 sqgetGlobalVar('username', $username, SQ_SESSION);
 sqgetGlobalVar('ID' , $ID);
 
 sqgetGlobalVar('username', $username, SQ_SESSION);
@@ -54,6 +60,11 @@ switch ($action) {
             setPref($data_dir, $username, 'spamcop_method', $meth);
         }
         break;
             setPref($data_dir, $username, 'spamcop_method', $meth);
         }
         break;
+    case 'type':
+        if (isset($type)) {
+            setPref($data_dir, $username, 'spamcop_type', $type);
+        }
+       break;
     case 'save_id':
         if (isset($ID)) {
             $ID = trim($ID);
     case 'save_id':
         if (isset($ID)) {
             $ID = trim($ID);
@@ -122,6 +133,30 @@ spamcop_load();
            <input type="submit" value="<?php echo _("Save Method"); ?>">
          </td></form>
        </tr>
            <input type="submit" value="<?php echo _("Save Method"); ?>">
          </td></form>
        </tr>
+       <tr>
+                 <?php
+         echo html_tag('td',_("Spam Service Type:"),'right');
+         ?>
+         <form method="post" action="options.php">
+         <td>
+           <select name="type">
+             <option value="free"
+               <?php
+                 if ($spamcop_type == 'free') echo ' selected';
+                 echo ">"._("Free reporting");
+               ?>
+             </option>
+             <option value="member"
+               <?php
+                 if ($spamcop_type == 'member') echo ' selected';
+                 echo ">"._("Member services");
+               ?>
+             </option>
+           </select>
+           <input type="hidden" name="action" value="type">
+           <input type="submit" value="<?php echo _("Save Service Type"); ?>">
+          </td></form>
+       </tr>
        <tr>
          <?php
            echo html_tag('td',_("Your SpamCop authorization code:") . "<br />" .
        <tr>
          <?php
            echo html_tag('td',_("Your SpamCop authorization code:") . "<br />" .
@@ -166,7 +201,11 @@ echo _("When you press the button on the confirmation page, this will pop open a
 echo "</p>\n";
 
 echo "<p>";
 echo "</p>\n";
 
 echo "<p>";
-echo _("The SpamCop service will display information as it finds it, so scroll down until you see a form button.  It might pause a little while it is looking up information, so be a little patient.  Read what it says, and submit the spam.  Close the browser window.  Press Cancel or click on the appropriate mail folder to see messages and/or delete the spam.");
+echo _("The SpamCop service will display information as it finds it, so scroll down until you see a form button. It might pause a little while it is looking up information, so be a little patient. Read what it says, and submit the spam. Close the browser window.  Press Cancel or click on the appropriate mail folder to see messages and/or delete the spam.");
+echo "</p>\n";
+
+echo "<p><b>". _("Spamcop Service Type") . "</b><br />\n";
+echo _("Service type option allows selecting which spamcop services you are using. Member services use different web reporting forms  and does not display nags. You can purchase these services, if you want to support SpamCop.");
 echo "</p>\n";
 
 echo "<p>";
 echo "</p>\n";
 
 echo "<p>";
index 06cf3389e18021bda3ed9cc4cd80a3bdece5b9e7..afe03abcf67369800666fd5c25a853f031943e8d 100755 (executable)
@@ -37,23 +37,20 @@ function squirrelmail_plugin_init_spamcop() {
 }
 
 
 }
 
 
-// Load the settings
-// Validate some of it (make '' into 'default', etc.)
+/**
+ * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
+ */
 function spamcop_load() {
    global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
 function spamcop_load() {
    global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
-      $spamcop_method, $spamcop_id, $spamcop_quick_report;
+      $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
 
    $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
    $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
    $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
 
    $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
    $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
    $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
+   $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
    $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
     if ($spamcop_method == '') {
    $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
     if ($spamcop_method == '') {
-// This variable is not used
-//      if (getPref($data_dir, $username, 'spamcop_form'))
-//         $spamcop_method = 'web_form';
-//      else
-
-// Default to web_form. It is faster.
+      // Default to web_form. It is faster.
        $spamcop_method = 'web_form';
        setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
     }
        $spamcop_method = 'web_form';
        setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
     }
@@ -61,24 +58,36 @@ function spamcop_load() {
        $spamcop_method = 'web_form';
        setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
    }
        $spamcop_method = 'web_form';
        setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
    }
+   if ($spamcop_type == '') {
+       $spamcop_type = 'free';
+       setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
+   }
    if ($spamcop_id == '')
       $spamcop_enabled = 0;
 }
 
 
    if ($spamcop_id == '')
       $spamcop_enabled = 0;
 }
 
 
-// Show the link on the read-a-message screen
+/**
+ * Shows spamcop link on the read-a-message screen
+ */
 function spamcop_show_link() {
 function spamcop_show_link() {
-   global $spamcop_enabled, $spamcop_method, $spamcop_quick_report;
+   global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
 
    if (! $spamcop_enabled)
       return;
 
    /* GLOBALS */
    sqgetGlobalVar('passed_id',    $passed_id,    SQ_FORM);
 
    if (! $spamcop_enabled)
       return;
 
    /* GLOBALS */
    sqgetGlobalVar('passed_id',    $passed_id,    SQ_FORM);
+   sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
    sqgetGlobalVar('mailbox',      $mailbox,      SQ_FORM);
    sqgetGlobalVar('startMessage', $startMessage, SQ_FORM);
    /* END GLOBALS */
 
    sqgetGlobalVar('mailbox',      $mailbox,      SQ_FORM);
    sqgetGlobalVar('startMessage', $startMessage, SQ_FORM);
    /* END GLOBALS */
 
+   // catch unset passed_ent_id
+   if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) {
+    $passed_ent_id = 0;
+   }
+
    echo "<br>\n";
 
     /* 
    echo "<br>\n";
 
     /* 
@@ -90,24 +99,24 @@ function spamcop_show_link() {
        $spamcop_method = 'web_form';
     }
    
        $spamcop_method = 'web_form';
     }
    
-   if ($spamcop_method == 'web_form') {
+    // Javascript is used only in web based reporting
+    // don't insert javascript if javascript is disabled
+   if ($spamcop_method == 'web_form' && $javascript_on) {
 ?><script language="javascript" type="text/javascript">
 ?><script language="javascript" type="text/javascript">
-document.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP echo urlencode($passed_id); ?>&amp;js_web=1&amp;mailbox=<?PHP echo urlencode($mailbox); ?>" target="_blank">');
+document.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP echo urlencode($passed_id); ?>&amp;js_web=1&amp;mailbox=<?PHP echo urlencode($mailbox); ?>&amp;passed_ent_id=<?PHP echo urlencode($passed_ent_id); ?>" target="_blank">');
 document.write("<?PHP echo _("Report as Spam"); ?>");
 document.write("</a>");
 document.write("<?PHP echo _("Report as Spam"); ?>");
 document.write("</a>");
-</script><noscript>
-<a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP echo urlencode($passed_id); ?>&amp;mailbox=<?PHP echo urlencode($mailbox); ?>&amp;startMessage=<?PHP echo urlencode($startMessage); ?>">
-<?PHP echo _("Report as Spam"); ?></a>
-</noscript><?PHP
+</script><?PHP
    } else {
    } else {
-?><a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP echo urlencode($passed_id); ?>&amp;mailbox=<?PHP echo urlencode($mailbox); ?>&amp;startMessage=<?PHP echo urlencode($startMessage); ?>">
+?><a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP echo urlencode($passed_id); ?>&amp;mailbox=<?PHP echo urlencode($mailbox); ?>&amp;startMessage=<?PHP echo urlencode($startMessage); ?>&amp;passed_ent_id=<?PHP echo urlencode($passed_ent_id); ?>">
 <?PHP echo _("Report as Spam"); ?></a>
 <?PHP
    }
 }
 
 <?PHP echo _("Report as Spam"); ?></a>
 <?PHP
    }
 }
 
-
-// Show the link to our own custom options page
+/**
+ * Show spamcop options block
+ */
 function spamcop_options()
 {
    global $optpage_blocks;
 function spamcop_options()
 {
    global $optpage_blocks;
@@ -121,7 +130,9 @@ function spamcop_options()
 }
 
 
 }
 
 
-// When we send the email, we optionally trash it then too
+/**
+ * When we send the email, we optionally trash it then too
+ */
 function spamcop_while_sending()
 {
    global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge, 
 function spamcop_while_sending()
 {
    global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge, 
index c7b1397c6d20b988fe47a28f8d45d2f9c0dbfe49..02456ff5d637e40ed3300fb03cdee774cbc344eb 100644 (file)
@@ -17,10 +17,13 @@ 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');
 
+/**
+ * Stores message in attachment directory, when email based reports are used
+ */
 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, 
                                       $passed_ent_id='', $imapConnection) {
     global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
 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, 
     $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
     if (!$passed_ent_id) {
         $body_a = sqimap_run_command($imapConnection, 
@@ -66,12 +69,16 @@ sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
 
 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
 
 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) ) {
 
 if (! sqgetGlobalVar('startMessage', $startMessage, SQ_GET) ) {
     $startMessage = 1;
 }
 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
-    $passed_ent_id = '';
+    $passed_ent_id = 0;
+}
+if (! sqgetGlobalVar('js_web', $js_web, SQ_GET) ) {
+    $js_web = 0;
 }
 
 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
 }
 
 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
@@ -82,8 +89,14 @@ if(! sqgetGlobalVar('composesession', $composesession, SQ_SESSION) ) {
 }
 /* END GLOBALS */
 
 }
 /* END GLOBALS */
 
-    
-    displayPageHeader($color, $mailbox);
+// 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);
+}
 
     $imap_stream = sqimap_login($username, $key, $imapServerAddress, 
        $imapPort, 0);
 
     $imap_stream = sqimap_login($username, $key, $imapServerAddress, 
        $imapPort, 0);
@@ -112,7 +125,7 @@ if(! sqgetGlobalVar('composesession', $composesession, SQ_SESSION) ) {
 
         $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
         $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, 
 
         $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
         $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, 
-                                      $passed_ent_id='', $imap_stream);
+                                      $passed_ent_id, $imap_stream);
 
        $compose_messages[$session] = $composeMessage;
        sqsession_register($compose_messages, 'compose_messages');
 
        $compose_messages[$session] = $composeMessage;
        sqsession_register($compose_messages, 'compose_messages');
@@ -166,18 +179,23 @@ echo "</p>";
   <input type="hidden" name="session" value="<?PHP echo $session?>">
   <input type="submit" name="send" value="Send Spam Report">
 <?PHP } else {
   <input type="hidden" name="session" value="<?PHP echo $session?>">
   <input type="submit" name="send" value="Send Spam Report">
 <?PHP } else {
-   $spam_message = mime_fetch_body ($imap_stream, $passed_id, 0, 50000);
+   $spam_message = mime_fetch_body ($imap_stream, $passed_id, $passed_ent_id, 50000);
 
    if (strlen($spam_message) == 50000) {
       $Warning = "\n[truncated by SpamCop]\n";
       $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
    }
 
    if (strlen($spam_message) == 50000) {
       $Warning = "\n[truncated by SpamCop]\n";
       $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
    }
+   if ($spamcop_type=='member') {
+     $action_url="http://members.spamcop.net/sc";
+   } else {
+     $action_url="http://www.spamcop.net/sc";
+   }
    if (isset($js_web) && $js_web) {
    if (isset($js_web) && $js_web) {
-?>  <form method="post" action="http://www.spamcop.net/sc" name="submitspam"
-    enctype="multipart/form-data"><?PHP
+     echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
+       " enctype=\"multipart/form-data\">\n";
    } else {
    } else {
-?>  <form method="post" action="http://www.spamcop.net/sc" name="submitspam"
-    enctype="multipart/form-data" target="_blank"><?PHP
+     echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
+       " enctype=\"multipart/form-data\" target=\"_blank\">\n";
    } ?>
   <input type="hidden" name="action" value="submit">
   <input type="hidden" name="oldverbose" value="1">
    } ?>
   <input type="hidden" name="action" value="submit">
   <input type="hidden" name="oldverbose" value="1">