Add controls for page referal verification and security token system to the configura...
[squirrelmail.git] / src / vcard.php
1 <?php
2
3 /**
4 * vcard.php
5 *
6 * This file shows an attched vcard
7 *
8 * @copyright &copy; 1999-2009 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
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_id, SQ_GET, NULL, SQ_TYPE_BIGINT);
39 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
40 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
41 sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
42 /* end globals */
43
44 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
45 sqimap_mailbox_select($imapConnection, $mailbox);
46
47 displayPageHeader($color);
48
49 $msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
50 '&amp;startMessage='.urlencode($startMessage).
51 '&amp;passed_id='.urlencode($passed_id);
52 $msg_url = set_url_var($msg_url, 'ent_id', 0);
53
54 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
55
56 $entity_vcard = getEntity($message,$ent_id);
57
58 $vcard = mime_fetch_body($imapConnection, $passed_id, $ent_id);
59 $vcard = decodeBody($vcard, $entity_vcard->header->encoding);
60 $vcard = explode ("\n",$vcard);
61 foreach ($vcard as $l) {
62 $k = substr($l, 0, strpos($l, ':'));
63 $v = substr($l, strpos($l, ':') + 1);
64 $attributes = explode(';', $k);
65 $k = strtolower(array_shift($attributes));
66 foreach ($attributes as $attr) {
67 if ($attr == 'quoted-printable')
68 $v = quoted_printable_decode($v);
69 else
70 $k .= ';' . strtolower($attr);
71 }
72
73 $v = str_replace(';', "\n", $v);
74 $vcard_nice[$k] = $v;
75 }
76
77 if ($vcard_nice['version'] == '2.1') {
78 // get firstname and lastname for sm addressbook
79 $vcard_nice['firstname'] = substr($vcard_nice['n'],
80 strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
81 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
82 strpos($vcard_nice['n'], "\n"));
83 // workaround for Outlook, should be fixed in a better way,
84 // maybe in new 'vCard' class.
85 if (isset($vcard_nice['email;pref;internet'])) {
86 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
87 }
88 } else {
89 $oTemplate->assign('note', sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."), htmlspecialchars($vcard_nice['version'])));
90 $oTemplate->display('note.tpl');
91
92 $vcard_nice['firstname'] = '';
93 $vcard_nice['lastname'] = '';
94 }
95
96 foreach ($vcard_nice as $k => $v) {
97 $v = htmlspecialchars($v);
98 $v = trim($v);
99 $vcard_safe[$k] = trim(nl2br($v));
100 }
101
102 $ShowValues = array(
103 'fn' => _("Name"),
104 'title' => _("Title"),
105 'email;internet' => _("E-mail"),
106 'url' => _("Web Page"),
107 'org' => _("Organization / Department"),
108 'adr' => _("Address"),
109 'tel;work' => _("Work Phone"),
110 'tel;home' => _("Home Phone"),
111 'tel;cell' => _("Cellular Phone"),
112 'tel;fax' => _("Fax"),
113 'note' => _("Note"));
114
115 if (isset($vcard_safe['email;internet'])) {
116 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
117 $vcard_safe['email;internet']);
118 }
119
120 if (isset($vcard_safe['url'])) {
121 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '" target="_blank">' .
122 $vcard_safe['url'] . '</a>';
123 }
124
125 $vcard = array();
126 foreach ($ShowValues as $k => $v) {
127 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
128 $vcard[$v] = $vcard_safe[$k];
129 }
130 }
131
132 $dl = '../src/download.php?absolute_dl=true&amp;passed_id=' .
133 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
134 '&amp;ent_id=' . urlencode($ent_id);
135
136 if (isset($vcard_nice['email;internet'])) {
137 $email = $vcard_nice['email;internet'];
138 } else {
139 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
140 $header = $message->rfc822_header;
141 $from_name = $header->getAddr_s('from');
142
143 $email = getEmail(decodeHeader($from_name));
144 }
145
146 $opts = array();
147 if (isset($vcard_nice['url'])) {
148 $opts[$vcard_nice['url']] = _("Web Page");
149 }
150 if (isset($vcard_nice['adr'])) {
151 $opts[$vcard_nice['adr']] = _("Address");
152 }
153 if (isset($vcard_nice['title'])) {
154 $opts[$vcard_nice['title']] = _("Title");
155 }
156 if (isset($vcard_nice['org'])) {
157 $opts[$vcard_nice['org']] = _("Organization / Department");
158 }
159 if (isset($vcard_nice['title'])) {
160 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title &amp; Org. / Dept.");
161 }
162 if (isset($vcard_nice['tel;work'])) {
163 $opts[$vcard_nice['tel;work']] = _("Work Phone");
164 }
165 if (isset($vcard_nice['tel;home'])) {
166 $opts[$vcard_nice['tel;home']] = _("Home Phone");
167 }
168 if (isset($vcard_nice['tel;cell'])) {
169 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
170 }
171 if (isset($vcard_nice['tel;fax'])) {
172 $opts[$vcard_nice['tel;fax']] = _("Fax");
173 }
174 if (isset($vcard_nice['note'])) {
175 $opts[$vcard_nice['note']] = _("Note");
176 }
177
178 $oTemplate->assign('view_message_link', $msg_url);
179 $oTemplate->assign('download_link', $dl);
180 $oTemplate->assign('vcard', $vcard);
181
182 $oTemplate->assign('nickname', $vcard_nice['firstname'].'-'.$vcard_safe['lastname']);
183 $oTemplate->assign('firstname', $vcard_safe['firstname']);
184 $oTemplate->assign('lastname', $vcard_safe['lastname']);
185 $oTemplate->assign('email', $email);
186 $oTemplate->assign('info', $opts);
187
188 $oTemplate->display('vcard.tpl');
189
190 $oTemplate->display('footer.tpl');