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