Correct value of undefined hostname
[squirrelmail.git] / src / vcard.php
CommitLineData
7baf86a9 1<?php
895905c0 2
35586184 3/**
4 * vcard.php
5 *
35586184 6 * This file shows an attched vcard
7 *
4b5049de 8 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 10 * @version $Id$
8f6f9ba5 11 * @package squirrelmail
35586184 12 */
7baf86a9 13
ebd2391c 14/** This is the vcard page */
15define('PAGE_NAME', 'vcard');
16
30967a1e 17/**
202bcbcc 18 * Include the SquirrelMail initialization file.
30967a1e 19 */
202bcbcc 20require('../include/init.php');
86725763 21
22/* SquirrelMail required files. */
ae299e07 23
24/** imap functions depend on date functions */
25include_once(SM_PATH . 'functions/date.php');
26/** form functions */
27include_once(SM_PATH . 'functions/forms.php');
28/** mime decoding */
29include_once(SM_PATH . 'functions/mime.php');
30/** url parser */
31include_once(SM_PATH . 'functions/url_parser.php');
32/** imap functions used to retrieve vcard */
33include_once(SM_PATH . 'functions/imap_general.php');
34include_once(SM_PATH . 'functions/imap_messages.php');
7baf86a9 35
0b97a708 36/* globals */
f38b7cf0 37
38sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
39sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
40sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
41sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
0b97a708 42/* end globals */
43
906f7e9f 44$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
65c3ec94 45sqimap_mailbox_select($imapConnection, $mailbox);
7baf86a9 46
876fdb60 47displayPageHeader($color);
7baf86a9 48
33c8b76b 49$msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
164584f0 50 '&amp;startMessage='.urlencode($startMessage).
51 '&amp;passed_id='.urlencode($passed_id);
24d16195 52$msg_url = set_url_var($msg_url, 'ent_id', 0);
33c8b76b 53
65c3ec94 54$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
55
24d16195 56$entity_vcard = getEntity($message,$ent_id);
65c3ec94 57
d444fa27 58$vcard = mime_fetch_body($imapConnection, $passed_id, $ent_id);
65c3ec94 59$vcard = decodeBody($vcard, $entity_vcard->header->encoding);
60$vcard = explode ("\n",$vcard);
61foreach ($vcard as $l) {
62 $k = substr($l, 0, strpos($l, ':'));
63 $v = substr($l, strpos($l, ':') + 1);
64 $attributes = explode(';', $k);
65 $k = strtolower(array_shift($attributes));
66 foreach ($attributes as $attr) {
67 if ($attr == 'quoted-printable')
68 $v = quoted_printable_decode($v);
69 else
40a9d8b3 70 $k .= ';' . strtolower($attr);
65c3ec94 71 }
72
0f8a1ce9 73 $v = str_replace(';', "\n", $v);
65c3ec94 74 $vcard_nice[$k] = $v;
75}
76
77if ($vcard_nice['version'] == '2.1') {
78 // get firstname and lastname for sm addressbook
40a9d8b3 79 $vcard_nice['firstname'] = substr($vcard_nice['n'],
80 strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
81 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
82 strpos($vcard_nice['n'], "\n"));
83 // workaround for Outlook, should be fixed in a better way,
84 // maybe in new 'vCard' class.
85 if (isset($vcard_nice['email;pref;internet'])) {
86 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
87 }
65c3ec94 88} else {
a88fa973 89 $oTemplate->assign('note', sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."), htmlspecialchars($vcard_nice['version'])));
90 $oTemplate->display('note.tpl');
91
d543fbac 92 $vcard_nice['firstname'] = '';
93 $vcard_nice['lastname'] = '';
65c3ec94 94}
95
96foreach ($vcard_nice as $k => $v) {
97 $v = htmlspecialchars($v);
98 $v = trim($v);
99 $vcard_safe[$k] = trim(nl2br($v));
100}
101
102$ShowValues = array(
103 'fn' => _("Name"),
104 'title' => _("Title"),
674a2ca2 105 'email;internet' => _("E-mail"),
65c3ec94 106 'url' => _("Web Page"),
107 'org' => _("Organization / Department"),
108 'adr' => _("Address"),
109 'tel;work' => _("Work Phone"),
110 'tel;home' => _("Home Phone"),
111 'tel;cell' => _("Cellular Phone"),
112 'tel;fax' => _("Fax"),
113 'note' => _("Note"));
114
d62c4938 115if (isset($vcard_safe['email;internet'])) {
116 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
117 $vcard_safe['email;internet']);
65c3ec94 118}
d62c4938 119
65c3ec94 120if (isset($vcard_safe['url'])) {
a88fa973 121 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '" target="_blank">' .
3c621ba1 122 $vcard_safe['url'] . '</a>';
65c3ec94 123}
124
a88fa973 125$vcard = array();
65c3ec94 126foreach ($ShowValues as $k => $v) {
a88fa973 127 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
128 $vcard[$v] = $vcard_safe[$k];
65c3ec94 129 }
130}
7baf86a9 131
a88fa973 132$dl = '../src/download.php?absolute_dl=true&amp;passed_id=' .
133 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
134 '&amp;ent_id=' . urlencode($ent_id);
d444fa27 135
d444fa27 136if (isset($vcard_nice['email;internet'])) {
a88fa973 137 $email = $vcard_nice['email;internet'];
d444fa27 138} else {
916669ad 139 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
140 $header = $message->rfc822_header;
141 $from_name = $header->getAddr_s('from');
142
a88fa973 143 $email = getEmail(decodeHeader($from_name));
d444fa27 144}
145
64c9e87e 146$opts = array();
65c3ec94 147if (isset($vcard_nice['url'])) {
64c9e87e 148 $opts[$vcard_nice['url']] = _("Web Page");
65c3ec94 149}
150if (isset($vcard_nice['adr'])) {
64c9e87e 151 $opts[$vcard_nice['adr']] = _("Address");
65c3ec94 152}
153if (isset($vcard_nice['title'])) {
64c9e87e 154 $opts[$vcard_nice['title']] = _("Title");
65c3ec94 155}
156if (isset($vcard_nice['org'])) {
64c9e87e 157 $opts[$vcard_nice['org']] = _("Organization / Department");
65c3ec94 158}
159if (isset($vcard_nice['title'])) {
407e7032 160 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title &amp; Org. / Dept.");
65c3ec94 161}
162if (isset($vcard_nice['tel;work'])) {
64c9e87e 163 $opts[$vcard_nice['tel;work']] = _("Work Phone");
65c3ec94 164}
165if (isset($vcard_nice['tel;home'])) {
64c9e87e 166 $opts[$vcard_nice['tel;home']] = _("Home Phone");
65c3ec94 167}
168if (isset($vcard_nice['tel;cell'])) {
64c9e87e 169 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
65c3ec94 170}
171if (isset($vcard_nice['tel;fax'])) {
64c9e87e 172 $opts[$vcard_nice['tel;fax']] = _("Fax");
65c3ec94 173}
174if (isset($vcard_nice['note'])) {
64c9e87e 175 $opts[$vcard_nice['note']] = _("Note");
65c3ec94 176}
64c9e87e 177
a88fa973 178$oTemplate->assign('view_message_link', $msg_url);
179$oTemplate->assign('download_link', $dl);
180$oTemplate->assign('vcard', $vcard);
d444fa27 181
a88fa973 182$oTemplate->assign('nickname', $vcard_nice['firstname'].'-'.$vcard_safe['lastname']);
183$oTemplate->assign('firstname', $vcard_safe['firstname']);
184$oTemplate->assign('lastname', $vcard_safe['lastname']);
185$oTemplate->assign('email', $email);
186$oTemplate->assign('info', $opts);
6b2eed75 187
a88fa973 188$oTemplate->display('vcard.tpl');
d444fa27 189
5c4ff7bf 190$oTemplate->display('footer.tpl');