--- vcard.module	2008-01-26 21:48:31.000000000 +0100
+++ vcard.module	2008-06-06 20:29:02.000000000 +0200
@@ -94,7 +94,7 @@
   if (!_vcard_init()) {
     drupal_set_message(t('The PEAR package Contact_Vcard_Build (required by vcard.module) has not been installed properly, please read INSTALL.txt.'), 'error');
   }
-
+  
   $form['field_mappings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Field Mappings'),
@@ -110,7 +110,116 @@
       '#options' => $options,
     );
   }
-
+    
+  $form['vcard_encoding'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Encoding'),
+    '#description' => t('You can specify different encodings for vCards (solves problems with software lacking UTF-8 support)')
+  );
+  
+  $form['vcard_encoding']['vcard_encoding'] = array(
+    '#type' => 'select',
+    '#title' => 'vCard Encoding',
+    '#default_value' => variable_get('vcard_encoding', 'UTF-8'),
+    '#options' => array(
+    
+    /* Unicode */
+    'UTF-8' => 'UTF-8 (Unicode)',
+    'ucs2-interal' => 'UCS2 internal (Unicode)',
+    'iso-10646-ucs-2' => 'ISO 10646 UCS2 (Unicode)',
+    'unicode-1-1-utf7' => 'UTF7 (Unicode)',
+    
+    /* ISO */
+    'ISO-8859-1' => 'ISO-8859-1 (Western Europe)',
+    'ISO-8859-2' => 'ISO-8859-2 (Western and Central Europe)',
+    'ISO-8859-3' => 'ISO-8859-3 (Western Europe and South European (Turkish, Maltese plus Esperanto)',
+    'ISO-8859-4' => 'ISO-8859-4 (Western Europe and Baltic Countries (Lithuania, Estonia and Lapp)',
+    'ISO-8859-5' => 'ISO-8859-5 (Cyrillic alphabet)',
+    'ISO-8859-6' => 'ISO-8859-6 (Arabic)',
+    'ISO-8859-7' => 'ISO-8859-7 (Greek)', 
+    'ISO-8859-8' => 'ISO-8859-8 (Hebrew)',
+    'ISO-8859-9' => 'ISO-8859-9 (Western Europe with amended Turkish character set)',
+    'ISO-8859-10' => 'ISO-8859-10 (Western Europe with rationalised character set for Nordic languages, including complete Icelandic set)',
+    'ISO-8859-11' => 'ISO-8859-11 (Thai)',
+    'ISO-8859-12' => 'ISO-8859-13 (Baltic languages plus Polish)',
+    'ISO-8859-13' => 'ISO-8859-14 (Celtic languages (Irish Gaelic, Scottish, Welsh))',
+    'ISO-8859-14' => 'ISO-8859-15 (Added the Euro sign and other rationalisations to ISO-8859-1)',
+    'ISO-8859-15' => 'ISO-8859-16 (Central European languages (Polish, Czech, Slovenian, Slovak, Hungarian, Albanian, Romanian, German, Italian)',
+    
+    /* ISO-2022 */
+    'ISO-2022-JP' => 'ISO-2022 (Japanese)',
+    'ISO-2022-JP-2' => 'ISO-2022-JP-2 (Multilingual Extension of ISO-2022-JP)',
+    'ISO-2022-KR' => 'ISO-2022 (Korean)',
+    'ISO-2022-cn' => 'ISO-2022 (Chinese)',
+    
+    /* EUC */
+    'EUC-JP' => 'EUC-JP (Extended Unix Code Japanese)',
+    'GB2312' => 'GB2312 (Simplified Chinese Characters)',
+    'EUR-KR' => 'EUC-KR (Extended Unix Code Korean)',
+    'X-EUC-TW' => 'EUC-TW (Extended Unix Code Taiwan)',
+    
+    /* KOI */
+    'koi8-r' => 'KOI8-R (Kyrillic Russia)',
+    'koi8-u' => 'KOI8-U (Kyrillic Ukraine)',
+    'koi8-ru' => 'KOI8-RU (Kryillic Russia + Belarusian and Ukrainian Characters)',
+    
+    /* Windows */
+    'Windows-1250' => 'Windows-1250 (for Central European languages that use Latin script)',
+    'Windows-1251' => 'Windows-1251 (for Cryillic alphabets)',
+    'Windows-1252' => 'Windows-1252 (for Western languages)',
+    'Windows-1253' => 'Windows-1253 (for Greek)',
+    'Windows-1254' => 'Windows-1254 (for Turkish)',
+    'Windows-1255' => 'Windows-1255 (for Hebrew)',
+    'Windows-1256' => 'Windows-1256 (for Arabic)',
+    'Windows-1257' => 'Windows-1257 (for Baltic languages)',
+    'Windows-1258' => 'Windows-1258 (for Vietnamese)',
+    
+    /* IBM-DOS */
+    'CP437' => 'Codepage 437 (DOS-US)',
+    'CP737' => 'Codepage 737 (DOS-Greek)',
+    'CP775' => 'Codepage 775 (DOS Estonian, Lithnian and Latvian)',
+    'CP850' => 'Codepage 850 (DOS Latin 1)',
+    'CP852' => 'Codepage 852 (DOS Central European)',
+    'CP855' => 'Codepage 855 (DOS Cyrillic)',
+    'CP857' => 'Codepage 857 (DOS Turkish)',
+    'CP860' => 'Codepage 860 (DOS Portuguese)',
+    'CP861' => 'Codepage 861 (DOS Icelandic)',
+    'CP862' => 'Codepage 862 (DOS Hebrew)',
+    'CP863' => 'Codepage 863 (DOS French)',
+    'CP864' => 'Codepage 864 (DOS Arabic)',
+    'CP865' => 'Codepage 865 (DOS Nordic languages except Icelandic)',
+    'CP866' => 'Codepage 866 (DOS Cyrillic based on GOST 19768-87)',
+    'CP869' => 'Codepage 869 (DOS Greek including all characters from ISO-8869-7)',
+    'CP874' => 'Codepage 875 (DOS Thai)',
+    
+    /* Apple */
+    'X-MAC-CE' => 'MAC-CE (Macintosh CE for Central Eastern Europe)',
+    'X-MAC-CROATIAN' => 'MAC-CE (Macintosh CE for Central Eastern Europe)',
+    'X-MAC-CYRILLIC' => 'MAC-CYRILLIC (Macintosh CE for Cyrillic)',
+    'X-MAC-DINGBATS' => 'MAC-DINGBATS (Macintosh Dingbats)',
+    'X-MAC-GREEK' => 'MAC-GREEK (Macintosh Greek)',
+    'X-MAC-ICELAND' => 'MAC-ICELAND (Macintosh Iceland)',
+    'X-MAC-ROMAN' => 'MAC-ROMAN (Macintosh Roman)',
+    'X-MAC-ROMANIA' => 'MAC-ROMANIA (Macintosh Romania)',
+    'X-MAC-THAI' => 'MAC-THAI (Macintosh Thailand)',
+    'X-MAC-TURKISH' => 'MAC-TURKISH (Macintosh Turkish)',
+    'X-MAC-UKRAINE' => 'MAC-UKRAINE (Macintosh Ukraine)',
+    
+    /* CJK */
+    'BIG5' => 'BIG5 (Traditional Chinese Characters)',
+    'CNS11643' => 'CNS11643 (Chinese Standard Interchange Code)',
+    'GB_23112-80' => 'GB_23112-80 (ASCII Printable Characters Chinese)',
+    'GB12345' => 'GB12345',
+    'JOHAB' => 'JOHAB (Korean Encoding)',
+    'KSX1001' => 'KSX1001',
+    'SHIFT_JIS' => 'Shift JIS (Japanese)',
+    'JIS_X0201' => 'JIS_X0201',
+    'JIS_X0208-1983' => 'JIS_X0208-1983',
+    'JIS_X0212-1990' => 'JIS_X0212-1990'
+    
+   )
+  );
+ 
   return system_settings_form($form);
 }
 
@@ -192,10 +301,21 @@
   if ($account->location['latitude'] && $account->location['longitude']) {
     $vcard->setGeo($account->location['latitude'], $account->location['longitude']);
   }
-
-  header('Content-type: text/x-vcard');
-  header('Content-Disposition: attachment; filename="'. $account->name .'.vcf"');
-  print $vcard->fetch();
+  
+  header('Content-type: text/x-vcard; charset="'.variable_get("vcard_encoding", "UTF-8").'";');
+  header('Content-Disposition: attachment; filename="'. $account->name.'.vcf"');
+  
+  $vcard_content = $vcard->fetch();
+
+  // If user has selected another encoding than utf8, convert the charset of the vcard content via iconv
+  if(variable_get('vcard_encoding', 'UTF-8') != 'UTF-8')
+  {
+     // If iconv fails converting the charset, use utf8_decode, which outputs ISO-8859-1
+     if(!($vcard_content = iconv('UTF-8', variable_get('vcard_encoding', 'ISO-8859-1'), $vcard_content)))
+       $vcard_content = utf8_decode($vcard_content);
+  }
+    
+  print $vcard_content;
   exit;
 }
 
