- Fix error with SpamCop reporting plugin not being able to send report as
[squirrelmail.git] / plugins / spamcop / functions.php
index 44c542ef7be10603b8b5551dc8617d2c7cfe3feb..85cccf49f7acabe02ad5553514aaae55a0539e23 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * SpamCop plugin - functions
  *
- * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @copyright 1999-2010 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
@@ -59,14 +59,14 @@ function spamcop_load_function() {
  * @since 1.5.1
  * @access private
  */
-function spamcop_show_link_function() {
-    global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
+function spamcop_show_link_function(&$links) {
+    global $spamcop_enabled, $spamcop_method, $spamcop_quick_report;
 
     if (! $spamcop_enabled)
         return;
 
     /* GLOBALS */
-    sqgetGlobalVar('passed_id',    $passed_id,    SQ_FORM);
+    sqgetGlobalVar('passed_id',    $passed_id,    SQ_FORM, NULL, SQ_TYPE_BIGINT);
     sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
     sqgetGlobalVar('mailbox',      $mailbox,      SQ_FORM);
     if ( sqgetGlobalVar('startMessage', $startMessage, SQ_FORM) ) {
@@ -79,8 +79,6 @@ function spamcop_show_link_function() {
         $passed_ent_id = 0;
     }
 
-    echo "<br />\n";
-
     /*
        Catch situation when user uses quick_email and does not update
        preferences. User gets web_form link. If prefs are set to
@@ -90,19 +88,24 @@ function spamcop_show_link_function() {
         $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 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); ?>&amp;passed_ent_id=<?php echo urlencode($passed_ent_id); ?>" target="_blank">');
-document.write("<?php echo _("Report as Spam"); ?>");
-document.write("</a>");
-</script><?php
-    } 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); ?>&amp;passed_ent_id=<?php echo urlencode($passed_ent_id); ?>">
-<?php echo _("Report as Spam"); ?></a>
-<?php
+// FIXME: do we need this javascript and if so, fix it
+// <script 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); >&amp;passed_ent_id=<php echo urlencode($passed_ent_id); >" target="_blank">');
+//document.write("<php echo _("Report as Spam"); >");
+//document.write("</a>");
+//</script>
+
+
+    $url =  '../plugins/spamcop/spamcop.php?passed_id=' . urlencode($passed_id) .
+                '&amp;mailbox=' . urlencode($mailbox) . '&amp;startMessage=' . urlencode($startMessage) .
+                '&amp;passed_ent_id=' . urlencode($passed_ent_id);
+    if ( $spamcop_method == 'web_form' && checkForJavascript() ) {
+        $url .= '&amp;js_web=1';
     }
+
+    $links[] = array ( 'URL' => $url,
+        'Text' => _("Report as Spam")
+    );
 }
 
 /**
@@ -177,9 +180,9 @@ function spamcop_enable_disable($option,$disable_action,$enable_action) {
  */
 function spamcop_getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
                                       $passed_ent_id='', $imapConnection) {
-    global $attachment_dir, $username;
+                                          
+    global $username, $attachment_dir;
 
-    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
     if (!$passed_ent_id) {
         $body_a = sqimap_run_command($imapConnection,
                                     'FETCH '.$passed_id.' RFC822',
@@ -195,22 +198,15 @@ function spamcop_getMessage_RFC822_Attachment($message, $composeMessage, $passed
         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');
+        $filename = sq_get_attach_tempfile();
+        $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+        
+        $fp = fopen("$hashed_attachment_dir/$filename", 'wb');
         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);
+                         $filename);
     }
+    
     return $composeMessage;
 }
-?>
\ No newline at end of file