Added spamcop so that it can get translated and hundreds of other
authorfidian <fidian@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 4 Jan 2002 14:19:36 +0000 (14:19 +0000)
committerfidian <fidian@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 4 Jan 2002 14:19:36 +0000 (14:19 +0000)
programmers can work on it.  I'm officially handing the baton on this plugin
to anyone who will take it.  :-)

It has been updated to work the the way that SpamCop now works (or at least
I *think* I did it correctly).  Just needs major code cleanup and
internationalization.

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

plugins/spamcop/README [new file with mode: 0755]
plugins/spamcop/options.php [new file with mode: 0755]
plugins/spamcop/setup.php [new file with mode: 0755]
plugins/spamcop/spamcop.php [new file with mode: 0644]

diff --git a/plugins/spamcop/README b/plugins/spamcop/README
new file mode 100755 (executable)
index 0000000..d0a6e5c
--- /dev/null
@@ -0,0 +1,62 @@
+SpamCop Reporting -- Version 1.5
+
+Helps you identify spam and send a proper message to the correct address to
+SpamCop.  (See http://spamcop.net/ for more information)
+
+
+Features
+========
+
+* Quick one-click interface to report spam via email
+* Alternate, but immediate form-based processing
+
+
+Description
+===========
+
+Tired of getting spam?  SpamCop helps you report it to the proper people.
+It even creates spam reports and will mail them off for you.  All that is
+required to send a spam report is about a few seconds of your time and about
+five clicks.
+
+It is strongly suggested you set up a mail forwarder account and have it
+forwarded to your current mailbox.  Sometimes mail reported with SpamCop
+gets on weird spam mailing lists.  If your happens to get on the list, you
+can then just delete the forwarder and get a new one.  Make sure to use the
+forwarder to sign up for SpamCop and get the required information for the
+plugin.
+
+This plugin is also an example of how to use the identity hooks.  Just open
+up setup.php and read the comments.
+
+
+Future Work
+===========
+
+* Dunno
+
+
+Installation
+============
+
+As with other plugins, just uncompress the archive in the plugins
+directory, go back to the main directory, run configure and add the plugin.
+
+Questions/comments/flames/etc can be sent to the SquirrelMail Plugins list.
+
+
+Changes
+=======
+1.5 - Reworked system to match up with SpamCop changes.  Modified code to
+      keep it up-to-date with current SquirrelMail changes.
+
+1.4 - Added forms-based reporting, thanks to Stefan Sels
+
+1.3 - Fixed table rendition -- added &nbsp;
+
+1.2 - Added support for the multiple identities in SquirrelMail 1.1.2
+      (not required to use the plugin)
+      
+1.1 - Fixed a stupid bug
+
+1.0 - Initial version
diff --git a/plugins/spamcop/options.php b/plugins/spamcop/options.php
new file mode 100755 (executable)
index 0000000..13140bf
--- /dev/null
@@ -0,0 +1,139 @@
+<?php
+   chdir ("..");
+   require_once('../src/validate.php');
+
+   displayPageHeader($color, "None");   
+
+   if (! isset($action))
+      $action = '';
+   if ($action == 'enable')
+      setPref($data_dir, $username, 'spamcop_enabled', 1);
+   elseif ($action == 'disable')
+      setPref($data_dir, $username, 'spamcop_enabled', '');
+   elseif ($action == 'save')
+      setPref($data_dir, $username, 'spamcop_delete', '');
+   elseif ($action == 'delete')
+      setPref($data_dir, $username, 'spamcop_delete', 1);
+   elseif ($action == 'meth' && isset($meth))
+      setPref($data_dir, $username, 'spamcop_method', $meth);
+   elseif ($action == 'save_id' && isset($ID))
+      setPref($data_dir, $username, 'spamcop_id', $ID);
+
+   global $spamcop_enabled, $spamcop_delete;
+   spamcop_load();
+
+   ?>
+      <br>
+      <table width=95% align=center border=0 cellpadding=2 cellspacing=0><tr><td bgcolor="<?php echo $color[0] ?>">
+         <center><b><?php echo _("Options") ?> - Message Filtering</b></center>
+      </td></tr></table>
+      <br>
+      
+      <table align=center>
+        <tr>
+         <td align=right>SpamCop link is:</td>
+         <td><?PHP if ($spamcop_enabled) { 
+         ?>Enabled (<a href="options.php?action=disable">Disable it</a>)
+         <?PHP } else {
+         ?>Disabled (<a href="options.php?action=enable">Enable it</a>)
+         <?PHP }
+         ?></td>
+       </tr>
+        <tr>
+         <td align=right valign=top>Delete spam when reported:<br>
+           <font size="-2">(Only works with email-based reporting)</font>
+         </td>
+         <td valign=top><?PHP if ($spamcop_delete) { 
+         ?>Enabled (<a href="options.php?action=save">Disable it</a>)
+         <?PHP } else {
+         ?>Disabled (<a href="options.php?action=delete">Enable it</a>)
+         <?PHP }
+         ?></td>
+       </tr>
+       <tr>
+         <td align=right>Spam Reporting Method:</td>
+         <form method=post action=options.php><td>
+           <select name=meth>
+             <option value="quick_email"<?PHP
+               if ($spamcop_method == 'quick_email') echo ' SELECTED'
+               ?>>Quick email-based reporting</option>
+             <option value="thorough_email"<?PHP
+               if ($spamcop_method == 'thorough_email') echo ' SELECTED'
+               ?>>Thorough email-based reporting</option>
+             <option value="web_form"<?PHP
+               if ($spamcop_method == 'web_form') echo ' SELECTED'
+               ?>>Web-based form</option>
+           </select>
+           <input type=hidden name=action value=meth>
+           <input type=submit value="Save Method">
+         </td></form>
+       </tr>
+       <tr>
+         <td valign=top align=right>Your SpamCop authorization code:<br>
+           <font size="-2">(see below)</font>
+         </td>
+         <form method=post action=options.php><td valign=top>
+           <input type=text size=30 name="ID" value="<?PHP
+             echo htmlspecialchars($spamcop_id) ?>">
+           <input type=hidden name=action value=save_id>
+           <input type=submit value="Save ID">
+         </td></form>
+       </tr>
+      </table>
+
+<p>SpamCop is a free service that greatly assists in finding the true source
+of the spam and helps in letting the proper people know about the abuse.</p>
+
+<p>To use it, you must get a SpamCop authorization code.  There is a free <a
+href="http://spamcop.net/anonsignup.shtml">sign up page</a> so you can use
+SpamCop.</p>
+
+<p><b>Before you sign up, be warned:</b>  Some users have reported that the
+email addresses used with SpamCop find their way onto spam lists.  To be
+safe, you can just create an email forwarding account and have all SpamCop
+reports get sent to there.  Also, if it gets flooded with spam, you can then
+just delete that account with no worries about losing your real email address.
+Just go create an email forwarder somewhere (<a 
+href="http://www.yahoo.com/">Yahoo!</a> has a <a
+href="http://dir.yahoo.com/Business_and_Economy/Business_to_Business/Communications_and_Networking/Internet_and_World_Wide_Web/Email_Providers/Forwarding_Services/Free_Forwarding/">list
+of places</a>) so that messages from system administrators and whatnot can
+be sent to you.</p>
+
+<p>Once you have signed up with SpamCop and have received your SpamCop
+authorization code, you need to enable this plugin -- just click the link
+above.  Once enabled, you go about your normal life.  If you encounter a
+spam message in your mailbox, just view it.  On the right-hand side, near
+the top of where the message is displayed, you will see a link to report 
+this message as spam.  Clicking on it brings you to a confirmation page.
+Confirming that you want the spam report sent will do different things with
+different reporting methods.</p>
+
+<p><b>Email-based Reporting</b><br>
+Pressing the button forwards the message to the SpamCop service and will
+optionally delete the message.  From there, you just need to go to your 
+INBOX and quite soon a message should appear from SpamCop.  (It gets sent to
+the account you registered with, so make sure that your mail forwarder works!)
+Open it up, click on the appropriate link at the top, and a new browser 
+window will open.</p>
+
+<p>Currently, the quick reporting just forwards the request to the thorough
+reporting.  Also, it appears that this is for members (non-free) only.
+Hopefully this will change soon.</p>
+
+<p><b>Web-based Reporting</b><br>
+When you press the button on the confirmation page, this will pop open a new
+browser window and the SpamCop service should appear inside.  The message
+will not be deleted (working on that part), but you won't need to wait for a
+response email to start the spam reporting.</p>
+
+<p>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.</p>
+
+<p><b>For more information</b> about SpamCop, it's services, spam in general, 
+and many related topics, try reading through SpamCop's <a
+href="http://spamcop.net/help.shtml">Help and Feedback</a> section.</p>
+
+</body></html>
diff --git a/plugins/spamcop/setup.php b/plugins/spamcop/setup.php
new file mode 100755 (executable)
index 0000000..b8e7058
--- /dev/null
@@ -0,0 +1,115 @@
+<?php
+
+
+/* Initialize the plugin */
+function squirrelmail_plugin_init_spamcop() {
+   global $squirrelmail_plugin_hooks, $data_dir, $username,
+      $spamcop_is_composing;
+
+   $squirrelmail_plugin_hooks['options_register']['spamcop'] =
+      'spamcop_options';
+   $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] =
+      'spamcop_load';
+   $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] =
+      'spamcop_show_link';
+      
+   if (isset($spamcop_is_composing)) {
+      $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
+         'spamcop_while_sending';
+   }
+}
+
+
+// Load the settings
+// Validate some of it (make '' into 'default', etc.)
+function spamcop_load() {
+   global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
+      $spamcop_method, $spamcop_id;
+
+   $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_id = getPref($data_dir, $username, 'spamcop_id');
+   if ($spamcop_method == '') {
+      if (getPref($data_dir, $username, 'spamcop_form'))
+         $spamcop_method = 'web_form';
+      else
+         $spamcop_method = 'thorough_email';
+      setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
+   }
+   if ($spamcop_id == '')
+      $spamcop_enabled = 0;
+}
+
+
+// Show the link on the read-a-message screen
+function spamcop_show_link() {
+   global $passed_id, $mailbox, $ent_num, $spamcop_enabled, $startMessage,
+      $spamcop_method;
+
+   // This was stolen from printer_friendly
+   // Do I really need/want it?
+   if (!trim($mailbox))
+      $mailbox = 'INBOX';
+
+   if (! $spamcop_enabled)
+      return;
+
+   echo "<br>\n";
+   
+   if ($spamcop_method == 'web_form') {
+?><script language=javascript>
+document.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP
+echo urlencode($passed_id); ?>&js_web=1&mailbox=<?PHP
+echo urlencode($mailbox); ?>" target="_blank">');
+document.write("<?PHP echo _("Report as Spam"); ?>");
+document.write("</a>");
+</script><noscript>
+<a href="../plugins/spamcop/spamcop_web.php?passed_id=<?PHP
+echo urlencode($passed_id); ?>&mailbox=<?PHP
+echo urlencode($mailbox); ?>&startMessage=<?PHP
+echo urlencode($startMessage); ?>"><?PHP
+echo _("Report as Spam"); ?></a>
+</noscript><?PHP
+   } else {
+?><a href="../plugins/spamcop/spamcop_web.php?passed_id=<?PHP
+echo urlencode($passed_id); ?>&mailbox=<?PHP
+echo urlencode($mailbox); ?>&startMessage=<?PHP
+echo urlencode($startMessage); ?>"><?PHP
+echo _("Report as Spam"); ?></a><?PHP
+   }
+}
+
+
+// Show the link to our own custom options page
+function spamcop_options()
+{
+   global $optionpages;
+   
+   $optionpages[] = array(
+      'name' => _("SpamCop - Spam Reporting"),
+      'url' => '../plugins/spamcop/options.php',
+      'desc' => _("Help fight the battle against unsolicited email.  SpamCop reads the spam email and determines the correct addresses to send complaints to.  Quite fast, really smart, and easy to use."),
+      'js' => false
+   );
+}
+
+
+// When we send the email, we optionally trash it then too
+function spamcop_while_sending()
+{
+   global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge, 
+      $username, $key, $imapServerAddress, $imapPort;
+
+   if ($spamcop_delete) {
+      $imapConnection = sqimap_login($username, $key, $imapServerAddress, 
+         $imapPort, 0);
+      sqimap_mailbox_select($imapConnection, $mailbox);
+      sqimap_messages_delete($imapConnection, $spamcop_is_composing, 
+         $spamcop_is_composing, $mailbox);
+      if ($auto_expunge)
+         sqimap_mailbox_expunge($imapConnection, $mailbox, true);
+   }
+}
+
+?>
diff --git a/plugins/spamcop/spamcop.php b/plugins/spamcop/spamcop.php
new file mode 100644 (file)
index 0000000..1822da7
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+
+    chdir('..');
+    include_once ('../src/validate.php');
+    include_once ('../functions/imap.php');
+    
+    displayPageHeader($color, $mailbox);
+
+    $imap_stream = sqimap_login($username, $key, $imapServerAddress, 
+       $imapPort, 0);
+    sqimap_mailbox_select($imap_stream, $mailbox);
+    fputs($imap_stream, 'a010 FETCH ' . $passed_id . ' RFC822' . "\r\n");
+    $read = sqimap_read_data($imap_stream, 'a010', true, $response, $message);
+    array_shift($read);
+
+    if ($spamcop_method == 'quick_email' || 
+        $spamcop_method == 'thorough_email') {
+       // Use email-based reporting -- save as an attachment
+       if (!isset($attachments)) {
+          $attachments = array();
+          session_register('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';
+       $fp = fopen($attachment_dir . $file, 'w');
+       foreach ($read as $line) {
+          fputs($fp, $line);
+       }
+       $attachments[] = $newAttachment;
+    
+       $fn = getPref($data_dir, $username, 'full_name');
+       $em = getPref($data_dir, $username, 'email_address');
+    
+       $HowItLooks = $fn . ' ';
+       if ($em != '')
+          $HowItLooks .= '<' . $em . '>';
+    }
+
+?>
+
+<p>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.</p>
+
+<table align=center width="75%" border=0 cellpadding=0 cellspacing=0>
+<tr>
+<td align=left valign=top>
+<?PHP if (isset($js_web) && $js_web) {
+   ?><form method=post action="javascript:return false">
+  <input type=button value="Close Window" 
+  onClick="window.close(); return true;">
+   <?PHP
+} else {
+   ?><form method=post action="../../src/right_main.php">
+  <input type=hidden name="mailbox" value="<?PHP echo
+     htmlspecialchars($mailbox) ?>">
+  <input type=hidden name="startMessage" value="<?PHP echo
+     htmlspecialchars($startMessage) ?>">
+  <input type=submit value="Cancel / Done">
+   <?PHP
+}
+  ?></form>
+</td>
+<td align=right valign=top>
+<?PHP if ($spamcop_method == 'thorough_email' ||
+          $spamcop_method == 'quick_email') {
+   if ($spamcop_method == 'thorough_email')
+      $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net';
+   else
+      $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net';
+?>  <form method=post action="../../src/compose.php">
+  <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_cc" value="">
+  <input type=hidden name="send_to_bcc" value="">
+  <input type=hidden name="subject" value="reply anyway">
+  <input type=hidden name="identity" value="default">
+  <input type=submit name="send" value="Send Spam Report">
+<?PHP } else {
+   $Message = implode('', $read);
+   if (strlen($Message) > 50000) {
+      $Warning = "\n[truncated by SpamCop]\n";
+      $Message = substr($Message, 0, 50000 - strlen($Warning)) . $Warning;
+   }
+   if (isset($js_web) && $js_web) {
+?>  <form method=post action="http://spamcop.net/sc" name="submitspam"
+    enctype="multipart/form-data"><?PHP
+   } else {
+?>  <form method=post action="http://spamcop.net/sc" name="submitspam"
+    enctype="multipart/form-data" target="_blank"><?PHP
+   } ?>
+  <input type=hidden name=action value=submit>
+  <input type=hidden name=oldverbose value=1>
+  <input type=hidden name=code value="<?PHP echo $spamcop_id ?>">
+  <input type=hidden name=spam value="<?PHP
+          echo htmlspecialchars($Message);
+  ?>">
+  <input type=submit name="x1" value="Send Spam Report">
+<?PHP }
+?>  </form>
+</td>
+</tr>
+</table>
+  </body>
+</html>