6 * Copyright (c) 1999-2005 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/mime.php');
24 require_once(SM_PATH
. 'functions/url_parser.php');
27 sqgetGlobalVar('username', $username, SQ_SESSION
);
28 sqgetGlobalVar('key', $key, SQ_COOKIE
);
29 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
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
);
37 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
38 sqimap_mailbox_select($imapConnection, $mailbox);
40 displayPageHeader($color, 'None');
42 echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
43 'align="center">' . "\n" .
44 '<tr><td bgcolor="' . $color[0] . '"><b><center>' .
45 _("Viewing a Business Card") . " - ";
47 $msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
48 '&startMessage='.urlencode($startMessage).
49 '&passed_id='.urlencode($passed_id);
51 $msg_url = set_url_var($msg_url, 'ent_id', 0);
53 echo '<a href="'.$msg_url.'">'. _("View message") . '</a>' .
54 '</center></b></td></tr>';
56 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
58 $entity_vcard = getEntity($message,$ent_id);
60 $vcard = mime_fetch_body($imapConnection, $passed_id, $ent_id);
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);
72 $k .= ';' . strtolower($attr);
75 $v = str_replace(';', "\n", $v);
79 if ($vcard_nice['version'] == '2.1') {
80 // get firstname and lastname for sm addressbook
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'];
91 echo '<tr><td align="center">' .
92 sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."),
93 htmlspecialchars($vcard_nice['version'])) .
95 $vcard_nice['firstname'] = '';
96 $vcard_nice['lastname'] = '';
99 foreach ($vcard_nice as $k => $v) {
100 $v = htmlspecialchars($v);
102 $vcard_safe[$k] = trim(nl2br($v));
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"));
118 echo '<tr><td><br />' .
119 '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n";
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']);
126 if (isset($vcard_safe['url'])) {
127 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' .
128 $vcard_safe['url'] . '</a>';
131 foreach ($ShowValues as $k => $v) {
132 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
133 echo "<tr><td align=\"right\" valign=\"top\"><b>$v:</b></td><td>" .
134 $vcard_safe[$k] . "</td><tr>\n";
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
>
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
>
153 echo addInput('addaddr[nickname]', $vcard_safe['firstname'] .
154 '-' . $vcard_safe['lastname'], '20');
157 * If the vCard comes with an e-mail address it should be added to the
158 * address book, otherwise the user must add one manually to avoid an
159 * error message in src/addressbook.php. SquirrelMail is nice enough to
160 * suggest the e-mail address of the sender though.
162 if (isset($vcard_nice['email;internet'])) {
163 echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
165 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
166 $header = $message->rfc822_header
;
167 $from_name = $header->getAddr_s('from');
170 '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' .
171 addInput('addaddr[email]',
172 getEmail(decodeHeader($from_name)), '20');
176 '<tr><td align="right"><b>' . _("Additional info") . ':</b></td><td>';
179 if (isset($vcard_nice['url'])) {
180 $opts[$vcard_nice['url']] = _("Web Page");
182 if (isset($vcard_nice['adr'])) {
183 $opts[$vcard_nice['adr']] = _("Address");
185 if (isset($vcard_nice['title'])) {
186 $opts[$vcard_nice['title']] = _("Title");
188 if (isset($vcard_nice['org'])) {
189 $opts[$vcard_nice['org']] = _("Organization / Department");
191 if (isset($vcard_nice['title'])) {
192 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
194 if (isset($vcard_nice['tel;work'])) {
195 $opts[$vcard_nice['tel;work']] = _("Work Phone");
197 if (isset($vcard_nice['tel;home'])) {
198 $opts[$vcard_nice['tel;home']] = _("Home Phone");
200 if (isset($vcard_nice['tel;cell'])) {
201 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
203 if (isset($vcard_nice['tel;fax'])) {
204 $opts[$vcard_nice['tel;fax']] = _("Fax");
206 if (isset($vcard_nice['note'])) {
207 $opts[$vcard_nice['note']] = _("Note");
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.
215 if (count($opts) == 0) {
216 echo addInput('addaddr[label]', '', '20');
218 echo addSelect('addaddr[label]', $opts, '', TRUE);
223 <tr
><td colspan
="2" align
="center"><br
/>
226 echo addHidden('addaddr[firstname]', $vcard_safe['firstname']) .
227 addHidden('addaddr[lastname]', $vcard_safe['lastname']) .
228 addSubmit(_("Add to Address Book"), 'addaddr[SUBMIT]');
235 <tr
><td align
="center">
237 echo '<a href="../src/download.php?absolute_dl=true&passed_id=' .
238 urlencode($passed_id) . '&mailbox=' . urlencode($mailbox) .
239 '&ent_id=' . urlencode($ent_id) . '">' .
240 _("Download this as a file") . '</a>';
243 <table border
="0" cellspacing
="0" cellpadding
="2" align
="center">
244 <tr
><td bgcolor
="<?php echo $color[4]; ?>">