# Tag Replace - [Python Regular Expressions](Python-Regular-Expressions) Sub function, Match function - [Definitions](#definitions) - [Introduction](#introduction) - [Simple `replace ` processing](#simple-replace-tag-replacementstring-processing) - [User attribute `replace ` processing](#user-attribute-replace-tag-userreplacement-processing) - [Example](#example) ## Definitions ``` ::= country| countrycode| customtype| extendedaddress| formatted| locality| pobox| postalcode| primary| region| streetaddress| type ::= domain| primaryemail| username ::= customtype| type| value ::= addressmeas| customgender| type ::= customtype| type| value ::= customtype| type| value ::= area| buildingid| buildingname| customtype| deskcode| floorname| floorsection| type ::= familyname| fullname| givenname ::= costcenter| customtype| department| description| domain| fulltimeequivalent| location| name| primary| symbol| title| type ::= address| customtype| primary| type ::= customtype| primary| type| value ::= accountid| gecos| gid| homedirectory| operatingsystemtype| primary| shell| systemid| uid| username ::= customtype| type| value ::= expirationtimeusec| fingerprint| key ::= customtype| primary| type| value ::= address.| email.| externalid.| gender.| im.| keyword.| location.| name.| organization.| otheremail.| phone.| posix.| relation.| sshkeys.| website.| ::= address...| externalid...| im...| keyword...| location...| organization...| otheremail...| phone...| posix...| relation...| sshkeys...| website... ::= photourl ::= ::= (field:)| (field:)| (field:)| (schema:.)| ::= See: https://docs.python.org/3/library/re.html ::= ::= ::= > ``` ## Introduction Several commands use template files for messages and signatures; Gam has the ability to replace tags in the template with data from the command line or from user attributes. ``` replace ``` Instances of `{Tag}` will be replaced by ``. ``` replaceregex ``` The `` is used as a match pattern against `` to produce ``. Instances of `{Tag}` will be replaced by ``. ## Simple `replace ` processing This command allows simple text replacement in the message. ``` gam sendemail [subject ] [] (replace )* (replaceregex )* ``` * Every instance of `{Tag}` in the subject and message will be replaced by ``. * Instances of the form `{RT}...{Tag1}...{Tag2}...{/RT}` will be eliminated if there are no `` values for all `TagN` or if the `` values are all empty strings. * Instances of the form `{RTL}...{RT}...{Tag1}...{/RT}{RT}...{Tag2}...{/RT}{/RTL}` will be eliminated if none of the embedded `{RT}...{Tag}...{/RT}` have values. You can control the case of the letters in `replace `: * `{PC}...{Tag1}...{Tag2}...{/PC}` - For all sequences of letters between `{PC}` and `{/PC}`, the first letter is converted to uppercase, subsequent letters to lowercase. * `{UC}...{Tag1}...{Tag2}...{/UC}` - All letters between `{UC}` and `{/UC}` will be converted to uppercase * `{LC}...{Tag1}...{Tag2}...{/LC}` - All letters between `{LC}` and `{/LC}` will be converted to lowercase ## User attribute `replace ` processing These commands allow simple text replacement in the message/signature as well as substitution of select user attributes. ``` gam create|update user * [notify [subject ] [notifypassword ] [from ] [mailbox ] [replyto ] [] (replace )* (replaceregex )* gam draft|import|insert message (replace )* (replaceregex )* gam create|update sendas [ (replace )* (replaceregex )*] gam signature (replace )* (replaceregex )* gam vacation (replace )* (replaceregex )*] ``` * Every instance of `{Tag}` in the subject/message/signature will be replaced by `` or ``. * Instances of the form `{RT}...{Tag1}...{Tag2}...{/RT}` will be eliminated if there are no `` values for all `TagN` or if the `` values are all empty strings. * Instances of the form `{RTL}...{RT}...{Tag1}...{/RT}{RT}...{Tag2}...{/RT}{/RTL}` will be eliminated if none of the embedded `{RT}...{Tag}...{/RT}` have values. You can control the case of the letters in `replace `: * `{PC}...{Tag1}...{Tag2}...{/PC}` - For all sequences of letters between `{PC}` and `{/PC}`, the first letter is converted to uppercase, subsequent letters to lowercase. * `{UC}...{Tag1}...{Tag2}...{/UC}` - All letters between `{UC}` and `{/UC}` will be converted to uppercase * `{LC}...{Tag1}...{Tag2}...{/LC}` - All letters between `{LC}` and `{/LC}` will be converted to lowercase `` specifies the data that replaces `{Tag}` in the subject/message/signature. * `field:` - A subfield value from a user attribute * For attributes `address`, `organization`, `otheremails` and `phone`, the attribute instance marked `primary` will be used. If there is no attribute instance marked `primary`, the first attribute instance will be used. * For attribute `location`, the first attribute instance will be used. * If `` is empty or does not exist, an empty string will be used * `field:` - A subfield value from a user attribute where a second subfield value is used to select the attribute * Select based on type: `phone.value.type.work` * Select primary instance: `otheremails.address.primary.true` * `schema:.` - A custom schema value from the user's profile. * `` - A literal string in which the following substitutions will be made: * `#email#` and `#user#` will be replaced by the user's primary email address * `#username#` will be replaced by the local part of the user's primary email address ## Example The file SigTemplate.txt contains: ```

Name: {first} {last}
{RT}Address: {address}
{/RT} {RT}Department: {department}, Title: {title}
{/RT} {RT}Location: Building: {building}, Floor: {floor}, Section: {section}, Desk: {desk}
{/RT} {RTL}{RT}Office: {officephone} {/RT}{RT}Mobile: {mobilephone}{/RT}
{/RTL} Email: {email}

``` This command will update the signatures of the specified users. * The `replace` arguments can appear in any order. ``` gam signature file SigTemplate.txt html replace first field:name.givenname replace last field:name.familyname replace officephone field:phone.value.type.work replace mobilephone field:phone.value.type.work replace mobilephone field:phone.value.type.work replace mobilephone field:phone.value.type.mobile replace email field:email.primaryemail replace address field:address.formatted replace department field:organization.department replace title field:organization.title replace building field:location.buildingname replace floor field:location.floorname replace section field:location.floorsection replace desk field:location.deskcode ``` 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 ```