HTML escaping.
[squirrelmail.git] / src / vcard.php
CommitLineData
7baf86a9 1<?php
895905c0 2
35586184 3/**
4 * vcard.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file shows an attched vcard
10 *
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
35586184 13 */
7baf86a9 14
30967a1e 15/**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
846a3a21 19Define('SM_PATH','../');
86725763 20
21/* SquirrelMail required files. */
08185f2a 22require_once(SM_PATH . 'include/validate.php');
86725763 23require_once(SM_PATH . 'functions/date.php');
24require_once(SM_PATH . 'functions/page_header.php');
25require_once(SM_PATH . 'functions/mime.php');
08185f2a 26require_once(SM_PATH . 'include/load_prefs.php');
7baf86a9 27
0b97a708 28/* globals */
f38b7cf0 29sqgetGlobalVar('username', $username, SQ_SESSION);
30sqgetGlobalVar('key', $key, SQ_COOKIE);
31sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
32
33sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
34sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
35sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
36sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
0b97a708 37/* end globals */
38
65c3ec94 39$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
40sqimap_mailbox_select($imapConnection, $mailbox);
7baf86a9 41
42
65c3ec94 43displayPageHeader($color, 'None');
7baf86a9 44
24d16195 45echo '<br><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
46 'align="center">' . "\n" .
47 '<tr><td bgcolor="' . $color[0] . '">' .
7baf86a9 48 '<b><center>' .
24d16195 49 _("Viewing a Business Card") . " - ";
33c8b76b 50$msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
164584f0 51 '&amp;startMessage='.urlencode($startMessage).
52 '&amp;passed_id='.urlencode($passed_id);
33c8b76b 53
24d16195 54$msg_url = set_url_var($msg_url, 'ent_id', 0);
33c8b76b 55
24d16195 56echo '<a href="'.$msg_url.'">'. _("View message") . '</a>';
57
65c3ec94 58echo '</center></b></td></tr>';
59
60$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
61
24d16195 62$entity_vcard = getEntity($message,$ent_id);
65c3ec94 63
24d16195 64$vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id);
65c3ec94 65$vcard = decodeBody($vcard, $entity_vcard->header->encoding);
66$vcard = explode ("\n",$vcard);
67foreach ($vcard as $l) {
68 $k = substr($l, 0, strpos($l, ':'));
69 $v = substr($l, strpos($l, ':') + 1);
70 $attributes = explode(';', $k);
71 $k = strtolower(array_shift($attributes));
72 foreach ($attributes as $attr) {
73 if ($attr == 'quoted-printable')
74 $v = quoted_printable_decode($v);
75 else
40a9d8b3 76 $k .= ';' . strtolower($attr);
65c3ec94 77 }
78
0f8a1ce9 79 $v = str_replace(';', "\n", $v);
65c3ec94 80 $vcard_nice[$k] = $v;
81}
82
83if ($vcard_nice['version'] == '2.1') {
84 // get firstname and lastname for sm addressbook
40a9d8b3 85 $vcard_nice['firstname'] = substr($vcard_nice['n'],
86 strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
87 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
88 strpos($vcard_nice['n'], "\n"));
89 // workaround for Outlook, should be fixed in a better way,
90 // maybe in new 'vCard' class.
91 if (isset($vcard_nice['email;pref;internet'])) {
92 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
93 }
65c3ec94 94} else {
24d16195 95 echo '<tr><td align=center>vCard Version ' . $vcard_nice['version'] .
96 ' is not supported. Some information might not be converted ' .
97 "correctly.</td></tr>\n";
65c3ec94 98}
99
100foreach ($vcard_nice as $k => $v) {
101 $v = htmlspecialchars($v);
102 $v = trim($v);
103 $vcard_safe[$k] = trim(nl2br($v));
104}
105
106$ShowValues = array(
107 'fn' => _("Name"),
108 'title' => _("Title"),
109 'email;internet' => _("Email"),
110 'url' => _("Web Page"),
111 'org' => _("Organization / Department"),
112 'adr' => _("Address"),
113 'tel;work' => _("Work Phone"),
114 'tel;home' => _("Home Phone"),
115 'tel;cell' => _("Cellular Phone"),
116 'tel;fax' => _("Fax"),
117 'note' => _("Note"));
118
24d16195 119echo '<tr><td><br>' .
120 '<TABLE border=0 cellpadding=2 cellspacing=0 align=center>' . "\n";
65c3ec94 121
d62c4938 122if (isset($vcard_safe['email;internet'])) {
123 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
124 $vcard_safe['email;internet']);
65c3ec94 125}
d62c4938 126
65c3ec94 127if (isset($vcard_safe['url'])) {
24d16195 128 $vcard_safe['url'] = '<A HREF="' . $vcard_safe['url'] . '">' .
129 $vcard_safe['url'] . '</A>';
65c3ec94 130}
131
132foreach ($ShowValues as $k => $v) {
133 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
24d16195 134 echo "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] .
135 "</td><tr>\n";
65c3ec94 136 }
137}
7baf86a9 138
65c3ec94 139echo '</table>' .
7baf86a9 140 '<br>' .
141 '</td></tr></table>' .
24d16195 142 '<table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
143 'align="center">' .
144 '<tr>' .
145 '<td bgcolor="' . $color[0] . '">' .
146 '<b><center>' .
147 _("Add to Addressbook") .
148 '</td></tr>' .
149 '<tr><td align=center>' .
64c9e87e 150 addForm('../src/addressbook.php', 'POST', 'f_add') .
24d16195 151 '<table border=0 cellpadding=2 cellspacing=0 align=center>' .
152 '<tr><td align=right><b>Nickname:</b></td>' .
64c9e87e 153 '<td>'.
154 addInput('addaddr[nickname]', $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'], '20').
155 '</td></tr>' .
156 '<tr><td align=right><b>Note Field Contains:</b></td><td>' ;
7baf86a9 157
64c9e87e 158$opts = array();
65c3ec94 159if (isset($vcard_nice['url'])) {
64c9e87e 160 $opts[$vcard_nice['url']] = _("Web Page");
65c3ec94 161}
162if (isset($vcard_nice['adr'])) {
64c9e87e 163 $opts[$vcard_nice['adr']] = _("Address");
65c3ec94 164}
165if (isset($vcard_nice['title'])) {
64c9e87e 166 $opts[$vcard_nice['title']] = _("Title");
65c3ec94 167}
168if (isset($vcard_nice['org'])) {
64c9e87e 169 $opts[$vcard_nice['org']] = _("Organization / Department");
65c3ec94 170}
171if (isset($vcard_nice['title'])) {
64c9e87e 172 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
65c3ec94 173}
174if (isset($vcard_nice['tel;work'])) {
64c9e87e 175 $opts[$vcard_nice['tel;work']] = _("Work Phone");
65c3ec94 176}
177if (isset($vcard_nice['tel;home'])) {
64c9e87e 178 $opts[$vcard_nice['tel;home']] = _("Home Phone");
65c3ec94 179}
180if (isset($vcard_nice['tel;cell'])) {
64c9e87e 181 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
65c3ec94 182}
183if (isset($vcard_nice['tel;fax'])) {
64c9e87e 184 $opts[$vcard_nice['tel;fax']] = _("Fax");
65c3ec94 185}
186if (isset($vcard_nice['note'])) {
64c9e87e 187 $opts[$vcard_nice['note']] = _("Note");
65c3ec94 188}
64c9e87e 189
190echo addSelect('addaddr[label]', $opts, '', TRUE);
191echo '</td></tr>' .
24d16195 192 '<tr><td colspan=2 align=center>' .
64c9e87e 193 addHidden('addaddr[email]', $vcard_nice['email;internet']).
194 addHidden('addaddr[firstname]', $vcard_safe['firstname']).
195 addHidden('addaddr[lastname]', $vcard_safe['lastname']).
196 addSubmit(_("Add to Address Book"), 'addaddr[SUBMIT]').
7baf86a9 197 '</td></tr>' .
fab3baa6 198 '</table>' .
64c9e87e 199 '</form>' .
24d16195 200 '</td></tr>' .
201 '<tr><td align=center>' .
202 '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
164584f0 203 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
0fa23001 204 '&amp;ent_id=' . urlencode($ent_id) . '">' .
24d16195 205 _("Download this as a file") . '</A>' .
206 '</TD></TR></TABLE>' .
207
208 '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>' .
209 '<TR><TD BGCOLOR="' . $color[4] . '">' .
dcc1cc82 210 '</TD></TR></TABLE>' .
211 '</body></html>';
65c3ec94 212
dcc1cc82 213?>