Zimlet to add custom header

Interested in talking about Mash-up's? This is the place.
Post Reply
uxbod
Ambassador
Ambassador
Posts: 7811
Joined: Fri Sep 12, 2014 10:21 pm

Zimlet to add custom header

Post by uxbod »

Would anybody know whether it is possible from a Zimlet to add a custom header to an email when it is sent ? We wish to create a Zimlet button that when clicked from within the email compose window of the ZWC would add Secure: Yes as a custom header. Any ideas please ?????
uxbod
Ambassador
Ambassador
Posts: 7811
Joined: Fri Sep 12, 2014 10:21 pm

Zimlet to add custom header

Post by uxbod »

Sorry to bump but it would be great if one of the devs could provide some input on this as I now have another requirement for the ability to be able to add a custom header ?
9450first
Posts: 33
Joined: Fri Sep 12, 2014 11:10 pm

Zimlet to add custom header

Post by 9450first »

I took a look into the code and some docs.

It seems is very difficult to achieve it because the interface between Zimlet and backend is SOAP, and in the SOAP there is no such parameter.

Taking into account my experience with ZCS that almost everything is achievable if you know how and to whom to address it, I believe it would be possible to do it: extend the ZCS backend or add priavte method for sending emails; in compose window replace buttons to point to your extension + add additional parameter on the interface with custom header.

Everything could be packed in one Zimlet.
Hope it helps.
Cheers,

first
9450first
Posts: 33
Joined: Fri Sep 12, 2014 11:10 pm

Zimlet to add custom header

Post by 9450first »

Forgot to mention that if you need to add fixed header to every email, that is easy achievable via patching ZCS backend. The patch should look like one jar (replacing original one) copied to three different folders.
Cheers,

first
4210share
Posts: 1
Joined: Sat Sep 13, 2014 2:28 am

Zimlet to add custom header

Post by 4210share »

Hi Guys,

I m like new in Zimbra world, actually I did some successful basic multi-server setup.. and now I m trying to customize my instance with new services adds.

I m struggling on a point, thatÂ’s turning on a real nightmare. I want to do achieve the following:



In the client web side: Tagging mail with a header

In the backend side: and when the mail header is tagged: doing some persistence in the sent mail, and sending some event when the mail is read.


I think for that I have to patch/overwrite some classes, but which ones? how can I deploy my patch? Or there is another proper and safety way to do that.
A kinf of help of support will save my life !!
Many thanks.
User avatar
barrydegraaff
Zimbra Employee
Zimbra Employee
Posts: 242
Joined: Tue Jun 17, 2014 3:31 am
Contact:

Re: Zimlet to add custom header

Post by barrydegraaff »

So here is an example on how to sent a custom header with a new message from a Zimlet.

You will have to tell the server what headers are allowed with:
zmprov mcf zimbraCustomMimeHeaderNameAllowed X-original-crazyness

X-original-crazyness is in this case my custom header,

Then make a soap request like so:

Code: Select all

OpenPGPZimlet.prototype.singleClicked =
function() {
      this._sendEmail ('subject', 'bodyHtml', 'bodyText', 'admin@myzimbra.com', 'admin@myzimbra.com', 'dates', 'accountInfo');
   
};

