+ $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
+ $form_name = "FormMsgs" . $safe_name;
+
+ echo '<form name="' . $form_name . '" method="post" action="'.$php_self.'">' ."\n"
+ . $moveFields;
+
+ $button_str = '';
+ // display flag buttons only if supported
+ if ($show_flag_buttons &&
+ in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true) ) {
+ $button_str .= getButton('SUBMIT', 'markUnflagged', _("Unflag"));
+ $button_str .= getButton('SUBMIT', 'markFlagged', _("Flag"));
+ $button_str .= " \n";
+ }
+ if (in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true)) {
+ $button_str .= getButton('SUBMIT', 'markUnread', _("Unread"));
+ $button_str .= getButton('SUBMIT', 'markRead', _("Read"));
+ $button_str .= " \n";
+ }
+ $button_str .= getButton('SUBMIT', 'attache',_("Forward")) .
+ " \n";
+ if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) {
+ $button_str .= getButton('SUBMIT', 'delete',_("Delete"));
+ $button_str .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
+ $button_str .= " \n";
+ }
+ if (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY') {
+ $button_str .= getButton('SUBMIT', 'expungeButton',_("Expunge")) .' ' . _("mailbox") . "\n";
+ $button_str .= ' ';
+ }
+?>
+ <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>">
+ <tr>
+ <td>
+ <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0">
+ <tr>
+ <?php echo html_tag('td', '<small>' . $paginator . $thread_link_str . '</small>', 'left') . "\n"; ?>
+ <?php echo html_tag('td', '', 'center') . "\n"; ?>
+ <?php echo html_tag('td', '<small>' . $msg_cnt_str . '</small>', 'right') . "\n"; ?>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="<?php echo $color[0]; ?>">
+ <td>
+ <table border="0" width="100%" cellpadding="1" cellspacing="0">
+ <tr>
+ <?php echo html_tag('td', '', 'left') . "\n"; ?>
+ <small>
+ <?php echo $button_str; ?>
+ <?php do_hook('mailbox_display_buttons'); ?>
+ </small>
+ </td>
+ <?php
+ if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) {
+ ?>
+ <?php echo html_tag('td', '', 'right'); ?>
+ <small> <tt>
+ <select name="targetMailbox">
+ <?php echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes); ?>
+ </select></tt>
+ <?php echo getButton('SUBMIT', 'moveButton',_("Move")); ?>
+ </small>
+ <?php
+ }
+ ?>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+<?php
+ do_hook('mailbox_form_before');
+}
+
+/**
+* Function to add the last row in a message list, it contains the paginator and info about
+* the number of messages.
+*
+* @param integer $num_msgs number of messages in a mailbox
+* @param string $paginator_str Paginator string [Prev | Next] [ 1 2 3 ... 91 92 94 ] [Show all]
+* @param string $msg_cnt_str Message count string Viewing Messages: 21 to 1861 (20 total)
+*/
+function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str) {
+global $color;
+if ($num_msgs) {
+ /* space between list and footer */
+?>
+<tr><td height="5" bgcolor="<?php echo $color[4]; ?>" colspan="1"></td></tr>
+<tr>
+ <td>
+ <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>">
+ <tr>
+ <td>
+ <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0">
+ <tr>
+ <?php echo html_tag('td', '<small>' . $paginator_str . '</small>', 'left'); ?>
+ <?php echo html_tag('td', '<small>' . $msg_cnt_str . '</small>', 'right'); ?>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+</tr>
+<?php
+}
+ /* End of message-list table */
+
+ do_hook('mailbox_index_after');
+ echo "</form>\n";
+}
+
+/**
+* Prints the table header for the messages list view
+*
+* @param array $aMailbox
+*/
+function printHeader($aMailbox) {
+ global $index_order, $internal_date_sort, $color;
+
+ if ($aMailbox['SORT_METHOD'] != 'THREAD') {
+ $showsort = true;
+ } else {
+ $showsort = false;
+ }
+
+ echo html_tag( 'tr' ,'' , 'center', $color[5] );
+
+ /* calculate the width of the subject column based on the
+ * widths of the other columns */
+ $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
+ $subjectwidth = 100;
+ foreach($index_order as $item) {
+ $subjectwidth -= $widths[$item];
+ }
+
+ foreach ($index_order as $item) {
+ switch ($item) {
+ case 1: /* checkbox */
+ echo html_tag( 'td',get_selectall_link($aMailbox) , '', '', 'width="1%"' );
+ break;
+ case 5: /* flags */
+ echo html_tag( 'td','' , '', '', 'width="1%"' );
+ break;
+ case 2: /* from */
+ if (handleAsSent($aMailbox['NAME'])) {
+ echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
+ . '<b>' . _("To") . '</b>';
+ if ($showsort) {
+ ShowSortButton($aMailbox, SQSORT_TO_ASC, SQSORT_TO_DEC);
+ }
+ } else {
+ echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
+ . '<b>' . _("From") . '</b>';
+ if ($showsort) {
+ ShowSortButton($aMailbox, SQSORT_FROM_ASC, SQSORT_FROM_DEC);
+ }
+ }
+ echo "</td>\n";
+ break;
+ case 3: /* date */
+ echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
+ . '<b>' . _("Date") . '</b>';
+ if ($showsort) {
+ if ($internal_date_sort) {
+ ShowSortButton($aMailbox, SQSORT_INT_DATE_ASC, SQSORT_INT_DATE_DEC);
+ } else {
+ ShowSortButton($aMailbox, SQSORT_DATE_ASC, SQSORT_DATE_DEC);
+ }
+ }
+ echo "</td>\n";
+ break;
+ case 4: /* subject */
+ echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
+ . '<b>' . _("Subject") . '</b>';
+ if ($showsort) {
+ ShowSortButton($aMailbox, SQSORT_SUBJ_ASC, SQSORT_SUBJ_DEC);
+ }
+ echo "</td>\n";
+ break;
+ case 6: /* size */
+ echo html_tag( 'td', '', 'center','','width="5%" nowrap')
+ . '<b>' . _("Size") . '</b>';
+ if ($showsort) {
+ ShowSortButton($aMailbox, SQSORT_SIZE_ASC, SQSORT_SIZE_DEC);
+ }
+ echo "</td>\n";
+ break;
+ }
+ }
+ echo "</tr>\n";
+}
+
+
+/**
+* This function shows the sort button. Isn't this a good comment?
+*
+* @param array $aMailbox
+* @param integer $Down
+* @param integer $Up
+*/
+function ShowSortButton($aMailbox, $Down, $Up ) {
+ global $PHP_SELF;
+
+ /* Figure out which image we want to use. */
+ if ($aMailbox['SORT'] != $Up && $aMailbox['SORT'] != $Down) {
+ $img = 'sort_none.png';
+ $which = $Up;
+ } elseif ($aMailbox['SORT'] == $Up) {
+ $img = 'up_pointer.png';
+ $which = $Down;
+ } else {
+ $img = 'down_pointer.png';
+ $which = 0;
+ }
+
+ if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
+ $source_url = $regs[1];
+ } else {
+ $source_url = $PHP_SELF;
+ }
+
+ /* Now that we have everything figured out, show the actual button. */
+ echo ' <a href="' . $source_url .'?srt=' . $which
+ . '&startMessage=1&mailbox=' . urlencode($aMailbox['NAME'])
+ . '"><img src="../images/' . $img
+ . '" border="0" width="12" height="10" alt="sort" title="'
+ . _("Click here to change the sorting of the message list") .'" /></a>';
+}
+
+/**
+* FIXME: Undocumented function
+*
+* @param array $aMailbox
+*/
+function get_selectall_link($aMailbox) {
+ global $checkall, $javascript_on;
+ global $PHP_SELF;
+
+ $result = '';
+ if ($javascript_on) {
+ $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
+ $func_name = "CheckAll" . $safe_name;
+ $form_name = "FormMsgs" . $safe_name;
+ $result = '<script language="JavaScript" type="text/javascript">'
+ . "\n<!-- \n"
+ . "function " . $func_name . "() {\n"
+ . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
+ . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
+ . " document." . $form_name . ".elements[i].name.substring(0,3) == 'msg'){\n"
+ . " document." . $form_name . ".elements[i].checked = "
+ . " !(document." . $form_name . ".elements[i].checked);\n"
+ . " }\n"
+ . " }\n"
+ . "}\n"
+ . "//-->\n"
+ . '</script>'
+ . '<input type="checkbox" name="toggleAll" title="'._("Toggle All").'" onclick="'.$func_name.'();" />';
+// . <a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
+// . "</a>\n";
+ } else {
+ if (strpos($PHP_SELF, "?")) {
+ $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($aMailbox['NAME'])
+ . "&startMessage=$aMailbox[PAGEOFFSET]&srt=$aMailbox[SORT]&checkall=";
+ } else {
+ $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
+ . "&startMessage=$aMailbox[PAGEOFFSET]&srt=$aMailbox[SORT]&checkall=";
+ }
+ if (isset($checkall) && $checkall == '1') {
+ $result .= '0';
+ } else {
+ $result .= '1';
+ }
+
+ if (isset($aMailbox['SEARCH']) && $aMailbox['SEARCH'][0]) {
+ $result .= '&where=' . urlencode($aMailbox['SEARCH'][0])
+ . '&what=' . urlencode($aMailbox['SEARCH'][1]);
+ }
+ $result .= "\">";
+ $result .= _("All");
+ $result .= "</a>\n";
+ }
+
+ /* Return our final result. */
+ return ($result);
+}
+
+/**
+* This function computes the "Viewing Messages..." string.
+*
+* @param integer $start_msg first message number
+* @param integer $end_msg last message number
+* @param integer $num_msgs total number of message in folder
+* @return string
+*/
+function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
+ /* Compute the $msg_cnt_str. */
+ $result = '';
+ if ($start_msg < $end_msg) {
+ $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
+ '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs);
+ } else if ($start_msg == $end_msg) {
+ $result = sprintf(_("Viewing Message: %s (1 total)"), '<b>'.$start_msg.'</b>');
+ } else {
+ $result = '<br />';
+ }
+ /* Return our result string. */
+ return ($result);
+}
+
+/**
+* Generate a paginator link.
+*
+* @param mixed $box Mailbox name
+* @param mixed $start_msg Message Offset
+* @param mixed $use
+* @param string $text text used for paginator link
+* @return string
+*/
+function get_paginator_link($box, $start_msg, $text) {
+ sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER);
+ $result = "<a href=\"$php_self?startMessage=$start_msg&mailbox=$box\" "
+ . ">$text</a>";
+
+ return ($result);
+}
+
+/**
+* This function computes the paginator string.
+*
+* @param string $box mailbox name
+* @param integer $iOffset offset in total number of messages
+* @param integer $iTotal total number of messages
+* @param integer $iLimit maximum number of messages to show on a page
+* @param bool $bShowAll show all messages at once (non paginate mode)
+* @return string $result paginate string with links to pages
+*/
+function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) {
+ global $username, $data_dir;
+ sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER);
+
+ /* Initialize paginator string chunks. */
+ $prv_str = '';
+ $nxt_str = '';
+ $pg_str = '';
+ $all_str = '';
+
+ $box = urlencode($box);
+
+ /* Create simple strings that will be creating the paginator. */
+ $spc = ' '; /* This will be used as a space. */
+ $sep = '|'; /* This will be used as a seperator. */
+
+ /* Get some paginator preference values. */
+ $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
+ $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
+
+ /* Make sure that our start message number is not too big. */
+ $iOffset = min($iOffset, $iTotal);
+
+ /* Compute the starting message of the previous and next page group. */
+ $next_grp = $iOffset + $iLimit;
+ $prev_grp = $iOffset - $iLimit;
+
+ if (!$bShowAll) {
+ /* Compute the basic previous and next strings. */
+ if (($next_grp <= $iTotal) && ($prev_grp >= 0)) {
+ $prv_str = get_paginator_link($box, $prev_grp, _("Previous"));
+ $nxt_str = get_paginator_link($box, $next_grp, _("Next"));
+ } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) {
+ $prv_str = get_paginator_link($box, $prev_grp, _("Previous"));
+ $nxt_str = _("Next");
+ } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) {
+ $prv_str = _("Previous");
+ $nxt_str = get_paginator_link($box, $next_grp, _("Next"));
+ }
+
+ /* Page selector block. Following code computes page links. */
+ if ($iLimit != 0 && $pg_sel && ($iTotal > $iLimit)) {
+ /* Most importantly, what is the current page!!! */
+ $cur_pg = intval($iOffset / $iLimit) + 1;
+
+ /* Compute total # of pages and # of paginator page links. */
+ $tot_pgs = ceil($iTotal / $iLimit); /* Total number of Pages */
+ $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
+
+ /* Compute the size of the four quarters of the page links. */
+
+ /* If we can, just show all the pages. */
+ if (($tot_pgs - 1) <= $pg_max) {
+ $q1_pgs = $cur_pg - 1;
+ $q2_pgs = $q3_pgs = 0;
+ $q4_pgs = $tot_pgs - $cur_pg;
+
+ /* Otherwise, compute some magic to choose the four quarters. */
+ } else {
+ /*
+ * Compute the magic base values. Added together,
+ * these values will always equal to the $pag_pgs.
+ * NOTE: These are DEFAULT values and do not take
+ * the current page into account. That is below.
+ */
+ $q1_pgs = floor($vis_pgs/4);
+ $q2_pgs = round($vis_pgs/4, 0);
+ $q3_pgs = ceil($vis_pgs/4);
+ $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
+
+ /* Adjust if the first quarter contains the current page. */
+ if (($cur_pg - $q1_pgs) < 1) {
+ $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
+ $q1_pgs = $cur_pg - 1;
+ $q2_pgs = 0;
+ $q3_pgs += ceil($extra_pgs / 2);
+ $q4_pgs += floor($extra_pgs / 2);
+
+ /* Adjust if the first and second quarters intersect. */
+ } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
+ $extra_pgs = $q2_pgs;
+ $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
+ $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
+ $q3_pgs += ceil($extra_pgs / 2);
+ $q4_pgs += floor($extra_pgs / 2);
+
+ /* Adjust if the fourth quarter contains the current page. */
+ } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
+ $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
+ $q3_pgs = 0;
+ $q4_pgs = $tot_pgs - $cur_pg;
+ $q1_pgs += floor($extra_pgs / 2);
+ $q2_pgs += ceil($extra_pgs / 2);
+
+ /* Adjust if the third and fourth quarter intersect. */
+ } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
+ $extra_pgs = $q3_pgs;
+ $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
+ $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
+ $q1_pgs += floor($extra_pgs / 2);
+ $q2_pgs += ceil($extra_pgs / 2);
+ }
+ }
+
+ /*
+ * I am leaving this debug code here, commented out, because
+ * it is a really nice way to see what the above code is doing.
+ * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
+ * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br />';
+ */
+
+ /* Print out the page links from the compute page quarters. */
+
+ /* Start with the first quarter. */
+ if (($q1_pgs == 0) && ($cur_pg > 1)) {
+ $pg_str .= "...$spc";
+ } else {
+ for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
+ $start = (($pg-1) * $iLimit) + 1;
+ $pg_str .= get_paginator_link($box, $start, $pg) . $spc;
+ }
+ if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
+ $pg_str .= "...$spc";
+ }
+ }
+
+ /* Continue with the second quarter. */
+ for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
+ $start = (($pg-1) * $iLimit) + 1;
+ $pg_str .= get_paginator_link($box, $start, $pg) . $spc;
+ }
+
+ /* Now print the current page. */
+ $pg_str .= $cur_pg . $spc;
+
+ /* Next comes the third quarter. */
+ for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
+ $start = (($pg-1) * $iLimit) + 1;
+ $pg_str .= get_paginator_link($box, $start, $pg) . $spc;
+ }
+
+ /* And last, print the forth quarter page links. */
+ if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
+ $pg_str .= "...$spc";
+ } else {
+ if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
+ $pg_str .= "...$spc";
+ }
+ for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
+ $start = (($pg-1) * $iLimit) + 1;
+ $pg_str .= get_paginator_link($box, $start,$pg) . $spc;
+ }
+ }
+ }
+ } else {
+ $pg_str = "<a href=\"$php_self?showall=0"
+ . "&startMessage=1&mailbox=$box\" "
+ . ">" ._("Paginate") . '</a>';
+ }
+
+ /* Put all the pieces of the paginator string together. */
+ /**
+ * Hairy code... But let's leave it like it is since I am not certain
+ * a different approach would be any easier to read. ;)
+ */
+ $result = '';
+ if ( $prv_str || $nxt_str ) {
+
+ /* Compute the 'show all' string. */
+ $all_str = "<a href=\"$php_self?showall=1"
+ . "&startMessage=1&mailbox=$box\" "
+ . ">" . _("Show All") . '</a>';
+ $result .= '[';
+ $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
+ $result .= ($nxt_str != '' ? $nxt_str : '');
+ $result .= ']' . $spc ;
+
+ }
+
+ $result .= ($pg_str != '' ? $spc . '['.$spc.$pg_str.']' . $spc : '');
+ $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : '');
+
+ /* If the resulting string is blank, return a non-breaking space. */
+ if ($result == '') {
+ $result = ' ';
+ }
+
+ /* Return our final magical paginator string. */
+ return ($result);
+}
+
+/**
+* FIXME: Undocumented function
+*/
+function truncateWithEntities($subject, $trim_at)
+{
+ $ent_strlen = strlen($subject);
+ if (($trim_at <= 0) || ($ent_strlen <= $trim_at))
+ return $subject;
+
+ global $languages, $squirrelmail_language;
+
+ /*
+ * see if this is entities-encoded string
+ * If so, Iterate through the whole string, find out
+ * the real number of characters, and if more
+ * than $trim_at, substr with an updated trim value.
+ */
+ $trim_val = $trim_at;
+ $ent_offset = 0;
+ $ent_loc = 0;
+ while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
+ (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) {
+ $trim_val += ($ent_loc_end-$ent_loc);
+ $ent_offset = $ent_loc_end+1;
+ }
+ if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val + 6))) {
+ $i = strpos($subject,';',$trim_val);
+ if ($i) {
+ $trim_val = strpos($subject,';',$trim_val);
+ }
+ }
+ // only print '...' when we're actually dropping part of the subject
+ if ($ent_strlen <= $trim_val)
+ return $subject;
+
+ if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
+ function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
+ return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
+ }
+
+ return substr_replace($subject, '...', $trim_val);
+}
+
+/**
+* FIXME: Undocumented function
+*/
+function processSubject($subject, $threadlevel = 0) {
+ /* Shouldn't ever happen -- caught too many times in the IMAP functions */
+ if ($subject == '') {
+ return _("(no subject)");
+ }
+
+ global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
+ $trim_at = $truncate_subject;
+
+ /* if this is threaded, subtract two chars per indentlevel */
+ if (($threadlevel > 0) && ($threadlevel <= 10))
+ $trim_at -= (2*$threadlevel);
+
+ return truncateWithEntities($subject, $trim_at);
+}
+
+
+/**
+* Creates button
+*
+* @deprecated see form functions available in 1.5.1 and 1.4.3.
+* @param string $type
+* @param string $name
+* @param string $value
+* @param string $js
+* @param bool $enabled
+*/
+function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
+ $disabled = ( $enabled ? '' : 'disabled ' );
+ $js = ( $js ? $js.' ' : '' );
+ return '<input '.$disabled.$js.
+ 'type="'.$type.
+ '" name="'.$name.
+ '" value="'.$value .
+ '" style="padding: 0px; margin: 0px" />';
+}
+
+/**
+* Puts string into cell, aligns it and adds <small> tag
+*
+* @param string $string string
+* @param string $align alignment
+*/
+function getSmallStringCell($string, $align) {
+ return html_tag('td',
+ '<small>' . $string . ': </small>',
+ $align,
+ '',
+ 'nowrap' );
+}
+
+/**
+* This should go in imap_mailbox.php
+* @param string $mailbox
+*/
+function handleAsSent($mailbox) {
+ global $handleAsSent_result;
+
+ /* First check if this is the sent or draft folder. */
+ $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
+
+ /* Then check the result of the handleAsSent hook. */
+ do_hook('check_handleAsSent_result', $mailbox);
+
+ /* And return the result. */
+ return $handleAsSent_result;
+}
+
+/**
+ * Process messages list form and handle the cache gracefully. If $sButton and
+ * $aUid are provided as argument then you can fake a message list submit and
+ * use it i.e. in read_body.php for del move next and update the cache
+ *
+ * @param resource $imapConnection imap connection
+ * @param array $aMailbox (reference) cached mailbox
+ * @param string $sButton fake a submit button
+ * @param array $aUid fake the $msg array
+ * @return string $sError error string in case of an error
+ * @author Marc Groot Koerkamp
+ */
+function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = array()) {
+
+ /* incoming formdata */
+ $sButton = (sqgetGlobalVar('moveButton', $sTmp, SQ_POST)) ? 'move' : $sButton;
+ $sButton = (sqgetGlobalVar('expungeButton', $sTmp, SQ_POST)) ? 'expunge' : $sButton;
+ $sButton = (sqgetGlobalVar('attache', $sTmp, SQ_POST)) ? 'attache' : $sButton;
+ $sButton = (sqgetGlobalVar('delete', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton;
+ $sButton = (sqgetGlobalVar('undeleteButton', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton;
+ $sButton = (sqgetGlobalVar('markRead', $sTmp, SQ_POST)) ? 'setSeen' : $sButton;
+ $sButton = (sqgetGlobalVar('markUnread', $sTmp, SQ_POST)) ? 'unsetSeen' : $sButton;
+ $sButton = (sqgetGlobalVar('markFlagged', $sTmp, SQ_POST)) ? 'setFlagged' : $sButton;
+ $sButton = (sqgetGlobalVar('markUnflagged', $sTmp, SQ_POST)) ? 'unsetFlagged' : $sButton;
+ sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST);
+ sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_POST);
+ sqgetGlobalVar('msg', $msg, SQ_POST);
+
+ $sError = '';
+ $mailbox = $aMailbox['NAME'];
+
+ /* retrieve the check boxes */
+ $aUid = (isset($msg) && is_array($msg)) ? array_values($msg) : $aUid;
+
+ if (count($aUid) && $sButton != 'expunge') {
+ $aUpdatedMsgs = false;
+ $bExpunge = false;
+ switch ($sButton) {
+ case 'setDeleted':
+ // check if id exists in case we come from read_body
+ if (count($aUid) == 1 && is_array($aMailbox['UIDSET'][$aMailbox['SETINDEX']]) &&
+ !in_array($aUid[0],$aMailbox['UIDSET'][$aMailbox['SETINDEX']])) {
+ break;
+ }
+ // What kind of hook is this, can it be removed? Disabled for now because it can invalidate the cache
+ //if (!boolean_hook_function('move_messages_button_action', NULL, 1)) {
+ $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid,$bypass_trash);
+ $bExpunge = true;
+ //}
+ break;
+ case 'unsetDeleted':
+ case 'setSeen':
+ case 'unsetSeen':
+ case 'setFlagged':
+ case 'unsetFlagged':
+ // get flag
+ $sFlag = (substr($sButton,0,3) == 'set') ? '\\'.substr($sButton,3) : '\\'.substr($sButton,5);
+ $bSet = (substr($sButton,0,3) == 'set') ? true : false;
+ $aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true);
+ break;
+ case 'move':
+ $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox);
+ sqsession_register($targetMailbox,'lastTargetMailbox');
+ $bExpunge = true;
+ break;
+ case 'attache':
+ $aMsgHeaders = array();
+ foreach ($aUid as $iUid) {
+ $aMsgHeaders[$iUid] = $aMailbox['MSG_HEADERS'][$iUid];
+ }
+ if (count($aMsgHeaders)) {
+ $composesession = attachSelectedMessages($imapConnection,$aMsgHeaders);
+ // dirty hack, add info to $aMailbox
+ $aMailbox['FORWARD_SESSION'] = $composesession;
+ }
+ break;
+ }
+ /**
+ * Updates messages is an array containing the result of the untagged
+ * fetch responses send by the imap server due to a flag change. That
+ * response is parsed in a array with msg arrays by the parseFetch function
+ */
+ if ($aUpdatedMsgs) {
+ // Update the message headers cache
+ $aDeleted = array();
+ foreach ($aUpdatedMsgs as $iUid => $aMsg) {
+ if (isset($aMsg['FLAGS'])) {
+ /**
+ * Only update the cached headers if the header is
+ * cached.
+ */
+ if (isset($aMailbox['MSG_HEADERS'][$iUid])) {
+ $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS'];
+ }
+ /**
+ * Count the messages with the \Delete flag set so we can determine
+ * if the number of expunged messages equals the number of flagged
+ * messages for deletion.
+ */
+ if (isset($aMsg['FLAGS']['\\deleted']) && $aMsg['FLAGS']['\\deleted']) {
+ $aDeleted[] = $iUid;
+ }
+ }
+ }
+ if ($bExpunge && $aMailbox['AUTO_EXPUNGE'] &&
+ $iExpungedMessages = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true))
+ {
+ if (count($aDeleted) != $iExpungedMessages) {
+ // there are more messages deleted permanently then we expected
+ // invalidate the cache
+ $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = false;
+ $aMailbox['MSG_HEADERS'] = false;
+ } else {
+ // remove expunged messages from cache
+ $aUidSet = $aMailbox['UIDSET'][$aMailbox['SETINDEX']];
+ if (is_array($aUidSet)) {
+ // create a UID => array index temp array
+ $aUidSetDummy = array_flip($aUidSet);
+ foreach ($aDeleted as $iUid) {
+ // get the id as well in case of SQM_SORT_NONE
+ if ($aMailbox['SORT'] == SQSORT_NONE) {
+ $aMailbox['ID'] = false;
+ //$iId = $aMailbox['MSG_HEADERS'][$iUid]['ID'];
+ //unset($aMailbox['ID'][$iId]);
+ }
+ // unset the UID and message header
+ unset($aUidSetDummy[$iUid]);
+ unset($aMailbox['MSG_HEADERS'][$iUid]);
+ }
+ $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = array_keys($aUidSetDummy);
+ }
+ }
+ // update EXISTS info
+ if ($iExpungedMessages) {
+ $aMailbox['EXISTS'] -= (int) $iExpungedMessages;
+ }
+ // Change the startMessage number if the mailbox was changed
+ if (($aMailbox['PAGEOFFSET']+$iExpungedMessages-1) >= $aMailbox['EXISTS']) {
+ $aMailbox['PAGEOFFSET'] = ($aMailbox['PAGEOFFSET'] > $aMailbox['LIMIT']) ?
+ $aMailbox['PAGEOFFSET'] - $aMailbox['LIMIT'] : 1;
+ }
+ }
+ }
+ } else {
+ if ($sButton == 'expunge') {
+ /**
+ * on expunge we do not know which messages will be deleted
+ * so it's useless to try to sync the cache
+
+ * Close the mailbox so we do not need to parse the untagged expunge
+ * responses which do not contain uid info.
+ * NB: Closing a mailbox is faster then expunge because the imap
+ * server does not need to generate the untagged expunge responses
+ */
+ sqimap_run_command($imapConnection,'CLOSE',false,$result,$message);
+ $aMbxResponse = sqimap_mailbox_select($imapConnection,$aMailbox['NAME']);
+ // update the $aMailbox array
+ $aMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
+ $aMailbox['UIDSET'] = false;
+ } else {
+ if ($sButton) {
+ $sError = _("No messages were selected.");
+ }
+ }
+ }
+ return $sError;
+}
+
+function attachSelectedMessages($imapConnection,$aMsgHeaders) {
+ global $username, $attachment_dir,
+ $data_dir, $composesession,
+ $compose_messages;
+
+ if (!isset($compose_messages)) {
+ $compose_messages = array();
+ sqsession_register($compose_messages,'compose_messages');
+ }
+
+ if (!$composesession) {
+ $composesession = 1;
+ sqsession_register($composesession,'composesession');
+ } else {
+ $composesession++;
+ sqsession_register($composesession,'composesession');
+ }
+
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+
+ $composeMessage = new Message();
+ $rfc822_header = new Rfc822Header();
+ $composeMessage->rfc822_header = $rfc822_header;
+ $composeMessage->reply_rfc822_header = '';
+
+ foreach($aMsgHeaders as $iUid => $aMsgHeader) {
+ /**
+ * Retrieve the full message
+ */
+ $body_a = sqimap_run_command($imapConnection, "FETCH $iUid RFC822", true, $response, $readmessage, TRUE);
+
+ if ($response == 'OK') {
+ $subject = (isset($aMsgHeader['SUBJECT'])) ? $aMsgHeader['SUBJECT'] : $iUid;
+
+ array_shift($body_a);
+ array_pop($body_a);
+ $body = implode('', $body_a);
+ $body .= "\r\n";
+
+ $localfilename = GenerateRandomString(32, 'FILE', 7);
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+
+ $fp = fopen( $full_localfilename, 'wb');
+ fwrite ($fp, $body);
+ fclose($fp);
+ $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
+ $full_localfilename);
+ }
+ }
+
+ $compose_messages[$composesession] = $composeMessage;
+ sqsession_register($compose_messages,'compose_messages');
+ return $composesession;