7baf86a9 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * vcard.php |
5 | * |
35586184 |
6 | * This file shows an attched vcard |
7 | * |
47ccfad4 |
8 | * @copyright © 1999-2006 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 |
17 | require('../include/init.php'); |
86725763 |
18 | |
19 | /* SquirrelMail required files. */ |
ae299e07 |
20 | |
21 | /** imap functions depend on date functions */ |
22 | include_once(SM_PATH . 'functions/date.php'); |
23 | /** form functions */ |
24 | include_once(SM_PATH . 'functions/forms.php'); |
25 | /** mime decoding */ |
26 | include_once(SM_PATH . 'functions/mime.php'); |
27 | /** url parser */ |
28 | include_once(SM_PATH . 'functions/url_parser.php'); |
29 | /** imap functions used to retrieve vcard */ |
30 | include_once(SM_PATH . 'functions/imap_general.php'); |
31 | include_once(SM_PATH . 'functions/imap_messages.php'); |
7baf86a9 |
32 | |
0b97a708 |
33 | /* globals */ |
f38b7cf0 |
34 | sqgetGlobalVar('username', $username, SQ_SESSION); |
35 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
36 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
37 | |
38 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
39 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
40 | sqgetGlobalVar('ent_id', $ent_id, SQ_GET); |
41 | sqgetGlobalVar('startMessage', $startMessage, SQ_GET); |
0b97a708 |
42 | /* end globals */ |
43 | |
65c3ec94 |
44 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
45 | sqimap_mailbox_select($imapConnection, $mailbox); |
7baf86a9 |
46 | |
65c3ec94 |
47 | displayPageHeader($color, 'None'); |
7baf86a9 |
48 | |
3c621ba1 |
49 | echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' . |
50 | 'align="center">' . "\n" . |
f265009a |
51 | '<tr><td bgcolor="' . $color[0] . '"><b><div style="text-align: center;">' . |
3c621ba1 |
52 | _("Viewing a Business Card") . " - "; |
53 | |
33c8b76b |
54 | $msg_url = 'read_body.php?mailbox='.urlencode($mailbox). |
164584f0 |
55 | '&startMessage='.urlencode($startMessage). |
56 | '&passed_id='.urlencode($passed_id); |
33c8b76b |
57 | |
24d16195 |
58 | $msg_url = set_url_var($msg_url, 'ent_id', 0); |
33c8b76b |
59 | |
d444fa27 |
60 | echo '<a href="'.$msg_url.'">'. _("View message") . '</a>' . |
f265009a |
61 | '</div></b></td></tr>'; |
65c3ec94 |
62 | |
63 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
64 | |
24d16195 |
65 | $entity_vcard = getEntity($message,$ent_id); |
65c3ec94 |
66 | |
d444fa27 |
67 | $vcard = mime_fetch_body($imapConnection, $passed_id, $ent_id); |
65c3ec94 |
68 | $vcard = decodeBody($vcard, $entity_vcard->header->encoding); |
69 | $vcard = explode ("\n",$vcard); |
70 | foreach ($vcard as $l) { |
71 | $k = substr($l, 0, strpos($l, ':')); |
72 | $v = substr($l, strpos($l, ':') + 1); |
73 | $attributes = explode(';', $k); |
74 | $k = strtolower(array_shift($attributes)); |
75 | foreach ($attributes as $attr) { |
76 | if ($attr == 'quoted-printable') |
77 | $v = quoted_printable_decode($v); |
78 | else |
40a9d8b3 |
79 | $k .= ';' . strtolower($attr); |
65c3ec94 |
80 | } |
81 | |
0f8a1ce9 |
82 | $v = str_replace(';', "\n", $v); |
65c3ec94 |
83 | $vcard_nice[$k] = $v; |
84 | } |
85 | |
86 | if ($vcard_nice['version'] == '2.1') { |
87 | // get firstname and lastname for sm addressbook |
40a9d8b3 |
88 | $vcard_nice['firstname'] = substr($vcard_nice['n'], |
89 | strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n'])); |
90 | $vcard_nice['lastname'] = substr($vcard_nice['n'], 0, |
91 | strpos($vcard_nice['n'], "\n")); |
92 | // workaround for Outlook, should be fixed in a better way, |
93 | // maybe in new 'vCard' class. |
94 | if (isset($vcard_nice['email;pref;internet'])) { |
95 | $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet']; |
96 | } |
65c3ec94 |
97 | } else { |
89ac34a4 |
98 | echo '<tr><td align="center">' . |
1bae252c |
99 | sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."), |
100 | htmlspecialchars($vcard_nice['version'])) . |
134e4174 |
101 | "</td></tr>\n"; |
d543fbac |
102 | $vcard_nice['firstname'] = ''; |
103 | $vcard_nice['lastname'] = ''; |
65c3ec94 |
104 | } |
105 | |
106 | foreach ($vcard_nice as $k => $v) { |
107 | $v = htmlspecialchars($v); |
108 | $v = trim($v); |
109 | $vcard_safe[$k] = trim(nl2br($v)); |
110 | } |
111 | |
112 | $ShowValues = array( |
113 | 'fn' => _("Name"), |
114 | 'title' => _("Title"), |
674a2ca2 |
115 | 'email;internet' => _("E-mail"), |
65c3ec94 |
116 | 'url' => _("Web Page"), |
117 | 'org' => _("Organization / Department"), |
118 | 'adr' => _("Address"), |
119 | 'tel;work' => _("Work Phone"), |
120 | 'tel;home' => _("Home Phone"), |
121 | 'tel;cell' => _("Cellular Phone"), |
122 | 'tel;fax' => _("Fax"), |
123 | 'note' => _("Note")); |
124 | |
3c621ba1 |
125 | echo '<tr><td><br />' . |
126 | '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n"; |
65c3ec94 |
127 | |
d62c4938 |
128 | if (isset($vcard_safe['email;internet'])) { |
129 | $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']), |
130 | $vcard_safe['email;internet']); |
65c3ec94 |
131 | } |
d62c4938 |
132 | |
65c3ec94 |
133 | if (isset($vcard_safe['url'])) { |
3c621ba1 |
134 | $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' . |
135 | $vcard_safe['url'] . '</a>'; |
65c3ec94 |
136 | } |
137 | |
138 | foreach ($ShowValues as $k => $v) { |
139 | if (isset($vcard_safe[$k]) && $vcard_safe[$k]) { |
d444fa27 |
140 | echo "<tr><td align=\"right\" valign=\"top\"><b>$v:</b></td><td>" . |
141 | $vcard_safe[$k] . "</td><tr>\n"; |
65c3ec94 |
142 | } |
143 | } |
7baf86a9 |
144 | |
d444fa27 |
145 | ?> |
146 | </table> |
147 | <br /> |
148 | </td></tr></table> |
149 | <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center"> |
150 | <tr><td bgcolor="<?php echo $color[0]; ?>"> |
f265009a |
151 | <div style="text-align: center;"><b><?php echo _("Add to address book"); ?></b></div> |
d444fa27 |
152 | </td></tr> |
153 | <tr><td align="center"> |
154 | <?php echo addForm('../src/addressbook.php', 'post', 'f_add'); ?><br /> |
155 | <table border="0" cellpadding="2" cellspacing="0" align="center"> |
156 | <tr><td align="right"><b><?php echo _("Nickname"); ?>:</b></td> |
157 | <td> |
158 | <?php |
159 | |
160 | echo addInput('addaddr[nickname]', $vcard_safe['firstname'] . |
161 | '-' . $vcard_safe['lastname'], '20'); |
162 | |
163 | /* |
916669ad |
164 | * If the vCard comes with an e-mail address it should be added to the |
d444fa27 |
165 | * address book, otherwise the user must add one manually to avoid an |
916669ad |
166 | * error message in src/addressbook.php. SquirrelMail is nice enough to |
167 | * suggest the e-mail address of the sender though. |
d444fa27 |
168 | */ |
169 | if (isset($vcard_nice['email;internet'])) { |
170 | echo addHidden('addaddr[email]', $vcard_nice['email;internet']); |
171 | } else { |
916669ad |
172 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
173 | $header = $message->rfc822_header; |
174 | $from_name = $header->getAddr_s('from'); |
175 | |
d444fa27 |
176 | echo '</td></tr>' . |
177 | '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' . |
916669ad |
178 | addInput('addaddr[email]', |
179 | getEmail(decodeHeader($from_name)), '20'); |
d444fa27 |
180 | } |
181 | |
182 | echo '</td></tr>' . |
183 | '<tr><td align="right"><b>' . _("Additional info") . ':</b></td><td>'; |
7baf86a9 |
184 | |
64c9e87e |
185 | $opts = array(); |
65c3ec94 |
186 | if (isset($vcard_nice['url'])) { |
64c9e87e |
187 | $opts[$vcard_nice['url']] = _("Web Page"); |
65c3ec94 |
188 | } |
189 | if (isset($vcard_nice['adr'])) { |
64c9e87e |
190 | $opts[$vcard_nice['adr']] = _("Address"); |
65c3ec94 |
191 | } |
192 | if (isset($vcard_nice['title'])) { |
64c9e87e |
193 | $opts[$vcard_nice['title']] = _("Title"); |
65c3ec94 |
194 | } |
195 | if (isset($vcard_nice['org'])) { |
64c9e87e |
196 | $opts[$vcard_nice['org']] = _("Organization / Department"); |
65c3ec94 |
197 | } |
198 | if (isset($vcard_nice['title'])) { |
407e7032 |
199 | $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept."); |
65c3ec94 |
200 | } |
201 | if (isset($vcard_nice['tel;work'])) { |
64c9e87e |
202 | $opts[$vcard_nice['tel;work']] = _("Work Phone"); |
65c3ec94 |
203 | } |
204 | if (isset($vcard_nice['tel;home'])) { |
64c9e87e |
205 | $opts[$vcard_nice['tel;home']] = _("Home Phone"); |
65c3ec94 |
206 | } |
207 | if (isset($vcard_nice['tel;cell'])) { |
64c9e87e |
208 | $opts[$vcard_nice['tel;cell']] = _("Cellular Phone"); |
65c3ec94 |
209 | } |
210 | if (isset($vcard_nice['tel;fax'])) { |
64c9e87e |
211 | $opts[$vcard_nice['tel;fax']] = _("Fax"); |
65c3ec94 |
212 | } |
213 | if (isset($vcard_nice['note'])) { |
64c9e87e |
214 | $opts[$vcard_nice['note']] = _("Note"); |
65c3ec94 |
215 | } |
64c9e87e |
216 | |
d444fa27 |
217 | /* |
218 | * If the vcard comes with nothing but name and e-mail address, the user gets |
219 | * the chance to type some additional info. If there's more info in the card, |
220 | * the user gets to choose what will be added as additional info. |
221 | */ |
222 | if (count($opts) == 0) { |
223 | echo addInput('addaddr[label]', '', '20'); |
224 | } else { |
225 | echo addSelect('addaddr[label]', $opts, '', TRUE); |
226 | } |
227 | |
2841ba15 |
228 | ?> |
229 | </td></tr> |
d444fa27 |
230 | <tr><td colspan="2" align="center"><br /> |
2841ba15 |
231 | <?php |
6b2eed75 |
232 | |
d444fa27 |
233 | echo addHidden('addaddr[firstname]', $vcard_safe['firstname']) . |
234 | addHidden('addaddr[lastname]', $vcard_safe['lastname']) . |
674a2ca2 |
235 | addSubmit(_("Add to address book"), 'addaddr[SUBMIT]'); |
d444fa27 |
236 | |
2841ba15 |
237 | ?> |
238 | </td></tr> |
239 | </table> |
240 | </form> |
241 | </td></tr> |
242 | <tr><td align="center"> |
243 | <?php |
d444fa27 |
244 | echo '<a href="../src/download.php?absolute_dl=true&passed_id=' . |
2841ba15 |
245 | urlencode($passed_id) . '&mailbox=' . urlencode($mailbox) . |
d444fa27 |
246 | '&ent_id=' . urlencode($ent_id) . '">' . |
2841ba15 |
247 | _("Download this as a file") . '</a>'; |
248 | ?> |
249 | </td></tr></table> |
2841ba15 |
250 | <table border="0" cellspacing="0" cellpadding="2" align="center"> |
251 | <tr><td bgcolor="<?php echo $color[4]; ?>"> |
252 | </td></tr></table> |
5c4ff7bf |
253 | <?php |
254 | $oTemplate->display('footer.tpl'); |
202bcbcc |
255 | ?> |