7baf86a9 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * vcard.php |
5 | * |
6c84ba1e |
6 | * Copyright (c) 1999-2005 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 | * |
30967a1e |
11 | * @version $Id$ |
8f6f9ba5 |
12 | * @package squirrelmail |
35586184 |
13 | */ |
7baf86a9 |
14 | |
30967a1e |
15 | /** |
16 | * Path for SquirrelMail required files. |
17 | * @ignore |
18 | */ |
846a3a21 |
19 | Define('SM_PATH','../'); |
86725763 |
20 | |
21 | /* SquirrelMail required files. */ |
08185f2a |
22 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
23 | require_once(SM_PATH . 'functions/mime.php'); |
916669ad |
24 | require_once(SM_PATH . 'functions/url_parser.php'); |
7baf86a9 |
25 | |
0b97a708 |
26 | /* globals */ |
f38b7cf0 |
27 | sqgetGlobalVar('username', $username, SQ_SESSION); |
28 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
29 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
30 | |
31 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
32 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
33 | sqgetGlobalVar('ent_id', $ent_id, SQ_GET); |
34 | sqgetGlobalVar('startMessage', $startMessage, SQ_GET); |
0b97a708 |
35 | /* end globals */ |
36 | |
65c3ec94 |
37 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
38 | sqimap_mailbox_select($imapConnection, $mailbox); |
7baf86a9 |
39 | |
65c3ec94 |
40 | displayPageHeader($color, 'None'); |
7baf86a9 |
41 | |
3c621ba1 |
42 | echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' . |
43 | 'align="center">' . "\n" . |
d444fa27 |
44 | '<tr><td bgcolor="' . $color[0] . '"><b><center>' . |
3c621ba1 |
45 | _("Viewing a Business Card") . " - "; |
46 | |
33c8b76b |
47 | $msg_url = 'read_body.php?mailbox='.urlencode($mailbox). |
164584f0 |
48 | '&startMessage='.urlencode($startMessage). |
49 | '&passed_id='.urlencode($passed_id); |
33c8b76b |
50 | |
24d16195 |
51 | $msg_url = set_url_var($msg_url, 'ent_id', 0); |
33c8b76b |
52 | |
d444fa27 |
53 | echo '<a href="'.$msg_url.'">'. _("View message") . '</a>' . |
54 | '</center></b></td></tr>'; |
65c3ec94 |
55 | |
56 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
57 | |
24d16195 |
58 | $entity_vcard = getEntity($message,$ent_id); |
65c3ec94 |
59 | |
d444fa27 |
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 { |
89ac34a4 |
91 | echo '<tr><td align="center">' . |
1bae252c |
92 | sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."), |
93 | htmlspecialchars($vcard_nice['version'])) . |
134e4174 |
94 | "</td></tr>\n"; |
d543fbac |
95 | $vcard_nice['firstname'] = ''; |
96 | $vcard_nice['lastname'] = ''; |
65c3ec94 |
97 | } |
98 | |
99 | foreach ($vcard_nice as $k => $v) { |
100 | $v = htmlspecialchars($v); |
101 | $v = trim($v); |
102 | $vcard_safe[$k] = trim(nl2br($v)); |
103 | } |
104 | |
105 | $ShowValues = array( |
106 | 'fn' => _("Name"), |
107 | 'title' => _("Title"), |
108 | 'email;internet' => _("Email"), |
109 | 'url' => _("Web Page"), |
110 | 'org' => _("Organization / Department"), |
111 | 'adr' => _("Address"), |
112 | 'tel;work' => _("Work Phone"), |
113 | 'tel;home' => _("Home Phone"), |
114 | 'tel;cell' => _("Cellular Phone"), |
115 | 'tel;fax' => _("Fax"), |
116 | 'note' => _("Note")); |
117 | |
3c621ba1 |
118 | echo '<tr><td><br />' . |
119 | '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n"; |
65c3ec94 |
120 | |
d62c4938 |
121 | if (isset($vcard_safe['email;internet'])) { |
122 | $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']), |
123 | $vcard_safe['email;internet']); |
65c3ec94 |
124 | } |
d62c4938 |
125 | |
65c3ec94 |
126 | if (isset($vcard_safe['url'])) { |
3c621ba1 |
127 | $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' . |
128 | $vcard_safe['url'] . '</a>'; |
65c3ec94 |
129 | } |
130 | |
131 | foreach ($ShowValues as $k => $v) { |
132 | if (isset($vcard_safe[$k]) && $vcard_safe[$k]) { |
d444fa27 |
133 | echo "<tr><td align=\"right\" valign=\"top\"><b>$v:</b></td><td>" . |
134 | $vcard_safe[$k] . "</td><tr>\n"; |
65c3ec94 |
135 | } |
136 | } |
7baf86a9 |
137 | |
d444fa27 |
138 | ?> |
139 | </table> |
140 | <br /> |
141 | </td></tr></table> |
142 | <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center"> |
143 | <tr><td bgcolor="<?php echo $color[0]; ?>"> |
144 | <center><b><?php echo _("Add to Addressbook"); ?></b></center> |
145 | </td></tr> |
146 | <tr><td align="center"> |
147 | <?php echo addForm('../src/addressbook.php', 'post', 'f_add'); ?><br /> |
148 | <table border="0" cellpadding="2" cellspacing="0" align="center"> |
149 | <tr><td align="right"><b><?php echo _("Nickname"); ?>:</b></td> |
150 | <td> |
151 | <?php |
152 | |
153 | echo addInput('addaddr[nickname]', $vcard_safe['firstname'] . |
154 | '-' . $vcard_safe['lastname'], '20'); |
155 | |
156 | /* |
916669ad |
157 | * If the vCard comes with an e-mail address it should be added to the |
d444fa27 |
158 | * address book, otherwise the user must add one manually to avoid an |
916669ad |
159 | * error message in src/addressbook.php. SquirrelMail is nice enough to |
160 | * suggest the e-mail address of the sender though. |
d444fa27 |
161 | */ |
162 | if (isset($vcard_nice['email;internet'])) { |
163 | echo addHidden('addaddr[email]', $vcard_nice['email;internet']); |
164 | } else { |
916669ad |
165 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
166 | $header = $message->rfc822_header; |
167 | $from_name = $header->getAddr_s('from'); |
168 | |
d444fa27 |
169 | echo '</td></tr>' . |
170 | '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' . |
916669ad |
171 | addInput('addaddr[email]', |
172 | getEmail(decodeHeader($from_name)), '20'); |
d444fa27 |
173 | } |
174 | |
175 | echo '</td></tr>' . |
176 | '<tr><td align="right"><b>' . _("Additional info") . ':</b></td><td>'; |
7baf86a9 |
177 | |
64c9e87e |
178 | $opts = array(); |
65c3ec94 |
179 | if (isset($vcard_nice['url'])) { |
64c9e87e |
180 | $opts[$vcard_nice['url']] = _("Web Page"); |
65c3ec94 |
181 | } |
182 | if (isset($vcard_nice['adr'])) { |
64c9e87e |
183 | $opts[$vcard_nice['adr']] = _("Address"); |
65c3ec94 |
184 | } |
185 | if (isset($vcard_nice['title'])) { |
64c9e87e |
186 | $opts[$vcard_nice['title']] = _("Title"); |
65c3ec94 |
187 | } |
188 | if (isset($vcard_nice['org'])) { |
64c9e87e |
189 | $opts[$vcard_nice['org']] = _("Organization / Department"); |
65c3ec94 |
190 | } |
191 | if (isset($vcard_nice['title'])) { |
64c9e87e |
192 | $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept."); |
65c3ec94 |
193 | } |
194 | if (isset($vcard_nice['tel;work'])) { |
64c9e87e |
195 | $opts[$vcard_nice['tel;work']] = _("Work Phone"); |
65c3ec94 |
196 | } |
197 | if (isset($vcard_nice['tel;home'])) { |
64c9e87e |
198 | $opts[$vcard_nice['tel;home']] = _("Home Phone"); |
65c3ec94 |
199 | } |
200 | if (isset($vcard_nice['tel;cell'])) { |
64c9e87e |
201 | $opts[$vcard_nice['tel;cell']] = _("Cellular Phone"); |
65c3ec94 |
202 | } |
203 | if (isset($vcard_nice['tel;fax'])) { |
64c9e87e |
204 | $opts[$vcard_nice['tel;fax']] = _("Fax"); |
65c3ec94 |
205 | } |
206 | if (isset($vcard_nice['note'])) { |
64c9e87e |
207 | $opts[$vcard_nice['note']] = _("Note"); |
65c3ec94 |
208 | } |
64c9e87e |
209 | |
d444fa27 |
210 | /* |
211 | * If the vcard comes with nothing but name and e-mail address, the user gets |
212 | * the chance to type some additional info. If there's more info in the card, |
213 | * the user gets to choose what will be added as additional info. |
214 | */ |
215 | if (count($opts) == 0) { |
216 | echo addInput('addaddr[label]', '', '20'); |
217 | } else { |
218 | echo addSelect('addaddr[label]', $opts, '', TRUE); |
219 | } |
220 | |
2841ba15 |
221 | ?> |
222 | </td></tr> |
d444fa27 |
223 | <tr><td colspan="2" align="center"><br /> |
2841ba15 |
224 | <?php |
6b2eed75 |
225 | |
d444fa27 |
226 | echo addHidden('addaddr[firstname]', $vcard_safe['firstname']) . |
227 | addHidden('addaddr[lastname]', $vcard_safe['lastname']) . |
228 | addSubmit(_("Add to Address Book"), 'addaddr[SUBMIT]'); |
229 | |
2841ba15 |
230 | ?> |
231 | </td></tr> |
232 | </table> |
233 | </form> |
234 | </td></tr> |
235 | <tr><td align="center"> |
236 | <?php |
d444fa27 |
237 | echo '<a href="../src/download.php?absolute_dl=true&passed_id=' . |
2841ba15 |
238 | urlencode($passed_id) . '&mailbox=' . urlencode($mailbox) . |
d444fa27 |
239 | '&ent_id=' . urlencode($ent_id) . '">' . |
2841ba15 |
240 | _("Download this as a file") . '</a>'; |
241 | ?> |
242 | </td></tr></table> |
2841ba15 |
243 | <table border="0" cellspacing="0" cellpadding="2" align="center"> |
244 | <tr><td bgcolor="<?php echo $color[4]; ?>"> |
245 | </td></tr></table> |
916669ad |
246 | </body></html> |