6 * This file shows an attched vcard
8 * @copyright © 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
15 * Path for SquirrelMail required files.
18 Define('SM_PATH','../');
20 /* SquirrelMail required files. */
21 include_once(SM_PATH
. 'include/validate.php');
22 require_once(SM_PATH
. 'functions/mime.php');
23 require_once(SM_PATH
. 'functions/url_parser.php');
26 sqgetGlobalVar('username', $username, SQ_SESSION
);
27 sqgetGlobalVar('key', $key, SQ_COOKIE
);
28 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
30 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
);
31 sqgetGlobalVar('mailbox', $mailbox, SQ_GET
);
32 sqgetGlobalVar('ent_id', $ent_id, SQ_GET
);
33 sqgetGlobalVar('startMessage', $startMessage, SQ_GET
);
36 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
37 sqimap_mailbox_select($imapConnection, $mailbox);
39 displayPageHeader($color, 'None');
41 echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
42 'align="center">' . "\n" .
43 '<tr><td bgcolor="' . $color[0] . '"><b><div style="text-align: center;">' .
44 _("Viewing a Business Card") . " - ";
46 $msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
47 '&startMessage='.urlencode($startMessage).
48 '&passed_id='.urlencode($passed_id);
50 $msg_url = set_url_var($msg_url, 'ent_id', 0);
52 echo '<a href="'.$msg_url.'">'. _("View message") . '</a>' .
53 '</div></b></td></tr>';
55 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
57 $entity_vcard = getEntity($message,$ent_id);
59 $vcard = mime_fetch_body($imapConnection, $passed_id, $ent_id);
60 $vcard = decodeBody($vcard, $entity_vcard->header
->encoding
);
61 $vcard = explode ("\n",$vcard);
62 foreach ($vcard as $l) {
63 $k = substr($l, 0, strpos($l, ':'));
64 $v = substr($l, strpos($l, ':') +
1);
65 $attributes = explode(';', $k);
66 $k = strtolower(array_shift($attributes));
67 foreach ($attributes as $attr) {
68 if ($attr == 'quoted-printable')
69 $v = quoted_printable_decode($v);
71 $k .= ';' . strtolower($attr);
74 $v = str_replace(';', "\n", $v);
78 if ($vcard_nice['version'] == '2.1') {
79 // get firstname and lastname for sm addressbook
80 $vcard_nice['firstname'] = substr($vcard_nice['n'],
81 strpos($vcard_nice['n'], "\n") +
1, strlen($vcard_nice['n']));
82 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
83 strpos($vcard_nice['n'], "\n"));
84 // workaround for Outlook, should be fixed in a better way,
85 // maybe in new 'vCard' class.
86 if (isset($vcard_nice['email;pref;internet'])) {
87 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
90 echo '<tr><td align="center">' .
91 sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."),
92 htmlspecialchars($vcard_nice['version'])) .
94 $vcard_nice['firstname'] = '';
95 $vcard_nice['lastname'] = '';
98 foreach ($vcard_nice as $k => $v) {
99 $v = htmlspecialchars($v);
101 $vcard_safe[$k] = trim(nl2br($v));
106 'title' => _("Title"),
107 'email;internet' => _("E-mail"),
108 'url' => _("Web Page"),
109 'org' => _("Organization / Department"),
110 'adr' => _("Address"),
111 'tel;work' => _("Work Phone"),
112 'tel;home' => _("Home Phone"),
113 'tel;cell' => _("Cellular Phone"),
114 'tel;fax' => _("Fax"),
115 'note' => _("Note"));
117 echo '<tr><td><br />' .
118 '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n";
120 if (isset($vcard_safe['email;internet'])) {
121 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
122 $vcard_safe['email;internet']);
125 if (isset($vcard_safe['url'])) {
126 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' .
127 $vcard_safe['url'] . '</a>';
130 foreach ($ShowValues as $k => $v) {
131 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
132 echo "<tr><td align=\"right\" valign=\"top\"><b>$v:</b></td><td>" .
133 $vcard_safe[$k] . "</td><tr>\n";
141 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="2" align
="center">
142 <tr
><td bgcolor
="<?php echo $color[0]; ?>">
143 <div style
="text-align: center;"><b
><?php
echo _("Add to address book"); ?
></b
></div
>
145 <tr
><td align
="center">
146 <?php
echo addForm('../src/addressbook.php', 'post', 'f_add'); ?
><br
/>
147 <table border
="0" cellpadding
="2" cellspacing
="0" align
="center">
148 <tr
><td align
="right"><b
><?php
echo _("Nickname"); ?
>:</b
></td
>
152 echo addInput('addaddr[nickname]', $vcard_safe['firstname'] .
153 '-' . $vcard_safe['lastname'], '20');
156 * If the vCard comes with an e-mail address it should be added to the
157 * address book, otherwise the user must add one manually to avoid an
158 * error message in src/addressbook.php. SquirrelMail is nice enough to
159 * suggest the e-mail address of the sender though.
161 if (isset($vcard_nice['email;internet'])) {
162 echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
164 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
165 $header = $message->rfc822_header
;
166 $from_name = $header->getAddr_s('from');
169 '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' .
170 addInput('addaddr[email]',
171 getEmail(decodeHeader($from_name)), '20');
175 '<tr><td align="right"><b>' . _("Additional info") . ':</b></td><td>';
178 if (isset($vcard_nice['url'])) {
179 $opts[$vcard_nice['url']] = _("Web Page");
181 if (isset($vcard_nice['adr'])) {
182 $opts[$vcard_nice['adr']] = _("Address");
184 if (isset($vcard_nice['title'])) {
185 $opts[$vcard_nice['title']] = _("Title");
187 if (isset($vcard_nice['org'])) {
188 $opts[$vcard_nice['org']] = _("Organization / Department");
190 if (isset($vcard_nice['title'])) {
191 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
193 if (isset($vcard_nice['tel;work'])) {
194 $opts[$vcard_nice['tel;work']] = _("Work Phone");
196 if (isset($vcard_nice['tel;home'])) {
197 $opts[$vcard_nice['tel;home']] = _("Home Phone");
199 if (isset($vcard_nice['tel;cell'])) {
200 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
202 if (isset($vcard_nice['tel;fax'])) {
203 $opts[$vcard_nice['tel;fax']] = _("Fax");
205 if (isset($vcard_nice['note'])) {
206 $opts[$vcard_nice['note']] = _("Note");
210 * If the vcard comes with nothing but name and e-mail address, the user gets
211 * the chance to type some additional info. If there's more info in the card,
212 * the user gets to choose what will be added as additional info.
214 if (count($opts) == 0) {
215 echo addInput('addaddr[label]', '', '20');
217 echo addSelect('addaddr[label]', $opts, '', TRUE);
222 <tr
><td colspan
="2" align
="center"><br
/>
225 echo addHidden('addaddr[firstname]', $vcard_safe['firstname']) .
226 addHidden('addaddr[lastname]', $vcard_safe['lastname']) .
227 addSubmit(_("Add to address book"), 'addaddr[SUBMIT]');
234 <tr
><td align
="center">
236 echo '<a href="../src/download.php?absolute_dl=true&passed_id=' .
237 urlencode($passed_id) . '&mailbox=' . urlencode($mailbox) .
238 '&ent_id=' . urlencode($ent_id) . '">' .
239 _("Download this as a file") . '</a>';
242 <table border
="0" cellspacing
="0" cellpadding
="2" align
="center">
243 <tr
><td bgcolor
="<?php echo $color[4]; ?>">
246 $oTemplate->display('footer.tpl');