Compare commits

..

3 Commits

Author SHA1 Message Date
Ross Scroggs
c81121df58 Updated code to validate both <RegularExpression> and <ReplacementString>
Some checks failed
Build and test GAM / build (Win64, build, 10, VC-WIN64A, windows-2022) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 3, linux-aarch64, ubuntu-24.04-arm) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 4, linux-aarch64, ubuntu-22.04-arm) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 6, linux-aarch64, ubuntu-22.04-arm, yes) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 8, darwin64-arm64, macos-14) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 9, darwin64-arm64, macos-15) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 1, linux-x86_64, ubuntu-22.04) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 2, linux-x86_64, ubuntu-24.04) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 5, linux-x86_64, ubuntu-22.04, yes) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 7, darwin64-x86_64, macos-13) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 11, ubuntu-24.04, 3.10) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 12, ubuntu-24.04, 3.11) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 13, ubuntu-24.04, 3.12) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Check for Google Root CA Updates / check-apis (push) Has been cancelled
Build and test GAM / merge (push) Has been cancelled
Build and test GAM / publish (push) Has been cancelled
2025-04-01 12:49:03 -07:00
Ross Scroggs
defac7d9a8 Added replaceregex <RegularExpression> <ReplacementString> <Tag> <String>
Some checks are pending
Build and test GAM / build (Win64, build, 10, VC-WIN64A, windows-2022) (push) Waiting to run
Build and test GAM / build (aarch64, build, 3, linux-aarch64, ubuntu-24.04-arm) (push) Waiting to run
Build and test GAM / build (aarch64, build, 4, linux-aarch64, ubuntu-22.04-arm) (push) Waiting to run
Build and test GAM / build (aarch64, build, 6, linux-aarch64, ubuntu-22.04-arm, yes) (push) Waiting to run
Build and test GAM / build (aarch64, build, 8, darwin64-arm64, macos-14) (push) Waiting to run
Build and test GAM / build (aarch64, build, 9, darwin64-arm64, macos-15) (push) Waiting to run
Build and test GAM / build (x86_64, build, 1, linux-x86_64, ubuntu-22.04) (push) Waiting to run
Build and test GAM / build (x86_64, build, 2, linux-x86_64, ubuntu-24.04) (push) Waiting to run
Build and test GAM / build (x86_64, build, 5, linux-x86_64, ubuntu-22.04, yes) (push) Waiting to run
Build and test GAM / build (x86_64, build, 7, darwin64-x86_64, macos-13) (push) Waiting to run
Build and test GAM / build (x86_64, test, 11, ubuntu-24.04, 3.10) (push) Waiting to run
Build and test GAM / build (x86_64, test, 12, ubuntu-24.04, 3.11) (push) Waiting to run
Build and test GAM / build (x86_64, test, 13, ubuntu-24.04, 3.12) (push) Waiting to run
Build and test GAM / merge (push) Blocked by required conditions
Build and test GAM / publish (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Check for Google Root CA Updates / check-apis (push) Waiting to run
2025-03-31 13:26:04 -07:00
Ross Scroggs
d308ad1271 Updated show events to honor show_convert_cr_nl
Some checks failed
Build and test GAM / build (Win64, build, 10, VC-WIN64A, windows-2022) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 3, linux-aarch64, ubuntu-24.04-arm) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 4, linux-aarch64, ubuntu-22.04-arm) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 6, linux-aarch64, ubuntu-22.04-arm, yes) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 8, darwin64-arm64, macos-14) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 9, darwin64-arm64, macos-15) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 1, linux-x86_64, ubuntu-22.04) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 2, linux-x86_64, ubuntu-24.04) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 5, linux-x86_64, ubuntu-22.04, yes) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 7, darwin64-x86_64, macos-13) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 11, ubuntu-24.04, 3.10) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 12, ubuntu-24.04, 3.11) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 13, ubuntu-24.04, 3.12) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Check for Google Root CA Updates / check-apis (push) Has been cancelled
Build and test GAM / merge (push) Has been cancelled
Build and test GAM / publish (push) Has been cancelled
2025-03-30 08:16:38 -07:00
4 changed files with 224 additions and 80 deletions

View File