OpenPGPZimlet.prototype._sendEmail =
function(subject, bodyHtml, bodyText, to, ccEmails, dates, accountInfo) {
    var jsonObj = {
        SendMsgRequest: {
            _jsns: "urn:zimbraMail"
        }
    };
    alert('y');
    var request = jsonObj.SendMsgRequest;
    request.suid = (new Date()).getTime();
    var msgNode = request.m = {};
    var identity = appCtxt.getIdentityCollection().defaultIdentity;
    msgNode.idnt = identity.id;

    var isPrimary = identity == null || identity.isDefault;
    var mainAcct = appCtxt.accountList.mainAccount.getEmail();
    var addr = identity.sendFromAddress || mainAcct;
    var displayName = identity.sendFromDisplay;
    var addrNodes = msgNode.e = [];
    var f_addrNode = {
        t: "f",
        a: addr
    };
    if (displayName) {
        f_addrNode.p = displayName;
    }
    addrNodes.push(f_addrNode);

    var t_addrNode = {
        t: "t",
        a: to,
        add: "0"
    };
    addrNodes.push(t_addrNode);
    if (ccEmails && (ccEmails instanceof Array)) {
        for (var i = 0; i < ccEmails.length; i++) {
            var ccEmail = ccEmails[i];
            var t_addrNode = {
                t: "c",
                a: ccEmail.address,
                add: "0"
            };
            addrNodes.push(t_addrNode);
        }
    }
    //zmprov mcf zimbraCustomMimeHeaderNameAllowed X-original-crazyness
    msgNode.header = {
        name: "X-original-crazyness",
        _content: "test"
    };
    
    msgNode.su = {
        _content: subject
    };
    var topNode = {
        ct: "multipart/alternative"
    };
    msgNode.mp = [topNode];
    var partNodes = topNode.mp = [];

    //text part..
    var content = bodyText;
    var partNode = {
        ct: "text/plain"
    };
    partNode.content = {
        _content: content
    };
    partNodes.push(partNode);

    //html part..
    var content = ["<html><head><style type='text/css'>p { margin: 0; }</style></head>",
    "<body><div style='font-family: Times New Roman; font-size: 12pt; color: #000000'>",
    bodyHtml, "</div></body></html>"].join("");

    var partNode = {
        ct: "text/html"
    };
    partNode.content = {
        _content: content
    };
    partNodes.push(partNode);
    //var callback = new AjxCallback(this, this._sendEmailCallack, [dates, accountInfo]);
    //var errCallback = new AjxCallback(this, this._sendEmailErrCallback);
    return appCtxt.getAppController().sendRequest({
        jsonObj: jsonObj,
        asyncMode: true,
        noBusyOverlay: true
    });
};

User avatar
barrydegraaff
Zimbra Employee
Zimbra Employee
Posts: 242
Joined: Tue Jun 17, 2014 3:31 am
Contact:

Re: Zimlet to add custom header

Post by barrydegraaff »

basically look at

Code: Select all

    //zmprov mcf zimbraCustomMimeHeaderNameAllowed X-original-crazyness
    msgNode.header = {
        name: "X-original-crazyness",
        _content: "test"
    };
User avatar
barrydegraaff
Zimbra Employee
Zimbra Employee
Posts: 242
Joined: Tue Jun 17, 2014 3:31 am
Contact:

Re: Zimlet to add custom header

Post by barrydegraaff »

Or even better:

yourzimlet.prototype.addCustomMimeHeaders =
function(customHeaders) {
customHeaders.push({name:"header1", _content:"headerValue"});
};

https://files.zimbra.com/docs/zimlet/zc ... imeHeaders
Filly
Posts: 13
Joined: Sat Sep 13, 2014 12:25 am

Re: Zimlet to add custom header

Post by Filly »

I've managed to implement this custom header, but the problem now is that the value of the header is with double-quotes and apple does not like that :(

when using the custom header feature then the header looks like this

Code: Select all

X-Uniform-Type-Identifier: "com.apple.mail-note"
but it needs to be without the double qoutes

Code: Select all

X-Uniform-Type-Identifier: com.apple.mail-note
I've actually tested this with manual Export/Import and know for sure that the double quotes are not working. Damn you Apple

Anyone knows how to remove those double quotes

here is how I tried it (both versions with double/single quotes)

Code: Select all

com_zgheb_blueprint_HandlerObject.prototype.addCustomMimeHeaders = function (customHeaders)
{
    customHeaders.push({ name: "X-Uniform-Type-Identifier", _content: "com.apple.mail-note" });
};
the version with SendMsgRequest

Code: Select all

msgNode.header = [
        {
            name: "X-Uniform-Type-Identifier",
            _content: 'com.apple.mail-note'
        }
]
Filly
Posts: 13
Joined: Sat Sep 13, 2014 12:25 am

Re: Zimlet to add custom header

Post by Filly »

in my case, when there is a "." in the value of my custom header then it gets double qouted :(

non-custom headers are allowed to have special characters without being double quoted.

is there anything I can do about that special treatment with the custom headers? I have full control over my zimbra Server
Post Reply