Source for file vcard.php

Documentation is available at vcard.php

  1. <?php
  2.  
  3. /**
  4.  * vcard.php
  5.  *
  6.  * This file shows an attched vcard
  7.  *
  8.  * @copyright 1999-2012 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: vcard.php 14346 2012-12-09 12:06:30Z kink $
  11.  * @package squirrelmail
  12.  */
  13.  
  14. /** This is the vcard page */
  15. define('PAGE_NAME''vcard');
  16.  
  17. /**
  18.  * Include the SquirrelMail initialization file.
  19.  */
  20. require('../include/init.php');
  21.  
  22. /* SquirrelMail required files. */
  23.  
  24. /** imap functions depend on date functions */
  25. include_once(SM_PATH 'functions/date.php');
  26. /** form functions */
  27. include_once(SM_PATH 'functions/forms.php');
  28. /** mime decoding */
  29. include_once(SM_PATH 'functions/mime.php');
  30. /** url parser */
  31. include_once(SM_PATH 'functions/url_parser.php');
  32. /** imap functions used to retrieve vcard */
  33. include_once(SM_PATH 'functions/imap_general.php');
  34. include_once(SM_PATH 'functions/imap_messages.php');
  35.  
  36. /* globals */
  37.  
  38. sqgetGlobalVar('passed_id'$passed_idSQ_GETNULLSQ_TYPE_BIGINT);
  39. sqgetGlobalVar('mailbox'$mailboxSQ_GET);
  40. sqgetGlobalVar('ent_id'$ent_idSQ_GET);
  41. sqgetGlobalVar('startMessage'$startMessageSQ_GET);
  42. /* end globals */
  43.  
  44. $imapConnection sqimap_login($usernamefalse$imapServerAddress$imapPort0);
  45. sqimap_mailbox_select($imapConnection$mailbox);
  46.  
  47.  
  48. $msg_url 'read_body.php?mailbox='.urlencode($mailbox).
  49.     '&amp;startMessage='.urlencode($startMessage).
  50.     '&amp;passed_id='.urlencode($passed_id);
  51. $msg_url set_url_var($msg_url'ent_id'0);
  52.  
  53. $message sqimap_get_message($imapConnection$passed_id$mailbox);
  54.  
  55. $entity_vcard getEntity($message,$ent_id);
  56.  
  57. $vcard mime_fetch_body($imapConnection$passed_id$ent_id);
  58. $vcard decodeBody($vcard$entity_vcard->header->encoding);
  59. $vcard explode ("\n",$vcard);
  60. foreach ($vcard as $l{
  61.     $k substr($l0strpos($l':'));
  62.     $v substr($lstrpos($l':'1);
  63.     $attributes explode(';'$k);
  64.     $k strtolower(array_shift($attributes));
  65.     foreach ($attributes as $attr)     {
  66.         if ($attr == 'quoted-printable')
  67.         $v quoted_printable_decode($v);
  68.         else
  69.             $k .= ';' strtolower($attr);
  70.     }
  71.  
  72.     $v str_replace(';'"\n"$v);
  73.     $vcard_nice[$k$v;
  74. }
  75.  
  76. if ($vcard_nice['version'== '2.1'{
  77.     // get firstname and lastname for sm addressbook
  78.     $vcard_nice['firstname'substr($vcard_nice['n'],
  79.     strpos($vcard_nice['n']"\n"1strlen($vcard_nice['n']));
  80.     $vcard_nice['lastname'substr($vcard_nice['n']0,
  81.         strpos($vcard_nice['n']"\n"));
  82.     // workaround for Outlook, should be fixed in a better way,
  83.     // maybe in new 'vCard' class.
  84.     if (isset($vcard_nice['email;pref;internet'])) {
  85.        $vcard_nice['email;internet'$vcard_nice['email;pref;internet'];
  86.     }
  87. else {
  88.     $oTemplate->assign('note'sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly.")sm_encode_html_special_chars($vcard_nice['version'])));
  89.     $oTemplate->display('note.tpl');
  90.  
  91.     $vcard_nice['firstname''';
  92.     $vcard_nice['lastname''';
  93. }
  94.  
  95. foreach ($vcard_nice as $k => $v{
  96.     $v sm_encode_html_special_chars($v);
  97.     $v trim($v);
  98.     $vcard_safe[$ktrim(nl2br($v));
  99. }
  100.  
  101. $ShowValues array(
  102.     'fn' =>             _("Name"),
  103.     'title' =>          _("Title"),
  104.     'email;internet' => _("E-mail"),
  105.     'url' =>            _("Web Page"),
  106.     'org' =>            _("Organization / Department"),
  107.     'adr' =>            _("Address"),
  108.     'tel;work' =>       _("Work Phone"),
  109.     'tel;home' =>       _("Home Phone"),
  110.     'tel;cell' =>       _("Cellular Phone"),
  111.     'tel;fax' =>        _("Fax"),
  112.     'note' =>           _("Note"));
  113.  
  114. if (isset($vcard_safe['email;internet'])) {
  115.     $vcard_safe['email;internet'makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
  116.         $vcard_safe['email;internet']);
  117. }
  118.  
  119. if (isset($vcard_safe['url'])) {
  120.     $vcard_safe['url''<a href="' $vcard_safe['url''" target="_blank">' .
  121.         $vcard_safe['url''</a>';
  122. }
  123.  
  124. $vcard array();
  125. foreach ($ShowValues as $k => $v{
  126.     if (isset($vcard_safe[$k]&& $vcard_safe[$k]{
  127.         $vcard[$v$vcard_safe[$k];
  128.     }
  129. }
  130.  
  131. $dl '../src/download.php?absolute_dl=true&amp;passed_id=' .
  132.      urlencode($passed_id'&amp;mailbox=' urlencode($mailbox.
  133.      '&amp;ent_id=' urlencode($ent_id);
  134.  
  135. if (isset($vcard_nice['email;internet'])) {
  136.     $email $vcard_nice['email;internet'];
  137. else {
  138.     $message sqimap_get_message($imapConnection$passed_id$mailbox);
  139.     $header $message->rfc822_header;
  140.     $from_name $header->getAddr_s('from');
  141.  
  142.     $email getEmail(decodeHeader($from_name));
  143. }
  144.  
  145. $opts array();
  146. if (isset($vcard_nice['url'])) {
  147.     $opts[$vcard_nice['url']] _("Web Page");
  148. }
  149. if (isset($vcard_nice['adr'])) {
  150.     $opts[$vcard_nice['adr']] _("Address");
  151. }
  152. if (isset($vcard_nice['title'])) {
  153.     $opts[$vcard_nice['title']] _("Title");
  154. }
  155. if (isset($vcard_nice['org'])) {
  156.     $opts[$vcard_nice['org']] _("Organization / Department");
  157. }
  158. if (isset($vcard_nice['title'])) {
  159.     $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] _("Title &amp; Org. / Dept.");
  160. }
  161. if (isset($vcard_nice['tel;work'])) {
  162.     $opts[$vcard_nice['tel;work']] _("Work Phone");
  163. }
  164. if (isset($vcard_nice['tel;home'])) {
  165.     $opts[$vcard_nice['tel;home']] _("Home Phone");
  166. }
  167. if (isset($vcard_nice['tel;cell'])) {
  168.     $opts[$vcard_nice['tel;cell']] _("Cellular Phone");
  169. }
  170. if (isset($vcard_nice['tel;fax'])) {
  171.     $opts[$vcard_nice['tel;fax']] _("Fax");
  172. }
  173. if (isset($vcard_nice['note'])) {
  174.     $opts[$vcard_nice['note']] _("Note");
  175. }
  176.  
  177. $oTemplate->assign('view_message_link'$msg_url);
  178. $oTemplate->assign('download_link'$dl);
  179. $oTemplate->assign('vcard'$vcard);
  180.  
  181. $oTemplate->assign('nickname'$vcard_nice['firstname'].'-'.$vcard_safe['lastname']);
  182. $oTemplate->assign('firstname'$vcard_safe['firstname']);
  183. $oTemplate->assign('lastname'$vcard_safe['lastname']);
  184. $oTemplate->assign('email'$email);
  185. $oTemplate->assign('info'$opts);
  186.  
  187. $oTemplate->display('vcard.tpl');
  188.  
  189. $oTemplate->display('footer.tpl');

Documentation generated on Sat, 25 May 2013 04:20:46 +0200 by phpDocumentor 1.4.3