data_dir doesn't need to be readable. It has to executable, but that's
[squirrelmail.git] / src / vcard.php
... / ...
CommitLineData
1<?php
2
3/**
4 * vcard.php
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file shows an attched vcard
10 *
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15/**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
19Define('SM_PATH','../');
20
21/* SquirrelMail required files. */
22require_once(SM_PATH . 'include/validate.php');
23require_once(SM_PATH . 'functions/mime.php');
24require_once(SM_PATH . 'functions/url_parser.php');
25
26/* globals */
27sqgetGlobalVar('username', $username, SQ_SESSION);
28sqgetGlobalVar('key', $key, SQ_COOKIE);
29sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
30
31sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
32sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
33sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
34sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
35/* end globals */
36
37$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
38sqimap_mailbox_select($imapConnection, $mailbox);
39
40displayPageHeader($color, 'None');
41
42echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
43 'align="center">' . "\n" .
44 '<tr><td bgcolor="' . $color[0] . '"><b><center>' .
45 _("Viewing a Business Card") . " - ";
46
47$msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
48 '&amp;startMessage='.urlencode($startMessage).
49 '&amp;passed_id='.urlencode($passed_id);
50
51$msg_url = set_url_var($msg_url, 'ent_id', 0);
52
53echo '<a href="'.$msg_url.'">'. _("View message") . '</a>' .
54 '</center></b></td></tr>';
55
56$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
57
58$entity_vcard = getEntity($message,$ent_id);
59
60$vcard = mime_fetch_body($imapConnection, $passed_id, $ent_id);
61$vcard = decodeBody($vcard, $entity_vcard->header->encoding);
62$vcard = explode ("\n",$vcard);
63foreach ($vcard as $l) {
64 $k = substr($l, 0, strpos($l, ':'));
65 $v = substr($l, strpos($l, ':') + 1);
66 $attributes = explode(';', $k);
67 $k = strtolower(array_shift($attributes));
68 foreach ($attributes as $attr) {
69 if ($attr == 'quoted-printable')
70 $v = quoted_printable_decode($v);
71 else
72 $k .= ';' . strtolower($attr);
73 }
74
75 $v = str_replace(';', "\n", $v);
76 $vcard_nice[$k] = $v;
77}
78
79if ($vcard_nice['version'] == '2.1') {
80 // get firstname and lastname for sm addressbook
81 $vcard_nice['firstname'] = substr($vcard_nice['n'],
82 strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
83 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
84 strpos($vcard_nice['n'], "\n"));
85 // workaround for Outlook, should be fixed in a better way,
86 // maybe in new 'vCard' class.
87 if (isset($vcard_nice['email;pref;internet'])) {
88 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
89 }
90} else {
91 echo '<tr><td align="center">' .
92 sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."),
93 htmlspecialchars($vcard_nice['version'])) .
94 "</td></tr>\n";
95 $vcard_nice['firstname'] = '';
96 $vcard_nice['lastname'] = '';
97}
98
99foreach ($vcard_nice as $k => $v) {
100 $v = htmlspecialchars($v);
101 $v = trim($v);
102 $vcard_safe[$k] = trim(nl2br($v));
103}
104
105$ShowValues = array(
106 'fn' => _("Name"),
107 'title' => _("Title"),
108 'email;internet' => _("Email"),
109 'url' => _("Web Page"),
110 'org' => _("Organization / Department"),
111 'adr' => _("Address"),
112 'tel;work' => _("Work Phone"),
113 'tel;home' => _("Home Phone"),
114 'tel;cell' => _("Cellular Phone"),
115 'tel;fax' => _("Fax"),
116 'note' => _("Note"));
117
118echo '<tr><td><br />' .
119 '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n";
120
121if (isset($vcard_safe['email;internet'])) {
122 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
123 $vcard_safe['email;internet']);
124}
125
126if (isset($vcard_safe['url'])) {
127 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' .
128 $vcard_safe['url'] . '</a>';
129}
130
131foreach ($ShowValues as $k => $v) {
132 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
133 echo "<tr><td align=\"right\" valign=\"top\"><b>$v:</b></td><td>" .
134 $vcard_safe[$k] . "</td><tr>\n";
135 }
136}
137
138?>
139</table>
140<br />
141</td></tr></table>
142<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
143<tr><td bgcolor="<?php echo $color[0]; ?>">
144<center><b><?php echo _("Add to Addressbook"); ?></b></center>
145</td></tr>
146<tr><td align="center">
147<?php echo addForm('../src/addressbook.php', 'post', 'f_add'); ?><br />
148<table border="0" cellpadding="2" cellspacing="0" align="center">
149<tr><td align="right"><b><?php echo _("Nickname"); ?>:</b></td>
150<td>
151<?php
152
153echo addInput('addaddr[nickname]', $vcard_safe['firstname'] .
154 '-' . $vcard_safe['lastname'], '20');
155
156/*
157 * If the vCard comes with an e-mail address it should be added to the
158 * address book, otherwise the user must add one manually to avoid an
159 * error message in src/addressbook.php. SquirrelMail is nice enough to
160 * suggest the e-mail address of the sender though.
161 */
162if (isset($vcard_nice['email;internet'])) {
163 echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
164} else {
165 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
166 $header = $message->rfc822_header;
167 $from_name = $header->getAddr_s('from');
168
169 echo '</td></tr>' .
170 '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' .
171 addInput('addaddr[email]',
172 getEmail(decodeHeader($from_name)), '20');
173}
174
175echo '</td></tr>' .
176 '<tr><td align="right"><b>' . _("Additional info") . ':</b></td><td>';
177
178$opts = array();
179if (isset($vcard_nice['url'])) {
180 $opts[$vcard_nice['url']] = _("Web Page");
181}
182if (isset($vcard_nice['adr'])) {
183 $opts[$vcard_nice['adr']] = _("Address");
184}
185if (isset($vcard_nice['title'])) {
186 $opts[$vcard_nice['title']] = _("Title");
187}
188if (isset($vcard_nice['org'])) {
189 $opts[$vcard_nice['org']] = _("Organization / Department");
190}
191if (isset($vcard_nice['title'])) {
192 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
193}
194if (isset($vcard_nice['tel;work'])) {
195 $opts[$vcard_nice['tel;work']] = _("Work Phone");
196}
197if (isset($vcard_nice['tel;home'])) {
198 $opts[$vcard_nice['tel;home']] = _("Home Phone");
199}
200if (isset($vcard_nice['tel;cell'])) {
201 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
202}
203if (isset($vcard_nice['tel;fax'])) {
204 $opts[$vcard_nice['tel;fax']] = _("Fax");
205}
206if (isset($vcard_nice['note'])) {
207 $opts[$vcard_nice['note']] = _("Note");
208}
209
210/*
211 * If the vcard comes with nothing but name and e-mail address, the user gets
212 * the chance to type some additional info. If there's more info in the card,
213 * the user gets to choose what will be added as additional info.
214 */
215if (count($opts) == 0) {
216 echo addInput('addaddr[label]', '', '20');
217} else {
218 echo addSelect('addaddr[label]', $opts, '', TRUE);
219}
220
221?>
222</td></tr>
223<tr><td colspan="2" align="center"><br />
224<?php
225
226echo addHidden('addaddr[firstname]', $vcard_safe['firstname']) .
227 addHidden('addaddr[lastname]', $vcard_safe['lastname']) .
228 addSubmit(_("Add to Address Book"), 'addaddr[SUBMIT]');
229
230?>
231</td></tr>
232</table>
233</form>
234</td></tr>
235<tr><td align="center">
236<?php
237echo '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
238 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
239 '&amp;ent_id=' . urlencode($ent_id) . '">' .
240 _("Download this as a file") . '</a>';
241?>
242</td></tr></table>
243<table border="0" cellspacing="0" cellpadding="2" align="center">
244<tr><td bgcolor="<?php echo $color[4]; ?>">
245</td></tr></table>
246</body></html>