4) XSS in help.php:
[squirrelmail.git] / src / vcard.php
1 <?php
2
3 /**
4 * vcard.php
5 *
6 * Copyright (c) 1999-2002 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 * $Id$
12 */
13
14 /* Path for SquirrelMail required files. */
15 define('SM_PATH','../');
16
17 /* SquirrelMail required files. */
18 require_once(SM_PATH . 'include/validate.php');
19 require_once(SM_PATH . 'functions/date.php');
20 require_once(SM_PATH . 'functions/page_header.php');
21 require_once(SM_PATH . 'functions/mime.php');
22 require_once(SM_PATH . 'include/load_prefs.php');
23
24 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
25 sqimap_mailbox_select($imapConnection, $mailbox);
26
27
28 displayPageHeader($color, 'None');
29
30 echo '<br><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
31 'align="center">' . "\n" .
32 '<tr><td bgcolor="' . $color[0] . '">' .
33 '<b><center>' .
34 _("Viewing a Business Card") . " - ";
35 $msg_url = 'read_body.php?' . $QUERY_STRING;
36 $msg_url = set_url_var($msg_url, 'ent_id', 0);
37 echo '<a href="'.$msg_url.'">'. _("View message") . '</a>';
38
39 echo '</center></b></td></tr>';
40
41 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
42
43 $entity_vcard = getEntity($message,$ent_id);
44
45 $vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id);
46 $vcard = decodeBody($vcard, $entity_vcard->header->encoding);
47 $vcard = explode ("\n",$vcard);
48 foreach ($vcard as $l) {
49 $k = substr($l, 0, strpos($l, ':'));
50 $v = substr($l, strpos($l, ':') + 1);
51 $attributes = explode(';', $k);
52 $k = strtolower(array_shift($attributes));
53 foreach ($attributes as $attr) {
54 if ($attr == 'quoted-printable')
55 $v = quoted_printable_decode($v);
56 else
57 $k .= ';' . $attr;
58 }
59
60 $v = str_replace(';', "\n", $v);
61 $vcard_nice[$k] = $v;
62 }
63
64 if ($vcard_nice['version'] == '2.1') {
65 // get firstname and lastname for sm addressbook
66 $vcard_nice["firstname"] = substr($vcard_nice["n"],
67 strpos($vcard_nice["n"], "\n") + 1, strlen($vcard_nice["n"]));
68 $vcard_nice["lastname"] = substr($vcard_nice["n"], 0,
69 strpos($vcard_nice["n"], "\n"));
70 } else {
71 echo '<tr><td align=center>vCard Version ' . $vcard_nice['version'] .
72 ' is not supported. Some information might not be converted ' .
73 "correctly.</td></tr>\n";
74 }
75
76 foreach ($vcard_nice as $k => $v) {
77 $v = htmlspecialchars($v);
78 $v = trim($v);
79 $vcard_safe[$k] = trim(nl2br($v));
80 }
81
82 $ShowValues = array(
83 'fn' => _("Name"),
84 'title' => _("Title"),
85 'email;internet' => _("Email"),
86 'url' => _("Web Page"),
87 'org' => _("Organization / Department"),
88 'adr' => _("Address"),
89 'tel;work' => _("Work Phone"),
90 'tel;home' => _("Home Phone"),
91 'tel;cell' => _("Cellular Phone"),
92 'tel;fax' => _("Fax"),
93 'note' => _("Note"));
94
95 echo '<tr><td><br>' .
96 '<TABLE border=0 cellpadding=2 cellspacing=0 align=center>' . "\n";
97
98 if (isset($vcard_safe['email;internet'])) { $vcard_safe['email;internet'] = '<A HREF="../src/compose.php?send_to=' .
99 $vcard_safe['email;internet'] . '">' . $vcard_safe['email;internet'] .
100 '</A>';
101 }
102 if (isset($vcard_safe['url'])) {
103 $vcard_safe['url'] = '<A HREF="' . $vcard_safe['url'] . '">' .
104 $vcard_safe['url'] . '</A>';
105 }
106
107 foreach ($ShowValues as $k => $v) {
108 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
109 echo "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] .
110 "</td><tr>\n";
111 }
112 }
113
114 echo '</table>' .
115 '<br>' .
116 '</td></tr></table>' .
117 '<table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
118 'align="center">' .
119 '<tr>' .
120 '<td bgcolor="' . $color[0] . '">' .
121 '<b><center>' .
122 _("Add to Addressbook") .
123 '</td></tr>' .
124 '<tr><td align=center>' .
125 '<FORM ACTION="../src/addressbook.php" METHOD="POST" NAME=f_add>' .
126 '<table border=0 cellpadding=2 cellspacing=0 align=center>' .
127 '<tr><td align=right><b>Nickname:</b></td>' .
128 '<td><input type=text name="addaddr[nickname]" size=20 value="' .
129 $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'] .
130 '"></td></tr>' .
131 '<tr><td align=right><b>Note Field Contains:</b></td><td>' .
132 '<select name="addaddr[label]">';
133
134 if (isset($vcard_nice['url'])) {
135 echo '<option value="' . htmlspecialchars($vcard_nice['url']) .
136 '">' . _("Web Page") . "</option>\n";
137 }
138 if (isset($vcard_nice['adr'])) {
139 echo '<option value="' . $vcard_nice['adr'] .
140 '">' . _("Address") . "</option>\n";
141 }
142 if (isset($vcard_nice['title'])) {
143 echo '<option value="' . $vcard_nice['title'] .
144 '">' . _("Title") . "</option>\n";
145 }
146 if (isset($vcard_nice['org'])) {
147 echo '<option value="' . $vcard_nice['org'] .
148 '">' . _("Organization / Department") . "</option>\n";
149 }
150 if (isset($vcard_nice['title'])) {
151 echo '<option value="' . $vcard_nice['title'] .
152 '; ' . $vcard_nice['org'] .
153 '">' . _("Title & Org. / Dept.") . "</option>\n";
154 }
155 if (isset($vcard_nice['tel;work'])) {
156 echo '<option value="' . $vcard_nice['tel;work'] .
157 '">' . _("Work Phone") . "</option>\n";
158 }
159 if (isset($vcard_nice['tel;home'])) {
160 echo '<option value="' . $vcard_nice['tel;home'] .
161 '">' . _("Home Phone") . "</option>\n";
162 }
163 if (isset($vcard_nice['tel;cell'])) {
164 echo '<option value="' . $vcard_nice['tel;cell'] .
165 '">' . _("Cellular Phone") . "</option>\n";
166 }
167 if (isset($vcard_nice['tel;fax'])) {
168 echo '<option value="' . $vcard_nice['tel;fax'] .
169 '">' . _("Fax") . "</option>\n";
170 }
171 if (isset($vcard_nice['note'])) {
172 echo '<option value="' . $vcard_nice['note'] .
173 '">' . _("Note") . "</option>\n";
174 }
175 echo '</select>' .
176 '</td></tr>' .
177 '<tr><td colspan=2 align=center>' .
178 '<INPUT NAME="addaddr[email]" type=hidden value="' .
179 htmlspecialchars($vcard_nice['email;internet']) . '">' .
180 '<INPUT NAME="addaddr[firstname]" type=hidden value="' .
181 $vcard_safe['firstname'] . '">' .
182 '<INPUT NAME="addaddr[lastname]" type=hidden value="' .
183 $vcard_safe['lastname'] . '">' .
184 '<INPUT TYPE=submit NAME="addaddr[SUBMIT]" ' .
185 'VALUE="Add to Address Book">' .
186 '</td></tr>' .
187 '</table>' .
188 '</FORM>' .
189 '</td></tr>' .
190 '<tr><td align=center>' .
191 '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
192 $passed_id . '&amp;mailbox=' . urlencode($mailbox) .
193 '&amp;passed_ent_id=' . $passed_ent_id . '">' .
194 _("Download this as a file") . '</A>' .
195 '</TD></TR></TABLE>' .
196
197 '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>' .
198 '<TR><TD BGCOLOR="' . $color[4] . '">' .
199 '</TD></TR></TABLE>' .
200 '</body></html>';
201
202 ?>