Page 1 of 1

Zimlet to add custom header

Posted: Wed Feb 02, 2011 9:40 am
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 ?????

Zimlet to add custom header

Posted: Tue Jul 12, 2011 2:40 am
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 ?

Zimlet to add custom header

Posted: Tue Jul 12, 2011 12:08 pm
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

Zimlet to add custom header

Posted: Tue Jul 12, 2011 12:21 pm
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

Zimlet to add custom header

Posted: Wed Feb 29, 2012 8:44 am
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.

Re: Zimlet to add custom header

Posted: Wed Mar 15, 2017 11:49 am
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
    });
};


Re: Zimlet to add custom header

Posted: Wed Mar 15, 2017 11:49 am
by barrydegraaff
basically look at

Code: Select all

    //zmprov mcf zimbraCustomMimeHeaderNameAllowed X-original-crazyness
    msgNode.header = {
        name: "X-original-crazyness",
        _content: "test"
    };

Re: Zimlet to add custom header

Posted: Tue Apr 11, 2017 1:05 pm
by barrydegraaff
Or even better:

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

https://files.zimbra.com/docs/zimlet/zc ... imeHeaders

Re: Zimlet to add custom header

Posted: Mon Oct 07, 2019 2:48 pm
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'
        }
]

Re: Zimlet to add custom header

Posted: Tue Oct 08, 2019 11:53 am
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