home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / admin / view.php < prev    next >
Encoding:
PHP Script  |  2003-12-29  |  9.0 KB  |  272 lines

  1. <?php
  2. /////////////////////////////////////////////////////////
  3. //
  4. //    source/view.php
  5. //
  6. //    (C)Copyright 2000-2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
  7. //
  8. //        This file is part of IlohaMail.
  9. //        IlohaMail is free software released under the GPL
  10. //        license.  See enclosed file COPYING for details,
  11. //        or see http://www.fsf.org/copyleft/gpl.html
  12. //
  13. /////////////////////////////////////////////////////////
  14.  
  15. /********************************************************
  16.  
  17.     AUTHOR: Ryo Chijiiwa <ryo@ilohamail.org>
  18.     FILE: view.php
  19.     PURPOSE:
  20.         Display message part data (whether it be text, images, or whatever).  Decode as necessary.
  21.         Sets HTTP "Content-Type" header as appropriate, so that the browser will (hopefully) know
  22.         what to do with the data.
  23.     PRE-CONDITIONS:
  24.         $user - Session ID
  25.         $folder - Folder in which message to open is in
  26.         $id - Message ID (not UID)
  27.         $part - IMAP (or MIME?) part code to view.
  28.  
  29. ********************************************************/
  30.  
  31. include_once("../include/super2global.inc");
  32. include_once("../include/nocache.inc");
  33.  
  34. if ((isset($user))&&(isset($folder))){
  35.     include_once("../include/session_auth.inc");
  36.     include_once("../include/icl.inc");
  37.  
  38.     $view_conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
  39.     if ($iil_errornum==-11){
  40.         for ($i=0; (($i<10)&&(!$view_conn)); $i++){
  41.             sleep(1);
  42.             $view_conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
  43.         }
  44.     }
  45.     if (!$view_conn){
  46.         echo "failed\n".$iil_error;
  47.         flush();
  48.     }else{
  49.  
  50.         // Let's look for MSIE as it needs special treatment
  51.         if  (strpos (getenv('HTTP_USER_AGENT'), "MSIE"))
  52.             $DISPOSITION_MODE="inline";
  53.         else
  54.             $DISPOSITION_MODE="attachment";
  55.  
  56.         //get basic info
  57.         include_once("../include/mime.inc");
  58.         $header = iil_C_FetchHeader($view_conn, $folder, $id);
  59.         $structure_str=iil_C_FetchStructureString($view_conn, $folder, $id);
  60.         $structure=iml_GetRawStructureArray($structure_str);
  61.  
  62.         //if part id not specified but content-id is, 
  63.         //find corresponding part id
  64.         if (!isset($part) && $cid){
  65.             if (!ereg("^<", $cid)) $cid = "<".$cid;
  66.             if (!ereg(">$", $cid)) $cid.= ">";
  67.             
  68.             //fetch parts list
  69.             $parts_list = iml_GetPartList($structure, "");
  70.             
  71.             //search for cid
  72.             if (is_array($parts_list)){
  73.                 reset($parts_list);
  74.                 while(list($part_id,$part_a)=each($parts_list)){
  75.                     if ($part_a["id"]==$cid){
  76.                         $part = $part_id;
  77.                     }
  78.                 }
  79.             }
  80.             
  81.             //we couldn't find part with cid, die
  82.             if (!isset($part)) exit;
  83.         }
  84.         
  85.         if (isset($source)){
  86.             //show source
  87.             header("Content-type: text/plain");
  88.             iil_C_PrintSource(&$view_conn, $folder, $id, $part);
  89.         }else if ($show_header){
  90.             //show header
  91.             header("Content-Type: text/plain");
  92.             $header = iil_C_FetchPartHeader($view_conn, $folder, $id, $part);
  93.             //$header = str_replace("\r", "", $header);
  94.             //$header = str_replace("\n", "\r\n", $header);
  95.             echo $header;
  96.         }else if ($printer_friendly){
  97.             //show printer friendly version
  98.             include_once("../include/ryosimap.inc");
  99.             include("../lang/".$my_prefs["charset"].".inc");
  100.  
  101.             //get message info
  102.             $conn = $view_conn;
  103.             
  104.             $num_parts=iml_GetNumParts($structure, $part);
  105.             $parent_type=iml_GetPartTypeCode($structure, $part);
  106.             $uid = $header->uid;
  107.  
  108.             //get basic header fields
  109.             $subject = encodeHTML(LangDecodeSubject($header->subject, $my_prefs["charset"]));
  110.             $from = LangShowAddresses($header->from,  $my_prefs["charset"], $user);
  111.             $to = LangShowAddresses($header->to,  $my_prefs["charset"], $user);
  112.             if (!empty($header->cc)) $cc = LangShowAddresses($header->cc,  $my_prefs["charset"], $user);
  113.             else $cc = "";
  114.  
  115.             header("Content-type: text/html");
  116.  
  117.             //output
  118.             ?>
  119.             <html>
  120.             <head><title><?php echo $subject ?></title></head>
  121.             <body>
  122.             <?php
  123.             echo "<b>Subject: </b>$subject<br>\n";
  124.             echo "<b>Date: </b>".htmlspecialchars($header->date)."<br>\n";
  125.             echo "<b>From: </b>".$from."<br>\n";
  126.             echo "<b>To: </b>".$to."<br>\n";
  127.             if (!empty($cc)) echo "<b>CC: </b>".$cc."<br>\n";
  128. //20094
  129.             include("../include/read_message_handler.inc");
  130.             ?>
  131.             </body>
  132.             </html>
  133.             <?php
  134.  
  135.         }else if(isset($tneffid)){
  136.             //show ms-tnef
  137.  
  138.             include("../include/tnef_decoder.inc");            
  139.             $type=iml_GetPartTypeCode($structure, $part);
  140.             $typestring=iml_GetPartTypeString($structure, $part);
  141.             list($type, $subtype) = explode("/", $typestring);
  142.             $body=iil_C_FetchPartBody($view_conn, $folder, $id, $part);
  143.             $encoding=iml_GetPartEncodingCode($structure, $part);
  144.             if ($encoding == 3 ) $body=base64_decode($body);
  145.             else if ($encoding == 4) $body=quoted_printable_decode($body);
  146.             $charset=iml_GetPartCharset($structure, $part);
  147.             if (strcasecmp($charset, "utf-8")==0){
  148.                 include_once("../include/utf8.inc");
  149.                 $is_unicode = true;
  150.                 $body = utf8ToUnicodeEntities($body);
  151.             }else{
  152.                 $is_unicode = false;
  153.             }
  154.             //$body=LangConvert($body, $my_charset, $charset);
  155.             $tnef_files=tnef_decode($body);
  156.             header("Content-type: ".$tnef_files[$tneffid]['type0']."/".$tnef_files[$tneffid]['type1']."; name=\"".$tnef_files[$tneffid]['name']."\"");
  157.             header("Content-Disposition: ".$DISPOSITION_MODE."; filename=\"".$tnef_files[$tneffid]['name']."\"");
  158.             header("Expires: 0");
  159.             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  160.             header("Pragma: public");
  161.             echo($tnef_files[$tneffid]['stream']);
  162.         }else{            
  163.             $header_obj = $header;
  164.             $type=iml_GetPartTypeCode($structure, $part);
  165.             if ($is_html) $typestr = "text/html";
  166.             else if (empty($part) || $part==0) $typestr = $header_obj->ctype;
  167.             else $typestr = iml_GetPartTypeString($structure, $part);
  168.             list($majortype, $subtype) = explode("/", $typestr);
  169.  
  170.             // structure string
  171.             if ($show_struct){
  172.                 echo $structure_str;
  173.                     exit;
  174.             }
  175.  
  176.             // format and send HTTP header
  177.             if ($type==$MIME_APPLICATION){
  178.                 $name = str_replace("/",".",iml_GetPartName($structure, $part));
  179.                 header("Content-type: $typestr; name=\"".$name."\"");
  180.                 header("Content-Disposition: ".$DISPOSITION_MODE."; filename=\"".$name."\"");
  181.                 header("Expires: 0");
  182.                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  183.                 header("Pragma: public");
  184.             }else if ($type==$MIME_MESSAGE){
  185.                 $name=str_replace("/",".", iml_GetPartName($structure, $part));
  186.                 header("Content-Type: text/plain; name=\"".$name."\"");
  187.             }else if ($type != $MIME_INVALID){
  188.                 $charset=iml_GetPartCharset($structure, $part);
  189.                 $name=str_replace("/",".", iml_GetPartName($structure, $part));
  190.                 $header="Content-type: $typestr";
  191.                 if (!empty($charset)) $header.="; charset=\"".$charset."\"";
  192.                 if (!empty($name)) $header.="; name=\"".$name."\"";
  193.                 header($header);
  194.                 if ($type!=$MIME_TEXT && $type!=$MIME_IMAGE){
  195.                     header("Content-Disposition: ".$DISPOSITION_MODE."; filename=\"".$name."\"");
  196.                     header("Expires: 0");
  197.                     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  198.                     header("Pragma: public");
  199.                 }else if (!empty($name)){
  200.                     header("Content-Disposition: inline; filename=\"".$name."\"");
  201.                 }
  202.             }else{
  203.                 if ($debug) echo "Invalid type code!\n";
  204.             }
  205.             if ($debug) echo "Type code = $type ;\n";
  206.             
  207.             //check if text/html
  208.             if ($type==$MIME_TEXT && strcasecmp($subtype, "html")==0){
  209.                 $is_html = true;
  210.                 $img_url = "view.php?user=$user&folder=$folder&id=$id&cid=";
  211.                 //echo "IS HTML<br>\n";
  212.             }else{
  213.                 $is_html = false;
  214.                 //echo "IS NOT HTML $type $subtype <br>\n";
  215.             }
  216.  
  217.             // send actual output
  218.             if ($print){
  219.                 // straight output, no processing
  220.                 iil_C_PrintPartBody($view_conn, $folder, $id, $part);
  221.                 if ($debug) echo $view_conn->error;
  222.             }else{
  223.                 // process as necessary, based on encoding
  224.                 $encoding=iml_GetPartEncodingCode($structure, $part);
  225.                 if ($debug) echo "Part code = $encoding;\n";
  226.  
  227.                 if ($raw){
  228.                     iil_C_PrintPartBody($view_conn, $folder, $id, $part);
  229.                 }else if ($encoding==3){
  230.                     // base 64
  231.                     if ($debug) echo "Calling iil_C_PrintBase64Body\n"; flush();
  232.                     if ($is_html){
  233.                         $body = iil_C_FetchPartBody($view_conn, $folder, $id, $part);
  234.                         $body = ereg_replace("[^a-zA-Z0-9\/\+]", "", $body);
  235.                         $body = base64_decode($body);
  236.                         $body = eregi_replace("src=\"cid:", "src=\"".$img_url, $body);
  237.                         echo $body;
  238.                     }else{
  239.                         iil_C_PrintBase64Body($view_conn, $folder, $id, $part);
  240.                     }
  241.                 }else if ($encoding == 4){
  242.                     // quoted printable
  243.                     $body = iil_C_FetchPartBody($view_conn, $folder, $id, $part);
  244.                     if ($debug) echo "Read ".strlen($body)." bytes\n";
  245.                     $body=quoted_printable_decode(str_replace("=\r\n","",$body));
  246.                     $charset=iml_GetPartCharset($structure, $part);
  247.                     if (strcasecmp($charset, "utf-8")==0){
  248.                         include_once("../include/utf8.inc");
  249.                         $body = utf8ToUnicodeEntities($body);
  250.                     }
  251.                     if ($is_html){
  252.                         $body = eregi_replace("src=\"cid:", "src=\"".$img_url, $body);
  253.                     }
  254.                     echo $body;
  255.                 }else{
  256.                     // otherwise, just dump it out
  257.                     if ($is_html){
  258.                         $body = iil_C_FetchPartBody($view_conn, $folder, $id, $part);
  259.                         $body = eregi_replace("src=\"cid:", "src=\"".$img_url, $body);
  260.                         echo $body;
  261.                     }else{
  262.                         iil_C_PrintPartBody($view_conn, $folder, $id, $part);
  263.                     }
  264.                 }
  265.                 if ($debug) echo $view_conn->error;
  266.             }
  267.         }
  268.         iil_Close($view_conn);
  269.     }
  270. }
  271. ?>
  272.