Changeset 4bfe4ec in github for program/steps/mail/get.inc


Ignore:
Timestamp:
May 22, 2012 4:26:36 AM (13 months ago)
Author:
Aleksander Machniak <alec@…>
Branches:
master, HEAD, dev-browser-capabilities, pdo
Children:
5a575b7
Parents:
38a08c0
Message:

Remove last instance of storage_connect() with possible performance
improvement when a message part body is in cache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/steps/mail/get.inc

    rb4f95a9 r4bfe4ec  
    3939ob_end_clean(); 
    4040 
    41 // Now we need IMAP connection 
    42 if (!$RCMAIL->storage_connect()) { 
    43   // Get action is often executed simultanously. 
    44   // Some servers have MAXPERIP or other limits. 
    45   // To workaround this we'll wait for some time 
    46   // and try again (once). 
    47   // Note: Random sleep interval is used to minimize concurency 
    48   // in getting message parts 
    49   if (!isset($_GET['_redirected'])) { 
    50     usleep(rand(10,30)*100000); // 1-3 sec. 
    51     header('Location: ' . $_SERVER['REQUEST_URI'] . '&_redirected=1'); 
    52   } 
    53   else { 
    54     raise_error(array( 
    55       'code' => 500, 'type' => 'php', 
    56       'file' => __FILE__, 'line' => __LINE__, 
    57       'message' => 'Unable to get/display message part. IMAP connection error'), 
    58       true, true); 
    59   } 
    60   // Don't kill session, just quit (#1486995) 
    61   exit; 
    62 } 
    63  
    6441// similar code as in program/steps/mail/show.inc 
    6542if (!empty($_GET['_uid'])) { 
     
    6744  $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET)); 
    6845} 
     46 
     47// check connection status 
     48check_storage_status(); 
    6949 
    7050// show part page 
     
    138118      } 
    139119 
     120      // check connection status 
     121      if ($part->size && empty($part->body)) { 
     122        check_storage_status(); 
     123      } 
     124 
    140125      $OUTPUT = new rcube_output_html(); 
    141126      $OUTPUT->write($out); 
     
    171156      // do content filtering to avoid XSS through fake images 
    172157      if (!empty($_REQUEST['_embed']) && $browser->ie && $browser->ver <= 8) { 
    173         if ($part->body) 
     158        if ($part->body) { 
    174159          echo preg_match('/<(script|iframe|object)/i', $part->body) ? '' : $part->body; 
     160          $sent = true; 
     161        } 
    175162        else if ($part->size) { 
    176163          $stdout = fopen('php://output', 'w'); 
    177164          stream_filter_register('rcube_content', 'rcube_content_filter') or die('Failed to register content filter'); 
    178165          stream_filter_append($stdout, 'rcube_content'); 
    179           $RCMAIL->storage->get_message_part($MESSAGE->uid, $part->mime_id, $part, false, $stdout); 
     166          $sent = $RCMAIL->storage->get_message_part($MESSAGE->uid, $part->mime_id, $part, false, $stdout); 
    180167        } 
    181168      } 
    182169      else { 
    183170        // turn off output buffering and print part content 
    184         if ($part->body) 
     171        if ($part->body) { 
    185172          echo $part->body; 
    186         else if ($part->size) 
    187           $RCMAIL->storage->get_message_part($MESSAGE->uid, $part->mime_id, $part, true); 
     173          $sent = true; 
     174        } 
     175        else if ($part->size) { 
     176          $sent = $RCMAIL->storage->get_message_part($MESSAGE->uid, $part->mime_id, $part, true); 
     177        } 
     178      } 
     179 
     180      // check connection status 
     181      if ($part->size && !$sent) { 
     182        check_storage_status(); 
    188183      } 
    189184    } 
     
    214209 
    215210 
     211function check_storage_status() 
     212{ 
     213    $error = rcmail::get_instance()->storage->get_error_code(); 
     214 
     215    // Check if we have a connection error 
     216    if ($error == rcube_imap_generic::ERROR_BAD) { 
     217        ob_end_clean(); 
     218 
     219        // Get action is often executed simultanously. 
     220        // Some servers have MAXPERIP or other limits. 
     221        // To workaround this we'll wait for some time 
     222        // and try again (once). 
     223        // Note: Random sleep interval is used to minimize concurency 
     224        // in getting message parts 
     225 
     226        if (!isset($_GET['_redirected'])) { 
     227            usleep(rand(10,30)*100000); // 1-3 sec. 
     228            header('Location: ' . $_SERVER['REQUEST_URI'] . '&_redirected=1'); 
     229        } 
     230        else { 
     231            raise_error(array( 
     232                'code' => 500, 'type' => 'php', 
     233                'file' => __FILE__, 'line' => __LINE__, 
     234                'message' => 'Unable to get/display message part. IMAP connection error'), 
     235                true, true); 
     236        } 
     237 
     238        // Don't kill session, just quit (#1486995) 
     239        exit; 
     240    } 
     241} 
Note: See TracChangeset for help on using the changeset viewer.