[SOLVED] Help - Creating signatures via SOAP Howdy All,
I have a "create user" script for zimbra, to be able to create new users, add them to a range of distribution lists, create aliases for them, and assign them to a COS all via the command line.
Im looking for a way to add a signature to the user's account after we create it (or during if its possible).
We have folks who use both Thunderbird and Zimbra Web, and they all have a default thunderbird.sig with their user details created when their user account is created on the system (before email account is created)
Ive come up with the following snippet of xml that kinda works - but theres two problems...
First, a global admin user (who is running the script) creates and auth token
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<context xmlns="urn:zimbra"/>
</soap:Header>
<soap:Body>
<AuthRequest xmlns="urn:zimbraAdmin">
<name>$USER@domain.com</name>
<password>$PASS</password>
</AuthRequest>
</soap:Body>
</soap:Envelope>
(where $USER and $PASS are the global admin's username and password)
Upon a valid return result, we strip the token ID out from the response
cat /tmp/authtoken.out | sed -e 's/>/ /g' -e 's/</ /g' | awk '{print $14}'
Which leaves us with the $AUTHTOKEN string which is used to perform other functions.
We then Create the user using the AUTHTOKEN, and assign them a COS
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<context xmlns="urn:zimbra">
<authToken>$AUTHTOKEN</authToken>
</context>
</soap:Header>
<soap:Body>
<CreateAccountRequest xmlns="urn:zimbraAdmin">
<name>$USERNAME@domain.com</name>
<password></password>
<a xmlns="" n="givenName">$FIRSTNAME</a>
<a xmlns="" n="sn">$LASTNAME</a>
<a xmlns="" n="displayName">$FIRSTNAME $LASTNAME</a>
<a xmlns="" n="zimbraCOSId">e00428a1-0c00-11d9-836a-000d93afea2a</a>
</CreateAccountRequest>
</soap:Body>
</soap:Envelope>
once the user is created, we query the server for the user's zimbraID that was created - where $USERNAME is the user's zimbra login name
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<context xmlns="urn:zimbra">
<authToken>$AUTHTOKEN</authToken>
</context>
</soap:Header>
<soap:Body>
<GetAccountRequest xmlns="urn:zimbraAdmin" applyCos="0" attrs="zimbraId">
<account by="name">$USERNAME</account>
</GetAccountRequest>
</soap:Body>
</soap:Envelope>
We then manipulate the output of the response to get the zimbraID for the user and this is used as $ID below
cat /tmp/id.out | awk -F\" '{print $10}'
So, once we have $ID, $USERNAME, $AUTHTOKEN - we use the following xml to create a sig.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<context xmlns="urn:zimbra">
<authToken>$AUTHTOKEN</authToken>
</context>
</soap:Header>
<soap:Body>
<CreateSignatureRequest xmlns="urn:zimbraAccount">
<signature name="SIG" id="$ID">
<content type="text/plain">"`cat /home/$USERNAME/.thunderbird/$USERNAME.default/$USERNAME.sig`"</content>
</signature>
</CreateSignatureRequest>
<CreateSignatureResponse>
<signature id="$ID" name="SIG"/>
</CreateSignatureResponse>
</soap:Body>
</soap:Envelope>
The two problems are:
a) The sig is created... BUT - the sig was created for the admin user running the script - i think i have since worked out that $ID referred to in the <signature> tags, refers to an ID number you want to set the signature name to - and not "apply the sig to the user ID" captured above.
2) the 2nd part, when we populate the <content> by doing a cat of the user's pre-made sig, it ignores new line and all the text is generated on one line. The format of the sig file is:
--
Firstname Lastname
Job Role | Comany Name
Company Address
Company Ph. | Mobile No.
Is someone able to help here? - a) make the sig be created for the user we've created, not the user running the script, b) how can i preserve the format of the sig, so it doesnt add the content all on one line
Cheers
Last edited by PhD; 10-23-2011 at 11:36 PM..
|