Per comments in the commit - setting the session cookie over and over can be troubles...
[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 *
f197ec88 8 * @copyright 1999-2016 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
51bbe8fa 38sqgetGlobalVar('passed_id', $passed_id, SQ_GET, NULL, SQ_TYPE_BIGINT);
f38b7cf0 39sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
40sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
41sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
0b97a708 42/* end globals */
43
a9805897 44global $imap_stream_options; // in case not defined in config
45$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
65c3ec94 46sqimap_mailbox_select($imapConnection, $mailbox);
7baf86a9 47
876fdb60 48displayPageHeader($color);
7baf86a9 49
33c8b76b 50$msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
164584f0 51 '&amp;startMessage='.urlencode($startMessage).
52 '&amp;passed_id='.urlencode($passed_id);
24d16195 53$msg_url = set_url_var($msg_url, 'ent_id', 0);
33c8b76b 54
65c3ec94 55$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
56
24d16195 57$entity_vcard = getEntity($message,$ent_id);
65c3ec94 58
d444fa27 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 {
3047e291 90 $oTemplate->assign('note', sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."), sm_encode_html_special_chars($vcard_nice['version'])));
a88fa973 91 $oTemplate->display('note.tpl');
92
d543fbac 93 $vcard_nice['firstname'] = '';
94 $vcard_nice['lastname'] = '';
65c3ec94 95}
96
97foreach ($vcard_nice as $k => $v) {
3047e291 98 $v = sm_encode_html_special_chars($v);
65c3ec94 99 $v = trim($v);
100 $vcard_safe[$k] = trim(nl2br($v));
101}
102
103$ShowValues = array(
104 'fn' => _("Name"),
105 'title' => _("Title"),
674a2ca2 106 'email;internet' => _("E-mail"),
65c3ec94 107 'url' => _("Web Page"),
108 'org' => _("Organization / Department"),
109 'adr' => _("Address"),
110 'tel;work' => _("Work Phone"),
111 'tel;home' => _("Home Phone"),
112 'tel;cell' => _("Cellular Phone"),
113 'tel;fax' => _("Fax"),
114 'note' => _("Note"));
115
d62c4938 116if (isset($vcard_safe['email;internet'])) {
117 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
118 $vcard_safe['email;internet']);
65c3ec94 119}
d62c4938 120
65c3ec94 121if (isset($vcard_safe['url'])) {
a88fa973 122 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '" target="_blank">' .
3c621ba1 123 $vcard_safe['url'] . '</a>';
65c3ec94 124}
125
a88fa973 126$vcard = array();
65c3ec94 127foreach ($ShowValues as $k => $v) {
a88fa973 128 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
129 $vcard[$v] = $vcard_safe[$k];
65c3ec94 130 }
131}
7baf86a9 132
a88fa973 133$dl = '../src/download.php?absolute_dl=true&amp;passed_id=' .
134 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
135 '&amp;ent_id=' . urlencode($ent_id);
d444fa27 136
d444fa27 137if (isset($vcard_nice['email;internet'])) {
a88fa973 138 $email = $vcard_nice['email;internet'];
d444fa27 139} else {
916669ad 140 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
141 $header = $message->rfc822_header;
142 $from_name = $header->getAddr_s('from');
143
a88fa973 144 $email = getEmail(decodeHeader($from_name));
d444fa27 145}
146
64c9e87e 147$opts = array();
65c3ec94 148if (isset($vcard_nice['url'])) {
64c9e87e 149 $opts[$vcard_nice['url']] = _("Web Page");
65c3ec94 150}
151if (isset($vcard_nice['adr'])) {
64c9e87e 152 $opts[$vcard_nice['adr']] = _("Address");
65c3ec94 153}
154if (isset($vcard_nice['title'])) {
64c9e87e 155 $opts[$vcard_nice['title']] = _("Title");
65c3ec94 156}
157if (isset($vcard_nice['org'])) {
64c9e87e 158 $opts[$vcard_nice['org']] = _("Organization / Department");
65c3ec94 159}
160if (isset($vcard_nice['title'])) {
407e7032 161 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title &amp; Org. / Dept.");
65c3ec94 162}
163if (isset($vcard_nice['tel;work'])) {
64c9e87e 164 $opts[$vcard_nice['tel;work']] = _("Work Phone");
65c3ec94 165}
166if (isset($vcard_nice['tel;home'])) {
64c9e87e 167 $opts[$vcard_nice['tel;home']] = _("Home Phone");
65c3ec94 168}
169if (isset($vcard_nice['tel;cell'])) {
64c9e87e 170 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
65c3ec94 171}
172if (isset($vcard_nice['tel;fax'])) {
64c9e87e 173 $opts[$vcard_nice['tel;fax']] = _("Fax");
65c3ec94 174}
175if (isset($vcard_nice['note'])) {
64c9e87e 176 $opts[$vcard_nice['note']] = _("Note");
65c3ec94 177}
64c9e87e 178
a88fa973 179$oTemplate->assign('view_message_link', $msg_url);
180$oTemplate->assign('download_link', $dl);
181$oTemplate->assign('vcard', $vcard);
d444fa27 182
a88fa973 183$oTemplate->assign('nickname', $vcard_nice['firstname'].'-'.$vcard_safe['lastname']);
184$oTemplate->assign('firstname', $vcard_safe['firstname']);
185$oTemplate->assign('lastname', $vcard_safe['lastname']);
186$oTemplate->assign('email', $email);
187$oTemplate->assign('info', $opts);
6b2eed75 188
a88fa973 189$oTemplate->display('vcard.tpl');
d444fa27 190
5c4ff7bf 191$oTemplate->display('footer.tpl');