Zimlet to add custom header

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

Zimlet to add custom header

Postby uxbod » Wed Feb 02, 2011 9:40 am

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

Postby uxbod » Tue Jul 12, 2011 2:40 am

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

Postby 9450first » Tue Jul 12, 2011 12:08 pm

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

Postby 9450first » Tue Jul 12, 2011 12:21 pm

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

Postby 4210share » Wed Feb 29, 2012 8:44 am

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
Posts: 35
Joined: Tue Jun 17, 2014 3:31 am

Re: Zimlet to add custom header

Postby barrydegraaff » Wed Mar 15, 2017 11:49 am

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
Posts: 35
Joined: Tue Jun 17, 2014 3:31 am

Re: Zimlet to add custom header

Postby barrydegraaff » Wed Mar 15, 2017 11:49 am

basically look at

Code: Select all

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

Re: Zimlet to add custom header

Postby barrydegraaff » Tue Apr 11, 2017 1:05 pm

Or even better:

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

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

Return to “Zimlets”

Who is online

Users browsing this forum: No registered users and 3 guests