home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / email / message.php < prev    next >
PHP Script  |  2004-03-08  |  16KB  |  447 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. require("../../Group-Office.php");
  14. require($GO_CONFIG->class_path."imap.class.inc");
  15. require($GO_CONFIG->class_path."email.class.inc");
  16. require($GO_CONFIG->class_path."filetypes.class.inc");
  17. require($GO_CONFIG->class_path."users.class.inc");
  18.  
  19. $users = new users();
  20. $filetypes = new filetypes();
  21. $mail = new imap();
  22. $email = new email();
  23.  
  24. $GO_SECURITY->authenticate();
  25. $GO_MODULES->authenticate('email');
  26.  
  27. require($GO_LANGUAGE->get_language_file('email'));
  28.  
  29. $link_back = (isset($_REQUEST['link_back']) && $_REQUEST['link_back'] != '') ? $_REQUEST['link_back'] : $_SERVER['REQUEST_URI'];
  30.  
  31. $to = '';
  32. $texts = '';
  33. $images = '';
  34.  
  35. $account_id = isset($_REQUEST['account_id']) ? $_REQUEST['account_id'] : 0;
  36. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  37. $mailbox = isset($_REQUEST['mailbox'])?  $_REQUEST['mailbox'] : "INBOX";
  38. $uid = isset($_REQUEST['uid']) ? $_REQUEST['uid'] : 0;
  39. $max_rows = isset($_REQUEST['max_rows']) ? $_REQUEST['max_rows'] : $_SESSION['GO_SESSION']['max_rows_list'];
  40. $first_row = (isset($_REQUEST['first_row'])) ? $_REQUEST['first_row'] : 0;
  41. $table_tabindex = isset($_REQUEST['table_tabindex']) ? $_REQUEST['table_tabindex'] : null;
  42. $return_to = (isset($_REQUEST['return_to']) && $_REQUEST['return_to'] != '') ? $_REQUEST['return_to'] : null;
  43. $link_back = (isset($_REQUEST['link_back']) && $_REQUEST['link_back'] != '') ? $_REQUEST['link_back'] : $_SERVER['REQUEST_URI'];
  44.  
  45. $print = isset($_REQUEST['print']) ? true : false;
  46.  
  47. $part = isset($_REQUEST['part']) ? $_REQUEST['part'] : '';
  48.  
  49. $account = $email->get_account($account_id);
  50.  
  51. if ($account && $mail->open($account['host'], $account['type'], $account['port'],$account['username'], $GO_CRYPTO->decrypt($account['password']),$mailbox))
  52. {
  53.     $mail_sort = isset($_REQUEST['mail_sort']) ? $_REQUEST['mail_sort'] : '';
  54.     $mail_reverse = isset($_REQUEST['mail_reverse']) ? $_REQUEST['mail_reverse'] : '';
  55.     $content = $mail->get_message($uid, $mail_sort, $mail_reverse, 'html', $part);
  56.     $subject = isset($content["subject"]) ? $content["subject"] : $ml_no_subject;
  57.  
  58. }else
  59. {
  60.     require($GO_THEME->theme_path.'header.inc');
  61.     echo '<table border="0" cellpadding="10" width="100%"><tr><td>';
  62.     echo '<p class="Error">'.$ml_connect_failed.' \''.$account['host'].'\' '.$ml_at_port.': '.$account['port'].'</p>';
  63.     echo '<p class="Error">'.imap_last_error().'</p>';
  64.     require($GO_THEME->theme_path.'footer.inc');
  65.     exit();
  66. }
  67.  
  68. //update notified mail state
  69. if ($content["new"] == '1')
  70. {
  71.     $_SESSION['notified_new_mail'] -= 1;
  72.     $_SESSION['unseen_in_mailbox'] -= 1;
  73. }
  74.  
  75. require($GO_THEME->theme_path."header.inc");
  76. if (!$print)
  77. {
  78.     echo '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ModuleIcons">';
  79.     echo '<td class="ModuleIcons">';
  80.     echo "<a href=\"javascript:popup('send.php?account_id=".$account_id."&uid=".$uid."&mailbox=".urlencode($mailbox)."&action=reply','".$GO_CONFIG->composer_width."','".$GO_CONFIG->composer_height."')\"><img src=\"".$GO_THEME->images['reply']."\" border=\"0\" height=\"32\" width=\"32\" /><br />".$ml_reply."</a></td>\n";
  81.     echo '<td class="ModuleIcons">';
  82.     echo "<a href=\"javascript:popup('send.php?account_id=".$account_id."&uid=".$uid."&mailbox=".urlencode($mailbox)."&action=reply_all','".$GO_CONFIG->composer_width."','".$GO_CONFIG->composer_height."')\"><img src=\"".$GO_THEME->images['reply_all']."\" border=\"0\" height=\"32\" width=\"32\" /><br />".$ml_reply_all."</a></td>\n";
  83.     echo '<td class="ModuleIcons">';
  84.     echo "<a href=\"javascript:popup('send.php?account_id=".$account_id."&uid=".$uid."&mailbox=".urlencode($mailbox)."&action=forward','".$GO_CONFIG->composer_width."','".$GO_CONFIG->composer_height."')\"><img src=\"".$GO_THEME->images['forward']."\" border=\"0\" height=\"32\" width=\"32\" /><br />".$ml_forward."</a></td>\n";
  85.     echo '<td class="ModuleIcons">';
  86.     echo "<a href=\"javascript:popup('properties.php?account_id=".$account_id."&uid=".$uid."&mailbox=".urlencode($mailbox)."','450','500')\"><img src=\"".$GO_THEME->images['properties']."\" border=\"0\" height=\"32\" width=\"32\" /><br />".$fbProperties."</a></td>\n";
  87.  
  88.     echo '<td class="ModuleIcons">';
  89.     echo '<a href="javascript:confirm_delete()"><img src="'.$GO_THEME->images['delete_big'].'" border="0" height="32" width="32" /><br />'.$ml_delete.'</a></td>';
  90.     echo '<td class="ModuleIcons">';
  91.     echo '<a href="javascript:popup(\'message.php?uid='.$uid.'&mailbox='.urlencode($mailbox).'&print=true\',\'\',\'\')"><img src="'.$GO_THEME->images['print'].'" border="0" height="32" width="32" /><br />'.$ml_print.'</a></td>';
  92.     if ($mail->is_imap() && $account['spam'] != '')
  93.     {
  94.         echo '<td class="ModuleIcons">';
  95.         echo '<a href="javascript:spam();"><img src="'.$GO_THEME->images['block'].'" border="0" height="32" width="32" /><br />'.$ml_block.'</a></td>';
  96.     }
  97.  
  98.     if ($content["previous"] != 0)
  99.     {
  100.         echo '<td class="ModuleIcons">';
  101.         echo '<a href="javascript:get_message('.$content["previous"].');"><img src="'.$GO_THEME->images['previous'].'" border="0" height="32" width="32" /><br />'.$cmdPrevious.'</a></td>';
  102.     }
  103.  
  104.     if ($content["next"] != 0)
  105.     {
  106.         echo '<td class="ModuleIcons">';
  107.         echo '<a href="javascript:get_message('.$content["next"].');"><img src="'.$GO_THEME->images['next'].'" border="0" height="32" width="32" /><br />'.$cmdNext.'</a></td>';
  108.     }
  109.     echo '<td class="ModuleIcons">';
  110.     echo '<a href="javascript:_close();"><img src="'.$GO_THEME->images['close'].'" border="0" height="32" width="32" /><br />'.$cmdClose.'</a></td>';
  111.     echo '</tr></table>';
  112. }
  113. ?>
  114. <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="email_client">
  115. <input type="hidden" name="empty_mailbox" />
  116. <input type="hidden" name="link_back" value="<?php echo $link_back; ?>" />
  117. <input type="hidden" name="return_to" value="<?php echo $return_to; ?>" />
  118. <input type="hidden" name="account_id" value="<?php echo $account_id; ?>" />
  119. <input type="hidden" name="uid" value="<?php echo $uid; ?>" />
  120. <input type="hidden" name="mailbox" value="<?php echo $mailbox; ?>" />
  121. <input type="hidden" name="first_row" value="<?php echo $first_row; ?>" />
  122. <input type="hidden" name="mail_sort" value="<?php echo $mail_sort; ?>" />
  123. <input type="hidden" name="mail_reverse" value="<?php echo $mail_reverse; ?>" />
  124. <input type="hidden" name="delete_message_uid" />
  125. <input type="hidden" name="spam_uid" />
  126. <input type="hidden" name="spam_address" />
  127.  
  128. <script type="text/javascript">
  129. <!--
  130. function _close()
  131. {
  132.     document.forms[0].link_back.value = '';
  133.     document.forms[0].action='<?php echo $return_to; ?>';
  134.     document.forms[0].return_to.value = '';
  135.     document.forms[0].submit();
  136. }
  137. function confirm_delete()
  138. {
  139.     <?php
  140.     $trash_folder = $account['trash'];
  141.     if ($trash_folder == '' || $trash_folder == $mailbox)
  142.     {
  143.         echo '
  144.             if (confirm("'.$ml_delete_message.'"))
  145.             {
  146.                 document.forms[0].link_back.value = "";
  147.                 document.forms[0].delete_message_uid.value = '.$uid.';
  148.                 document.forms[0].action = "index.php";
  149.                 document.forms[0].submit();
  150.             }
  151.         ';
  152.     }else
  153.     {
  154.         echo '
  155.             document.forms[0].link_back.value = "";
  156.             document.forms[0].delete_message_uid.value = '.$uid.';
  157.             document.forms[0].action= "index.php";
  158.             document.forms[0].submit();
  159.         ';
  160.     }
  161.     ?>
  162. }
  163.  
  164. function spam()
  165. {
  166.     document.forms[0].link_back.value = '';
  167.     document.forms[0].spam_address.value = "<?php echo $content["sender"]; ?>";
  168.     document.forms[0].spam_uid.value = '<?php echo $uid; ?>';
  169.     document.forms[0].action = "index.php";
  170.     document.forms[0].submit();
  171. }
  172.  
  173. function get_message(uid)
  174. {
  175.     document.forms[0].uid.value=uid;
  176.     document.forms[0].submit();
  177. }
  178.  
  179. //-->
  180. </script>
  181. <table border="0" width="100%">
  182. <tr>
  183.     <td>
  184.     <table border="0" cellpadding="1" cellspacing="0" class="TableBorder" width="100%">
  185.     <tr>
  186.         <td>
  187.         <table border="0" cellpadding="1" cellspacing="0" class="TableInside" width="100%">
  188.         <?php
  189.         switch ($content["priority"])
  190.         {
  191.             case "4":
  192.                 echo '<tr><td class="Table2"><table border="0" cellpadding="1" cellspacing="1"><tr><td><img src="'.$GO_THEME->images['info'].'" border="0" width="16" height="16" /></td><td class="Success">'.$ml_low_priority.'</td></tr></table></td></tr>';
  193.             break;
  194.  
  195.             case "2":
  196.                 echo '<tr><td class="Table2"><table border="0" cellpadding="1" cellspacing="1"><tr><td><img src="'.$GO_THEME->images['info'].'" border="0" width="16" height="16" /></td><td class="Error">'.$ml_high_priority.'</td></tr></table></td></tr>';
  197.             break;
  198.         }
  199.         ?>
  200.         <tr>
  201.             <td>
  202.             <table border="0" cellpadding="1" cellspacing="0">
  203.             <tr>
  204.                 <td><b><?php echo $ml_subject; ?>: </b></td>
  205.                 <td><?php echo $subject; ?></td>
  206.             </tr>
  207.  
  208.             <tr>
  209.                 <td><b><?php echo $ml_from; ?>: </b></td>
  210.                 <td>
  211.                 <?php
  212.                 echo show_profile_by_email($content['sender'], $content['from']).' <'.$content['sender'].'>';
  213.                 ?>
  214.                 </td>
  215.             </tr>
  216.             <tr>
  217.                 <td valign="top"><b><?php echo $ml_to; ?>: </b></td>
  218.                 <td>
  219.                 <?php
  220.                 $to == "";
  221.                 if (isset($content["to"]))
  222.                 {
  223.                     for ($i=0;$i<sizeof($content["to"]);$i++)
  224.                     {
  225.                         if ($i != 0)
  226.                         {
  227.                             $to .=", ";
  228.                         }
  229.                         $to .= $content["to"][$i];
  230.                     }
  231.                 }
  232.                 if ($to == "")
  233.                 {
  234.                     $to = $ml_no_reciepent;
  235.                 }
  236.                 echo $to;
  237.                 ?>
  238.                 </td>
  239.             </tr>
  240.             <?php
  241.             if (isset($content["cc"]))
  242.             {
  243.                 $cc = '';
  244.                 for ($i=0;$i<sizeof($content["cc"]);$i++)
  245.                 {
  246.                     if ($i != 0)
  247.                     {
  248.                         $cc .=", ";
  249.                     }
  250.                     $cc .= $content["cc"][$i];
  251.                 }
  252.                 if ($cc != '')
  253.                 {
  254.                     echo '<tr><td valign="top"><b>Cc:</b> </td><td>';
  255.                     echo $cc;
  256.                     echo '</td></tr>';
  257.                 }
  258.             }
  259.             if (isset($content["bcc"]))
  260.             {
  261.                 $bcc = '';
  262.                 for ($i=0;$i<sizeof($content["bcc"]);$i++)
  263.                 {
  264.                     if ($i != 0)
  265.                     {
  266.                         $bcc .=", ";
  267.                     }
  268.                     $bcc .= $content["bcc"][$i];
  269.                 }
  270.                 if ($bcc != '')
  271.                 {
  272.                     echo '<tr><td valign="top"><b>Bcc:</b> </td><td>';
  273.                     echo $bcc;
  274.                     echo '</td></tr>';
  275.                 }
  276.             }
  277.             ?>
  278.             <tr>
  279.                 <td><b><?php echo $strDate; ?>: </b></td>
  280.                 <td><?php echo date($_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'], get_time($content['udate'])); ?></td>
  281.             </tr>
  282.             </table>
  283.             </td>
  284.         </tr>
  285.         </table>
  286.         </td>
  287.     </tr>
  288.     </table>
  289.     </td>
  290. </tr>
  291. <tr>
  292.     <td>
  293.     <?php
  294.     $count = 0;
  295.     $splitter = 0;
  296.     $parts = array_reverse($mail->f("parts"));
  297.  
  298.     $attachments = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>";
  299.  
  300.     for ($i=0;$i<count($parts);$i++)
  301.     {
  302.  
  303.         if ((eregi("ATTACHMENT", $parts[$i]["disposition"]) && $parts[$i]["name"] != '') /*|| (eregi("INLINE", $parts[$i]["disposition"]) && $parts[$i]["name"] != '')*/ || eregi("message/rfc822", $parts[$i]["mime"]))
  304.         {
  305.  
  306.             if ($parts[$i]["name"] == "")
  307.             {
  308.                 $parts[$i]["name"] = $parts[$i]["mime"];
  309.                 $pos = strrpos($parts[$i]["name"] ,'/');
  310.                 if ($pos)
  311.                 {
  312.                     $parts[$i]["name"] = substr($parts[$i]["name"],$pos+1,strlen($parts[$i]["name"]));
  313.                 }
  314.  
  315.                 if ($extension = $filetypes->get_mime_extension($parts[$i]["mime"]))
  316.                 {
  317.                     $parts[$i]["name"] .='.'.$extension;
  318.                 }
  319.             }
  320.  
  321.             $target = '_blank';
  322.             $link = "attachment.php?account_id=".$account['id']."&mailbox=".urlencode($mailbox)."&uid=".$uid."&part=".$parts[$i]["number"]."&transfer=".$parts[$i]["transfer"]."&mime=".$parts[$i]["mime"]."&filename=".urlencode($parts[$i]["name"]);
  323.  
  324.             $splitter++;
  325.             $count++;
  326.  
  327.             $attachments .= '<td><img border="0" width="16" height="16" src="'.$GO_CONFIG->control_url.'icon.php?extension='.get_extension($parts[$i]["name"]).'&mime='.urlencode($parts[$i]["mime"]).'" /></td>';
  328.             $attachments .= '<td valign="center" nowrap> <a href="'.$link.'" target="'.$target.'" title="'.$parts[$i]["name"].'">'.cut_string($parts[$i]["name"],50).'</a> ('.format_size($parts[$i]["size"]).')</td>';
  329.             $filesystem_module = $GO_MODULES->get_module('filesystem');
  330.             if ($filesystem_module && $GO_SECURITY->has_permission($GO_SECURITY->user_id, $filesystem_module['acl_read']))
  331.             {
  332.                 $attachments .= "<td> <a title=\"".$ml_save_attachment."\" href=\"javascript:popup('save_attachment.php?account_id=".$account['id']."&mailbox=".urlencode($mailbox)."&uid=".$uid."&part=".$parts[$i]["number"]."&transfer=".$parts[$i]["transfer"]."&mime=".$parts[$i]["mime"]."&filename=".urlencode(addslashes($parts[$i]["name"]))."','600','400')\"><img src=\"".$GO_THEME->images['save']."\" border=\"0\" /></a>; </td>\n";
  333.             }else
  334.             {
  335.                 $attachments .='<td>;</td>';
  336.             }
  337.             if ($splitter == 3)
  338.             {
  339.                 $splitter = 0;
  340.                 $attachments .= "</tr><tr>";
  341.             }
  342.         }
  343.     }
  344.  
  345.     $attachments .= "</tr></table>";
  346.  
  347.     if ($count>0)
  348.     {
  349.         echo '<br /><table border="0" cellpadding="1" cellspacing="0" class="TableBorder" width="100%"><tr><td><table border="0" cellpadding="1" cellspacing="0" class="TableInside" width="100%"><tr><td valign="top">';
  350.         echo '<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="top"><b>'.$ml_attachments.':</b>  </td><td>'.$attachments.'</td></tr></table>';
  351.         echo '</td></tr></table></td></tr></table>';
  352.     }
  353.     ?>
  354.     </td>
  355. </tr>
  356. <tr>
  357.     <td>
  358.     <br />
  359.     <?php
  360.     //get all text and html content
  361.     for ($i=0;$i<sizeof($parts);$i++)
  362.     {
  363.         $mime = strtolower($parts[$i]["mime"]);
  364.  
  365.         if (($mime == "text/html") || ($mime == "text/plain") || ($mime == "text/enriched"))
  366.         {
  367.             $part = $mail->view_part($uid, $parts[$i]["number"], $parts[$i]["transfer"]);
  368.  
  369.             switch($mime)
  370.             {
  371.                 case 'text/plain':
  372.                     $part = text_to_html($part);
  373.                 break;
  374.  
  375.                 case 'text/html':
  376.                     $part = convert_html($part);
  377.                 break;
  378.  
  379.                 case 'text/enriched':
  380.                     $part = enriched_to_html($part);
  381.                 break;
  382.             }
  383.  
  384.             if ($parts[$i]["name"] != '')
  385.             {
  386.                 $texts .= "<p class=\"normal\" align=\"center\">--- ".$parts[$i]["name"]." ---</p>";
  387.             }else
  388.             {
  389.                 $texts .= '<br /><br /><br />';
  390.             }
  391.  
  392.             $texts .= $part;
  393.         }
  394.     }
  395.  
  396.     //Content-ID's that need to be replaced with urls when message needs to be reproduced
  397.     $replace_url = array();
  398.     $replace_id = array();
  399.     //preview all images
  400.  
  401.     for ($i=0;$i<sizeof($parts);$i++)
  402.     {
  403.         if (eregi("image",$parts[$i]["mime"]))
  404.         {
  405.             //when an image has an id it belongs somewhere in the text we gathered above so replace the
  406.             //source id with the correct link to display the image.
  407.             if ($parts[$i]["id"] != '')
  408.             {
  409.                 $tmp_id = $parts[$i]["id"];
  410.                 if (strpos($tmp_id,'>'))
  411.                 {
  412.                     $tmp_id = substr($parts[$i]["id"], 1,strlen($parts[$i]["id"])-2);
  413.                 }
  414.                 $id = "cid:".$tmp_id;
  415.                 $url = "attachment.php?account_id=".$account['id']."&mailbox=".$mailbox."&uid=".$uid."&part=".$parts[$i]["number"]."&transfer=".$parts[$i]["transfer"]."&mime=".$parts[$i]["mime"]."&filename=".urlencode($parts[$i]["name"]);
  416.                 $texts = str_replace($id, $url, $texts);
  417.                 //$_SESSION['replace_url'][] = $url;
  418.                 //$_SESSION['replace_id'][] = $parts[$i]["id"];
  419.             }else
  420.             {
  421.                 $images .= "<br /><p class=\"normal\" align=\"center\">--- ".$parts[$i]["name"]." ---</p><div align=\"center\"><img src=\"attachment.php?account_id=".$account['id']."&mailbox=".$mailbox."&uid=".$uid."&part=".$parts[$i]["number"]."&transfer=".$parts[$i]["transfer"]."&mime=".$parts[$i]["mime"]."&filename=".urlencode($parts[$i]["name"])."\" border=\"0\" /></div>";
  422.             }
  423.         }
  424.     }
  425.     echo $texts.$images;
  426.     ?>
  427.     </td>
  428. </tr>
  429. </table>
  430.  
  431. <?php
  432. if ($content["notification"] != '' && $content["new"] == 1)
  433. {
  434.     echo "<script type=\"text/javascript\">\npopup('"."notification.php?notification=".urlencode($content["notification"])."&date=".urlencode(date($_SESSION['GO_SESSION']['date_format'],$content['udate']))."&subject=".urlencode($subject)."&to=".urlencode($to)."','500','150');\n</script>\n";
  435. }
  436.  
  437. $mail->close();
  438.  
  439. echo '</form>';
  440.  
  441. if ($print)
  442. {
  443.     echo "\n<script type=\"text/javascript\">\nwindow.print();\n</script>\n";
  444. }
  445. require($GO_THEME->theme_path."footer.inc");
  446. ?>
  447.