home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / email / save_attachment.php < prev    next >
PHP Script  |  2004-03-08  |  3KB  |  108 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.  
  15. $GO_SECURITY->authenticate();
  16. require($GO_LANGUAGE->get_language_file('filesystem'));
  17. require($GO_CONFIG->class_path."imap.class.inc");
  18. require($GO_CONFIG->class_path."email.class.inc");
  19. $mail = new imap();
  20. $email = new email();
  21.  
  22. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  23. $filename= isset($_REQUEST['filename']) ? $_REQUEST['filename'] : '';
  24. if ($filename != '' && $_SERVER['REQUEST_METHOD'] != 'POST')
  25. {
  26.     $filename = stripslashes($filename);
  27.     $_SESSION['email_tmp_file'] = $GO_CONFIG->tmpdir.$filename;
  28.  
  29.     require($GO_CONFIG->class_path.'filetypes.class.inc');
  30.     $filetypes = new filetypes();
  31.     $extension = get_extension($filename);
  32.     if (!$type = $filetypes->get_type($extension))
  33.     {
  34.         $filetypes->add_type($extesnion, $mime);
  35.     }
  36. }
  37.  
  38. if ($filename == '')
  39. {
  40.     $filename = basename($_SESSION['email_tmp_file']);
  41. }else
  42. {
  43.     $filename = smartstrip($filename);
  44. }
  45.  
  46. if (isset($task) && $task == 'GO_HANDLER')
  47. {
  48.     require($GO_CONFIG->class_path.'filesystem.class.inc');
  49.     $fs = new filesystem();
  50.  
  51.     if (file_exists(smartstrip($_REQUEST['path']).'/'.$filename))
  52.     {
  53.         $feedback = '<p class="Error">'.$fbNameExists.'</p>';
  54.  
  55.     }elseif(!$fs->has_write_permission($GO_SECURITY->user_id, smartstrip($_REQUEST['path'])))
  56.     {
  57.         $feedback = '<p class="Error">'.$strAccessDenied.': '.smartstrip($_REQUEST['path']).'</p>';
  58.     }else
  59.     {
  60.         $new_path = smartstrip($_REQUEST['path']).'/'.$filename;
  61.         if ($fs->move($_SESSION['email_tmp_file'], $new_path))
  62.         {
  63.             $old_umask = umask(000);
  64.             chmod($new_path, $GO_CONFIG->create_mode);
  65.             umask($old_umask);
  66.             unset($_SESSION['tmp_account_id']);
  67.             unset($_SESSION['email_tmp_file']);
  68.  
  69.             echo "<script type=\"text/javascript\" language=\"javascript\">\n";
  70.             echo "window.close()\n";
  71.             echo "</script>\n";
  72.         }else
  73.         {
  74.             $feedback = '<p class="Error">'.$strSaveError.'</p>';
  75.         }
  76.     }
  77. }
  78. if (isset($_REQUEST['account_id']))
  79. {
  80.     $_SESSION['tmp_account_id'] = $_REQUEST['account_id'];
  81. }
  82.  
  83. $account = $email->get_account($_SESSION['tmp_account_id']);
  84.  
  85. if (!file_exists($_SESSION['email_tmp_file']) && !is_dir($_SESSION['email_tmp_file']))
  86. {
  87.     if ($mail->open($account['host'], $account['type'],$account['port'],$account['username'],$GO_CRYPTO->decrypt($account['password']), $_REQUEST['mailbox']))
  88.     {
  89.         $data = $mail->view_part($_REQUEST['uid'], $_REQUEST['part'], $_REQUEST['transfer'], $_REQUEST['mime']);
  90.         $mail->close();
  91.         $fp = fopen($_SESSION['email_tmp_file'],"w+");
  92.         fputs ($fp, $data, strlen($data));
  93.         fclose($fp);
  94.     }else
  95.     {
  96.         die('Could not connect to mail server!');
  97.     }
  98. }
  99. require_once('../../Group-Office.php');
  100.  
  101. $module = $GO_MODULES->get_module('email');
  102. $GO_HANDLER = $_SERVER['PHP_SELF'];
  103. $GO_CONFIG->window_mode = 'popup';
  104. $mode = 'save';
  105. $module = $GO_MODULES->get_module('filesystem');
  106. require($GO_CONFIG->root_path.$module['path'].'index.php');
  107. ?>
  108.