Happy New Year
[squirrelmail.git] / src / vcard.php
1 <?php
2
3 /**
4 * vcard.php
5 *
6 * This file shows an attched vcard
7 *
8 * @copyright 1999-2019 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** This is the vcard page */
15 define('PAGE_NAME', 'vcard');
16
17 /**
18 * Include the SquirrelMail initialization file.
19 */
20 require('../include/init.php');
21
22 /* SquirrelMail required files. */
23
24 /** imap functions depend on date functions */
25 include_once(SM_PATH . 'functions/date.php');
26 /** form functions */
27 include_once(SM_PATH . 'functions/forms.php');
28 /** mime decoding */
29 include_once(SM_PATH . 'functions/mime.php');
30 /** url parser */
31 include_once(SM_PATH . 'functions/url_parser.php');
32 /** imap functions used to retrieve vcard */
33 include_once(SM_PATH . 'functions/imap_general.php');
34 include_once(SM_PATH . 'functions/imap_messages.php');
35
36 /* globals */
37
38 sqgetGlobalVar('passed_id', $passed_id, SQ_GET, NULL, SQ_TYPE_BIGINT);
39 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
40 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
41 sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
42 /* end globals */
43
44 global $imap_stream_options; // in case not defined in config
45 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
46 sqimap_mailbox_select($imapConnection, $mailbox);
47
48 displayPageHeader($color);
49
50 $msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
51 '&amp;startMessage='.urlencode($startMessage).
52 '&amp;passed_id='.urlencode($passed_id);
53 $msg_url = set_url_var($msg_url, 'ent_id', 0);
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 $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'])));
91 $oTemplate->display('note.tpl');
92
93 $vcard_nice['firstname'] = '';
94 $vcard_nice['lastname'] = '';
95 }
96
97 foreach ($vcard_nice as $k => $v) {
98 $v = sm_encode_html_special_chars($v);
99 $v = trim($v);
100 $vcard_safe[$k] = trim(nl2br($v));
101 }
102
103 $ShowValues = array(
104 'fn' => _("Name"),
105 'title' => _("Title"),
106 'email;internet' => _("E-mail"),
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
116 if (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']);
119 }
120
121 if (isset($vcard_safe['url'])) {
122 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '" target="_blank">' .
123 $vcard_safe['url'] . '</a>';
124 }
125
126 $vcard = array();
127 foreach ($ShowValues as $k => $v) {
128 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
129 $vcard[$v] = $vcard_safe[$k];
130 }
131 }
132
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);
136
137 if (isset($vcard_nice['email;internet'])) {
138 $email = $vcard_nice['email;internet'];
139 } else {
140 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
141 $header = $message->rfc822_header;
142 $from_name = $header->getAddr_s('from');
143
144 $email = getEmail(decodeHeader($from_name));
145 }
146
147 $opts = array();
148 if (isset($vcard_nice['url'])) {
149 $opts[$vcard_nice['url']] = _("Web Page");
150 }
151 if (isset($vcard_nice['adr'])) {
152 $opts[$vcard_nice['adr']] = _("Address");
153 }
154 if (isset($vcard_nice['title'])) {
155 $opts[$vcard_nice['title']] = _("Title");
156 }
157 if (isset($vcard_nice['org'])) {
158 $opts[$vcard_nice['org']] = _("Organization / Department");
159 }
160 if (isset($vcard_nice['title'])) {
161 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title &amp; Org. / Dept.");
162 }
163 if (isset($vcard_nice['tel;work'])) {
164 $opts[$vcard_nice['tel;work']] = _("Work Phone");
165 }
166 if (isset($vcard_nice['tel;home'])) {
167 $opts[$vcard_nice['tel;home']] = _("Home Phone");
168 }
169 if (isset($vcard_nice['tel;cell'])) {
170 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
171 }
172 if (isset($vcard_nice['tel;fax'])) {
173 $opts[$vcard_nice['tel;fax']] = _("Fax");
174 }
175 if (isset($vcard_nice['note'])) {
176 $opts[$vcard_nice['note']] = _("Note");
177 }
178
179 $oTemplate->assign('view_message_link', $msg_url);
180 $oTemplate->assign('download_link', $dl);
181 $oTemplate->assign('vcard', $vcard);
182
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);
188
189 $oTemplate->display('vcard.tpl');
190
191 $oTemplate->display('footer.tpl');