Source for file setup.php

Documentation is available at setup.php

  1. <?php
  2.  
  3. /**
  4.  * newmail.php
  5.  *
  6.  * Copyright (c) 1999-2020 The SquirrelMail Project Team
  7.  * Copyright (c) 2000 by Michael Huttinger
  8.  * Licensed under the GNU GPL. For full terms see the file COPYING.
  9.  *
  10.  * Quite a hack -- but my first attempt at a plugin.  We were
  11.  * looking for a way to play a sound when there was unseen
  12.  * messages to look at.  Nice for users who keep the squirrel
  13.  * mail window up for long periods of time and want to know
  14.  * when mail arrives.
  15.  *
  16.  * Basically, I hacked much of left_main.php into a plugin that
  17.  * goes through each mail folder and increments a flag if
  18.  * there are unseen messages.  If the final count of unseen
  19.  * folders is > 0, then we play a sound (using the HTML at the
  20.  * far end of this script).
  21.  *
  22.  * This was tested with IE5.0 - but I hear Netscape works well,
  23.  * too (with a plugin).
  24.  *
  25.  * @version $Id: setup.php 14840 2020-01-07 07:42:38Z pdontthink $
  26.  * @package plugins
  27.  * @subpackage new_mail
  28.  */
  29.  
  30. /**
  31.  * Checks if mailbox contains new messages.
  32.  *
  33.  * @param stream $imapConnection 
  34.  * @param string $mailbox FIXME: option is not used
  35.  * @param string $real_box unformated mailbox name
  36.  * @param string $delimeter FIXME: option is not used
  37.  * @param string $unseen FIXME: option is not used
  38.  * @param integer $total_new number of new messages
  39.  * @return bool true, if there are new messages
  40.  */
  41. function CheckNewMailboxSound($imapConnection$mailbox$real_box$delimeter$unseen&$total_new{
  42.     global $folder_prefix$trash_folder$sent_folder,
  43.         $color$move_to_sent$move_to_trash,
  44.         $unseen_notify$unseen_type$newmail_allbox
  45.         $newmail_recent$newmail_changetitle;
  46.  
  47.     $mailboxURL urlencode($real_box);
  48.     $unseen $recent 0;
  49.  
  50.     // Skip folders for Sent and Trash
  51.  
  52.     if ($real_box == $sent_folder ||
  53.         $real_box == $trash_folder{
  54.         return 0;
  55.     }
  56.  
  57.     if (($unseen_notify == && $real_box == 'INBOX'||
  58.         ($unseen_notify == && ($newmail_allbox == 'on' ||
  59.                                  $real_box == 'INBOX'))) {
  60.         $status sqimap_status_messages$imapConnection$real_box);
  61.         if($newmail_recent == 'on'{
  62.             $total_new += $status['RECENT'];
  63.         else {
  64.             $total_new += $status['UNSEEN'];
  65.         }
  66.         if ($total_new{
  67.             return 1;
  68.         }
  69.     }
  70.     return 0;
  71. }
  72.  
  73.     global $squirrelmail_plugin_hooks;
  74.  
  75.     $squirrelmail_plugin_hooks['left_main_before']['newmail''newmail_plugin';
  76.     $squirrelmail_plugin_hooks['optpage_register_block']['newmail''newmail_optpage_register_block';
  77.     $squirrelmail_plugin_hooks['options_save']['newmail''newmail_sav';
  78.     $squirrelmail_plugin_hooks['loading_prefs']['newmail''newmail_pref';
  79.     $squirrelmail_plugin_hooks['optpage_set_loadinfo']['newmail''newmail_set_loadinfo';
  80. }
  81.  
  82.     // Gets added to the user's OPTIONS page.
  83.     global $optpage_blocks;
  84.  
  85.     if !soupNazi() ) {
  86.  
  87.         /* Register Squirrelspell with the $optionpages array. */
  88.         $optpage_blocks[array(
  89.             'name' => _("NewMail Options"),
  90.             'url'  => SM_PATH 'plugins/newmail/newmail_opt.php',
  91.             'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."),
  92.             'js'   => TRUE
  93.             );
  94.     }
  95. }
  96.  
  97. function newmail_sav({
  98.     global $data_dir$username;
  99.  
  100.     if sqgetGlobalVar('submit_newmail'$submitSQ_POST) ) {
  101.         $media_enable '';
  102.         $media_popup '';
  103.         $media_allbox '';
  104.         $media_recent '';
  105.         $media_changetitle '';
  106.         $media_sel '';
  107.  
  108.         sqgetGlobalVar('media_enable',         $media_enable,         SQ_POST);
  109.         sqgetGlobalVar('media_popup',          $media_popup,          SQ_POST);
  110.         sqgetGlobalVar('media_allbox',         $media_allbox,         SQ_POST);
  111.         sqgetGlobalVar('media_recent',         $media_recent,         SQ_POST);
  112.         sqgetGlobalVar('media_changetitle',    $media_changetitle,    SQ_POST);
  113.         sqgetGlobalVar('popup_height',         $newmail_popup_heightSQ_POST);
  114.         sqgetGlobalVar('popup_width',          $newmail_popup_width,  SQ_POST);        
  115.  
  116.         setPref($data_dir,$username,'newmail_enable',$media_enable);
  117.         setPref($data_dir,$username,'newmail_popup'$media_popup);
  118.         setPref($data_dir,$username,'newmail_allbox',$media_allbox);
  119.         setPref($data_dir,$username,'newmail_recent',$media_recent);
  120.         setPref($data_dir,$username,'newmail_popup_height',$newmail_popup_height);
  121.         setPref($data_dir,$username,'newmail_popup_width',$newmail_popup_width);
  122.         setPref($data_dir,$username,'newmail_changetitle',$media_changetitle);
  123.             
  124.         ifsqgetGlobalVar('media_sel'$media_selSQ_POST&&
  125.             ($media_sel == '(none)' || $media_sel == '(local media)') ) {
  126.             removePref($data_dir,$username,'newmail_media');
  127.         else {
  128.             setPref($data_dir,$username,'newmail_media',$media_sel);
  129.         }
  130.     }
  131. }
  132.  
  133. function newmail_pref({
  134.     global $username$data_dir$newmail_media$newmail_enable$newmail_popup,
  135.            $newmail_allbox$newmail_recent$newmail_changetitle$newmail_popup_height,
  136.            $newmail_popup_width;
  137.     
  138.  
  139.     $newmail_recent getPref($data_dir,$username,'newmail_recent');
  140.     $newmail_enable getPref($data_dir,$username,'newmail_enable');
  141.     $newmail_media getPref($data_dir$username'newmail_media''(none)');
  142.     $newmail_popup getPref($data_dir$username'newmail_popup');
  143.     $newmail_allbox getPref($data_dir$username'newmail_allbox');
  144.     $newmail_popup_height getPref($data_dir$username'newmail_popup_height',130);
  145.     $newmail_popup_width getPref($data_dir$username'newmail_popup_width',200);
  146.     $newmail_changetitle getPref($data_dir$username'newmail_changetitle');
  147.  
  148. }
  149.  
  150. /**
  151.  * Set loadinfo data
  152.  *
  153.  * Used by option page when saving settings.
  154.  */
  155. function newmail_set_loadinfo({
  156.     global $optpage$optpage_name;
  157.     if ($optpage=='newmail'{
  158.         $optpage_name=_("NewMail Options");
  159.     }
  160. }
  161.  
  162. function newmail_plugin({
  163.     global $username$key$imapServerAddress$imapPort,
  164.         $newmail_media$newmail_enable$newmail_popup,
  165.         $newmail_popup_height$newmail_popup_width$newmail_recent
  166.         $newmail_changetitle$imapConnection;
  167.  
  168.     include_once(SM_PATH 'functions/display_messages.php');
  169.  
  170.     if ($newmail_enable == 'on' ||
  171.         $newmail_popup == 'on' ||
  172.         $newmail_changetitle{
  173.  
  174.         // open a connection on the imap port (143)
  175.         $boxes sqimap_mailbox_list($imapConnection);
  176.         $delimeter sqimap_get_delimiter($imapConnection);
  177.  
  178.         $status 0;
  179.         $totalNew 0;
  180.  
  181.         for ($i 0;$i count($boxes)$i++{
  182.  
  183.             $line '';
  184.             $mailbox $boxes[$i]['formatted'];
  185.  
  186.             if (isset($boxes[$i]['unseen'])) {
  187.                 $boxes[$i]['unseen''';
  188.             }
  189.             if ($boxes[$i]['flags']{
  190.                 $noselect false;
  191.                 for ($h 0$h count($boxes[$i]['flags'])$h++{
  192.                     if (strtolower($boxes[$i]["flags"][$h]== 'noselect'{
  193.                         $noselect TRUE;
  194.                     }
  195.                 }
  196.                 if ($noselect{
  197.                     $status += CheckNewMailboxSound($imapConnection
  198.                                                     $mailbox,
  199.                                                     $boxes[$i]['unformatted']
  200.                                                     $delimeter
  201.                                                     $boxes[$i]['unseen'],
  202.                                                     $totalNew);
  203.                 }
  204.             else {
  205.                 $status += CheckNewMailboxSound($imapConnection
  206.                                                 $mailbox
  207.                                                 $boxes[$i]['unformatted'],
  208.                                                 $delimeter
  209.                                                 $boxes[$i]['unseen']
  210.                                                 $totalNew);
  211.             }
  212.  
  213.         }
  214.  
  215.         // sqimap_logout($imapConnection);
  216.  
  217.         // If we found unseen messages, then we
  218.         // will play the sound as follows:
  219.  
  220.         if ($newmail_changetitle{
  221.             global $org_title;
  222.             echo "<script language=\"javascript\" type=\"text/javascript\">\n" .
  223.                 "function ChangeTitleLoad() {\n";
  224.             if$totalNew || $totalNew == {
  225.                 echo 'window.parent.document.title = "' $org_title ' [' .
  226.                     sprintf(_("%s New Messages")$totalNew 
  227.                     "]\";\n";
  228.             else {
  229.                 echo 'window.parent.document.title = "' $org_title ' [' .
  230.                     sprintf(_("%s New Message")$totalNew 
  231.                     "]\";\n";
  232.             }
  233.             echo    "if (BeforeChangeTitle != null)\n".
  234.                 "BeforeChangeTitle();\n".
  235.                 "}\n".
  236.                 "BeforeChangeTitle = window.onload;\n".
  237.                 "window.onload = ChangeTitleLoad;\n".
  238.                 "</script>\n";
  239.         }
  240.  
  241.         if ($totalNew && $newmail_enable == 'on' && $newmail_media != '' && $newmail_media != '(none)'{
  242.             $newmail_media=sqm_baseuri().'plugins/newmail/sounds/'.basename($newmail_media);
  243.             echo '<embed src="'.sm_encode_html_special_chars($newmail_media)
  244.                 ."\" hidden=\"true\" autostart=\"true\" width=\"2\" height=\"2\">\n";
  245.         }
  246.         if ($totalNew && $newmail_popup == 'on'{
  247.             echo "<script language=\"JavaScript\">\n".
  248.                 "<!--\n".
  249.                 "function PopupScriptLoad() {\n".
  250.                 'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
  251.                 '", "SMPopup",'.
  252.                 "\"width=" . (int)$newmail_popup_width ",height=" . (int)$newmail_popup_height ",scrollbars=no\");\n".
  253.                 "if (BeforePopupScript != null)\n".
  254.                 "BeforePopupScript();\n".
  255.                 "}\n".
  256.                 "BeforePopupScript = window.onload;\n".
  257.                 "window.onload = PopupScriptLoad;\n".
  258.                 // Idea by:  Nic Wolfe ([email protected])
  259.                 // Web URL:  http://fineline.xs.mw
  260.                 // More code from Tyler Akins
  261.                 "// End -->\n".
  262.                 "</script>\n";
  263.         }
  264.     }
  265. }

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