@@ -1276,7 +1276,7 @@ If the pattern {{Section}} appears in <FileName>, it will be replaced with the n
For redirect csv, the optional arguments must appear in the order shown.
<Redirect> ::=
redirect csv <FileName> [multiprocess] [append] [noheader] [charset <Charset>]
[columndelimiter <Character>] [noescapechar [<Boolean>]] [quotechar <Character>]
[columndelimiter <Character>] [quotechar <Character>] [noescapechar [<Boolean>]]
[sortheaders <StringList>] [timestampcolumn <String>] [transpose [<Bopolean>]]
[todrive <ToDriveAttribute>*] |
redirect stdout <FileName> [multiprocess] [append] |
@@ -1908,7 +1908,7 @@ gam calendar|calendars <CalendarEntity> modify <CalendarSettings>+
<ChatContent> ::=
((text <String>)|
(textfile <FileName> [charset <CharSet>])|
(textfile <FileName> [charset <Charset>])|
(gdoc <UserGoogleDoc>)|
(gcsdoc <StorageBucketObjectName>))
@@ -3926,6 +3926,10 @@ gam print group-members [todrive <ToDriveAttribute>*]
# Cloud Identity Groups
<CBCMBrowser> ::= id:cbcm-browser.<DeviceId>
<ChromeOSDevice> ::= id:chrome-os-device.<DeviceId>
<BrowserDeviceList> ::= "(<CBCMBrowser>|<ChromeOSDevice>)(,(<CBCMBrowser>|<ChromeOSDevice>))*"
<CIGroupFieldsName> ::=
additionalgroupkeys|
createtime|
@@ -3955,12 +3959,12 @@ gam update cigroups <GroupEntity> create|add [<GroupRole>]
[usersonly|groupsonly]
[notsuspended|suspended] [notarchived|archived]
[expire|expires <Time>] [preview] [actioncsv]
<UserTypeEntity>
<UserTypeEntity>|<BrowserDeviceList>
gam update cigroups <GroupEntity> delete|remove [<GroupRole>]
[usersonly|groupsonly]
[notsuspended|suspended] [notarchived|archived]
[preview] [actioncsv]
<UserTypeEntity>
<UserTypeEntity>|<BrowserDeviceList>
gam update cigroups <GroupEntity> sync [<GroupRole>|ignorerole]
[usersonly|groupsonly] [addonly|removeonly]
[notsuspended|suspended] [notarchived|archived]
@@ -4731,8 +4735,10 @@ gam sendemail [recipient|to] <RecipientEntity>
[from <EmailAddress>] [mailbox <EmailAddress>] [replyto <EmailAddress>]
[cc <RecipientEntity>] [bcc <RecipientEntity>] [singlemessage]
[subject <String>]
[<MessageContent>] (replace <Tag> <String>)*
[html [<Boolean>]] (attach <FileName> [charset <CharSet>])*
[<MessageContent>]
(replace <Tag> <String>)*
(replaceregex <RegularExpression> <String> <Tag> <String>)*
[html [<Boolean>]] (attach <FileName> [charset <Charset>])*
(embedimage <FileName> <String>)*
[newuser <EmailAddress> firstname|givenname <String> lastname|familyname <string> password <Password>]
(<SMTPDateHeader> <Time>)* (<SMTPHeader> <String>)* (header <String> <String>)*
@@ -4740,8 +4746,10 @@ gam <UserTypeEntity> sendemail recipient|to <RecipientEntity>
[replyto <EmailAddress>]
[cc <RecipientEntity>] [bcc <RecipientEntity>] [singlemessage]
[subject <String>]
[<MessageContent>] (replace <Tag> <String>)*
[html [<Boolean>]] (attach <FileName> [charset <CharSet>])*
[<MessageContent>]
(replace <Tag> <String>)*
(replaceregex <RegularExpression> <String> <Tag> <String>)*
[html [<Boolean>]] (attach <FileName> [charset <Charset>])*
(embedimage <FileName> <String>)*
[newuser <EmailAddress> firstname|givenname <String> lastname|familyname <string> password <Password>]
(<SMTPDateHeader> <Time>)* (<SMTPHeader> <String>)* (header <String> <String>)*
@@ -4749,8 +4757,10 @@ gam <UserTypeEntity> sendemail from <EmailAddress>
[replyto <EmailAddress>]
[cc <RecipientEntity>] [bcc <RecipientEntity>] [singlemessage]
[subject <String>]
[<MessageContent>] (replace <Tag> <String>)*
[html [<Boolean>]] (attach <FileName> [charset <CharSet>])*
[<MessageContent>]
(replace <Tag> <String>)*
(replaceregex <RegularExpression> <String> <Tag> <String>)*
[html [<Boolean>]] (attach <FileName> [charset <Charset>])*
(embedimage <FileName> <String>)*
[newuser <EmailAddress> firstname|givenname <String> lastname|familyname <string> password <Password>]
(<SMTPDateHeader> <Time>)* (<SMTPHeader> <String>)* (header <String> <String>)*
@@ -5556,7 +5566,9 @@ gam create|add user <EmailAddress> [ignorenullpassword] <UserAttribute>*
[mailbox <EmailAaddress>]
[replyto <EmailAaddress>]
[<NotifyMessageContent>]
(replace <Tag> <UserReplacement>)*]
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
]
[logpassword <FileName>]
[addnumericsuffixonduplicate <Number>]
@@ -5565,7 +5577,7 @@ gam <UserTypeEntity> waitformailbox [retries <Number>]
gam update user <UserItem> [ignorenullpassword] <UserAttribute>*
[verifynotinvitable|alwaysevict] [noactionifalias]
[updateprimaryemail <RegularExpression> <EmailReplacement>]
[updateoufromgroup <FileName> [charset <CharSet>]
[updateoufromgroup <FileName> [charset <Charset>]
[columndelimiter <Character>] [noescapechar <Boolean>] [quotechar <Character>]
[fields <FieldNameList>] [keyfield <FieldName>] [datafield <FieldName>]]
[immutableous <OrgUnitEntity>]|
@@ -5577,10 +5589,12 @@ gam update user <UserItem> [ignorenullpassword] <UserAttribute>*
[subject <String>]
[notifypassword <String>]
[from <EmailAaddress>]
[mailbox <EmailAaddress>]
[replyto <EmailAaddress>]
[mailbox <EmailAddress>]
[replyto <EmailAddress>]
[<NotifyMessageContent>]
(replace <Tag> <UserReplacement>)*]
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
]
[notifyonupdate [<Boolean>]] [setchangepasswordoncreate [<Boolean>]]
[logpassword <FileName>]
gam delete user <UserItem> [noactionifalias]
@@ -5599,9 +5613,9 @@ gam info user [<UserItem>]
[formatjson]
gam update users <UserTypeEntity> [ignorenullpassword] <UserAttribute>*
[verifynotinvitable] [noactionifalias]
[verifynotinvitable|alwaysevict] [noactionifalias]
[updateprimaryemail <RegularExpression> <EmailReplacement>]
[updateoufromgroup <FileName> [charset <CharSet>]
[updateoufromgroup <FileName> [charset <Charset>]
[columndelimiter <Character>] [noescapechar <Boolean>] [quotechar <Character>]
[fields <FieldNameList>] [keyfield <FieldName>] [datafield <FieldName>]]
[clearschema <SchemaName>|<SchemaNameField>]
@@ -5611,13 +5625,15 @@ gam update users <UserTypeEntity> [ignorenullpassword] <UserAttribute>*
[notify <EmailAddressList>
[subject <String>]
[notifypassword <String>]
[from <EmailAaddress>]
[mailbox <EmailAaddress>]
[from <EmailAddress>]
[mailbox <EmailAddress>]
[replyto <EmailAaddress>]
[<NotifyMessageContent>]
(replace <Tag> <UserReplacement>)*]
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
]
[notifyonupdate [<Boolean>]] [setchangepasswordoncreate [<Boolean>]]
[logpassword <FileName>]
[verifynotinvitable]
gam delete users <UserTypeEntity> [noactionifalias]
gam undelete users <UserEntity> [ou|org|orgunit <OrgUnitPath>]
gam suspend users <UserTypeEntity> [noactionifalias]
@@ -5634,9 +5650,11 @@ gam info users <UserTypeEntity>
[formatjson]
gam <UserTypeEntity> update users [ignorenullpassword] <UserAttribute>*
[verifynotinvitable] [noactionifalias]
[verifynotinvitable|alwaysevict] [noactionifalias]
[updateprimaryemail <RegularExpression> <EmailReplacement>]
[updateoufromgroup <CSVFileInput> [keyfield <FieldName>] [datafield <FieldName>]]
[updateoufromgroup <FileName> [charset <Charset>]
[columndelimiter <Character>] [noescapechar <Boolean>] [quotechar <Character>]
[fields <FieldNameList>] [keyfield <FieldName>] [datafield <FieldName>]]
[clearschema <SchemaName>|<SchemaNameField>]
[createifnotfound] [notfoundpassword (random [<Integer>])|blocklogin|<Password>]
(groups [<GroupRole>] [[delivery] <DeliverySetting>] <GroupEntity>)*
@@ -5645,12 +5663,14 @@ gam <UserTypeEntity> update users [ignorenullpassword] <UserAttribute>*
[subject <String>]
[notifypassword <String>]
[from <EmailAaddress>]
[mailbox <EmailAaddress>]
[mailbox <EmailAddress>]
[replyto <EmailAddress>]
[<NotifyMessageContent>]
(replace <Tag> <UserReplacement>)*]
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
]
[notifyonupdate [<Boolean>]] [setchangepasswordoncreate [<Boolean>]]
[logpassword <FileName>]
[verifynotinvitable]
gam <UserTypeEntity> delete users [noactionifalias]
gam <UserEntity> undelete users [ou|org|orgunit <OrgUnitPath>]
gam <UserTypeEntity> suspend users [noactionifalias]
@@ -6161,7 +6181,7 @@ gam <UserTypeEntity> print focustime|outofoffice|workinglocation
<ChatContent> ::=
((text <String>)|
(textfile <FileName> [charset <CharSet>])|
(textfile <FileName> [charset <Charset>])|
(gdoc <UserGoogleDoc>)|
(gcsdoc <StorageBucketObjectName>))
@@ -6523,7 +6543,7 @@ gam <UserTypeEntity> update drivefile <DriveFileEntity> [copy] [returnidonly|ret
[timestamp [<Boolean>]] [timeformat <String>]
<DriveFileUpdateAttribute>*
[(gsheet|csvsheet <SheetEntity> [clearfilter])|(addsheet <String>)]
[charset <CharSet>] [columndelimiter <Character>]
[charset <Charset>] [columndelimiter <Character>]
<DriveFileCopyAttribute> ::=
(contentrestrictions (readonly false)|(readonly true [reason <String>]) [ownerrestricted [<Boolean>]])|
@@ -7528,22 +7548,28 @@ gam <UserTypeEntity> print labels|label [todrive <ToDriveAttribute>*]
(emlfile <FileName> [charset <Charset>])
gam <UserTypeEntity> draft message
<MessageContent> (replace <Tag> <UserReplacement>)*
<MessageContent>
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
(<SMTPDateHeader> <Time>)* (<SMTPHeader> <String>)* (header <String> <String>)*
(attach <FileName> [charset <CharSet>])*
(attach <FileName> [charset <Charset>])*
(embedimage <FileName> <String>)*
gam <UserTypeEntity> import message
<MessageContent> (replace <Tag> <UserReplacement>)*
<MessageContent>
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
(<SMTPDateHeader> <Time>)* (<SMTPHeader> <String>)* (header <String> <String>)*
(addlabel <LabelName>)* [labels <LabelNameList>]
(attach <FileName> [charset <CharSet>])*
(attach <FileName> [charset <Charset>])*
(embedimage <FileName> <String>)*
[deleted [<Boolean>]] [checkspam|nevermarkspam [<Boolean>]] [processforcalendar [<Boolean>]]
gam <UserTypeEntity> insert message
<MessageContent> (replace <Tag> <UserReplacement>)*
<MessageContent>
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
(<SMTPDateHeader> <Time>)* (<SMTPHeader> <String>)* (header <String> <String>)*
(addlabel <LabelName>)* [labels <LabelNameList>]
(attach <FileName> [charset <CharSet>])*
(attach <FileName> [charset <Charset>])*
(embedimage <FileName> <String>)*
[deleted [<Boolean>]]
@@ -7622,13 +7648,17 @@ gam <UserTypeEntity> print gmailprofile [todrive <ToDriveAttribute>*]
# Users - Gmail - Send As/Signature/Vacation
gam <UserTypeEntity> [create|add] sendas <EmailAddress> [name] <String>
[<SendAsContent> (replace <Tag> <UserReplacement>)*]
[<SendAsContent>
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*]
[html [<Boolean>]] [replyto <EmailAddress>] [default] [treatasalias <Boolean>]
[smtpmsa.host <SMTPHostName> smtpmsa.port 25|465|587
smtpmsa.username <UserName> smtpmsa.password <Password>
[smtpmsa.securitymode none|ssl|starttls]]
gam <UserTypeEntity> update sendas <EmailAddress> [name <String>]
[<SendAsContent> (replace <Tag> <UserReplacement>)*]
[<SendAsContent>
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*]
[html [<Boolean>]] [replyto <EmailAddress>] [default] [treatasalias <Boolean>]
gam <UserTypeEntity> delete sendas <EmailAddressEntity>
gam <UserTypeEntity> info sendas <EmailAddressEntity> [compact|format|html]
@@ -7638,7 +7668,9 @@ gam <UserTypeEntity> print sendas [compact]
[primary|default] [verifyonly] [todrive <ToDriveAttribute>*]
gam <UserTypeEntity> signature|sig
<SignatureContent> (replace <Tag> <UserReplacement>)*
<SignatureContent>
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
[html [<Boolean>]] [replyto <EmailAddress>] [default] [treatasalias <Boolean>]
[name <String>]
[primary]
@@ -7648,7 +7680,9 @@ gam <UserTypeEntity> print signature [compact]
[primary|default] [verifyonly] [todrive <ToDriveAttribute>*]
gam <UserTypeEntity> vacation [<Boolean>] [subject <String>]
[<VacationMessageContent> (replace <Tag> <UserReplacement>)*]
[<VacationMessageContent>
(replace <Tag> <UserReplacement>)*
(replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*]
[html [<Boolean>]] [contactsonly [<Boolean>]] [domainonly [<Boolean>]]
[start|startdate <Date>|Started] [end|enddate <Date>|NotSpecified]
gam <UserTypeEntity> show vacation [compact|format|html] [enabledonly]
@@ -7775,7 +7809,7 @@ gam <UserTypeEntity> check isinvitable [todrive <ToDriveAttribute>*]
<NoteContent> ::=
((text <String>)|
(textfile <FileName> [charset <CharSet>])|
(textfile <FileName> [charset <Charset>])|
(gdoc <UserGoogleDoc>)|
(gcsdoc <StorageBucketObjectName>)|
<JSONData>)

View File

@@ -1,3 +1,68 @@
7.05.20
Updated code to validate both `<RegularExpression>` and `<ReplacementString>`
in the following command line options; this will expose errors when the command
is being parsed rather than at run-time.
```
replaceregex <RegularExpression> <ReplacementString>
replacedescription <RegularExpression> <ReplacementString>
replacefilename <RegularExpression> <ReplacementString>
```
7.05.19
Added `replaceregex <RegularExpression> <ReplacementString> <Tag> <String>` to the following commands:
```
gam sendemail subject <String> <MessageContent>
gam <UserTypeEntity> sendemail subject <String> <MessageContent>
```
The `<RegularExpression>` is used as a match pattern against `<String>` to produce `<ReplacementString>`.
Instances of `{Tag}` will be replaced by `<ReplacementString>` in the message subject and body.
Added `replaceregex <RegularExpression> <ReplacementString> <Tag> <UserReplacement>` to the following commands:
```
gam create user <NotifyMessageContent>
gam update user <NotifyMessageContent>
gam update users <NotifyMessageContent>
gam <UserTypeEntity> update users <NotifyMessageContent>
gam <UserTypeEntity> draft message <MessageContent>
gam <UserTypeEntity> import message <MessageContent>
gam <UserTypeEntity> insert messageo <MessageContent>
gam <UserTypeEntity> create sendas <SendAsContent>
gam <UserTypeEntity> update sendas <SendAsContent>
gam <UserTypeEntity> signature <SignatureContent>
gam <UserTypeEntity> vacation subject <String> <VacationMessageContent>
```
The `<RegularExpression>` is used as a match pattern against `<UserReplacement>` to produce `<ReplacementString>`.
Instances of `{Tag}` will be replaced by `<ReplacementString>` in the indicated items.
For example, when adding a phone number to a signature, an unformatted number can be formatted:
```
replaceregex "(\d{3})(\d{3})(\d{4})" "(\1) \2-\3" Phone "9876543210"
replaces 9876543210 with (987) 654-3210
replaceregex "(\+\d{2})(\d{3})(\d{3})(\d{3})" "\1 \2 \3 \4" Phone "+61987654321"
replaces +61421221506 with +61 987 654 321
```
7.05.18
Updated `gam calendars <CalendarEntity> show events` and `gam <UserTypeEntity> show events`
to display the event description according to `show_convert_cr_nl` in `gam.cfg`;
previously, GAM assumed `show_convert_cr_nl = true`.
```
show_convert_cr_nl = false
description:
Line 1
Line 2
Line 3
show_convert_cr_nl = true
description: Line 1\nLine 2\nLine 3\n
```
7.05.17
Updated commands that delete drive ACLs to handle the following error:

View File

@@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki
"""
__author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
__version__ = '7.05.17'
__version__ = '7.05.20'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
#pylint: disable=wrong-import-position
@@ -1723,6 +1723,16 @@ def getREPattern(flags=0):
return validateREPattern(patstr, flags)
missingArgumentExit(Cmd.OB_RE_PATTERN)
def getREPatternReplacement(flags=0):
pattern = getREPattern(flags)
replacement = getString(Cmd.OB_STRING, minLen=0)
try:
re.sub(pattern, replacement, '')
return (pattern, replacement)
except re.error as e:
Cmd.Backup()
usageErrorExit(f'{Cmd.OB_RE_REPLACEMENT} {Msg.ERROR}: {e}')
def getSheetEntity(allowBlankSheet):
if Cmd.ArgumentsRemaining():
sheet = Cmd.Current()
@@ -4088,13 +4098,8 @@ def SetGlobalVariables():
GC.Values[GC.OUTPUT_DATEFORMAT] = GM.Globals[GM.OUTPUT_DATEFORMAT]
if not GC.Values[GC.OUTPUT_TIMEFORMAT]:
GC.Values[GC.OUTPUT_TIMEFORMAT] = GM.Globals[GM.OUTPUT_TIMEFORMAT]
# Create/set mode for oauth2.txt.lock
if not GM.Globals[GM.OAUTH2_TXT_LOCK]:
fileName = f'{GC.Values[GC.OAUTH2_TXT]}.lock'
if not os.path.isfile(fileName):
closeFile(openFile(fileName, mode=DEFAULT_FILE_APPEND_MODE))
os.chmod(fileName, 0o666)
GM.Globals[GM.OAUTH2_TXT_LOCK] = fileName
# Define lockfile: oauth2.txt.lock
GM.Globals[GM.OAUTH2_TXT_LOCK] = f'{GC.Values[GC.OAUTH2_TXT]}.lock'
# Override httplib2 settings
httplib2.debuglevel = GC.Values[GC.DEBUG_LEVEL]
# Reset global variables if required
@@ -4113,7 +4118,7 @@ def SetGlobalVariables():
if checkArgumentPresent(Cmd.MULTIPROCESSEXIT_CMD):
_setMultiprocessExit()
# redirect csv <FileName> [multiprocess] [append] [noheader] [charset <CharSet>]
# [columndelimiter <Character>] [noescapechar [<Boolean>]] [quotechar <Character>]]
# [columndelimiter <Character>] [quotechar <Character>]] [noescapechar [<Boolean>]]
# [sortheaders <StringList>] [timestampcolumn <String>] [transpose [<Boolean>]]
# [todrive <ToDriveAttribute>*]
# redirect stdout <FileName> [multiprocess] [append]
@@ -14522,7 +14527,13 @@ def _initTagReplacements():
'fieldsSet': set(), 'fields': '',
'schemasSet': set(), 'customFieldMask': None}
def _getTagReplacement(tagReplacements, allowSubs):
def _getTagReplacement(myarg, tagReplacements, allowSubs):
if myarg == 'replace':
trregex = None
elif myarg == 'replaceregex':
trregex = getREPatternReplacement(re.IGNORECASE)
else:
return False
matchTag = getString(Cmd.OB_TAG)
matchReplacement = getString(Cmd.OB_STRING, minLen=0)
if matchReplacement.startswith('field:'):
@@ -14567,7 +14578,8 @@ def _getTagReplacement(tagReplacements, allowSubs):
tagReplacements['fieldsSet'].add(field)
tagReplacements['fields'] = ','.join(tagReplacements['fieldsSet'])
tagReplacements['tags'][matchTag] = {'field': field, 'subfield': subfield,
'matchfield': matchfield, 'matchvalue': matchvalue, 'value': ''}
'matchfield': matchfield, 'matchvalue': matchvalue, 'value': '',
'trregex': trregex}
if field == 'locations' and subfield == 'buildingName':
_makeBuildingIdNameMap()
elif matchReplacement.startswith('schema:'):
@@ -14585,15 +14597,21 @@ def _getTagReplacement(tagReplacements, allowSubs):
tagReplacements['fields'] = ','.join(tagReplacements['fieldsSet'])
tagReplacements['schemasSet'].add(schemaName)
tagReplacements['customFieldMask'] = ','.join(tagReplacements['schemasSet'])
tagReplacements['tags'][matchTag] = {'schema': schemaName, 'schemafield': schemaField, 'value': ''}
tagReplacements['tags'][matchTag] = {'schema': schemaName, 'schemafield': schemaField, 'value': '',
'trregex': trregex}
elif ((matchReplacement.find('#') >= 0) and
(matchReplacement.find('#user#') >= 0) or (matchReplacement.find('#email#') >= 0) or (matchReplacement.find('#username#') >= 0)):
if not allowSubs:
usageErrorExit(Msg.USER_SUBS_NOT_ALLOWED_TAG_REPLACEMENT)
tagReplacements['subs'] = True
tagReplacements['tags'][matchTag] = {'template': matchReplacement, 'value': ''}
tagReplacements['tags'][matchTag] = {'template': matchReplacement, 'value': '',
'trregex': trregex}
else:
tagReplacements['tags'][matchTag] = {'value': matchReplacement}
if trregex is None:
tagReplacements['tags'][matchTag] = {'value': matchReplacement}
else:
tagReplacements['tags'][matchTag] = {'value': re.sub(trregex[0], trregex[1], matchReplacement)}
return True
def _getTagReplacementFieldValues(user, i, count, tagReplacements, results=None):
if results is None:
@@ -14675,6 +14693,9 @@ def _getTagReplacementFieldValues(user, i, count, tagReplacements, results=None)
tag['value'] = str(results.get('customSchemas', {}).get(tag['schema'], {}).get(tag['schemafield'], ''))
elif tag.get('template'):
tag['value'] = _substituteForUser(tag['template'], user, userName)
trregex = tag.get('trregex', None)
if trregex is not None:
tag['value'] = re.sub(trregex[0], trregex[1], tag['value'])
RTL_PATTERN = re.compile(r'(?s){RTL}.*?{/RTL}')
RT_PATTERN = re.compile(r'(?s){RT}.*?{/RT}')
@@ -14927,7 +14948,9 @@ def getRecipients():
# gam sendemail [recipient|to] <RecipientEntity> [from <EmailAddress>] [mailbox <EmailAddress>] [replyto <EmailAddress>]
# [cc <RecipientEntity>] [bcc <RecipientEntity>] [singlemessage]
# [subject <String>]
# [<MessageContent>] (replace <Tag> <String>)*
# [<MessageContent>]
# (replace <Tag> <String>)*
# (replaceregex <RegularExpression> <String> <Tag> <String>)*
# [html [<Boolean>]] (attach <FileName> [charset <CharSet>])*
# (embedimage <FileName> <String>)*
# [newuser <EmailAddress> firstname|givenname <String> lastname|familyname <string> password <Password>]
@@ -14935,7 +14958,9 @@ def getRecipients():
# gam <UserTypeEntity> sendemail recipient <RecipientEntity> [replyto <EmailAddress>]
# [cc <RecipientEntity>] [bcc <RecipientEntity>] [singlemessage]
# [subject <String>]
# [<MessageContent>] (replace <Tag> <String>)*
# [<MessageContent>]
# (replace <Tag> <String>)*
# (replaceregex <RegularExpression> <String> <Tag> <String>)*
# [html [<Boolean>]] (attach <FileName> [charset <CharSet>])*
# (embedimage <FileName> <String>)*
# [newuser <EmailAddress> firstname|givenname <String> lastname|familyname <string> password <Password>]
@@ -14943,7 +14968,9 @@ def getRecipients():
# gam <UserTypeEntity> sendemail from <EmailAddress> [replyto <EmailAddress>]
# [cc <RecipientEntity>] [bcc <RecipientEntity>] [singlemessage]
# [subject <String>]
# [<MessageContent>] (replace <Tag> <String>)*
# [<MessageContent>]
# (replace <Tag> <String>)*
# (replaceregex <RegularExpression> <String> <Tag> <String>)*
# [html [<Boolean>]] (attach <FileName> [charset <CharSet>])*
# (embedimage <FileName> <String>)*
# [newuser <EmailAddress> firstname|givenname <String> lastname|familyname <string> password <Password>]
@@ -15006,8 +15033,8 @@ def doSendEmail(users=None):
body['name']['familyName'] = getString(Cmd.OB_STRING, minLen=0, maxLen=60)
elif myarg in {'password', 'notifypassword'}:
body['password'] = notify['password'] = getString(Cmd.OB_PASSWORD, maxLen=100)
elif myarg == 'replace':
_getTagReplacement(tagReplacements, False)
elif _getTagReplacement(myarg, tagReplacements, False):
pass
elif myarg == 'attach':
attachments.append((getFilename(), getCharSet()))
elif myarg == 'embedimage':
@@ -38537,7 +38564,7 @@ def _getCalendarEventAttribute(myarg, body, parameters, function):
elif myarg == 'description':
body['description'] = getStringWithCRsNLs()
elif function == 'update' and myarg == 'replacedescription':
parameters['replaceDescription'].append((getREPattern(re.IGNORECASE), getString(Cmd.OB_STRING, minLen=0)))
parameters['replaceDescription'].append(getREPatternReplacement(re.IGNORECASE))
elif myarg == 'location':
body['location'] = getString(Cmd.OB_STRING, minLen=0)
elif myarg == 'source':
@@ -39410,7 +39437,10 @@ def _showCalendarEvent(primaryEmail, calId, eventEntityType, event, k, kcount, F
Ind.Increment()
for field in EVENT_SHOW_ORDER:
if field in event:
showJSON(field, event[field], skipObjects, EVENT_TIME_OBJECTS)
if field != 'description':
showJSON(field, event[field], skipObjects, EVENT_TIME_OBJECTS)
else:
printKeyValueWithCRsNLs(field, event[field])
skipObjects.add(field)
showJSON(None, event, skipObjects)
Ind.Decrement()
@@ -42837,8 +42867,8 @@ def getUserAttributes(cd, updateCmd, noUid=False):
notify['mailbox'] = getString(Cmd.OB_EMAIL_ADDRESS)
elif PwdOpts.ProcessArgument(myarg, notify, notFoundBody):
pass
elif myarg == 'replace':
_getTagReplacement(tagReplacements, True)
elif _getTagReplacement(myarg, tagReplacements, True):
pass
elif myarg == 'admin':
value = getBoolean()
if updateCmd or value:
@@ -43255,9 +43285,9 @@ def createUserAddAliases(cd, user, aliasList, i, count):
# [from <EmailAaddress>]
# [replyto <EmailAaddress>]
# [<NotifyMessageContent>]
# (replace <Tag> <UserReplacement>)*]
# (replace <Tag> <UserReplacement>)*
# (replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*]
# [logpassword <FileName>] [ignorenullpassword]
# [verifynotinvitable]
# [addnumericsuffixonduplicate <Number>]
def doCreateUser():
cd = buildGAPIObject(API.DIRECTORY)
@@ -43356,8 +43386,9 @@ def verifyUserPrimaryEmail(cd, user, createIfNotFound, i, count):
# [notifypassword <String>]
# [from <EmailAaddress>]
# [replyto <EmailAaddress>]
# [<NotifyMessageContent>]
# (replace <Tag> <UserReplacement>)*]
# [<NotifyMessageContent>
# (replace <Tag> <UserReplacement>)*
# (replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*]
# [notifyonupdate [<Boolean>]]
# [logpassword <FileName>] [ignorenullpassword]
def updateUsers(entityList):
@@ -52805,7 +52836,7 @@ def getDriveFileAttribute(myarg, body, parameters, updateCmd):
elif myarg =='stripnameprefix':
parameters[DFA_STRIPNAMEPREFIX] = getString(Cmd.OB_STRING, minLen=0)
elif myarg == 'replacefilename':
parameters[DFA_REPLACEFILENAME].append((getREPattern(re.IGNORECASE), getString(Cmd.OB_STRING, minLen=0)))
parameters[DFA_REPLACEFILENAME].append(getREPatternReplacement(re.IGNORECASE))
elif myarg in {'convert', 'ocr'}:
deprecatedArgument(myarg)
stderrWarningMsg(Msg.USE_MIMETYPE_TO_SPECIFY_GOOGLE_FORMAT)
@@ -58362,7 +58393,7 @@ def getCopyMoveOptions(myarg, copyMoveOptions):
elif myarg =='stripnameprefix':
copyMoveOptions['stripNamePrefix'] = getString(Cmd.OB_STRING, minLen=0)
elif myarg == 'replacefilename':
copyMoveOptions['replaceFilename'].append((getREPattern(re.IGNORECASE), getString(Cmd.OB_STRING, minLen=0)))
copyMoveOptions['replaceFilename'].append(getREPatternReplacement(re.IGNORECASE))
elif myarg == 'showpermissionmessages':
copyMoveOptions['showPermissionMessages'] = getBoolean()
elif myarg == 'sendemailifrequired':
@@ -69993,8 +70024,8 @@ def _draftImportInsertMessage(users, operation):
internalDateSource = 'dateHeader'
if checkArgumentPresent('emlutf8'):
emlEncoding = UTF8
elif myarg == 'replace':
_getTagReplacement(tagReplacements, True)
elif _getTagReplacement(myarg, tagReplacements, True):
pass
elif operation in IMPORT_INSERT and myarg == 'addlabel':
addLabelNames.append(getString(Cmd.OB_LABEL_NAME, minLen=1))
elif operation in IMPORT_INSERT and myarg == 'labels':
@@ -70129,7 +70160,9 @@ def _draftImportInsertMessage(users, operation):
userGmailServiceNotEnabledWarning(user, i, count)
# gam <UserTypeEntity> draft message
# <MessageContent> (replace <Tag> <UserReplacement>)*
# <MessageContent>
# (replace <Tag> <UserReplacement>)*
# (replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
# (<SMTPDateHeader> <Time>)* (<SMTPHeader> <String>)* (header <String> <String>)*
# (attach <FileName> [charset <CharSet>])*
# (embedimage <FileName> <String>)*
@@ -70137,7 +70170,9 @@ def draftMessage(users):
_draftImportInsertMessage(users, 'draft')
# gam <UserTypeEntity> import message
# <MessageContent> (replace <Tag> <UserReplacement>)*
# <MessageContent>
# (replace <Tag> <UserReplacement>)*
# (replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
# (<SMTPDateHeader> <Time>)* (<SMTPHeader> <String>)* (header <String> <String>)*
# (addlabel <LabelName>)* [labels <LabelNameList>]
# (attach <FileName> [charset <CharSet>])*
@@ -70147,7 +70182,9 @@ def importMessage(users):
_draftImportInsertMessage(users, 'import')
# gam <UserTypeEntity> insert message
# <MessageContent> (replace <Tag> <UserReplacement>)*
# <MessageContent>
# (replace <Tag> <UserReplacement>)*
# (replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*
# (<SMTPDateHeader> <Time>)* (<SMTPHeader> <String>)* (header <String> <String>)*
# (addlabel <LabelName>)* [labels <LabelNameList>]
# (attach <FileName> [charset <CharSet>])*
@@ -72434,8 +72471,8 @@ def _processSendAs(user, i, count, entityType, emailAddress, j, jcount, gmail, f
return userDefined
def getSendAsAttributes(myarg, body, tagReplacements):
if myarg == 'replace':
_getTagReplacement(tagReplacements, True)
if _getTagReplacement(myarg, tagReplacements, True):
pass
elif myarg == 'name':
body['displayName'] = getString(Cmd.OB_NAME, minLen=0)
elif myarg == 'replyto':
@@ -72454,13 +72491,17 @@ SMTPMSA_SECURITY_MODES = ['none', 'ssl', 'starttls']
SMTPMSA_REQUIRED_FIELDS = ['host', 'port', 'username', 'password']
# gam <UserTypeEntity> [create] sendas <EmailAddress> [name] <String>
# [<SendAsContent> (replace <Tag> <UserReplacement>)*]
# [<SendAsContent>
# (replace <Tag> <UserReplacement>)*
# (replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*]
# [html [<Boolean>]] [replyto <EmailAddress>] [default] [treatasalias <Boolean>]
# [smtpmsa.host <SMTPHostName> smtpmsa.port 25|465|587
# smtpmsa.username <UserName> smtpmsa.password <Password>
# [smtpmsa.securitymode none|ssl|starttls]]
# gam <UserTypeEntity> update sendas <EmailAddress> [name <String>]
# [<SendAsContent> (replace <Tag> <UserReplacement>)*]
# [<SendAsContent>
# (replace <Tag> <UserReplacement>)*
# (replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*]
# [html [<Boolean>]] [replyto <EmailAddress>] [default] [treatasalias <Boolean>]
def createUpdateSendAs(users):
updateCmd = Act.Get() == Act.UPDATE
@@ -73297,6 +73338,7 @@ def printShowCSEKeyPairs(users):
# gam <UserTypeEntity> signature|sig
# <SignatureContent>
# (replace <Tag> <String>)*
# (replaceregex <RegularExpression> <String> <Tag> <String>)*
# [html [<Boolean>]] [replyto <EmailAddress>] [default] [treatasalias <Boolean>]
# [name <String>]
# [primary]
@@ -73390,7 +73432,9 @@ def _showVacation(user, i, count, result, showDisabled, sigReplyFormat):
Ind.Decrement()
# gam <UserTypeEntity> vacation [<Boolean>] [subject <String>]
# [<VacationMessageContent> (replace <Tag> <UserReplacement>)*]
# [<VacationMessageContent>
# (replace <Tag> <UserReplacement>)*
# (replaceregex <RegularExpression> <String> <Tag> <UserReplacement>)*]
# [html [<Boolean>]] [contactsonly [<Boolean>]] [domainonly [<Boolean>]]
# [start|startdate <Date>|Started] [end|enddate <Date>|NotSpecified]
def setVacation(users):
@@ -73408,8 +73452,8 @@ def setVacation(users):
message, _, html = getStringOrFile(myarg)
if html:
responseBodyType = 'responseBodyHtml'
elif myarg == 'replace':
_getTagReplacement(tagReplacements, True)
elif _getTagReplacement(myarg, tagReplacements, True):
pass
elif myarg == 'html':
if getBoolean():
responseBodyType = 'responseBodyHtml'

View File

@@ -991,6 +991,7 @@ class GamCLArgs():
OB_RESOURCE_ENTITY = 'ResourceEntity'
OB_RESOURCE_ID = 'ResourceID'
OB_RE_PATTERN = 'REPattern'
OB_RE_REPLACEMENT = 'REReplacement'
OB_ROLE_ASSIGNMENT_ID = 'RoleAssignmentID'
OB_ROLE_ITEM = 'RoleItem'
OB_ROLE_LIST = 'RoleList'