6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file shows an attched vcard
12 * @package squirrelmail
16 * Path for SquirrelMail required files.
19 Define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 require_once(SM_PATH
. 'include/validate.php');
23 require_once(SM_PATH
. 'functions/date.php');
24 require_once(SM_PATH
. 'functions/page_header.php');
25 require_once(SM_PATH
. 'functions/mime.php');
26 require_once(SM_PATH
. 'include/load_prefs.php');
29 sqgetGlobalVar('username', $username, SQ_SESSION
);
30 sqgetGlobalVar('key', $key, SQ_COOKIE
);
31 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
33 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
);
34 sqgetGlobalVar('mailbox', $mailbox, SQ_GET
);
35 sqgetGlobalVar('ent_id', $ent_id, SQ_GET
);
36 sqgetGlobalVar('startMessage', $startMessage, SQ_GET
);
39 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
40 sqimap_mailbox_select($imapConnection, $mailbox);
43 displayPageHeader($color, 'None');
45 echo '<br><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
46 'align="center">' . "\n" .
47 '<tr><td bgcolor="' . $color[0] . '">' .
49 _("Viewing a Business Card") . " - ";
50 $msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
51 '&startMessage='.urlencode($startMessage).
52 '&passed_id='.urlencode($passed_id);
54 $msg_url = set_url_var($msg_url, 'ent_id', 0);
56 echo '<a href="'.$msg_url.'">'. _("View message") . '</a>';
58 echo '</center></b></td></tr>';
60 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
62 $entity_vcard = getEntity($message,$ent_id);
64 $vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id);
65 $vcard = decodeBody($vcard, $entity_vcard->header
->encoding
);
66 $vcard = explode ("\n",$vcard);
67 foreach ($vcard as $l) {
68 $k = substr($l, 0, strpos($l, ':'));
69 $v = substr($l, strpos($l, ':') +
1);
70 $attributes = explode(';', $k);
71 $k = strtolower(array_shift($attributes));
72 foreach ($attributes as $attr) {
73 if ($attr == 'quoted-printable')
74 $v = quoted_printable_decode($v);
76 $k .= ';' . strtolower($attr);
79 $v = str_replace(';', "\n", $v);
83 if ($vcard_nice['version'] == '2.1') {
84 // get firstname and lastname for sm addressbook
85 $vcard_nice['firstname'] = substr($vcard_nice['n'],
86 strpos($vcard_nice['n'], "\n") +
1, strlen($vcard_nice['n']));
87 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
88 strpos($vcard_nice['n'], "\n"));
89 // workaround for Outlook, should be fixed in a better way,
90 // maybe in new 'vCard' class.
91 if (isset($vcard_nice['email;pref;internet'])) {
92 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
95 echo '<tr><td align="center">' .
96 sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."),$vcard_nice['version']) .
100 foreach ($vcard_nice as $k => $v) {
101 $v = htmlspecialchars($v);
103 $vcard_safe[$k] = trim(nl2br($v));
108 'title' => _("Title"),
109 'email;internet' => _("Email"),
110 'url' => _("Web Page"),
111 'org' => _("Organization / Department"),
112 'adr' => _("Address"),
113 'tel;work' => _("Work Phone"),
114 'tel;home' => _("Home Phone"),
115 'tel;cell' => _("Cellular Phone"),
116 'tel;fax' => _("Fax"),
117 'note' => _("Note"));
119 echo '<tr><td><br>' .
120 '<TABLE border=0 cellpadding=2 cellspacing=0 align=center>' . "\n";
122 if (isset($vcard_safe['email;internet'])) {
123 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
124 $vcard_safe['email;internet']);
127 if (isset($vcard_safe['url'])) {
128 $vcard_safe['url'] = '<A HREF="' . $vcard_safe['url'] . '">' .
129 $vcard_safe['url'] . '</A>';
132 foreach ($ShowValues as $k => $v) {
133 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
134 echo "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] .
141 '</td></tr></table>' .
142 '<table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
145 '<td bgcolor="' . $color[0] . '">' .
147 _("Add to Addressbook") .
149 '<tr><td align=center>' .
150 addForm('../src/addressbook.php', 'POST', 'f_add') .
151 '<table border=0 cellpadding=2 cellspacing=0 align=center>' .
152 '<tr><td align=right><b>Nickname:</b></td>' .
154 addInput('addaddr[nickname]', $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'], '20').
156 '<tr><td align=right><b>Note Field Contains:</b></td><td>' ;
159 if (isset($vcard_nice['url'])) {
160 $opts[$vcard_nice['url']] = _("Web Page");
162 if (isset($vcard_nice['adr'])) {
163 $opts[$vcard_nice['adr']] = _("Address");
165 if (isset($vcard_nice['title'])) {
166 $opts[$vcard_nice['title']] = _("Title");
168 if (isset($vcard_nice['org'])) {
169 $opts[$vcard_nice['org']] = _("Organization / Department");
171 if (isset($vcard_nice['title'])) {
172 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
174 if (isset($vcard_nice['tel;work'])) {
175 $opts[$vcard_nice['tel;work']] = _("Work Phone");
177 if (isset($vcard_nice['tel;home'])) {
178 $opts[$vcard_nice['tel;home']] = _("Home Phone");
180 if (isset($vcard_nice['tel;cell'])) {
181 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
183 if (isset($vcard_nice['tel;fax'])) {
184 $opts[$vcard_nice['tel;fax']] = _("Fax");
186 if (isset($vcard_nice['note'])) {
187 $opts[$vcard_nice['note']] = _("Note");
190 echo addSelect('addaddr[label]', $opts, '', TRUE);
192 '<tr><td colspan=2 align=center>' .
193 addHidden('addaddr[email]', $vcard_nice['email;internet']).
194 addHidden('addaddr[firstname]', $vcard_safe['firstname']).
195 addHidden('addaddr[lastname]', $vcard_safe['lastname']).
196 addSubmit(_("Add to Address Book"), 'addaddr[SUBMIT]').
201 '<tr><td align=center>' .
202 '<a href="../src/download.php?absolute_dl=true&passed_id=' .
203 urlencode($passed_id) . '&mailbox=' . urlencode($mailbox) .
204 '&ent_id=' . urlencode($ent_id) . '">' .
205 _("Download this as a file") . '</A>' .
206 '</TD></TR></TABLE>' .
208 '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>' .
209 '<TR><TD BGCOLOR="' . $color[4] . '">' .
210 '</TD></TR></TABLE>' .