| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * vcard.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2003 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 | /* globals */ |
| 25 | $key = $_COOKIE['key']; |
| 26 | $username = $_SESSION['username']; |
| 27 | $onetimepad = $_SESSION['onetimepad']; |
| 28 | $mailbox = $_GET['mailbox']; |
| 29 | $passed_id = (int) $_GET['passed_id']; |
| 30 | $ent_id = $_GET['ent_id']; |
| 31 | $startMessage = (int) $_GET['startMessage']; |
| 32 | /* end globals */ |
| 33 | |
| 34 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 35 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 36 | |
| 37 | |
| 38 | displayPageHeader($color, 'None'); |
| 39 | |
| 40 | echo '<br><table width="100%" border="0" cellspacing="0" cellpadding="2" ' . |
| 41 | 'align="center">' . "\n" . |
| 42 | '<tr><td bgcolor="' . $color[0] . '">' . |
| 43 | '<b><center>' . |
| 44 | _("Viewing a Business Card") . " - "; |
| 45 | $msg_url = 'read_body.php?mailbox='.urlencode($mailbox). |
| 46 | '&startMessage='.$startMessage. |
| 47 | '&passed_id='.$passed_id; |
| 48 | |
| 49 | $msg_url = set_url_var($msg_url, 'ent_id', 0); |
| 50 | |
| 51 | echo '<a href="'.$msg_url.'">'. _("View message") . '</a>'; |
| 52 | |
| 53 | echo '</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>vCard Version ' . $vcard_nice['version'] . |
| 91 | ' is not supported. Some information might not be converted ' . |
| 92 | "correctly.</td></tr>\n"; |
| 93 | } |
| 94 | |
| 95 | foreach ($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 | |
| 114 | echo '<tr><td><br>' . |
| 115 | '<TABLE border=0 cellpadding=2 cellspacing=0 align=center>' . "\n"; |
| 116 | |
| 117 | if (isset($vcard_safe['email;internet'])) { $vcard_safe['email;internet'] = '<A HREF="../src/compose.php?send_to=' . |
| 118 | $vcard_safe['email;internet'] . '">' . $vcard_safe['email;internet'] . |
| 119 | '</A>'; |
| 120 | } |
| 121 | if (isset($vcard_safe['url'])) { |
| 122 | $vcard_safe['url'] = '<A HREF="' . $vcard_safe['url'] . '">' . |
| 123 | $vcard_safe['url'] . '</A>'; |
| 124 | } |
| 125 | |
| 126 | foreach ($ShowValues as $k => $v) { |
| 127 | if (isset($vcard_safe[$k]) && $vcard_safe[$k]) { |
| 128 | echo "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] . |
| 129 | "</td><tr>\n"; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | echo '</table>' . |
| 134 | '<br>' . |
| 135 | '</td></tr></table>' . |
| 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>' . |
| 151 | '<select name="addaddr[label]">'; |
| 152 | |
| 153 | if (isset($vcard_nice['url'])) { |
| 154 | echo '<option value="' . htmlspecialchars($vcard_nice['url']) . |
| 155 | '">' . _("Web Page") . "</option>\n"; |
| 156 | } |
| 157 | if (isset($vcard_nice['adr'])) { |
| 158 | echo '<option value="' . $vcard_nice['adr'] . |
| 159 | '">' . _("Address") . "</option>\n"; |
| 160 | } |
| 161 | if (isset($vcard_nice['title'])) { |
| 162 | echo '<option value="' . $vcard_nice['title'] . |
| 163 | '">' . _("Title") . "</option>\n"; |
| 164 | } |
| 165 | if (isset($vcard_nice['org'])) { |
| 166 | echo '<option value="' . $vcard_nice['org'] . |
| 167 | '">' . _("Organization / Department") . "</option>\n"; |
| 168 | } |
| 169 | if (isset($vcard_nice['title'])) { |
| 170 | echo '<option value="' . $vcard_nice['title'] . |
| 171 | '; ' . $vcard_nice['org'] . |
| 172 | '">' . _("Title & Org. / Dept.") . "</option>\n"; |
| 173 | } |
| 174 | if (isset($vcard_nice['tel;work'])) { |
| 175 | echo '<option value="' . $vcard_nice['tel;work'] . |
| 176 | '">' . _("Work Phone") . "</option>\n"; |
| 177 | } |
| 178 | if (isset($vcard_nice['tel;home'])) { |
| 179 | echo '<option value="' . $vcard_nice['tel;home'] . |
| 180 | '">' . _("Home Phone") . "</option>\n"; |
| 181 | } |
| 182 | if (isset($vcard_nice['tel;cell'])) { |
| 183 | echo '<option value="' . $vcard_nice['tel;cell'] . |
| 184 | '">' . _("Cellular Phone") . "</option>\n"; |
| 185 | } |
| 186 | if (isset($vcard_nice['tel;fax'])) { |
| 187 | echo '<option value="' . $vcard_nice['tel;fax'] . |
| 188 | '">' . _("Fax") . "</option>\n"; |
| 189 | } |
| 190 | if (isset($vcard_nice['note'])) { |
| 191 | echo '<option value="' . $vcard_nice['note'] . |
| 192 | '">' . _("Note") . "</option>\n"; |
| 193 | } |
| 194 | echo '</select>' . |
| 195 | '</td></tr>' . |
| 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">' . |
| 205 | '</td></tr>' . |
| 206 | '</table>' . |
| 207 | '</FORM>' . |
| 208 | '</td></tr>' . |
| 209 | '<tr><td align=center>' . |
| 210 | '<a href="../src/download.php?absolute_dl=true&passed_id=' . |
| 211 | $passed_id . '&mailbox=' . urlencode($mailbox) . |
| 212 | '&ent_id=' . urlencode($ent_id) . '">' . |
| 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>' . |
| 219 | '</body></html>'; |
| 220 | |
| 221 | ?> |