fix for forward as attachment from the messagelist
[squirrelmail.git] / src / vcard.php
CommitLineData
7baf86a9 1<?php
895905c0 2
35586184 3/**
4 * vcard.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file shows an attched vcard
10 *
11 * $Id$
12 */
7baf86a9 13
86725763 14/* Path for SquirrelMail required files. */
15define('SM_PATH','../');
16
17/* SquirrelMail required files. */
08185f2a 18require_once(SM_PATH . 'include/validate.php');
86725763 19require_once(SM_PATH . 'functions/date.php');
20require_once(SM_PATH . 'functions/page_header.php');
21require_once(SM_PATH . 'functions/mime.php');
08185f2a 22require_once(SM_PATH . 'include/load_prefs.php');
7baf86a9 23
65c3ec94 24$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
25sqimap_mailbox_select($imapConnection, $mailbox);
7baf86a9 26
27
65c3ec94 28displayPageHeader($color, 'None');
7baf86a9 29
24d16195 30echo '<br><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
31 'align="center">' . "\n" .
32 '<tr><td bgcolor="' . $color[0] . '">' .
7baf86a9 33 '<b><center>' .
24d16195 34 _("Viewing a Business Card") . " - ";
35$msg_url = 'read_body.php?' . $QUERY_STRING;
36$msg_url = set_url_var($msg_url, 'ent_id', 0);
37echo '<a href="'.$msg_url.'">'. _("View message") . '</a>';
38
65c3ec94 39echo '</center></b></td></tr>';
40
41$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
42
24d16195 43$entity_vcard = getEntity($message,$ent_id);
65c3ec94 44
24d16195 45$vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id);
65c3ec94 46$vcard = decodeBody($vcard, $entity_vcard->header->encoding);
47$vcard = explode ("\n",$vcard);
48foreach ($vcard as $l) {
49 $k = substr($l, 0, strpos($l, ':'));
50 $v = substr($l, strpos($l, ':') + 1);
51 $attributes = explode(';', $k);
52 $k = strtolower(array_shift($attributes));
53 foreach ($attributes as $attr) {
54 if ($attr == 'quoted-printable')
55 $v = quoted_printable_decode($v);
56 else
7baf86a9 57 $k .= ';' . $attr;
65c3ec94 58 }
59
0f8a1ce9 60 $v = str_replace(';', "\n", $v);
65c3ec94 61 $vcard_nice[$k] = $v;
62}
63
64if ($vcard_nice['version'] == '2.1') {
65 // get firstname and lastname for sm addressbook
66 $vcard_nice["firstname"] = substr($vcard_nice["n"],
67 strpos($vcard_nice["n"], "\n") + 1, strlen($vcard_nice["n"]));
68 $vcard_nice["lastname"] = substr($vcard_nice["n"], 0,
69 strpos($vcard_nice["n"], "\n"));
70} else {
24d16195 71 echo '<tr><td align=center>vCard Version ' . $vcard_nice['version'] .
72 ' is not supported. Some information might not be converted ' .
73 "correctly.</td></tr>\n";
65c3ec94 74}
75
76foreach ($vcard_nice as $k => $v) {
77 $v = htmlspecialchars($v);
78 $v = trim($v);
79 $vcard_safe[$k] = trim(nl2br($v));
80}
81
82$ShowValues = array(
83 'fn' => _("Name"),
84 'title' => _("Title"),
85 'email;internet' => _("Email"),
86 'url' => _("Web Page"),
87 'org' => _("Organization / Department"),
88 'adr' => _("Address"),
89 'tel;work' => _("Work Phone"),
90 'tel;home' => _("Home Phone"),
91 'tel;cell' => _("Cellular Phone"),
92 'tel;fax' => _("Fax"),
93 'note' => _("Note"));
94
24d16195 95echo '<tr><td><br>' .
96 '<TABLE border=0 cellpadding=2 cellspacing=0 align=center>' . "\n";
65c3ec94 97
24d16195 98if (isset($vcard_safe['email;internet'])) { $vcard_safe['email;internet'] = '<A HREF="../src/compose.php?send_to=' .
65c3ec94 99 $vcard_safe['email;internet'] . '">' . $vcard_safe['email;internet'] .
24d16195 100 '</A>';
65c3ec94 101}
102if (isset($vcard_safe['url'])) {
24d16195 103 $vcard_safe['url'] = '<A HREF="' . $vcard_safe['url'] . '">' .
104 $vcard_safe['url'] . '</A>';
65c3ec94 105}
106
107foreach ($ShowValues as $k => $v) {
108 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
24d16195 109 echo "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] .
110 "</td><tr>\n";
65c3ec94 111 }
112}
7baf86a9 113
65c3ec94 114echo '</table>' .
7baf86a9 115 '<br>' .
116 '</td></tr></table>' .
24d16195 117 '<table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
118 'align="center">' .
119 '<tr>' .
120 '<td bgcolor="' . $color[0] . '">' .
121 '<b><center>' .
122 _("Add to Addressbook") .
123 '</td></tr>' .
124 '<tr><td align=center>' .
125 '<FORM ACTION="../src/addressbook.php" METHOD="POST" NAME=f_add>' .
126 '<table border=0 cellpadding=2 cellspacing=0 align=center>' .
127 '<tr><td align=right><b>Nickname:</b></td>' .
128 '<td><input type=text name="addaddr[nickname]" size=20 value="' .
129 $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'] .
130 '"></td></tr>' .
131 '<tr><td align=right><b>Note Field Contains:</b></td><td>' .
7baf86a9 132 '<select name="addaddr[label]">';
133
65c3ec94 134if (isset($vcard_nice['url'])) {
135 echo '<option value="' . htmlspecialchars($vcard_nice['url']) .
136 '">' . _("Web Page") . "</option>\n";
137}
138if (isset($vcard_nice['adr'])) {
139 echo '<option value="' . $vcard_nice['adr'] .
140 '">' . _("Address") . "</option>\n";
141}
142if (isset($vcard_nice['title'])) {
143 echo '<option value="' . $vcard_nice['title'] .
144 '">' . _("Title") . "</option>\n";
145}
146if (isset($vcard_nice['org'])) {
147 echo '<option value="' . $vcard_nice['org'] .
148 '">' . _("Organization / Department") . "</option>\n";
149}
150if (isset($vcard_nice['title'])) {
151 echo '<option value="' . $vcard_nice['title'] .
152 '; ' . $vcard_nice['org'] .
153 '">' . _("Title & Org. / Dept.") . "</option>\n";
154}
155if (isset($vcard_nice['tel;work'])) {
156 echo '<option value="' . $vcard_nice['tel;work'] .
157 '">' . _("Work Phone") . "</option>\n";
158}
159if (isset($vcard_nice['tel;home'])) {
160 echo '<option value="' . $vcard_nice['tel;home'] .
161 '">' . _("Home Phone") . "</option>\n";
162}
163if (isset($vcard_nice['tel;cell'])) {
164 echo '<option value="' . $vcard_nice['tel;cell'] .
165 '">' . _("Cellular Phone") . "</option>\n";
166}
167if (isset($vcard_nice['tel;fax'])) {
168 echo '<option value="' . $vcard_nice['tel;fax'] .
169 '">' . _("Fax") . "</option>\n";
170}
171if (isset($vcard_nice['note'])) {
172 echo '<option value="' . $vcard_nice['note'] .
173 '">' . _("Note") . "</option>\n";
174}
175echo '</select>' .
7baf86a9 176 '</td></tr>' .
24d16195 177 '<tr><td colspan=2 align=center>' .
178 '<INPUT NAME="addaddr[email]" type=hidden value="' .
179 htmlspecialchars($vcard_nice['email;internet']) . '">' .
180 '<INPUT NAME="addaddr[firstname]" type=hidden value="' .
181 $vcard_safe['firstname'] . '">' .
182 '<INPUT NAME="addaddr[lastname]" type=hidden value="' .
183 $vcard_safe['lastname'] . '">' .
184 '<INPUT TYPE=submit NAME="addaddr[SUBMIT]" ' .
185 'VALUE="Add to Address Book">' .
7baf86a9 186 '</td></tr>' .
fab3baa6 187 '</table>' .
24d16195 188 '</FORM>' .
189 '</td></tr>' .
190 '<tr><td align=center>' .
191 '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
192 $passed_id . '&amp;mailbox=' . urlencode($mailbox) .
193 '&amp;passed_ent_id=' . $passed_ent_id . '">' .
194 _("Download this as a file") . '</A>' .
195 '</TD></TR></TABLE>' .
196
197 '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>' .
198 '<TR><TD BGCOLOR="' . $color[4] . '">' .
199 '</TD></TR></TABLE>' .
7baf86a9 200 '</body></html>';
65c3ec94 201
0f8a1ce9 202?>