Fix download link for vcard.
[squirrelmail.git] / src / vcard.php
index e6343006b2804e278a9a9cea0d44219db3cc6a68..cd104b9a6c98e87bd50997b15ffceba0ba08b30f 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * vcard.php
  *
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2003 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This file shows an attched vcard
  * $Id$
  */
 
-require_once('../src/validate.php');
-require_once('../functions/date.php');
-require_once('../functions/page_header.php');
-require_once('../functions/mime.php');
-require_once('../src/load_prefs.php');
+/* Path for SquirrelMail required files. */
+Define('SM_PATH','../');
+
+/* SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/date.php');
+require_once(SM_PATH . 'functions/page_header.php');
+require_once(SM_PATH . 'functions/mime.php');
+require_once(SM_PATH . 'include/load_prefs.php');
+
+/* globals */
+$key  = $_COOKIE['key'];
+$username = $_SESSION['username'];
+$onetimepad = $_SESSION['onetimepad'];
+$mailbox = urldecode($_GET['mailbox']);
+$passed_id = (int) $_GET['passed_id'];
+$ent_id = $_GET['ent_id'];
+$startMessage = (int) $_GET['startMessage'];
+/* end globals */
 
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 sqimap_mailbox_select($imapConnection, $mailbox);
@@ -28,23 +42,21 @@ echo '<br><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
         '<tr><td bgcolor="' . $color[0] . '">' .
         '<b><center>' .
         _("Viewing a Business Card") . " - ";
-if (isset($where) && isset($what)) {
-    // from a search
-    echo '<a href="../src/read_body.php?mailbox=' . urlencode($mailbox) .
-            '&amp;passed_id=' . $passed_id . '&amp;where=' . urlencode($where) .
-            '&amp;what=' . urlencode($what). '">' . _("View message") . '</a>';
-} else {
-    echo '<a href="../src/read_body.php?mailbox=' . urlencode($mailbox) .
-        '&amp;passed_id=' . $passed_id . '&amp;startMessage=' . $startMessage .
-        '&amp;show_more=0">' . _("View message") . '</a>';
-}
+$msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
+    '&amp;startMessage='.$startMessage.
+    '&amp;passed_id='.$passed_id;
+
+$msg_url = set_url_var($msg_url, 'ent_id', 0);
+
+echo '<a href="'.$msg_url.'">'. _("View message") . '</a>';
+
 echo '</center></b></td></tr>';
 
 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
 
-$entity_vcard = getEntity($message,$passed_ent_id);
+$entity_vcard = getEntity($message,$ent_id);
 
-$vcard = mime_fetch_body ($imapConnection, $passed_id, $passed_ent_id);
+$vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id);
 $vcard = decodeBody($vcard, $entity_vcard->header->encoding);
 $vcard = explode ("\n",$vcard);
 foreach ($vcard as $l) {
@@ -56,7 +68,7 @@ foreach ($vcard as $l) {
         if ($attr == 'quoted-printable')
         $v = quoted_printable_decode($v);
         else
-            $k .= ';' . $attr;
+            $k .= ';' . strtolower($attr);
     }
 
     $v = str_replace(';', "\n", $v);
@@ -65,10 +77,15 @@ foreach ($vcard as $l) {
 
 if ($vcard_nice['version'] == '2.1') {
     // get firstname and lastname for sm addressbook
-    $vcard_nice["firstname"] = substr($vcard_nice["n"],
-    strpos($vcard_nice["n"], "\n") + 1, strlen($vcard_nice["n"]));
-    $vcard_nice["lastname"] = substr($vcard_nice["n"], 0,
-        strpos($vcard_nice["n"], "\n"));
+    $vcard_nice['firstname'] = substr($vcard_nice['n'],
+    strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
+    $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
+        strpos($vcard_nice['n'], "\n"));
+    // workaround for Outlook, should be fixed in a better way,
+    // maybe in new 'vCard' class.
+    if (isset($vcard_nice['email;pref;internet'])) {
+       $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
+    }
 } else {
     echo '<tr><td align=center>vCard Version ' . $vcard_nice['version'] .
         ' is not supported.  Some information might not be converted ' .
@@ -192,7 +209,7 @@ echo '</select>' .
         '<tr><td align=center>' .
         '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
         $passed_id . '&amp;mailbox=' . urlencode($mailbox) .
-        '&amp;passed_ent_id=' . $passed_ent_id . '">' .
+        '&amp;ent_id=' . urlencode($ent_id) . '">' .
         _("Download this as a file") . '</A>' .
         '</TD></TR></TABLE>' .