Improve HTML escaping
[squirrelmail.git] / plugins / newmail / setup.php
index 99ffd360c3ebb2746d3b6da70799c2198c57d3ec..12bd65f75679a6926ce1cdd25ec2bedee2a7375c 100644 (file)
@@ -3,7 +3,7 @@
    /**
     * newmail.php
     *
-    * Copyright (c) 1999-2003 The SquirrelMail Project Team
+    * Copyright (c) 1999-2002 The SquirrelMail Project Team
     * Copyright (c) 2000 by Michael Huttinger
     * Licensed under the GNU GPL. For full terms see the file COPYING.
     *
     * too (with a plugin).
     *
     * $Id$
+    * @package plugins
+    * @subpackage newmail
     */
 
-    function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_unseen) {
+    /**
+    */
+    include_once(SM_PATH . 'functions/display_messages.php');
+
+    function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_new) {
     
         global $folder_prefix, $trash_folder, $sent_folder,
                $color, $move_to_sent, $move_to_trash,
@@ -33,7 +39,7 @@
                $newmail_recent, $newmail_changetitle;
 
         $mailboxURL = urlencode($real_box);
-        $unseen_found = 0;
+        $unseen = $recent = 0;
 
         // Skip folders for Sent and Trash
 
         if (($unseen_notify == 2 && $real_box == 'INBOX') ||
             ($unseen_notify == 3 && ($newmail_allbox == 'on' ||
                                      $real_box == 'INBOX'))) {
-            $unseen = sqimap_unseen_messages($imapConnection, $real_box);
-            $total_unseen += $unseen;
-
+            $status = sqimap_status_messages( $imapConnection, $real_box);
             if($newmail_recent == 'on') {
-                $unseen = sqimap_mailbox_select( $imapConnection, $real_box, TRUE, TRUE);
+                $total_new += $status['RECENT'];
+            } else {
+                $total_new += $status['UNSEEN'];
             }
-
-            if ($unseen > 0) {
-                $unseen_found = 1;
+            if ($total_new) {
+                    return 1;
             }
+            
         }
-        return( $unseen_found );
+        return 0;
     }
 
     function squirrelmail_plugin_init_newmail() {
        // Gets added to the user's OPTIONS page.
        global $optpage_blocks;
 
-       if ( !soupNazi() ) {
-
-           /* Register Squirrelspell with the $optionpages array. */
+       if ( checkForJavascript() ) {
+       /* Register Squirrelspell with the $optionpages array. */
            $optpage_blocks[] = array(
                'name' => _("NewMail Options"),
-               'url'  => '../plugins/newmail/newmail_opt.php',
+               'url'  => SM_PATH . 'plugins/newmail/newmail_opt.php',
                'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."),
                'js'   => TRUE
             );
     }
 
     function newmail_sav() {
-
-        global $data_dir, $username, $_POST;
-     
-        if ( isset($_POST['submit_newmail']) ) {
-
-            if(isset($_POST['media_enable'])) {
-                setPref($data_dir,$username,'newmail_enable',$_POST['media_enable']);
-            } else {
-                setPref($data_dir,$username,'newmail_enable','');
-            }
-            if(isset($_POST['media_popup'])) {
-                setPref($data_dir,$username,'newmail_popup',$_POST['media_popup']);
-            } else {
-                setPref($data_dir,$username,'newmail_popup','');
-            }
-            if(isset($_POST['media_allbox'])) {
-                setPref($data_dir,$username,'newmail_allbox',$_POST['media_allbox']);
+        global $data_dir, $username;
+
+        if ( sqgetGlobalVar('submit_newmail', $submit, SQ_POST) ) {        
+            $media_enable = '';
+            $media_popup = '';
+            $media_allbox = '';
+            $media_recent = '';
+            $media_changetitle = '';
+            $media_sel = '';
+
+            sqgetGlobalVar('media_enable',      $media_enable,      SQ_POST);
+            sqgetGlobalVar('media_popup',       $media_popup,       SQ_POST);
+            sqgetGlobalVar('media_allbox',      $media_allbox,      SQ_POST);
+            sqgetGlobalVar('media_recent',      $media_recent,      SQ_POST);
+            sqgetGlobalVar('media_changetitle', $media_changetitle, SQ_POST);
+
+            setPref($data_dir,$username,'newmail_enable',$media_enable);
+            setPref($data_dir,$username,'newmail_popup', $media_popup);
+            setPref($data_dir,$username,'newmail_allbox',$media_allbox);
+            setPref($data_dir,$username,'newmail_recent',$media_recent);
+            setPref($data_dir,$username,'newmail_changetitle',$media_changetitle);
+            
+            if( sqgetGlobalVar('media_sel', $media_sel, SQ_POST) &&
+                ($media_sel == '(none)' || $media_sel == '(local media)') ) {
+                removePref($data_dir,$username,'newmail_media');
             } else {
-                setPref($data_dir,$username,'newmail_allbox','');
-            }
-            if(isset($_POST['media_recent'])) {
-                setPref($data_dir,$username,'newmail_recent',$_POST['media_recent']);
-            } else {
-                setPref($data_dir,$username,'newmail_recent','');
-            }
-            if(isset($_POST['media_changetitle'])) {
-                setPref($data_dir,$username,'newmail_changetitle',$_POST['media_changetitle']);
-            } else {
-                setPref($data_dir,$username,'newmail_changetitle','');
-            }
-            if(isset($_POST['media_sel'])) {
-                if($_POST['media_sel'] == '(local media)') {
-                    setPref($data_dir,$username,'newmail_media',StripSlashes($_POST['media_file']));
-                } else {
-                    setPref($data_dir,$username,'newmail_media',$_POST['media_sel']);
-                }
-            } else {
-                setPref($data_dir,$username,'newmail_media','');
+                setPref($data_dir,$username,'newmail_media',$media_sel);
             }
             echo html_tag( 'p', _("New Mail Notification options saved"), 'center' );
         }
         
         $newmail_recent = getPref($data_dir,$username,'newmail_recent');
         $newmail_enable = getPref($data_dir,$username,'newmail_enable');
-        $newmail_media = getPref($data_dir, $username, 'newmail_media', '../plugins/newmail/sounds/Notify.wav');
+        $newmail_media = getPref($data_dir, $username, 'newmail_media', '(none)');
         $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
         $newmail_allbox = getPref($data_dir, $username, 'newmail_allbox');
         $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
 
         global $username, $key, $imapServerAddress, $imapPort,
                $newmail_media, $newmail_enable, $newmail_popup,
-               $newmail_recent, $newmail_changetitle, $imapConnection;
-        
+               $newmail_recent, $newmail_changetitle, $imapConnection, $PHP_SELF;
+
         if ($newmail_enable == 'on' ||
             $newmail_popup == 'on' ||
             $newmail_changetitle) {
                     "</script>\n";
             }
 
-            if ($totalNew > 0 && $newmail_enable == 'on') {
-                echo "<EMBED SRC=\"$newmail_media\" HIDDEN=TRUE AUTOSTART=TRUE>\n";
+            if ($totalNew > 0 && $newmail_enable == 'on' && $newmail_media != '' ) {
+                echo '<EMBED SRC="'.htmlspecialchars($newmail_media) .
+                    "\" HIDDEN=\"TRUE\" AUTOSTART=\"TRUE\">\n";
             }
             if ($totalNew > 0 && $newmail_popup == 'on') {
                 echo "<SCRIPT LANGUAGE=\"JavaScript\">\n".
                     "<!--\n".
                     "function PopupScriptLoad() {\n".
-                        'window.open("../plugins/newmail/newmail.php", "SMPopup",'.
+                        'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
+                                    '", "SMPopup",'.
                                      "\"width=200,height=130,scrollbars=no\");\n".
                         "if (BeforePopupScript != null)\n".
                             "BeforePopupScript();\n".
                     // More code from Tyler Akins
                     "// End -->\n".
                     "</script>\n";
-
             }
         }
     }