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

    folder_id = params[:thetisBoxSelKeeper].split(':').last
    mail_folder = MailFolder.find_by_id(folder_id)

    if folder_id == '0' \
        or mail_folder.nil? \
        or mail_folder.user_id != @login_user.id
      flash[:notice] = 'ERROR:' + t('msg.cannot_save_in_folder')
      get_mails
      return
    end

    unless params[:check_mail].blank?
      count = 0
      params[:check_mail].each do |email_id, value|
        if value == '1'

          begin
            email = Email.find(email_id)
            next if email.user_id != @login_user.id

            email.update_attribute(:mail_folder_id, folder_id)

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

          count += 1
        end
      end
      flash[:notice] = t('mail.moved', :count => count)
    end

    get_mails
  end