Update copyrights to 2010
[squirrelmail.git] / functions / imap_utf7_local.php
index 943f2620f4ff929b2c8a0047cd20f86d399e9a81..5b68b705cbf93f7e6dde94f8aa336274da7478ee 100644 (file)
@@ -1,40 +1,49 @@
 <?php
 
 /**
- * imap_utf7_local.php
- *
- * Copyright (c) 1999-2004 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
+ * functions/imap_utf7_local.php - utf7-imap functions
  *
  * This implements all functions that do imap UTF7 conversions.
+ * Before 1.3.2 functions were stored in imap_utf7_decode_local.php and
+ * imap_utf7_encode_local.php files.
  *
+ * @copyright 1999-2010 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  * @subpackage imap
+ * @since 1.3.2
  */
 
 /**
- * @param string $str
- * @param string $to_encoding
- * @param string $from_encoding
- * @param string $default_charset
- * @return string
+ * Function that uses php mbstring functions to convert from and to utf7-imap charset
+ *
+ * Since 1.5.1 list of supported charsets depends sq_mb_list_encoding function.
+ * Before that it was hardcoded to iso-8859-x, utf-8 and iso-2022-jp.
+ * @param string $str folder name
+ * @param string $to_encoding name of resulting charset
+ * @param string $from_encoding name of original charset
+ * @param string $default_charset default charset used by translation.
+ * @return string encoded folder name or ''
+ * @since 1.4.2
  */
-function sqimap_mb_convert_encoding($str, $to_encoding, $from_encoding, $default_charset)
-{
-    // Allows mbstring functions only with iso-8859-*, utf-8 and
-    // iso-2022-jp (Japanese)
-    // koi8-r and gb2312 can be added only in php 4.3+
-    if ( stristr($default_charset, 'iso-8859-') ||
-            stristr($default_charset, 'utf-8') ||
-            stristr($default_charset, 'iso-2022-jp') ) {
-        if (function_exists('mb_convert_encoding')) {
-            return mb_convert_encoding($str, $to_encoding, $from_encoding);
-        }
+function sqimap_mb_convert_encoding($str, $to_encoding, $from_encoding, $default_charset) {
+    $supported_encodings=sq_mb_list_encodings();
+    if ( in_array(strtolower($default_charset),$supported_encodings) &&
+         function_exists('mb_convert_encoding')) {
+        return mb_convert_encoding($str, $to_encoding, $from_encoding);
     }
     return '';
 }
 
+/**
+ * encode folder name to utf7-imap
+ *
+ * If mbstring functions do not support charset used by translation, falls back to iso-8859-1
+ * @param string $s folder name
+ * @return string utf7-imap encoded folder name
+ * @since 1.2.7
+ */
 function imap_utf7_encode_local($s) {
     global $languages, $squirrelmail_language;
 
@@ -88,6 +97,14 @@ function imap_utf7_encode_local($s) {
     return $utf7_s;
 }
 
+/**
+ * converts folder name from utf7-imap to charset used by translation
+ *
+ * If mbstring functions do not support charset used by translation, falls back to iso-8859-1
+ * @param string $s folder name in utf7-imap
+ * @return string folder name in charset used by translation
+ * @since 1.2.7
+ */
 function imap_utf7_decode_local($s) {
     global $languages, $squirrelmail_language;
 
@@ -135,7 +152,12 @@ function imap_utf7_decode_local($s) {
     }
     return $iso_8859_1_s;
 }
-
+/**
+ * Converts string to base64
+ * @param string $s string
+ * @return string base64 encoded string
+ * @since 1.2.7
+ */
 function encodeBASE64($s) {
     $B64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,';
     $p = 0;     // phase: 1 / 2 / 3 / 1 / 2 / 3...
@@ -168,6 +190,12 @@ function encodeBASE64($s) {
     return $e;
 }
 
+/**
+ * Converts string from base64
+ * @param string $s base64 encoded string
+ * @return string decoded string
+ * @since 1.2.7
+ */
 function decodeBASE64($s) {
     $B64Values = array(
             'A' =>  0, 'B' =>  1, 'C' =>  2, 'D' =>  3, 'E' =>  4, 'F' =>  5,
@@ -222,5 +250,3 @@ function decodeBASE64($s) {
     }
     return $d;
 }
-
-?>
\ No newline at end of file