  def update_folders_order
    Log.add_info(request, params.inspect)

    order_ary = params[:folders_order]

    folders = MailFolder.get_childs(params[:id], false, false)
    # folders must be ordered by xorder ASC.

    folders.sort! { |id_a, id_b|

      idx_a = order_ary.index(id_a)
      idx_b = order_ary.index(id_b)

      if idx_a.nil? or idx_b.nil?
        idx_a = folders.index(id_a)
        idx_b = folders.index(id_b)
      end

      idx_a - idx_b
    }

    idx = 1
    folders.each do |folder_id|
      begin
        folder = MailFolder.find(folder_id)
        next if folder.user_id != @login_user.id

        folder.update_attribute(:xorder, idx)

        if folder.xtype == MailFolder::XTYPE_ACCOUNT_ROOT
          mail_account = MailAccount.find_by_id(folder.mail_account_id)
          unless mail_account.nil?
            mail_account.update_attribute(:xorder, idx)
          end
        end

        idx += 1
      rescue => evar
        Log.add_error(request, evar)
      end
    end

    render(:text => '')
  end
The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.