$action = Misc::findSubmitButton();
switch ($action) {
    case 'new_message':
        Redirect::Page(URLBuilder::getURL(NULL, 'EditMessage.php', FALSE));
        break;
    case 'delete':
    case 'undelete':
        //Debug::setVerbosity( 11 );
        if (strtolower($action) == 'delete') {
            $delete = TRUE;
        } else {
            $delete = FALSE;
        }
        if (is_array($ids) and count($ids) > 0 and ($permission->Check('message', 'delete') or $permission->Check('message', 'delete_own'))) {
            $mlf = new MessageListFactory();
            $mlf->StartTransaction();
            foreach ($ids as $id) {
                //Only allow them to delete message they created.
                $mlf->getByCompanyIdAndUserIdAndId($current_company->getId(), $current_user->getId(), $id);
                foreach ($mlf as $m_obj) {
                    $m_obj->setDeleted($delete);
                    $m_obj->Save();
                }
            }
            $mlf->CommitTransaction();
        }
        Redirect::Page(URLBuilder::getURL(array('filter_folder_id' => $filter_folder_id), 'UserMessageList.php'));
        break;
    default:
        $mlf = new MessageListFactory();
        $folder_options = $mf->getOptions('folder');