Cleaning
[squirrelmail.git] / functions / mailbox_display.php
index 89ae5ebaab381a666e623b06cf65f33e07a60f37..e6e5f114431364407b4eeb1543070e7535ada174 100644 (file)
@@ -27,7 +27,7 @@
           }
           $GLOBALS["row_count"]++;
           if ($GLOBALS["row_count"] % 2) {
-          if (!isset($color[12])) $color[12] = "#EAEAEA";
+          if (!isset($color[12])) $color[12] = '#EAEAEA';
             $color_string = $color[12];
           }
       }
       $msg = $msgs[$key];
 
       $senderName = sqimap_find_displayable_name($msg['FROM']);
+      if( $mailbox == _("None") ) {
+         // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
+         $boxes = sqimap_mailbox_list($imapConnection);
+         // sqimap_logout($imapConnection);
+         $mailbox = $boxes[0]['unformatted'];
+         unset( $boxes );
+      }
       $urlMailbox = urlencode($mailbox);
       $subject = processSubject($msg['SUBJECT']);
 
       echo "<TR>\n";
 
-      if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true) 
-      { 
-         $flag = "<font color=$color[2]>"; 
-         $flag_end = '</font>'; 
+      if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
+      {
+         $flag = "<font color=$color[2]>";
+         $flag_end = '</font>';
       }
       else
       {
          $flag = '';
          $flag_end = '';
       }
-      if (!isset($msg['FLAG_SEEN']) || $msg['FLAG_SEEN'] == false) 
-      { 
-         $bold = '<b>'; 
-         $bold_end = '</b>'; 
+      if (!isset($msg['FLAG_SEEN']) || $msg['FLAG_SEEN'] == false)
+      {
+         $bold = '<b>';
+         $bold_end = '</b>';
       }
       else
       {
          $bold = '';
          $bold_end = '';
       }
-      if ($mailbox == $sent_folder) 
-      { 
-         $italic = '<i>'; 
-         $italic_end = '</i>'; 
+      if ($mailbox == $sent_folder)
+      {
+         $italic = '<i>';
+         $italic_end = '</i>';
       }
       else
       {
@@ -71,9 +78,9 @@
          $italic_end = '';
       }
       if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
-      { 
-         $fontstr = "<font color=\"$color[9]\">"; 
-         $fontstr_end = '</font>'; 
+      {
+         $fontstr = "<font color=\"$color[9]\">";
+         $fontstr_end = '</font>';
       }
       else
       {
          $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
       }
 
-      if ($checkall == 1) 
+      if ($checkall == 1)
          $checked = ' checked';
       else
          $checked = '';
-      
+
       for ($i=1; $i <= count($index_order); $i++) {
          switch ($index_order[$i]) {
             case 1: # checkbox
                do_hook("subject_link");
 
                if ($subject != $msg['SUBJECT']) {
-                 $title = get_html_translation_table(HTML_SPECIALCHARS);
-                 $title = array_flip($title);
-                 $title = strtr($msg['SUBJECT'], $title);
-                 $title = str_replace('"', "''", $title);
+                  $title = get_html_translation_table(HTML_SPECIALCHARS);
+                  $title = array_flip($title);
+                  $title = strtr($msg['SUBJECT'], $title);
+                  $title = str_replace('"', "''", $title);
                   echo " title=\"$title\"";
-              }
-              echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
+               }
+               echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
                break;
             case 5: # flags
                $stuff = false;
                echo "   <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
-               if (isset($msg['FLAG_ANSWERED']) && 
+               if (isset($msg['FLAG_ANSWERED']) &&
                    $msg['FLAG_ANSWERED'] == true) {
                   echo "A\n";
                   $stuff = true;
                }
+               if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
+                  echo "<font color=$color[8]>v</font>\n";
+                  $stuff = true;
+               }
                if ($msg['TYPE0'] == 'multipart') {
                   echo "+\n";
                   $stuff = true;
             if ($numMessages < $show_num)
                 $end_loop = $numMessages;
             elseif ($end > $numMessages)
-               $end_loop = $numMessages - $startMessage + 1;
-           else
+            $end_loop = $numMessages - $startMessage + 1;
+        else
                 $end_loop = $show_num;
          } else {
             $end = $numMessages;
 
          /* Only ignore messages flagged as deleted if we are using a
           * trash folder or auto_expunge */
-         if (((isset($move_to_trash) && $move_to_trash) 
+         if (((isset($move_to_trash) && $move_to_trash)
               || (isset($auto_expunge) && $auto_expunge)) && $sort != 6)
          {
             /** Find and remove the ones that are deleted */
                 $messages = array();
             $msgs = $messages;
          }
-      }         
+      }
 
       // There's gotta be messages in the array for it to sort them.
       if ($numMessages > 0 && ! $use_cache) {
       global $folder_prefix, $sent_folder;
       global $imapServerAddress;
       global $index_order, $real_endMessage, $real_startMessage, $checkall;
-      
+
       // if cache isn't already set, do it now
       if (!session_is_registered('msgs'))
          session_register('msgs');
          $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
       }
 
-      $More = '';
       if ($sort == 6) {
          $use = 0;
       } else {
          $use = 1;
       }
+      $lMore = '';
+      $rMore = '';
       if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
-         $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
-         $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
+         $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
+         $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
       }
       elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
-         $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
-         $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
+         $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
+         $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
       }
       elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
-         $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
-         $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
+         $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
+         $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
+      }
+      if( $lMore <> '' )
+        $lMore .= ' | ';
+
+      // Page selector block. Following code computes page links.
+      $mMore = '';
+      if( getPref($data_dir, $username, 'page_selector') && $numMessages > $show_num ) {
+
+        $j = intval( $numMessages / $show_num );
+        if( $numMessages % $show_num <> 0 )
+                $j++;
+        $startMessage = min( $startMessage, $numMessages );
+        for( $i = 0; $i < $j; $i++ ) {
+
+                $start = ( ( $i * $show_num ) + 1 );
+
+                if( $startMessage >= $start &&
+                $startMessage < $start + $show_num ) {
+                $mMore .= '<b>' . ($i+1) . '</b> ';
+                } else {
+                $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
+                        "&mailbox=$urlMailbox\" TARGET=\"right\">" .
+                        ($i+1) .
+                        '</a> ';
+                }
+        }
+        $mMore .= ' | ';
       }
 
       if (! isset($msg))
-          $msg = "";
+          $msg = '';
       mail_message_listing_beginning($imapConnection,
          "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
-          $mailbox, $sort, $Message, $More, $startMessage);
+          $mailbox, $sort, $Message, $lMore . $mMore . $rMore, $startMessage);
 
       $groupNum = $startMessage % ($show_num - 1);
       $real_startMessage = $startMessage;
 
       echo "<TR BGCOLOR=\"$color[4]\"><TD>";
       echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
-      echo "$More</td><td align=right>\n";
+      echo "$lMore$mMore$rMore</td><td align=right>\n";
       if (!$startMessage) $startMessage=1;
       ShowSelectAllLink($startMessage, $sort);
 
-      echo '</td></tr></table>';
-      echo '</td></tr>';
-      echo '</table>'; /** End of message-list table */
+      echo '</td></tr></table></td></tr></table>'; /** End of message-list table */
 
       do_hook('mailbox_index_after');
    }
       global $color, $index_order, $auto_expunge, $move_to_trash;
       global $checkall, $sent_folder;
       $urlMailbox = urlencode($mailbox);
-         /** This is the beginning of the message list table.  It wraps around all messages */
-      echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
 
-      if ($Message)
-      {
+      /** This is the beginning of the message list table.  It wraps around all messages */
+      echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
+      if ($Message) {
          echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
       }
 
       echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
       echo "$More</td><td align=right>\n";
       ShowSelectAllLink($startMessage, $sort);
-
-      echo '</td></tr></table>';
-      echo '</td></tr>';
+      echo '</td></tr></table></td></tr>';
 
       /** The delete and move options */
       echo "<TR><TD BGCOLOR=\"$color[0]\">";
 
-      echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
+      echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
       echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
-      echo "   <TR>\n";
-      echo "      <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
-
 
-      echo '         <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
-      echo '         <TT><SMALL><SELECT NAME="targetMailbox">';
+      echo "   <TR>\n";
+      echo "      <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER NOWRAP>\n";
+      echo '         <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n";
+      echo "      </TD>\n";
+      echo "      <TD>&nbsp;</TD>\n";
+      echo "      <TD WIDTH=\"1%\" ALIGN=RIGHT NOWRAP>\n";
+      echo '         <SMALL>&nbsp;' . _("Transform Selected Messages") . ": </SMALL><BR>\n";
+      echo "      </TD>\n";
+      echo "   </TR>\n";
+      echo "   <TR>\n";
+      echo "      <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n";
+      echo '         <TT><SMALL>&nbsp;&nbsp;&nbsp;<SELECT NAME="targetMailbox">';
 
       $boxes = sqimap_mailbox_list($imapConnection);
       for ($i = 0; $i < count($boxes); $i++) {
          }
       }
       echo '         </SELECT></SMALL></TT>';
-      echo '         <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
+      echo "         <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n";
       echo "      </TD>\n";
-      echo "      <TD WIDTH=40% ALIGN=RIGHT>\n";
+      echo "      <TD>&nbsp;</TD>\n";
+      echo "      <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
       if (! $auto_expunge) {
-         echo '         <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."</SMALL></NOBR>&nbsp;&nbsp;\n";
+         echo '         <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
       }
-      echo "         <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
+      echo "         <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n";
+      echo "         <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n";
+      echo "         <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n";
       echo "      </TD>\n";
       echo "   </TR>\n";
-
       echo "</TABLE>\n";
       do_hook('mailbox_form_before');
       echo '</TD></TR>';
             case 5: # flags
                echo '   <TD WIDTH="1%"><B>&nbsp;</B></TD>';
                break;
-               
+
             case 2: # from
                if ($mailbox == $sent_folder)
                   echo '   <TD WIDTH="25%"><B>'. _("To") .'</B>';
                else
                     echo '   <TD WIDTH="25%"><B>'. _("From") .'</B>';
-              ShowSortButton($sort, $mailbox, 2, 3);
+           ShowSortButton($sort, $mailbox, 2, 3);
                echo "</TD>\n";
                break;
-               
+
             case 3: # date
                echo '   <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
-              ShowSortButton($sort, $mailbox, 0, 1);
+               ShowSortButton($sort, $mailbox, 0, 1);
                echo "</TD>\n";
                break;
-               
+
             case 4: # subject
                echo '   <TD><B>'. _("Subject") .'</B> ';
-              ShowSortButton($sort, $mailbox, 4, 5);
+               ShowSortButton($sort, $mailbox, 4, 5);
                echo "</TD>\n";
                break;
-               
-            case 6: # size 
+
+            case 6: # size
                echo '   <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
                break;
          }
       }
       echo "</TR>\n";
    }
