]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/InboundEmail/parseEncoding.php
Add .gitignore
[Github/sugarcrm.git] / modules / InboundEmail / parseEncoding.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45 // takes a file as an argument and parses the stuff as text;
46
47 function write_array_to_file( $the_name, $the_array, $the_file ) {
48         
49     $the_string =   "<?php\n" .
50 '\n
51 if(empty(\$GLOBALS["sugarEntry"])) die("Not A Valid Entry Point");
52 /*********************************************************************************
53  * SugarCRM is a customer relationship management program developed by
54  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
55  * 
56  * This program is free software; you can redistribute it and/or modify it under
57  * the terms of the GNU Affero General Public License version 3 as published by the
58  * Free Software Foundation with the addition of the following permission added
59  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
60  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
61  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
62  * 
63  * This program is distributed in the hope that it will be useful, but WITHOUT
64  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
65  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
66  * details.
67  * 
68  * You should have received a copy of the GNU Affero General Public License along with
69  * this program; if not, see http://www.gnu.org/licenses or write to the Free
70  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
71  * 02110-1301 USA.
72  * 
73  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
74  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
75  * 
76  * The interactive user interfaces in modified source and object code versions
77  * of this program must display Appropriate Legal Notices, as required under
78  * Section 5 of the GNU Affero General Public License version 3.
79  * 
80  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
81  * these Appropriate Legal Notices must retain the display of the "Powered by
82  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
83  * technical reasons, the Appropriate Legal Notices must display the words
84  * "Powered by SugarCRM".
85  ********************************************************************************/
86 ' .
87
88
89                     "\n \$$the_name = " .
90                     var_export_helper( $the_array ) .
91                     ";\n?>\n";
92
93     if( $fh = @sugar_fopen( $the_file, "w" ) ){
94         fputs( $fh, $the_string);
95         fclose( $fh );
96         return( true );
97     }
98     else{
99         return( false );
100     }
101 }
102
103 function var_export_helper($tempArray) {         
104                 if(!is_array($tempArray)){
105                         return var_export($tempArray, true);    
106                 }
107          $addNone = 0;   
108          
109          foreach($tempArray as $key=>$val)       
110          {       
111                  if($key == '' && $val == '')    
112                          $addNone = 1;   
113          }       
114          
115          $newArray = var_export($tempArray, true);       
116          
117          if($addNone)    
118          {       
119                  $newArray = str_replace("array (", "array ( '' => '',", $newArray);     
120          }       
121          
122          return $newArray;
123  }
124
125 function grabFiles($url) {
126         $dh = fsockopen($url, 80);
127         while($fileName = readdir($dh)) {
128                 if(is_dir($url.$fileName)) {
129                         grabFiles($url.$fileName);
130                 }
131                 
132                 $fh = sugar_fopen($url.$fileName, "r");
133                 
134                 $fileContent = fread($fh, filesize($url.$fileName));
135                 
136                 $writeFile = "./{$fileName}";
137                 $fhLocal = sugar_fopen($writeFile, "w");
138                 
139                 fwrite($writeFile, $fileContent);
140         }
141 }
142
143 ///////////////////////////////////////////////////////////////////////////////
144 ////    START CODE
145
146 while($file = readdir($dhUnicode)) {
147         if(is_dir($file)) {
148                 $dhUniDeep = opendir("http://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/{$file}");
149                 
150         }
151 }
152
153
154
155
156
157
158
159 $dh = opendir("./");
160 $search = array(" ", "  ", "   ", "    ");
161 $replace = array("\t","\t","\t","\t");
162
163
164 if(is_resource($dh)) {
165         while($inputFile = readdir($dh)) {
166                 if(strpos($inputFile, "php")) {
167                         continue;
168                 }
169                 
170                 $inputFileVarSafe = str_replace("-","_",$inputFile);
171                 $outputFile = $inputFileVarSafe.".php";
172                 
173                 $fh = sugar_fopen($inputFile, "r");
174                 if(is_resource($fh)) {
175                         $charset = array();
176                         while($line = fgets($fh)) {
177                                 $commentPos = strpos($line, "#");
178                                 if($commentPos == 0) {
179                                         continue; // skip comment strings
180                                 }
181                                 
182
183                                 $exLine = str_replace($search, $replace, $line);
184                                 $exLine = explode("\t", $line);
185
186
187                                 $count = count($exLine);
188                                 if($count < 2) {
189                                         echo "count was {$count} :: file is {$inputFile} :: Error parsing line: {$line}\r";
190                                         continue; // unexpected explode
191                                 }
192                                 
193                                 // we know 0 is charset encoding
194                                 // we know 1 is unicode in hex
195                                 $countExLine = count($exLine);
196                                 for($i=1; $i<$countExLine; $i++) {
197                                         $exLine[$i] = trim($exLine[$i]);
198                                         if($exLine[$i] != "") {
199                                                 $unicode = $exLine[$i];
200                                                 break 1;
201                                         }
202                                 }
203                                 $charset[$exLine[0]] = $unicode;
204                                 
205                         }
206                         
207                         if(count($charset) > 0) {
208                                 write_array_to_file($inputFileVarSafe, $charset, $outputFile);
209                         }
210                         
211                 } else {
212                         echo "Error occured reading line from file!\r";
213                 }
214                 
215         }       
216 } else {
217         die("no directory handle");
218 }
219
220
221
222
223 echo "DONE\r";
224 ?>