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