Source for file move_messages.php

Documentation is available at move_messages.php

  1. <?php
  2.  
  3. /**
  4.  * move_messages.php
  5.  *
  6.  * Copyright (c) 1999-2006 The SquirrelMail Project Team
  7.  * Licensed under the GNU GPL. For full terms see the file COPYING.
  8.  *
  9.  * Enables message moving between folders on the IMAP server.
  10.  *
  11.  * $Id: move_messages.php,v 1.81.2.11 2006/05/13 20:01:15 tokul Exp $
  12.  */
  13.  
  14. /* Path for SquirrelMail required files. */
  15. define('SM_PATH','../');
  16.  
  17. /* SquirrelMail required files. */
  18. require_once(SM_PATH 'include/validate.php');
  19. require_once(SM_PATH 'functions/global.php');
  20. require_once(SM_PATH 'functions/display_messages.php');
  21. require_once(SM_PATH 'functions/imap.php');
  22. require_once(SM_PATH 'functions/html.php');
  23.  
  24. global $compose_new_win;
  25.  
  26. if !sqgetGlobalVar('composesession'$composesessionSQ_SESSION) ) {
  27.   $composesession 0;
  28. }
  29.  
  30. function attachSelectedMessages($msg$imapConnection{
  31.     global $username$attachment_dir$startMessage,
  32.            $data_dir$composesession$uid_support,
  33.        $msgs$thread_sort_messages$allow_server_sort$show_num,
  34.        $compose_messages;
  35.  
  36.     if (!isset($compose_messages)) {
  37.         $compose_messages array();
  38.             sqsession_register($compose_messages,'compose_messages');
  39.     }
  40.  
  41.     if (!$composesession{
  42.         $composesession 1;
  43.             sqsession_register($composesession,'composesession');
  44.     else {
  45.         $composesession++;
  46.         sqsession_register($composesession,'composesession');
  47.     }
  48.  
  49.     $hashed_attachment_dir getHashedDir($username$attachment_dir$composesession);
  50.  
  51.     if ($thread_sort_messages || $allow_server_sort{
  52.        $start_index=0;
  53.     else {
  54.        $start_index ($startMessage-1$show_num;
  55.     }
  56.  
  57.     $i 0;
  58.     $j 0;
  59.     $hashed_attachment_dir getHashedDir($username$attachment_dir);
  60.  
  61.     $composeMessage new Message();
  62.     $rfc822_header new Rfc822Header();
  63.     $composeMessage->rfc822_header $rfc822_header;
  64.     $composeMessage->reply_rfc822_header '';
  65.  
  66.     while ($j count($msg)) {
  67.         if (isset($msg[$i])) {
  68.             $id $msg[$i];
  69.             $body_a sqimap_run_command($imapConnection"FETCH $id RFC822",true$response$readmessage$uid_support);
  70.  
  71.             if ($response == 'OK'{
  72.  
  73.                 // fetch the subject for the message with $id from msgs.
  74.                 // is there a more efficient way to do this?
  75.                 foreach($msgs as $k => $vals{
  76.                     if($vals['ID'== $id{
  77.                         $subject $msgs[$k]['SUBJECT'];
  78.                         break;
  79.                     }
  80.                 }
  81.  
  82.                 array_shift($body_a);
  83.                 array_pop($body_a);
  84.                 $body implode(''$body_a);
  85.                 $body .= "\r\n";
  86.  
  87.                 $localfilename GenerateRandomString(32'FILE'7);
  88.                 $full_localfilename "$hashed_attachment_dir/$localfilename";
  89.  
  90.                 $fp fopen$full_localfilename'wb');
  91.                 fwrite ($fp$body);
  92.                 fclose($fp);
  93.                 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
  94.                      $full_localfilename);
  95.             }
  96.             $j++;
  97.         }
  98.         $i++;
  99.     }
  100.     $compose_messages[$composesession$composeMessage;
  101.     sqsession_register($compose_messages,'compose_messages');
  102.     return $composesession;
  103. }
  104.  
  105.  
  106.  
  107. /* get globals */
  108. sqgetGlobalVar('key',       $key,           SQ_COOKIE);
  109. sqgetGlobalVar('username',  $username,      SQ_SESSION);
  110. sqgetGlobalVar('onetimepad',$onetimepad,    SQ_SESSION);
  111. sqgetGlobalVar('delimiter'$delimiter,     SQ_SESSION);
  112. sqgetGlobalVar('base_uri',  $base_uri,      SQ_SESSION);
  113.  
  114. sqgetGlobalVar('mailbox'$mailbox);
  115. sqgetGlobalVar('startMessage'$startMessage);
  116. sqgetGlobalVar('msg'$msg);
  117.  
  118. sqgetGlobalVar('msgs',              $msgs,              SQ_SESSION);
  119. sqgetGlobalVar('composesession',    $composesession,    SQ_SESSION);
  120. sqgetGlobalVar('lastTargetMailbox'$lastTargetMailboxSQ_SESSION);
  121.  
  122. sqgetGlobalVar('moveButton',      $moveButton,      SQ_POST);
  123. sqgetGlobalVar('expungeButton',   $expungeButton,   SQ_POST);
  124. sqgetGlobalVar('targetMailbox',   $targetMailbox,   SQ_POST);
  125. sqgetGlobalVar('expungeButton',   $expungeButton,   SQ_POST);
  126. sqgetGlobalVar('undeleteButton',  $undeleteButton,  SQ_POST);
  127. sqgetGlobalVar('markRead',        $markRead,        SQ_POST);
  128. sqgetGlobalVar('markUnread',      $markUnread,      SQ_POST);
  129. sqgetGlobalVar('attache',         $attache,         SQ_POST);
  130. sqgetGlobalVar('location',        $location,        SQ_POST);
  131.  
  132. /* end of get globals */
  133.  
  134. $imapConnection sqimap_login($username$key$imapServerAddress$imapPort0);
  135. $mbx_response=sqimap_mailbox_select($imapConnection$mailbox);
  136.  
  137. $location set_url_var($location,'composenew',0,false);
  138. $location set_url_var($location,'composesession',0,false);
  139. $location set_url_var($location,'session',0,false);
  140.  
  141. // make sure that cache is not used
  142. $location set_url_var($location,'use_mailbox_cache',0,false);
  143.  
  144. /* remember changes to mailbox setting */
  145. if (!isset($lastTargetMailbox)) {
  146.     $lastTargetMailbox 'INBOX';
  147. }
  148. if ($targetMailbox != $lastTargetMailbox{
  149.     $lastTargetMailbox $targetMailbox;
  150.     sqsession_register($lastTargetMailbox'lastTargetMailbox');
  151. }
  152. $exception false;
  153.  
  154. do_hook('move_before_move');
  155.  
  156.  
  157. /*
  158.     Move msg list sorting up here, as it is used several times,
  159.     makes it more efficient to do it in one place for the code
  160. */
  161. $id array();
  162. if (isset($msg&& is_array($msg)) {
  163.     foreach$msg as $key=>$uid {
  164.         // using foreach removes the risk of infinite loops that was there //
  165.                 $id[$uid;
  166.     }
  167. }
  168.  
  169. // expunge-on-demand if user isn't using move_to_trash or auto_expunge
  170. if(isset($expungeButton)) {
  171.     $cnt sqimap_mailbox_expunge($imapConnection$mailboxtrue);
  172.     if (($startMessage+$cnt-1>= $mbx_response['EXISTS']{
  173.         if ($startMessage $show_num{
  174.             $location set_url_var($location,'startMessage',$startMessage-$show_num,false);
  175.         else {
  176.             $location set_url_var($location,'startMessage',1,false);
  177.         }
  178.     }
  179. elseif(isset($undeleteButton)) {
  180.     // undelete messages if user isn't using move_to_trash or auto_expunge
  181.     // Removes \Deleted flag from selected messages
  182.         if (count($id)) {
  183.         sqimap_toggle_flag($imapConnection$id'\\Deleted',false,true);
  184.     else {
  185.         $exception true;
  186.     }
  187. elseif (!isset($moveButton)) {
  188.     if (count($id)) {
  189.         $cnt count($id);
  190.         if (!isset($attache)) {
  191.             if (isset($markRead)) {
  192.                 sqimap_toggle_flag($imapConnection$id'\\Seen',true,true);
  193.             else if (isset($markUnread)) {
  194.                 sqimap_toggle_flag($imapConnection$id'\\Seen',false,true);
  195.             else  {
  196.                 sqimap_msgs_list_delete($imapConnection$mailbox$id);
  197.                 if ($auto_expunge{
  198.                     $cnt sqimap_mailbox_expunge($imapConnection$mailboxtrue);
  199.                 }
  200.                 if (($startMessage+$cnt-1>= $mbx_response['EXISTS']{
  201.                     if ($startMessage $show_num{
  202.                         $location set_url_var($location,'startMessage',$startMessage-$show_numfalse);
  203.                     else {
  204.                         $location set_url_var($location,'startMessage',1false);
  205.                     }
  206.                 }
  207.             }
  208.         else {
  209.             $composesession attachSelectedMessages($id$imapConnection);
  210.             $location set_url_var($location'session'$composesessionfalse);
  211.             if ($compose_new_win{
  212.                 $location set_url_var($location'composenew'1false);
  213.             else {
  214.                 $location str_replace('search.php','compose.php',$location);
  215.                 $location str_replace('right_main.php','compose.php',$location);
  216.             }
  217.         }
  218.     else {
  219.         $exception true;
  220.     }
  221. else {    // Move messages
  222.         if (count($id)) {
  223.         // move messages only when target mailbox is not the same as source mailbox
  224.                 if ($mailbox!=$targetMailbox{
  225.             sqimap_msgs_list_copy($imapConnection,$id,$targetMailbox);
  226.             if ($auto_expunge{
  227.                 $cnt sqimap_mailbox_expunge($imapConnection$mailboxtrue);
  228.             else {
  229.                 $cnt 0;
  230.             }
  231.  
  232.             if (($startMessage+$cnt-1>= $mbx_response['EXISTS']{
  233.                 if ($startMessage $show_num{
  234.                     $location set_url_var($location,'startMessage',$startMessage-$show_numfalse);
  235.                 else {
  236.                     $location set_url_var($location,'startMessage',1false);
  237.                 }
  238.             }
  239.         }
  240.     else {
  241.         $exception true;
  242.     }
  243. }
  244. // Log out this session
  245. sqimap_logout($imapConnection);
  246. if ($exception{
  247.     displayPageHeader($color$mailbox);
  248.     error_message(_("No messages were selected.")$mailbox$sort$startMessage$color);
  249. else {
  250.     header("Location$location");
  251.     exit;
  252. }
  253. ?>
  254. </BODY></HTML>

Documentation generated on Sat, 07 Oct 2006 16:32:38 +0300 by phpDocumentor 1.3.0RC6