Updated gam <UserTypeEntity> modify messages to improve error handling.

This commit is contained in:
Ross Scroggs
2024-08-28 17:53:51 -07:00
parent 41dd34ec9e
commit d3c7af784f
6 changed files with 44 additions and 19 deletions

View File

@ -10,6 +10,10 @@ Add the `-s` option to the end of the above commands to suppress creating the `g
See [Downloads-Installs](https://github.com/taers232c/GAMADV-XTD3/wiki/Downloads-Installs) for Windows or other options, including manual installation See [Downloads-Installs](https://github.com/taers232c/GAMADV-XTD3/wiki/Downloads-Installs) for Windows or other options, including manual installation
### 6.80.17
Updated `gam <UserTypeEntity> modify messages` to improve error handling.
### 6.80.16 ### 6.80.16
Fixed bug in `gam print vaultcounts` that caused a trap. Fixed bug in `gam print vaultcounts` that caused a trap.

View File

@ -251,7 +251,7 @@ writes the credentials into the file oauth2.txt.
admin@server:/Users/admin$ rm -f /Users/admin/GAMConfig/oauth2.txt admin@server:/Users/admin$ rm -f /Users/admin/GAMConfig/oauth2.txt
admin@server:/Users/admin$ gam version admin@server:/Users/admin$ gam version
WARNING: Config File: /Users/admin/GAMConfig/gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: /Users/admin/GAMConfig/oauth2.txt, Not Found WARNING: Config File: /Users/admin/GAMConfig/gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: /Users/admin/GAMConfig/oauth2.txt, Not Found
GAMADV-XTD3 6.80.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource GAMADV-XTD3 6.80.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com> Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.5 64-bit final Python 3.12.5 64-bit final
MacOS Sonoma 14.5 x86_64 MacOS Sonoma 14.5 x86_64
@ -923,7 +923,7 @@ writes the credentials into the file oauth2.txt.
C:\>del C:\GAMConfig\oauth2.txt C:\>del C:\GAMConfig\oauth2.txt
C:\>gam version C:\>gam version
WARNING: Config File: C:\GAMConfig\gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: C:\GAMConfig\oauth2.txt, Not Found WARNING: Config File: C:\GAMConfig\gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: C:\GAMConfig\oauth2.txt, Not Found
GAMADV-XTD3 6.80.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource GAMADV-XTD3 6.80.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com> Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.5 64-bit final Python 3.12.5 64-bit final
Windows-10-10.0.17134 AMD64 Windows-10-10.0.17134 AMD64

View File

@ -1,9 +1,9 @@
\\# Version and Help # Version and Help
Print the current version of Gam with details Print the current version of Gam with details
``` ```
gam version gam version
GAMADV-XTD3 6.80.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource GAMADV-XTD3 6.80.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com> Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.5 64-bit final Python 3.12.5 64-bit final
MacOS Sonoma 14.5 x86_64 MacOS Sonoma 14.5 x86_64
@ -15,7 +15,7 @@ Time: 2023-06-02T21:10:00-07:00
Print the current version of Gam with details and time offset information Print the current version of Gam with details and time offset information
``` ```
gam version timeoffset gam version timeoffset
GAMADV-XTD3 6.80.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource GAMADV-XTD3 6.80.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com> Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.5 64-bit final Python 3.12.5 64-bit final
MacOS Sonoma 14.5 x86_64 MacOS Sonoma 14.5 x86_64
@ -27,7 +27,7 @@ Your system time differs from www.googleapis.com by less than 1 second
Print the current version of Gam with extended details and SSL information Print the current version of Gam with extended details and SSL information
``` ```
gam version extended gam version extended
GAMADV-XTD3 6.80.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource GAMADV-XTD3 6.80.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com> Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.5 64-bit final Python 3.12.5 64-bit final
MacOS Sonoma 14.5 x86_64 MacOS Sonoma 14.5 x86_64
@ -64,7 +64,7 @@ MacOS High Sierra 10.13.6 x86_64
Path: /Users/Admin/bin/gamadv-xtd3 Path: /Users/Admin/bin/gamadv-xtd3
Version Check: Version Check:
Current: 5.35.08 Current: 5.35.08
Latest: 6.80.16 Latest: 6.80.17
echo $? echo $?
1 1
``` ```
@ -72,7 +72,7 @@ echo $?
Print the current version number without details Print the current version number without details
``` ```
gam version simple gam version simple
6.80.16 6.80.17
``` ```
In Linux/MacOS you can do: In Linux/MacOS you can do:
``` ```
@ -82,7 +82,7 @@ echo $VER
Print the current version of Gam and address of this Wiki Print the current version of Gam and address of this Wiki
``` ```
gam help gam help
GAM 6.80.16 - https://github.com/taers232c/GAMADV-XTD3 GAM 6.80.17 - https://github.com/taers232c/GAMADV-XTD3
Ross Scroggs <ross.scroggs@gmail.com> Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.5 64-bit final Python 3.12.5 64-bit final
MacOS Sonoma 14.5 x86_64 MacOS Sonoma 14.5 x86_64

View File

@ -2,6 +2,10 @@
Merged GAM-Team version Merged GAM-Team version
6.80.17
Updated `gam <UserTypeEntity> modify messages` to improve error handling.
6.80.16 6.80.16
Fixed bug in `gam print vaultcounts` that caused a trap. Fixed bug in `gam print vaultcounts` that caused a trap.

View File

@ -2409,6 +2409,12 @@ def entityDoesNotExistWarning(entityType, entityName, i=0, count=0):
[Ent.Singular(entityType), entityName, Msg.DOES_NOT_EXIST], [Ent.Singular(entityType), entityName, Msg.DOES_NOT_EXIST],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityListDoesNotExistWarning(entityValueList, i=0, count=0):
setSysExitRC(ENTITY_DOES_NOT_EXIST_RC)
writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Msg.DOES_NOT_EXIST],
currentCountNL(i, count)))
def entityUnknownWarning(entityType, entityName, i=0, count=0): def entityUnknownWarning(entityType, entityName, i=0, count=0):
domain = getEmailAddressDomain(entityName) domain = getEmailAddressDomain(entityName)
if (domain.endswith(GC.Values[GC.DOMAIN])) or (domain.endswith('google.com')): if (domain.endswith(GC.Values[GC.DOMAIN])) or (domain.endswith('google.com')):
@ -67502,12 +67508,12 @@ def createLabels(users, labelEntity):
if not buildPath: if not buildPath:
try: try:
callGAPI(gmail.users().labels(), 'create', callGAPI(gmail.users().labels(), 'create',
throwReasons=GAPI.GMAIL_THROW_REASONS+[GAPI.DUPLICATE, GAPI.PERMISSION_DENIED], throwReasons=GAPI.GMAIL_THROW_REASONS+[GAPI.DUPLICATE, GAPI.INVALID, GAPI.PERMISSION_DENIED],
userId='me', body=body, fields='') userId='me', body=body, fields='')
entityActionPerformed([Ent.USER, user, Ent.LABEL, label], l, lcount) entityActionPerformed([Ent.USER, user, Ent.LABEL, label], l, lcount)
except GAPI.duplicate: except GAPI.duplicate:
entityActionFailedWarning([Ent.USER, user, Ent.LABEL, label], Msg.DUPLICATE, l, lcount) entityActionFailedWarning([Ent.USER, user, Ent.LABEL, label], Msg.DUPLICATE, l, lcount)
except GAPI.permissionDenied as e: except (GAPI.invalid, GAPI.permissionDenied) as e:
entityActionFailedWarning([Ent.USER, user, Ent.LABEL, label], str(e), l, lcount) entityActionFailedWarning([Ent.USER, user, Ent.LABEL, label], str(e), l, lcount)
except (GAPI.serviceNotAvailable, GAPI.badRequest): except (GAPI.serviceNotAvailable, GAPI.badRequest):
entityServiceNotApplicableWarning(Ent.USER, user, i, count) entityServiceNotApplicableWarning(Ent.USER, user, i, count)
@ -68036,7 +68042,7 @@ def _initLabelNameMap(userGmailLabels):
labelNameMap[label['name']] = labelNameMap[label['name'].upper()] = label['id'] labelNameMap[label['name']] = labelNameMap[label['name'].upper()] = label['id']
return labelNameMap return labelNameMap
def _convertLabelNamesToIds(gmail, bodyLabels, labelNameMap, addLabelIfMissing): def _convertLabelNamesToIds(gmail, user, i, count, bodyLabels, labelNameMap, addLabel):
labelIds = [] labelIds = []
for label in bodyLabels: for label in bodyLabels:
if label in labelNameMap: if label in labelNameMap:
@ -68045,14 +68051,19 @@ def _convertLabelNamesToIds(gmail, bodyLabels, labelNameMap, addLabelIfMissing):
if label.upper() in labelNameMap: if label.upper() in labelNameMap:
labelIds.append(labelNameMap[label.upper()]) labelIds.append(labelNameMap[label.upper()])
continue continue
if not addLabelIfMissing: if not addLabel:
entityListDoesNotExistWarning([Ent.USER, user, Ent.LABEL, label], i, count)
continue continue
try: try:
results = callGAPI(gmail.users().labels(), 'create', results = callGAPI(gmail.users().labels(), 'create',
throwReasons=[GAPI.INVALID], throwReasons=[GAPI.INVALID],
userId='me', body={'labelListVisibility': 'labelShow', 'messageListVisibility': 'show', 'name': label}, fields='id') userId='me', body={'labelListVisibility': 'labelShow', 'messageListVisibility': 'show', 'name': label}, fields='id')
except GAPI.invalid as e: except GAPI.invalid as e:
entityActionFailedExit([Ent.LABEL, label], str(e)) action = Act.Get()
Act.Set(Act.CREATE)
entityActionFailedWarning([Ent.USER, user, Ent.LABEL, label], str(e), i, count)
Act.Set(action)
continue
labelNameMap[label] = labelNameMap[label.upper()] = results['id'] labelNameMap[label] = labelNameMap[label.upper()] = results['id']
labelIds.append(results['id']) labelIds.append(results['id'])
if label.find('/') != -1: if label.find('/') != -1:
@ -68289,7 +68300,7 @@ def _processMessagesThreads(users, entityType):
idsList += ',...' idsList += ',...'
try: try:
callGAPI(gmail.users().messages(), function, callGAPI(gmail.users().messages(), function,
throwReasons=GAPI.GMAIL_THROW_REASONS+[GAPI.INVALID_MESSAGE_ID, GAPI.INVALID, throwReasons=GAPI.GMAIL_THROW_REASONS+[GAPI.INVALID_MESSAGE_ID, GAPI.INVALID, GAPI.INVALID_ARGUMENT,
GAPI.FAILED_PRECONDITION, GAPI.PERMISSION_DENIED], GAPI.FAILED_PRECONDITION, GAPI.PERMISSION_DENIED],
userId='me', body=body) userId='me', body=body)
for messageId in body['ids']: for messageId in body['ids']:
@ -68300,7 +68311,7 @@ def _processMessagesThreads(users, entityType):
csvPF.WriteRow({'User': user, entityHeader: messageId, 'action': Act.Performed()}) csvPF.WriteRow({'User': user, entityHeader: messageId, 'action': Act.Performed()})
except (GAPI.serviceNotAvailable, GAPI.badRequest): except (GAPI.serviceNotAvailable, GAPI.badRequest):
mcount += bcount mcount += bcount
except (GAPI.invalid, GAPI.permissionDenied) as e: except (GAPI.invalid, GAPI.invalidArgument, GAPI.permissionDenied) as e:
_processMessageFailed(user, idsList, f'{str(e)} ({mcount+1}-{mcount+bcount}/{jcount})') _processMessageFailed(user, idsList, f'{str(e)} ({mcount+1}-{mcount+bcount}/{jcount})')
mcount += bcount mcount += bcount
except GAPI.invalidMessageId: except GAPI.invalidMessageId:
@ -68369,6 +68380,8 @@ def _processMessagesThreads(users, entityType):
csvPF.GetTodriveParameters() csvPF.GetTodriveParameters()
else: else:
unknownArgumentExit() unknownArgumentExit()
if function == 'modify' and not addLabelNames and not removeLabelNames:
missingArgumentExit('(addlabel <LabelName>)|(removelabel <LabelName>)')
_finalizeMessageSelectParameters(parameters, True) _finalizeMessageSelectParameters(parameters, True)
includeSpamTrash = Act.Get() in [Act.DELETE, Act.MODIFY, Act.UNTRASH] includeSpamTrash = Act.Get() in [Act.DELETE, Act.MODIFY, Act.UNTRASH]
if function == 'spam': if function == 'spam':
@ -68387,8 +68400,11 @@ def _processMessagesThreads(users, entityType):
if not userGmailLabels: if not userGmailLabels:
continue continue
labelNameMap = _initLabelNameMap(userGmailLabels) labelNameMap = _initLabelNameMap(userGmailLabels)
addLabelIds = _convertLabelNamesToIds(gmail, addLabelNames, labelNameMap, True) addLabelIds = _convertLabelNamesToIds(gmail, user, i, count, addLabelNames, labelNameMap, True)
removeLabelIds = _convertLabelNamesToIds(gmail, removeLabelNames, labelNameMap, False) removeLabelIds = _convertLabelNamesToIds(gmail, user, i, count, removeLabelNames, labelNameMap, False)
if not addLabelIds and not removeLabelIds:
entityActionNotPerformedWarning([Ent.USER, user], Msg.NO_LABELS_TO_PROCESS, i, count)
continue
try: try:
if parameters['messageEntity'] is None: if parameters['messageEntity'] is None:
printGettingAllEntityItemsForWhom(Ent.MESSAGE, user, i, count) printGettingAllEntityItemsForWhom(Ent.MESSAGE, user, i, count)
@ -69039,7 +69055,7 @@ def _draftImportInsertMessage(users, operation):
if not userGmailLabels: if not userGmailLabels:
continue continue
labelNameMap = _initLabelNameMap(userGmailLabels) labelNameMap = _initLabelNameMap(userGmailLabels)
body['labelIds'] = _convertLabelNamesToIds(gmail, addLabelNames, labelNameMap, True) body['labelIds'] = _convertLabelNamesToIds(gmail, user, i, count, addLabelNames, labelNameMap, True)
else: else:
body['labelIds'] = ['INBOX'] body['labelIds'] = ['INBOX']
result = callGAPI(gmail.users().messages(), function, result = callGAPI(gmail.users().messages(), function,

View File

@ -396,6 +396,7 @@ NO_ENTITIES_MATCHED = 'No {0} matched'
NO_FILTER_ACTIONS = 'No {0} actions specified' NO_FILTER_ACTIONS = 'No {0} actions specified'
NO_FILTER_CRITERIA = 'No {0} criteria specified' NO_FILTER_CRITERIA = 'No {0} criteria specified'
NO_LABELS_MATCH = 'No Labels match' NO_LABELS_MATCH = 'No Labels match'
NO_LABELS_TO_PROCESS = 'No Labels to process'
NO_MESSAGES_WITH_LABEL = 'No Messages with Label' NO_MESSAGES_WITH_LABEL = 'No Messages with Label'
NO_PARENTS_TO_CONVERT_TO_SHORTCUTS = 'No parents to convert to shortcuts' NO_PARENTS_TO_CONVERT_TO_SHORTCUTS = 'No parents to convert to shortcuts'
NO_REPORT_AVAILABLE = 'No {0} report available.' NO_REPORT_AVAILABLE = 'No {0} report available.'