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