]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/include/main.inc
Imported Upstream version 0.1~rc1
[roundcube.git] / program / include / main.inc
index 8a5017b9bf1ff61d7527c35322a96f916b47fb7a..f5c58a4225b6f198241540d8d3ed6ccf7be92b96 100644 (file)
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  +-----------------------------------------------------------------------+
 
- $Id: main.inc 567 2007-05-17 18:41:24Z thomasb $
+ $Id: main.inc 617 2007-06-13 06:57:22Z thomasb $
 
 */
 
-require_once('lib/des.inc');
 require_once('lib/utf7.inc');
-require_once('lib/utf8.class.php');
 require_once('include/rcmail_template.inc');
 
 
@@ -789,7 +787,12 @@ function show_message($message, $type='notice', $vars=NULL)
 // encrypt IMAP password using DES encryption
 function encrypt_passwd($pass)
   {
-  $cypher = des(get_des_key(), $pass, 1, 0, NULL);
+  $td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
+  $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
+  mcrypt_generic_init($td, get_des_key(), $iv);
+  $cypher = mcrypt_generic($td, $pass);
+  mcrypt_generic_deinit($td);
+  mcrypt_module_close($td);
   return base64_encode($cypher);
   }
 
@@ -797,7 +800,12 @@ function encrypt_passwd($pass)
 // decrypt IMAP password using DES encryption
 function decrypt_passwd($cypher)
   {
-  $pass = des(get_des_key(), base64_decode($cypher), 0, 0, NULL);
+  $td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
+  $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
+  mcrypt_generic_init($td, get_des_key(), $iv);
+  $pass = mdecrypt_generic($td, base64_decode($cypher));
+  mcrypt_generic_deinit($td);
+  mcrypt_module_close($td);
   return preg_replace('/\x00/', '', $pass);
   }
 
@@ -929,29 +937,17 @@ function rcube_charset_convert($str, $from, $to=NULL)
   if (function_exists('iconv') && $from!='UTF-7' && $to!='UTF-7')
     return iconv($from, $to, $str);
 
-  $conv = new utf8();
-
   // convert string to UTF-8
   if ($from=='UTF-7')
     $str = utf7_to_utf8($str);
   else if (($from=='ISO-8859-1') && function_exists('utf8_encode'))
     $str = utf8_encode($str);
-  else if ($from!='UTF-8')
-    {
-    $conv->loadCharset($from);
-    $str = $conv->strToUtf8($str);
-    }
 
   // encode string for output
   if ($to=='UTF-7')
     return utf8_to_utf7($str);
   else if ($to=='ISO-8859-1' && function_exists('utf8_decode'))
     return utf8_decode($str);
-  else if ($to!='UTF-8')
-    {
-    $conv->loadCharset($to);
-    return $conv->utf8ToStr($str);
-    }
 
   // return UTF-8 string
   return $str;