Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When reading literal_data from mail body from IMAP, use byte count instead of string-length count. #1217

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions modules/imap/hm-imap-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ private function command_number() {
private function read_literal($size, $max, $current, $line_length) {
$left_over = false;
$literal_data = $this->fgets($line_length);
$lit_size = mb_strlen($literal_data);
$lit_size = strlen($literal_data);
$current += $lit_size;
// We need to use non-multibyte string lengths, since "$size" is in bytes
while ($lit_size < $size) {
$chunk = $this->fgets($line_length);
$chunk_size = mb_strlen($chunk);
$chunk_size = strlen($chunk);
$lit_size += $chunk_size;
$current += $chunk_size;
$literal_data .= $chunk;
Expand All @@ -85,12 +86,12 @@ private function read_literal($size, $max, $current, $line_length) {
if ($this->max_read) {
while ($lit_size < $size) {
$temp = $this->fgets($line_length);
$lit_size += mb_strlen($temp);
$lit_size += strlen($temp);
}
}
elseif ($size < mb_strlen($literal_data)) {
$left_over = mb_substr($literal_data, $size);
$literal_data = mb_substr($literal_data, 0, $size);
elseif ($size < strlen($literal_data)) {
$left_over = substr($literal_data, $size);
$literal_data = substr($literal_data, 0, $size);
}
return array($literal_data, $left_over);
}
Expand Down
18 changes: 16 additions & 2 deletions tests/selenium/folder_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from base import WebTest, USER, PASS
from selenium.webdriver.common.by import By
from runner import test_runner
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import StaleElementReferenceException

class FolderListTests(WebTest):

Expand All @@ -12,10 +16,20 @@ def __init__(self):
self.wait_with_folder_list()

def reload_folder_list(self):
assert self.by_class('main_menu').text.startswith('Main')
main_menu = self.by_class('main_menu')
assert main_menu.text.startswith('Main')
self.by_class('update_message_list').click()
self.safari_workaround(3)
assert self.by_class('main_menu').text.startswith('Main')
# update_message_list triggers site reload, so we explicitly wait for element to become stale
WebDriverWait(self.driver, 20).until(EC.staleness_of(main_menu))
ignored_exceptions=(NoSuchElementException,StaleElementReferenceException,)
# And once it is stale, we can now wait for it to become available again.
main_menu = WebDriverWait(self.driver, 10,ignored_exceptions=ignored_exceptions).until(
EC.presence_of_element_located((By.CLASS_NAME, 'main_menu'))
)
main_menu = self.by_class('main_menu')
#and finally perform our test on the actual, refreshed element.
assert main_menu.text.startswith('Main')

def expand_section(self):
self.by_css('[data-source=".settings"]').click()
Expand Down