mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-08 21:53:36 +00:00
Add replace argument to gam signature/vacation to allow replacement in data read from file
This commit is contained in:
@ -43,6 +43,7 @@ If an item contains spaces, it should be surrounded by " or '.
|
||||
<DateTime> ::= <Year>-<Month>-<Day>(<Space>|T)<Hour>:<Minute>
|
||||
<Time> ::= <Year>-<Month>-<Day>(<Space>|T)<Hour>:<Minute>[:<Second>[.<MilliSeconds>[Z]]]
|
||||
<PrintJobAge> ::= <Number>(m|h|d)
|
||||
<REPattern> ::= <Python Regular Expression, see: https://docs.python.org/2/library/re.html>
|
||||
<UniqueID> ::= uid:<String>
|
||||
|
||||
# Named items
|
||||
@ -680,7 +681,7 @@ gam <UserTypeEntity> deprovision|deprov
|
||||
gam <UserTypeEntity> [add] label|labels <Name> [messagelistvisibility hide|show] [labellistvisibility hide|show|showifunread]
|
||||
gam <UserTypeEntity> update labelsettings <LabelName> [name <Name>] [messagelistvisibility hide|show] [labellistvisibility hide|show|showifunread]
|
||||
gam <UserTypeEntity> update label|labels [search <PythonRegularExpression>] [replace <LabelReplacement>] [merge]
|
||||
gam <UserTypeEntity> delete|del label|labels <LabelName>|regex:<LabelREPattern>|--ALL_LABELS--
|
||||
gam <UserTypeEntity> delete|del label|labels <LabelName>|regex:<REPattern>|--ALL_LABELS--
|
||||
gam <UserTypeEntity> show labels|label [onlyuser] [showcounts]
|
||||
|
||||
gam <UserTypeEntity> delete message|messages query <Query> [doit] [max_to_delete <Number>]
|
||||
@ -722,14 +723,15 @@ gam <UserTypeEntity> show sendas
|
||||
|
||||
gam <UserTypeEntity> shortcuts <Boolean>
|
||||
|
||||
gam <UserTypeEntity> signature|sig <String>|(file <FileName> [charset <Charset>])
|
||||
gam <UserTypeEntity> signature|sig <String>|(file <FileName> [charset <Charset>]) (replace <REPattern> <String>)*
|
||||
gam <UserTypeEntity> show signature|sig
|
||||
gam <UserTypeEntity> snippets <Boolean>
|
||||
|
||||
gam <UserTypeEntity> utf|utf8|utf-8|unicode <Boolean>
|
||||
|
||||
gam <UserTypeEntity> vacation <FalseValues>
|
||||
gam <UserTypeEntity> vacation <TrueValues> subject <String> (message <String>)|(file <FileName> [charset <CharSet>]) [contactsonly] [domainonly] [startdate <Date>] [enddate <Date>]
|
||||
gam <UserTypeEntity> vacation <TrueValues> subject <String> (message <String>)|(file <FileName> [charset <CharSet>]) (replace <REPattern> <String>)*
|
||||
[contactsonly] [domainonly] [startdate <Date>] [enddate <Date>]
|
||||
gam <UserTypeEntity> show vacation
|
||||
|
||||
gam <UserTypeEntity> webclips <Boolean>
|
||||
|
53
src/gam.py
53
src/gam.py
@ -379,6 +379,32 @@ def getCharSet(i):
|
||||
return (i, GC_Values.get(GC_CHARSET, GM_Globals[GM_SYS_ENCODING]))
|
||||
return (i+2, sys.argv[i+1])
|
||||
|
||||
def getREPattern(i):
|
||||
if i < len(sys.argv):
|
||||
patstr = sys.argv[i]
|
||||
if patstr:
|
||||
try:
|
||||
pattern = re.compile(patstr)
|
||||
return pattern
|
||||
except re.error as e:
|
||||
print u'ERROR: "{0}" is not a valid RE pattern: {1}'.format(patstr, e)
|
||||
sys.exit(2)
|
||||
print u'ERROR: expected an <REPattern>'
|
||||
sys.exit(2)
|
||||
|
||||
def getString(i, item, emptyOK=False, optional=False):
|
||||
if i < len(sys.argv):
|
||||
argstr = sys.argv[i]
|
||||
if argstr:
|
||||
return argstr
|
||||
if emptyOK or optional:
|
||||
return u''
|
||||
print u'ERROR: expected a Non-empty <{0}>'.format(item)
|
||||
sys.exit(2)
|
||||
elif optional:
|
||||
return u''
|
||||
print u'ERROR: expected a <{0}>'.format(item)
|
||||
sys.exit(2)
|
||||
#
|
||||
# Open a file
|
||||
#
|
||||
@ -5062,19 +5088,24 @@ def getForward(users):
|
||||
pass
|
||||
|
||||
def doSignature(users):
|
||||
import cgi
|
||||
i = 4
|
||||
if sys.argv[i].lower() == u'file':
|
||||
filename = sys.argv[i+1]
|
||||
i += 2
|
||||
i, encoding = getCharSet(i)
|
||||
signature = readFile(filename, encoding=encoding).replace(u'\\n', u'
').replace(u'\n', u'<br/>')
|
||||
signature = readFile(filename, encoding=encoding).replace(u'\\n', u'<br/>').replace(u'\n', u'<br/>')
|
||||
else:
|
||||
signature = cgi.escape(sys.argv[i]).replace(u'\\n', u'
').replace(u'"', u"'")
|
||||
xmlsig = u'''<?xml version="1.0" encoding="utf-8"?>
|
||||
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006">
|
||||
<apps:property name="signature" value="%s" />
|
||||
</atom:entry>''' % signature
|
||||
signature = getString(i, u'String', emptyOK=True).replace(u'\\n', u'<br/>').replace(u'\n', u'<br/>')
|
||||
i += 1
|
||||
while i < len(sys.argv):
|
||||
if sys.argv[i].lower() == u'replace':
|
||||
matchPattern = getREPattern(i+1)
|
||||
matchReplacement = getString(i+2, u'String', emptyOK=True)
|
||||
signature = matchPattern.sub(matchReplacement, signature)
|
||||
i += 3
|
||||
else:
|
||||
print u'ERROR: %s is not a valid argument for "gam <users> signature"' % sys.argv[i]
|
||||
sys.exit(2)
|
||||
emailsettings = getEmailSettingsObject()
|
||||
count = len(users)
|
||||
i = 1
|
||||
@ -5085,9 +5116,8 @@ def doSignature(users):
|
||||
else:
|
||||
emailsettings.domain = GC_Values[GC_DOMAIN] #make sure it's back at default domain
|
||||
print u"Setting Signature for %s (%s of %s)" % (user+u'@'+emailsettings.domain, i, count)
|
||||
uri = u'https://apps-apis.google.com/a/feeds/emailsettings/2.0/%s/%s/signature' % (emailsettings.domain, user)
|
||||
i += 1
|
||||
callGData(emailsettings, u'Put', soft_errors=True, data=xmlsig, uri=uri)
|
||||
callGData(emailsettings, u'UpdateSignature', soft_errors=True, username=user, signature=signature)
|
||||
|
||||
def getSignature(users):
|
||||
emailsettings = getEmailSettingsObject()
|
||||
@ -5161,6 +5191,11 @@ def doVacation(users):
|
||||
i += 2
|
||||
i, encoding = getCharSet(i)
|
||||
message = readFile(filename, encoding=encoding)
|
||||
elif sys.argv[i].lower() == u'replace':
|
||||
matchPattern = getREPattern(i+1)
|
||||
matchReplacement = getString(i+2, u'String', emptyOK=True)
|
||||
message = matchPattern.sub(matchReplacement, message)
|
||||
i += 3
|
||||
else:
|
||||
print u'ERROR: %s is not a valid argument for "gam <users> vacation"' % sys.argv[i]
|
||||
sys.exit(2)
|
||||
|
@ -59,6 +59,13 @@ Added argument to `gam update group` to allow removing members by role.
|
||||
`gam update group <Group> clear [members] [managers] [owners]`
|
||||
If no option follows clear, all members will removed.
|
||||
|
||||
Added argument to `gam <Users> signature` and `gam <Users> vacation` to allow pattern substitution in the signature and vacation message.
|
||||
`gam <Users> signature <String>|(file <FileName> [charset <Charset>]) (replace <REPattern> <String>)*`
|
||||
`gam <UserTypeEntity> vacation <TrueValues> subject <String> (message <String>)|(file <FileName> [charset <CharSet>]) (replace <REPattern> <String>)*
|
||||
[contactsonly] [domainonly] [startdate <Date>] [enddate <Date>]`
|
||||
This is especially useful with CSV files.
|
||||
`gam csv Users.csv gam signature file SignatureTemplate.txt replace '#User#' '~User' replace '#Title#' '~Title'`
|
||||
|
||||
Changed `gam print admins` to include 'id:' in OrgUnitID column as with other `gam print` commands.
|
||||
|
||||
Fixed GAM to handle both future date error messages in `gam report`
|
||||
|
Reference in New Issue
Block a user