
@echo off

::------------------------------------------------------------::
::                         SNC EMAIL                          ::  
::                                                            ::
:: 8b,dPPYba,  88       88 8b,dPPYba,  ,adPPYb,d8  ,adPPYba,  :: 
:: 88P'    "8a 88       88 88P'   "Y8 a8"    `Y88 a8P_____88  ::
:: 88       d8 88       88 88         8b       88 8PP"""""""  ::
:: 88b,   ,a8" "8a,   ,a88 88         "8a,   ,d88 "8b,   ,aa  ::
:: 88`YbbdP"'   `"YbbdP'Y8 88          `"YbbdP"Y8  `"Ybbd8"'  ::
:: 88                                  aa,    ,88             ::
:: 88                                   "Y8bbdP"              ::
::                                                            ::
::------------------------------------------------------------::

::Created by Neil Gloudemans 9/9/2019::
::Rather than having to type in the GAM commands one by one, I decided to automate::

::-----------------------------------------------------------------------------------------------------::

echo SNC EMAIL PURGE version 0.1
echo.
echo.
echo.
echo.
pause

::Set Email address::
:start 

set /P emailaddress="Enter Email Address for Purgee: "


::Test or Purge Question::
:choice1
set /P c=Are you testing or purging?[test/purge]
if /I "%c%" EQU "test" goto :test
if /I "%c%" EQU "purge" goto :purge
goto :choice1

:purge
::Check for Purge::
:choice2
set /P c=Are you sure you want to purge?[y/n]
if /I "%c%" EQU "y" goto :choice3
if /I "%c%" EQU "n" goto :choice1
goto :choice2
::Type of Purge::
:choice3
set /P c=Are you purging full or without categories?[full/without]
if /I "%c%" EQU "full" goto :full
if /I "%c%" EQU "without" goto :categories
goto :choice3


::Full Purge::
:full
echo WARNING: This purge will take some time depending on the person. Get comfy. 
pause
cd c:\users\glouns\gam
echo Searching all mail except Personal Label
gam user %emailaddress% delete messages query -label:"personal" doit maxtodelete 999999999
echo Searching Social Category
gam user %emailaddress% delete messages query "category:social  -label:personal" doit maxtodelete 999999999
echo Searching Updates Category
gam user %emailaddress% delete messages query "category:updates  -label:personal" doit maxtodelete 999999999
echo Searching Forums Category
gam user %emailaddress% delete messages query "category:forums  -label:personal" doit maxtodelete 999999999
echo Searching Promotions Category
gam user %emailaddress% delete messages query "category:promotions  -label:personal" doit maxtodelete 9999999999
echo Searching Important Category
gam user %emailaddress% delete messages query "label:important  -label:personal" doit maxtodelete 9999999999
echo Purge Complete
pause
goto :choice5




::No categories purge::
:categories
echo WARNING: This purge will only delete emails that are not in the Personal label, and not in the Categories. 
pause

cd c:\users\glouns\gam
echo Searching all mail except Personal Label and Categories
gam user %emailaddress% delete messages query "-label:personal" doit maxtodelete 999999999
echo Purge Complete
pause
goto :choice5



::Beginning of testing script::

:test

::Type of test::
:choice4
set /P c=Are you testing full or without categories?[full/without]
if /I "%c%" EQU "full" goto :fulltest
if /I "%c%" EQU "without" goto :categoriestest
goto :choice4


::Test everything::
:fulltest
cd c:\users\glouns\gam
echo Searching all mail except Personal Label
gam user %emailaddress% delete messages query "-label:personal" maxtodelete 9999999999
echo Searching Social Category
gam user %emailaddress% delete messages query "category:social  -label:personal" maxtodelete 9999999999
echo Searching Updates Category
gam user %emailaddress% delete messages query "category:updates  -label:personal" maxtodelete 9999999999
echo Searching Forums Category
gam user %emailaddress% delete messages query "category:forums  -label:personal" maxtodelete 9999999999
echo Searching Promotions Category
gam user %emailaddress% delete messages query "category:promotions  -label:personal" maxtodelete 9999999999
echo Searching Important Category
gam user %emailaddress% delete messages query "label:important  -label:personal" maxtodelete 9999999999
echo Test Complete
pause

goto :choice5



::Test without Categories::
:categoriestest
cd c:\users\glouns\gam
echo Searching all mail except Personal Label and Categories
gam user %emailaddress% delete messages query "-label:personal" maxtodelete 999999999
echo Test Complete

pause

goto :choice5




::Choice after completion::

:choice5
set /P c=Back to main menu?[y/n]
if /I "%c%" EQU "y" goto :start
if /I "%c%" EQU "n" goto :kill
goto :choice5


::End of script::

:kill
exit 0

