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