- Support UUencode content encoding (#1485839)

release-0.6
alecpl 15 years ago
parent 9c6dfdc1e8
commit 1c5be6f792

@ -1,6 +1,7 @@
CHANGELOG RoundCube Webmail CHANGELOG RoundCube Webmail
=========================== ===========================
- Support UUencode content encoding (#1485839)
- Minimize chance of race condition in session handling (#1485659, #1484678) - Minimize chance of race condition in session handling (#1485659, #1484678)
- Fix session handling on non-session SQL query error (#1485734) - Fix session handling on non-session SQL query error (#1485734)
- Fix html editor mode setting when reopening draft message (#1485834) - Fix html editor mode setting when reopening draft message (#1485834)

@ -1433,44 +1433,19 @@ class rcube_imap
if (!$part) $part = 'TEXT'; if (!$part) $part = 'TEXT';
if ($print) $body = iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part,
{ $o_part->encoding, $print, $fp);
$mode = $o_part->encoding == 'base64' ? 3 : ($o_part->encoding == 'quoted-printable' ? 1 : 2);
$body = iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part, $mode);
// we have to decode the part manually before printing if ($fp || $print)
if ($mode == 1) return true;
{
echo $this->mime_decode($body, $o_part->encoding);
$body = true;
}
}
else
{
if ($fp && $o_part->encoding == 'base64')
return iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part, 3, $fp);
else
$body = iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part, 1);
// decode part body // convert charset (if text or message part)
if ($o_part->encoding) if ($o_part->ctype_primary=='text' || $o_part->ctype_primary=='message') {
$body = $this->mime_decode($body, $o_part->encoding); // assume default if no charset specified
if (empty($o_part->charset))
$o_part->charset = $this->default_charset;
// convert charset (if text or message part) $body = rcube_charset_convert($body, $o_part->charset);
if ($o_part->ctype_primary=='text' || $o_part->ctype_primary=='message')
{
// assume default if no charset specified
if (empty($o_part->charset))
$o_part->charset = $this->default_charset;
$body = rcube_charset_convert($body, $o_part->charset);
}
if ($fp)
{
fwrite($fp, $body);
return true;
}
} }
return $body; return $body;
@ -1487,8 +1462,7 @@ class rcube_imap
function &get_body($uid, $part=1) function &get_body($uid, $part=1)
{ {
$headers = $this->get_headers($uid); $headers = $this->get_headers($uid);
return rcube_charset_convert( return rcube_charset_convert($this->get_message_part($uid, $part, NULL),
$this->mime_decode($this->get_message_part($uid, $part), 'quoted-printable'),
$headers->charset ? $headers->charset : $this->default_charset); $headers->charset ? $headers->charset : $this->default_charset);
} }
@ -1535,7 +1509,7 @@ class rcube_imap
if (!($msg_id = $this->_uid2id($uid))) if (!($msg_id = $this->_uid2id($uid)))
return FALSE; return FALSE;
iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, NULL, 2); iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, NULL, NULL, true);
} }
@ -2665,10 +2639,6 @@ class rcube_imap
{ {
switch (strtolower($encoding)) switch (strtolower($encoding))
{ {
case '7bit':
return $input;
break;
case 'quoted-printable': case 'quoted-printable':
return quoted_printable_decode($input); return quoted_printable_decode($input);
break; break;
@ -2677,6 +2647,14 @@ class rcube_imap
return base64_decode($input); return base64_decode($input);
break; break;
case 'x-uuencode':
case 'x-uue':
case 'uue':
case 'uuencode':
return convert_uudecode($input);
break;
case '7bit':
default: default:
return $input; return $input;
} }

@ -2308,25 +2308,37 @@ function iil_C_FetchPartHeader(&$conn, $mailbox, $id, $part) {
$part = empty($part) ? 'HEADER' : $part.'.MIME'; $part = empty($part) ? 'HEADER' : $part.'.MIME';
return iil_C_HandlePartBody($conn, $mailbox, $id, $part, 1); return iil_C_HandlePartBody($conn, $mailbox, $id, $part);
} }
function iil_C_HandlePartBody(&$conn, $mailbox, $id, $part='', $mode=1, $file=NULL) { function iil_C_HandlePartBody(&$conn, $mailbox, $id, $part='', $encoding=NULL, $print=NULL, $file=NULL) {
/* modes:
1: return string (or write to $file pointer)
2: print
3: base64 and print (or write to $file pointer)
*/
$fp = $conn->fp; $fp = $conn->fp;
$result = false; $result = false;
switch ($encoding) {
case 'base64':
$mode = 1;
break;
case 'quoted-printable':
$mode = 2;
break;
case 'x-uuencode':
case 'x-uue':
case 'uue':
case 'uuencode':
$mode = 3;
break;
default:
$mode = 0;
}
if (iil_C_Select($conn, $mailbox)) { if (iil_C_Select($conn, $mailbox)) {
$reply_key = '* ' . $id; $reply_key = '* ' . $id;
// format request // format request
$key = 'ftch' . ($c++) . ' '; $key = 'ftch0';
$request = $key . "FETCH $id (BODY.PEEK[$part])"; $request = $key . " FETCH $id (BODY.PEEK[$part])";
// send request // send request
if (!iil_PutLine($fp, $request)) { if (!iil_PutLine($fp, $request)) {
return false; return false;
@ -2352,14 +2364,13 @@ function iil_C_HandlePartBody(&$conn, $mailbox, $id, $part='', $mode=1, $file=NU
$result = substr($line, $from, $len); $result = substr($line, $from, $len);
} }
if ($mode == 2) { if ($mode == 1)
echo $result; $result = base64_decode($result);
} else if ($mode == 3) { else if ($mode == 2)
if ($file) $result = quoted_printable_decode($result);
fwrite($file, base64_decode($result)); else if ($mode == 3)
else $result = convert_uudecode($result);
echo base64_decode($result);
}
} else if ($line[$len-1] == '}') { } else if ($line[$len-1] == '}') {
//multi-line request, find sizes of content and receive that many bytes //multi-line request, find sizes of content and receive that many bytes
$from = strpos($line, '{') + 1; $from = strpos($line, '{') + 1;
@ -2381,13 +2392,6 @@ function iil_C_HandlePartBody(&$conn, $mailbox, $id, $part='', $mode=1, $file=NU
$line = rtrim($line, "\t\r\n\0\x0B"); $line = rtrim($line, "\t\r\n\0\x0B");
if ($mode == 1) { if ($mode == 1) {
if ($file)
fwrite($file, $line . "\n");
else
$result .= $line . "\n";
} else if ($mode == 2) {
echo $line . "\n";
} else if ($mode == 3) {
// create chunks with proper length for base64 decoding // create chunks with proper length for base64 decoding
$line = $prev.$line; $line = $prev.$line;
$length = strlen($line); $length = strlen($line);
@ -2401,8 +2405,32 @@ function iil_C_HandlePartBody(&$conn, $mailbox, $id, $part='', $mode=1, $file=NU
if ($file) if ($file)
fwrite($file, base64_decode($line)); fwrite($file, base64_decode($line));
else else if ($print)
echo base64_decode($line); echo base64_decode($line);
else
$result .= base64_decode($line);
} else if ($mode == 2) {
$line .= $line[sizeof($line)-1] != '=' ? "\n" : '';
if ($file)
fwrite($file, quoted_printable_decode($line));
else if ($print)
echo quoted_printable_decode($line);
else
$result .= quoted_printable_decode($line);
} else if ($mode == 3) {
if ($file)
fwrite($file, convert_uudecode($line));
else if ($print)
echo convert_uudecode($line);
else
$result .= convert_uudecode($line);
} else {
if ($file)
fwrite($file, $line . "\n");
else if ($print)
echo $line . "\n";
else
$result .= $line . "\n";
} }
} }
} }
@ -2412,43 +2440,28 @@ function iil_C_HandlePartBody(&$conn, $mailbox, $id, $part='', $mode=1, $file=NU
$line = iil_ReadLine($fp, 1024); $line = iil_ReadLine($fp, 1024);
} while (!iil_StartsWith($line, $key, true)); } while (!iil_StartsWith($line, $key, true));
if ($mode == 3 && $file) {
return true;
}
if ($result) { if ($result) {
$result = rtrim($result, "\t\r\n\0\x0B"); $result = rtrim($result, "\t\r\n\0\x0B");
if ($file) { if ($file) {
fwrite($file, $result); fwrite($file, $result);
return true; } else if ($print) {
} echo $result;
return $result; // substr($result, 0, strlen($result)-1); } else
return $result; // substr($result, 0, strlen($result)-1);
} }
return false; return true;
}
if ($mode==1) {
if ($file && $result) {
fwrite($file, $result);
return true;
}
return $result;
} }
return false; return false;
} }
function iil_C_FetchPartBody(&$conn, $mailbox, $id, $part, $file=NULL) { function iil_C_FetchPartBody(&$conn, $mailbox, $id, $part, $file=NULL) {
return iil_C_HandlePartBody($conn, $mailbox, $id, $part, 1, $file); return iil_C_HandlePartBody($conn, $mailbox, $id, $part, NULL, NULL, $file);
} }
function iil_C_PrintPartBody(&$conn, $mailbox, $id, $part) { function iil_C_PrintPartBody(&$conn, $mailbox, $id, $part) {
iil_C_HandlePartBody($conn, $mailbox, $id, $part, 2); iil_C_HandlePartBody($conn, $mailbox, $id, $part, NULL, true, NULL);
}
function iil_C_PrintBase64Body(&$conn, $mailbox, $id, $part) {
iil_C_HandlePartBody($conn, $mailbox, $id, $part, 3);
} }
function iil_C_CreateFolder(&$conn, $folder) { function iil_C_CreateFolder(&$conn, $folder) {
@ -2596,13 +2609,6 @@ function iil_C_FetchStructureString(&$conn, $folder, $id) {
return $result; return $result;
} }
function iil_C_PrintSource(&$conn, $folder, $id, $part) {
$header = iil_C_FetchPartHeader($conn, $folder, $id, $part);
//echo str_replace("\r", '', $header);
echo $header;
echo iil_C_PrintPartBody($conn, $folder, $id, $part);
}
function iil_C_GetQuota(&$conn) { function iil_C_GetQuota(&$conn) {
/* /*
* GETQUOTAROOT "INBOX" * GETQUOTAROOT "INBOX"

Loading…
Cancel
Save