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 / read_message.php < prev    next >
Encoding:
PHP Script  |  2003-07-03  |  11.8 KB  |  319 lines

  1. <?php
  2. /////////////////////////////////////////////////////////
  3. //    
  4. //    source/read_message.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: source/read_message.php
  19.     PURPOSE:
  20.         1.  Display important message headers
  21.         2.  Display message structure (i.e. attachments, multi-parts)
  22.         3.  Display message body (text, images, etc)
  23.         4.  Provide interfaces to delete/undelete or move messages
  24.         5.  Provide interface to view/download message parts (i.e. attachments)
  25.         6.  Provide interface to forward/reply to message
  26.     PRE-CONDITIONS:
  27.         $user - Session ID
  28.         $folder - Folder in which message to open is in
  29.         $id - Message ID (not UID)
  30.         [$part] - IMAP (or MIME?) part code to view.
  31.     COMMENTS:
  32.         This message should interpret and display mime messages correctly.
  33.         Since it is my goal to make this file as RFC822 compliant as possible, please
  34.         notify me for any violations or errors.
  35.         
  36. ********************************************************/
  37.  
  38. include("../include/super2global.inc");
  39. include("../include/header_main.inc");
  40. include("../include/icl.inc");
  41. include("../include/mime.inc");
  42. include("../include/cache.inc");
  43.  
  44.     //make sure folder is specified
  45.     if (empty($folder)){
  46.         echo "Folder not specified or invalid<br></body></html>";
  47.         exit;
  48.     }else{
  49.         $folder_ulr = urlencode($folder);
  50.     }
  51.     
  52.     //make sure message id is specified
  53.     if (empty($id)){
  54.         echo "Invalid or unspecified message id<br>\n";
  55.         echo "</body></html>";
  56.         exit;
  57.     }
  58.  
  59.     //connect to mail server
  60.     $conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
  61.     if (!$conn){
  62.         echo "<p>Failed to connect to mail server: $iil_error<br></body</html>";
  63.         exit;
  64.     }
  65.  
  66.     //let's have some totally useless code
  67.     $this_folder=$folder;
  68.     $folder=$this_folder;
  69.     if ($undelete){
  70.         iil_C_Undelete($conn, $folder, $id);
  71.     }
  72.     
  73.     //include lang modules
  74.     include("../lang/".$my_prefs["lang"]."defaultFolders.inc");
  75.     include("../lang/".$my_prefs["lang"]."read_message.inc");
  76.     include("../lang/".$my_prefs["lang"]."main.inc");
  77.     
  78.     
  79.     //get message info
  80.     $header = iil_C_FetchHeader($conn, $folder, $id);
  81.     $structure_str=iil_C_FetchStructureString($conn, $folder, $id); 
  82.     echo "\n<!-- ".$structure_str."-->\n"; flush();
  83.     $structure=iml_GetRawStructureArray($structure_str);
  84.     $num_parts=iml_GetNumParts($structure, $part);
  85.     $parent_type=iml_GetPartTypeCode($structure, $part);
  86.     $uid = $header->uid;
  87.     
  88.     if (($parent_type==1) && ($num_parts==1)){
  89.         $part = 1;
  90.         $num_parts=iml_GetNumParts($structure, $part);
  91.         $parent_type=iml_GetPartTypeCode($structure, $part);
  92.     }
  93.     
  94.     //flag as seen, if not traversing (i.e. using prev/next links)
  95.     if ((!$trav) || (!$my_prefs["nav_no_flag"])){
  96.         //flag as read
  97.         iil_C_Flag($conn, $folder, $id, "SEEN");
  98.         //reload folder list to refresh num unread
  99.         if (($ICL_CAPABILITY["folders"]) && ($my_prefs["list_folders"]) && ($my_prefs["showNumUnread"])){
  100.             echo "\n<script language=\"JavaScript\">\n";
  101.             echo "parent.list1.location=\"folders.php?user=".$user."\";\n";
  102.             echo "</script>\n";
  103.         }
  104.     }
  105.     
  106.     //generate next/previous links
  107.     $next_link = "";
  108.     $prev_link = "";
  109.     if (($my_prefs["showNav"]) && (isset($sort_field)) && (isset($sort_order))){
  110.         //fetch index
  111.         //attempt to read from cache
  112.         include("../include/main.inc");
  113.         $read_cache = false;
  114.         if (file_exists(realpath($CACHE_DIR))){
  115.             $cache_path = $CACHE_DIR.ereg_replace("[\\/]", "", $loginID.".".$host);
  116.             $index_a = main_ReadCache($cache_path, $folder, "1:".$num_msgs, $sort_field, $read_cache);
  117.         }
  118.         
  119.         //if read form cache fails, go to server                    
  120.         if (!$read_cache) $index_a=iil_C_FetchHeaderIndex($conn, $folder, "1:".$num_msgs, $sort_field);
  121.         
  122.         if ($index_a !== false){
  123.             //sort index
  124.             if (strcasecmp($sort_order, "ASC")==0) asort($index_a);
  125.             else if (strcasecmp($sort_order, "DESC")==0) arsort($index_a);
  126.             
  127.             //generate array where key is continuous and data contains message indices
  128.             $count = 0;
  129.             while ( list($index_id, $blah) = each($index_a) ){
  130.                 $table[$count] = $index_id;
  131.                 $count++;
  132.             }
  133.             
  134.             //look for current message
  135.             $current_key = array_search($id, $table);
  136.             $prev_id = $table[$current_key-1];
  137.             $next_id = $table[$current_key+1];
  138.             
  139.             if ($prev_id > 0){
  140.                 $prev_img = "<img border=\"0\" src=\"themes/".$my_prefs["theme"]."/images/leftarrow.gif\">";
  141.                 $prev_img = "<b><-</b>";
  142.                 $args = "user=$user&folder=".urlencode($folder)."&id=$prev_id&start=$start";
  143.                 $args.= "&num_msgs=$num_msgs&sort_field=$sort_field&sort_order=$sort_order&trav=1";
  144.                 $prev_link = "<a href=\"read_message.php?".$args."\" class=mainHeading>$prev_img</a>";
  145.             }
  146.             if ($next_id > 0){
  147.                 $next_img = "<img border=\"0\" src=\"themes/".$my_prefs["theme"]."/images/rightarrow.gif\">";
  148.                 $next_img = "<b>-></b>";
  149.                 $args = "user=$user&folder=".urlencode($folder)."&id=$next_id&start=$start";
  150.                 $args.= "&num_msgs=$num_msgs&sort_field=$sort_field&sort_order=$sort_order&trav=1";
  151.                 $next_link = "<a href=\"read_message.php?".$args."\" class=mainHeading>$next_img</a>";
  152.             }
  153.         }
  154.     }
  155.     
  156.     
  157.     //determine if there are multiple recipients (or recipients other than self)
  158.     //this, in turn, determines whether or not to show the "reply all" link
  159.     if ((!empty($header->cc)) || (substr_count($header->to, "@") > 1)){
  160.         $multiple_recipients = true;
  161.     }else if (empty($header->replyto) && substr_count($header->to, "@")==1){
  162.         $multiple_recipients = true;
  163.         
  164.         $to_a = LangParseAddressList($header->to);
  165.         $to_address = $to_a[0]["address"];
  166.         
  167.         if (!empty($my_prefs["email"]) && strcasecmp($to_address, $my_prefs["email"])==0){
  168.             //one recipient, main address
  169.             $multiple_recipients = false;
  170.         }else{
  171.             //one recipient.  check if known address for user
  172.             include_once("../include/data_manager.inc");
  173.             $dm = new DataManager_obj;
  174.             if ($dm->initialize($loginID, $host, $DB_IDENTITIES_TABLE, $DB_TYPE)){
  175.                 $identities_a = $dm->read();
  176.                 if (is_array($identities_a)){
  177.                     reset($identities_a);
  178.                     while ( list($k, $v) = each($identities_a) ){
  179.                         $v = $identities_a[$k];
  180.                         if (strcasecmp($v["email"], $to_address)==0
  181.                             || strcasecmp($v["replyto"], $to_address)==0){
  182.                                 $multiple_recipients = false;
  183.                         }
  184.                     }
  185.                 }
  186.             }
  187.         }
  188.     }else $multiple_recipients = false;
  189.  
  190.     //show toolbar
  191.     include("../include/read_message_tools.inc");
  192.     echo "<table width=\"100%\" bgcolor=\"".$my_colors["main_hilite"]."\">\n";
  193.     flush();                
  194.     
  195.     //show subject
  196.     echo "\n<!-- SUBJECT //-->\n";
  197.     echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"".$my_colors["main_darkbg"]."\">\n";
  198.     echo "<tr bgcolor=\"".$my_colors["main_darkbg"]."\"><td valign=\"top\" colspan=2>\n";
  199.         echo "\n<span class=\"mainHeading\"><b>".encodeUTFSafeHTML(LangDecodeSubject($header->subject, $my_prefs["charset"]))."</b>";
  200.         echo "<br> </td>\n";
  201.     echo "</tr>\n";
  202.     echo "</table>\n\n";
  203.     
  204.     //show header
  205.     echo "\n<!-- HEADER //-->\n";
  206.     echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"".$my_colors["main_head_bg"]."\">\n";
  207.     echo "<tr bgcolor=\"".$my_colors["main_hilite"]."\"><td valign=\"top\">\n";
  208.         echo "<b>".$mainStrings[9].":  </b>".$header->date."<br>\n"; 
  209.     echo "</td></tr>\n";
  210.     echo "<tr bgcolor=\"".$my_colors["main_hilite"]."\"><td valign=\"top\">\n";
  211.         echo "<b>".$mainStrings[8].":  </b>".LangDecodeAddressList($header->from,  $my_prefs["charset"], $user)."<br>\n";
  212.     echo "</td></tr>\n";
  213.     echo "<tr bgcolor=\"".$my_colors["main_hilite"]."\"><td valign=\"top\">\n";
  214.         echo "<b>".$mainStrings[7].": </b>".LangDecodeAddressList($header->to,  $my_prefs["charset"], $user)."<br>\n";
  215.     echo "</td></tr>\n";
  216.     if (!empty($header->cc)){
  217.         echo "<tr bgcolor=\"".$my_colors["main_hilite"]."\"><td valign=\"top\">\n";
  218.         echo "<b>CC: </b>".LangDecodeAddressList($header->cc,  $my_prefs["charset"], $user)."<br>\n";
  219.         echo "</td></tr>\n";
  220.     }
  221.     if (!empty($header->replyto)){
  222.         echo "<tr bgcolor=\"".$my_colors["main_hilite"]."\"><td valign=\"top\">\n";
  223.         echo "<b>Reply-To:  </b>".LangDecodeAddressList($header->replyto,  $my_prefs["charset"], $user)."<br>\n";
  224.         echo "</td></tr>\n";
  225.     }
  226.     echo "<tr bgcolor=\"".$my_colors["main_hilite"]."\"><td valign=\"top\">\n";
  227.         echo  "<b>$rmStrings[10]: </b>".ShowBytes($header->size)."<br>\n";
  228.     echo "</td></tr>\n";
  229.     
  230.     //show attachments/parts
  231.     if ($num_parts > 0){
  232.         echo "<tr bgcolor=\"".$my_colors["main_hilite"]."\"><td valign=\"top\">\n";
  233.         echo "<b>".$rmStrings[6].": </b>\n";
  234.         echo "<table size=100%><tr valign=top><tr>\n";
  235.         //echo "<td valign=\"top\"><b>".$rmStrings[6].": </b>\n";
  236.         echo "<td></td>\n";
  237.         echo "<td valign=\"top\"><b>    </b></td>\n";
  238.         $icons_a = array("text.gif", "multi.gif", "multi.gif", "application.gif", "music.gif", "image.gif", "movie.gif", "unknown.gif");
  239.  
  240.         for ($i=1;$i<=$num_parts;$i++){
  241.             //get attachment info
  242.             if ($parent_type == 1)
  243.                 $code=$part.(empty($part)?"":".").$i;
  244.             else if ($parent_type == 2){
  245.                 $code=$part.(empty($part)?"":".").$i;
  246.                 //echo implode(" ", iml_GetPartArray($structure, $code));
  247.             }
  248.                 
  249.             $type=iml_GetPartTypeCode($structure, $code);
  250.             $name=iml_GetPartName($structure, $code);
  251.             $typestring=iml_GetPartTypeString($structure,$code);
  252.             list($dummy, $subtype) = explode("/", $typestring);
  253.             $bytes=iml_GetPartSize($structure,$code);
  254.             $encoding=iml_GetPartEncodingCode($structure, $code);
  255.             $disposition = iml_GetPartDisposition($structure, $code);
  256.         
  257.             //format href
  258.             if (($type == 1) || ($type==2) || (($type==3)&&(strcasecmp($subtype, "ms-tnef")==0))) $href = "read_message.php?user=$user&folder=$folder_url&id=$id&part=".$code;
  259.             else $href = "view.php?user=$user&folder=$folder_url&id=$id&part=".$code;
  260.             
  261.             //show icon, file name, size
  262.             echo "<td align=\"center\">";
  263.             echo "<a href=\"".$href."\" ".(($type==1)||($type==2)||(($type==3)&&(strcasecmp($subtype, "ms-tnef")==0))?"":"target=_blank").">";
  264.             echo "<img src=\"themes/".$my_prefs["theme"]."/images/".$icons_a[$type]."\" border=0><br>";
  265.             echo "<span class=\"small\">";
  266.             if (is_string($name)) echo LangDecodeSubject($name, $my_charset);
  267.             if ($bytes>0) echo "<br>[".ShowBytes($bytes)."]";
  268.             if (is_string($typestring)) echo "<br>".$typestring;
  269.             echo "</span>";
  270.             echo "</a>";
  271.             echo "</td>\n";
  272.             if (($i % 4) == 0) echo "</tr><tr><td></td><td></td>";
  273.         }
  274.         echo "</tr>\n</table>\n";
  275.         echo "</td></tr>\n";
  276.     }
  277.     
  278.     //more header stuff (source/header links)
  279.     echo "<tr bgcolor=\"".$my_colors["main_hilite"]."\"><td valign=\"top\" align=\"center\">\n";
  280.     echo "<a href=\"view.php?user=$user&folder=$folder_url&id=$id&source=1\" target=\"_blank\">".$rmStrings[9]."</a>\n";
  281.     echo " | <a href=\"view.php?user=$user&folder=$folder_url&id=$id&show_header=1\" target=\"_blank\">".$rmStrings[12]."</a>\n";
  282.     echo " | <a href=\"view.php?user=$user&folder=$folder_url&id=$id&printer_friendly=1\" target=\"_blank\">".$rmStrings[16]."</a>\n";
  283.     if ($report_spam_to){
  284.         echo " | <a href=\"compose2.php?user=$user&folder=$folder_url&forward=1&id=$id&show_header=1&to=".urlencode($report_spam_to);
  285.         echo "\" target=\"_blank\">".$rmStrings[13]."</a>\n";
  286.     }
  287.     if ($header->answered){
  288.         echo " | ".$rmStrings[15]."\n";
  289.     }
  290.     echo "</td></tr>\n";
  291.  
  292.  
  293.     echo "<tr bgcolor=\"".$my_colors["main_bg"]."\"><td>\n";
  294.         
  295.     echo "<table width=\"90%\" align=\"left\" border=\"0\" cellpadding=\"5\"><tr><td>\n";
  296.     echo "\n<!-- BEGIN MESSAGE CELL //-->\n";
  297.     
  298.     /***** BEGIN READ MESSAGE HANDLER ****/
  299.     
  300.     //now include the handler that determines what to display and how    
  301.     include("../include/read_message_handler.inc");    
  302.     
  303.     /***** END READ MESSAGE HANDLER *****/
  304.     
  305.     echo "\n<!-- END MESSAGE CELL //-->\n";
  306.     echo "</td></tr></table>\n";
  307.     
  308.     echo "</td></tr></table>\n";
  309.     echo "</td></tr></table>\n";
  310.  
  311.     //show toolbar
  312.     include("../include/read_message_tools.inc");
  313.  
  314.  
  315.     iil_Close($conn);
  316.  
  317. ?>
  318. </BODY></HTML>
  319.