You are here

function mailhandler_switch_user in Mailhandler 5

Same name and namespace in other branches
  1. 6 mailhandler.retrieve.inc \mailhandler_switch_user()
  2. 7 mailhandler.retrieve.inc \mailhandler_switch_user()

Switch from original user to mail submision user and back.

Note: You first need to run mailhandler_switch_user without argument to store the current user. Call mailhandler_switch_user without argument to set the user back to the original user.

Parameters

$uid The user ID to switch to:

3 calls to mailhandler_switch_user()
mailhandler_admin_retrieve in ./mailhandler.module
Menu callback; Retrieve and process pending e-mails for a mailbox.
mailhandler_cron in ./mailhandler.module
Implementation of hook_cron(). Process msgs from all enabled mailboxes.
mailhandler_retrieve in ./mailhandler.module
Retrieve all msgs from a given mailbox and process them.

File

./mailhandler.module, line 394

Code

function mailhandler_switch_user($uid = NULL) {
  global $user;
  static $orig_user = array();
  if (isset($uid)) {
    session_save_session(FALSE);
    $user = user_load(array(
      'uid' => $uid,
    ));
  }
  else {
    if (count($orig_user)) {
      $user = array_shift($orig_user);
      session_save_session(TRUE);
      array_unshift($orig_user, $user);
    }
    else {
      $orig_user[] = $user;
    }
  }
}