[Svn] r2471 - in trunk/roundcubemail: . program/include program/lib

trac at roundcube.net trac at roundcube.net
Wed May 13 09:09:49 CEST 2009


Author: alec
Date: 2009-05-13 02:09:49 -0500 (Wed, 13 May 2009)
New Revision: 2471

Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/program/include/rcube_imap.php
   trunk/roundcubemail/program/lib/imap.inc
Log:
- Support UUencode content encoding (#1485839)


Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2009-05-12 20:04:11 UTC (rev 2470)
+++ trunk/roundcubemail/CHANGELOG	2009-05-13 07:09:49 UTC (rev 2471)
@@ -1,6 +1,7 @@
 CHANGELOG RoundCube Webmail
 ===========================
 
+- Support UUencode content encoding (#1485839)
 - Minimize chance of race condition in session handling (#1485659, #1484678)
 - Fix session handling on non-session SQL query error (#1485734)
 - Fix html editor mode setting when reopening draft message (#1485834)

Modified: trunk/roundcubemail/program/include/rcube_imap.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_imap.php	2009-05-12 20:04:11 UTC (rev 2470)
+++ trunk/roundcubemail/program/include/rcube_imap.php	2009-05-13 07:09:49 UTC (rev 2471)
@@ -1433,44 +1433,19 @@
 
     if (!$part) $part = 'TEXT';
 
-    if ($print)
-      {
-      $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);
+    $body = iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part,
+        $o_part->encoding, $print, $fp);
       
-      // we have to decode the part manually before printing
-      if ($mode == 1)
-        {
-        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);
+    if ($fp || $print)
+      return true;
 
-      // decode part body
-      if ($o_part->encoding)
-        $body = $this->mime_decode($body, $o_part->encoding);
+    // convert charset (if text or message part)
+    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;
 
-      // convert charset (if text or message part)
-      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;
-        }
+      $body = rcube_charset_convert($body, $o_part->charset);
       }
     
     return $body;
@@ -1487,8 +1462,7 @@
   function &get_body($uid, $part=1)
     {
     $headers = $this->get_headers($uid);
-    return rcube_charset_convert(
-      $this->mime_decode($this->get_message_part($uid, $part), 'quoted-printable'),
+    return rcube_charset_convert($this->get_message_part($uid, $part, NULL),
       $headers->charset ? $headers->charset : $this->default_charset);
     }
 
@@ -1535,7 +1509,7 @@
     if (!($msg_id = $this->_uid2id($uid)))
       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 @@
     {
     switch (strtolower($encoding))
       {
-      case '7bit':
-        return $input;
-        break;
-      
       case 'quoted-printable':
         return quoted_printable_decode($input);
         break;
@@ -2676,7 +2646,15 @@
       case 'base64':
         return base64_decode($input);
         break;
-      
+
+      case 'x-uuencode':
+      case 'x-uue':
+      case 'uue':
+      case 'uuencode':
+        return convert_uudecode($input);
+        break;
+						      
+      case '7bit':
       default:
         return $input;
       }

Modified: trunk/roundcubemail/program/lib/imap.inc
===================================================================
--- trunk/roundcubemail/program/lib/imap.inc	2009-05-12 20:04:11 UTC (rev 2470)
+++ trunk/roundcubemail/program/lib/imap.inc	2009-05-13 07:09:49 UTC (rev 2471)
@@ -2308,30 +2308,42 @@
 
 	$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) {
-	/* modes:
-        1: return string (or write to $file pointer)
-        2: print
-        3: base64 and print (or write to $file pointer)
-	*/
+function iil_C_HandlePartBody(&$conn, $mailbox, $id, $part='', $encoding=NULL, $print=NULL, $file=NULL) {
 	
 	$fp     = $conn->fp;
 	$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)) {
     		$reply_key = '* ' . $id;
 
     		// format request
-		$key     = 'ftch' . ($c++) . ' ';
-		$request = $key . "FETCH $id (BODY.PEEK[$part])";
+		$key     = 'ftch0';
+		$request = $key . " FETCH $id (BODY.PEEK[$part])";
     		// send request
 		if (!iil_PutLine($fp, $request)) {
 		    return false;
     		}
-        
+
     		// receive reply line
     		do {
         		$line = chop(iil_ReadLine($fp, 1000));
@@ -2352,14 +2364,13 @@
 				$result = substr($line, $from, $len);
 			}
 	    
-	                if ($mode == 2) {
-        		        echo $result;
-	                } else if ($mode == 3) {
-				if ($file)
-					fwrite($file, base64_decode($result));
-        		    	else
-					echo base64_decode($result);
-			}			     
+        		if ($mode == 1)
+				$result = base64_decode($result);
+			else if ($mode == 2)
+				$result = quoted_printable_decode($result);
+			else if ($mode == 3)
+				$result = convert_uudecode($result);
+
     		} else if ($line[$len-1] == '}') {
 	                //multi-line request, find sizes of content and receive that many bytes
         		$from     = strpos($line, '{') + 1;
@@ -2381,13 +2392,6 @@
 				$line = rtrim($line, "\t\r\n\0\x0B");
 
 		                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
 					$line = $prev.$line;
 					$length = strlen($line);
@@ -2401,8 +2405,32 @@
 
 					if ($file)
 						fwrite($file, base64_decode($line));
-            				else
+            				else if ($print)
 						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,45 +2440,30 @@
         			$line = iil_ReadLine($fp, 1024);
 			} while (!iil_StartsWith($line, $key, true));
         
-		if ($mode == 3 && $file) {
-			return true;
-		}
-	
     		if ($result) {
 	    		$result = rtrim($result, "\t\r\n\0\x0B");
 			if ($file) {
 				fwrite($file, $result);
-				return true;
-			}	
-			return $result; // substr($result, 0, strlen($result)-1);
+			} else if ($print) {
+				echo $result;
+			} 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;
 }
 
 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) {
-	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) {
 	$fp = $conn->fp;
 	if (iil_PutLine($fp, 'c CREATE "' . iil_Escape($folder) . '"')) {
@@ -2596,13 +2609,6 @@
 	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) {
 /*
  * GETQUOTAROOT "INBOX"

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list