-   
+
    function ShowSortButton($sort, $mailbox, $Up, $Down) {
       if ($sort != $Up && $sort != $Down) {
          $img = 'sort_none.gif';
          $which = $Up;
       } elseif ($sort == $Up) {
          $img = 'up_pointer.gif';
-        $which = $Down;
+         $which = $Down;
       } else {
          $img = 'down_pointer.gif';
-        $which = 6;
+         $which = 6;
       }
-      echo ' <a href="right_main.php?newsort=' . $which . 
-        '&startMessage=1&mailbox=' . urlencode($mailbox) . 
-        '"><IMG SRC="../images/' . $img . 
-        '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
+      echo ' <a href="right_main.php?newsort=' . $which .
+           '&startMessage=1&mailbox=' . urlencode($mailbox) .
+           '"><IMG SRC="../images/' . $img .
+           '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
    }
-   
+
    function ShowSelectAllLink($startMessage, $sort)
    {
        global $checkall, $PHP_SELF, $what, $where, $mailbox;
 
        // This code is from Philippe Mingo <mingo@rotedic.com>
-    
+
        ?>
 <script language="JavaScript">
 <!--
@@ -631,7 +674,7 @@ window.document.write('<a href="#" onClick="CheckAll();"><?php echo
            echo _("Unselect All");
        else
            echo _("Select All");
-          
+
        echo "</A>\n</noscript>\n";
    }
 
@@ -640,10 +683,10 @@ window.document.write('<a href="#" onClick="CheckAll();"><?php echo
       // Shouldn't ever happen -- caught too many times in the IMAP functions
       if ($subject == '')
           return _("(no subject)");
-         
+
       if (strlen($subject) <= 55)
           return $subject;
-         
+
       $ent_strlen=strlen($subject);
       $trim_val=50;
       $ent_offset=0;
@@ -654,15 +697,15 @@ window.document.write('<a href="#" onClick="CheckAll();"><?php echo
       while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
              ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
       {
-        $trim_val += ($ent_loc_end-$ent_loc)+1;
-        $ent_strlen -= $ent_loc_end-$ent_loc;
-        $ent_offset = $ent_loc_end+1;
+     $trim_val += ($ent_loc_end-$ent_loc)+1;
+     $ent_strlen -= $ent_loc_end-$ent_loc;
+     $ent_offset = $ent_loc_end+1;
       }
-      
+
       if ($ent_strlen <= 55)
           return $subject;
 
       return substr($subject, 0, $trim_val) . '...';
    }
 
-?>
+?>
\ No newline at end of file