How to make a simple SearchRequest?

Interested in talking about Mash-up's? This is the place.
raulicci
Posts: 14
Joined: Mon Aug 03, 2015 11:55 pm

How to make a simple SearchRequest?

Post by raulicci »

Hello friends,

I'm a little desperate because I can not perform a simple search on my zimlet.

I just want to make a search in the custom folder.

The search should only display messages that are within my custom folder.

Like when I click on the custom folder in the left pane. exactly the same.
this is what shows the html header by pressing the icon of my custom folder in the left pane.
{"Header":{"context":{"_jsns":"urn:zimbra","userAgent":{"name":"ZimbraWebClient - FF39 (Linux)","version":"8.6.0_GA_1153"},"session":{"_content":150,"id":150},"account":{"_content":"admin@localhost.local","by":"name"},"csrfToken":"0_a3050edfdf238eadfdfdfdff2f14b4968e3"}},"Body":{"SearchRequest":{"_jsns":"urn:zimbraMail","sortBy":"dateDesc","header":[{"n":"List-ID"},{"n":"X-Zimbra-DL"},{"n":"IN-REPLY-TO"}],"tz":{"id":"America/Mexico_City"},"locale":{"_content":"es_MX"},"offset":0,"limit":100,"query":"in:\"mycustomfolder\"","types":"conversation","recip":"0","fullConversation":1,"needExp":1}}}

I'm trying with this code, within my com_zimlet.js
com_zimbra_myzimlet_HandlerObject.prototype._getShowResultFolderId =
function(t) {
var e=AjxSoapDoc.create("SearchRequest","urn:zimbraMail");
var cuery="raulicci";
e.setMethodAttribute("types","conversation");
e.setMethodAttribute("limit",100);
e.setMethodAttribute("offset",0);
e.set("query",cuery);
t.response=appCtxt.getAppController().sendRequest({
soapDoc:e,noBusyOverlay:false}
);
this.handleSearchResponse(t)
};


so far I can not find a way to make the consultation, although I imagine it is something easy as already implemented in zimbra comes when one gives click on the icon in my custom folder in the left pane.
raulicci
Posts: 14
Joined: Mon Aug 03, 2015 11:55 pm

How to make a simple SearchRequest?

Post by raulicci »

Hello friends,
I could already make my query via SOAP and JSON, it was easy after reading much or as they say in Mexico, "a shitload".
Here is the snippet of code that makes it possible:
(for request)
var jsonObj = {SearchRequest:{_jsns:"urn:zimbraMail"}};
var request = jsonObj.SearchRequest;
request.sortBy = "dateDesc";
request.offset = 0;
request.limit = 100;
request.query = 'in:"MYCURRENTFOLDER"';
request.types = "conversation";
request.recips = "0";
request.fullConversation = 1;
request.needExp = 1;

var params = {
jsonObj:jsonObj,
asyncMode:true,
callback: (new AjxCallback(this, this._handleSOAPResponseJSON)),
errorCallback: (new AjxCallback(this, this._handleSOAPErrorResponseJSON)),
};
return appCtxt.getAppController().sendRequest(params);

(for response)
if (result.isException()) {
// do something with exception
var exception = result.getException();

return;
}
else {
response = { _jsns: "urn:zimbraMail", more: false };
}
// do something with response (in JSON format)
var response = result.getResponse();
var name = response.name;
var soapURL = response.publicURL;
var soapURL = response.soapURL;
var aller = result.getResponse();
var searchResult = new ZmSearchResult(this);

appCtxt.setStatusMsg("GetAccountInfoResponse (JSON) success - "+name);
alert(aller.toSource());
The alert response, shows the following:
({SearchResponse:{sortBy:"dateDesc", offset:0, c:[{id:"314", u:0, n:2, f:"s", d:1438663876000, su:"lokitox", fr:"lex", e:[{a:"admin@localhost.local", d:"admin", t:"f"}], m:[{id:"313", l:"300"}, {id:"312", l:"5", f:"s"}], sf:"1438663876000"}, {id:"-309", u:0, n:1, d:1438662639000, su:"Daily mail report for 2015-08-03", fr:"Grand Totals -- messages 91 received 117 delivered 0 forwarded 134 deferred (134 deferrals) 169 bounced 0 rejected (0%) 0 reject warnings 0 held 0 ...", e:[{a:"admin@localhost.local", d:"admin", t:"f"}], m:[{id:"309", s:"7232", l:"300"}], sf:"1438662639000"}], more:false, _jsns:"urn:zimbraMail"}})
 
Unfortunately even when I receive the response comes in json format, and I would like to know how to create a view style response tab INBOX.
as when we click on the icon for a custom folder that is in the left pane, and emails appear, just this folder.
even through the forum seems forgotten is that there is good talent here.
User avatar
jorgedlcruz
Zimbra Alumni
Zimbra Alumni
Posts: 2782
Joined: Thu May 22, 2014 4:47 pm

How to make a simple SearchRequest?

Post by jorgedlcruz »

Hi,
I think [mention:1c422e80286e4838a894e2e1d99e38ba:e9ed411860ed4f2ba0265705b8793d05] or [mention:3fc0b949c35446ac80e21681d631d87e:e9ed411860ed4f2ba0265705b8793d05] can help us here.

Best regards
Jorge de la Cruz https://jorgedelacruz.es
Systems Engineer at Veeam Software https://www.veeam.com/
raulicci
Posts: 14
Joined: Mon Aug 03, 2015 11:55 pm

How to make a simple SearchRequest?

Post by raulicci »

Thank you very much for answering [mention:8081d13fd51d42c888a04ad0bba5f6a6:e9ed411860ed4f2ba0265705b8793d05], I hope someone else can help me [mention:1c422e80286e4838a894e2e1d99e38ba:e9ed411860ed4f2ba0265705b8793d05] or [mention:3fc0b949c35446ac80e21681d631d87e:e9ed411860ed4f2ba0265705b8793d05], I am very desperate and do not know where to look
I want to show the emails in a TAB app, with the name of my folder.
I can already send the serachrequest with json, and I return a JSON response.
my question is how to convert my json response in a view as the inbox view, is that there are models.
but not if you use this code I found on some files of the same zimbra, I get an error when used.
com_zimbra_myappFirst_HandlerObject.prototype._handleSOAPResponseJSON =
function(result, callback) {
result = result;
if (result) {
var response = result.getResponse();

if (this.isGalSearch) { response = response.SearchGalResponse; }
else if (this.isCalResSearch) { response = response.SearchCalendarResourcesResponse; }
else if (this.isAutocompleteSearch) { response = response.AutoCompleteResponse; }
else if (this.isGalAutocompleteSearch) { response = response.AutoCompleteGalResponse; }
else if (this.soapInfo) { response = response[this.soapInfo.response]; }
else { response = response.SearchResponse; }
}
else {
response = { _jsns: "urn:zimbraMail", more: false };
}
searchResponse = result.getResponse().SearchResponse;


alert(searchResponse.toSource());

var getMsgResponse = searchResponse.c;
alert(getMsgResponse);
if (getMsgResponse) {
var msgs = [];
alert(msgs.toSource());
for (var i = 0; i < getMsgResponse.length; i++) {
msgs.push(getMsgResponse.m[0]);
}
var setItemCallback = this._handleSetItemCallback.bind(this, msgs, ZmApp.MAIL, callback);
ZmOfflineDB.setItem(msgs, ZmApp.MAIL, setItemCallback);
var searchResult = new ZmSearchResult(this);
searchResult.set(msgs, ZmApp.MAIL, setItemCallback);
result = result || new ZmCsfeResult();
result.set(searchResult);

if (callback) {
callback.run(result);
}
}

};
com_zimbra_myappFirst_HandlerObject.prototype.appLaunch =
function(appName) {
switch (appName) {
case this._tabFolder: {
var app = appCtxt.getApp(appName); // get access to ZmZimletApp
app.setContent(searchResponse.toSource()); // write HTML to app
//appCtxt.getAppController().activateApp("Mail");

//appCtxt.getAppController().activateApp(folderNamex);
break;
}
}
};
error
TypeError: this.search.types is undefined



thanks
raulicci
Posts: 14
Joined: Mon Aug 03, 2015 11:55 pm

How to make a simple SearchRequest?

Post by raulicci »

now I could search and displayed in html like inbox,

but now my problem is that, when conducted the search as follows:
return appCtxt.getSearchController().search(params);
I redirected to the tab "Mail"

and if I do my search like this:
return appCtxt.getSearchController()._toolbarSearch(params);

I open a new tab search filters.

and what I want is that the results are displayed in myself my zimlet tab.
among all the documentation I read that possibly modify the results with ZmSearchResultsController();
but I need help on how to implement it, to display the result of my search in my zimlet creating tab, not on the "Mail" tab or in a new tab.

Here is the complete code for my zimlet
/*
* ***** ABOUT BLOCK *****
*
* Raul Espinosa
*
* raul@ninja-code.de
*
* It is block is developer for panel folder tools like to firefox plugin.
* ***** END ABOUT BLOCK *****
*/
com_zimbra_folderana_HandlerObject = function() {};
com_zimbra_folderana_HandlerObject.prototype = new ZmZimletBase;
com_zimbra_folderana_HandlerObject.prototype.constructor =
com_zimbra_folderana_HandlerObject;

/**
* Double clicked.
*/
com_zimbra_folderana_HandlerObject.prototype.doubleClicked =
function() {
this.singleClicked();
};

/**
* Single clicked.
*/
com_zimbra_folderana_HandlerObject.prototype.singleClicked =
function() {
this._setFolderBtnListener();
};

/**
* Get all folders
*/
com_zimbra_folderana_HandlerObject.prototype._setFolderBtnListener =
function() {
if (!this._chooseFolderDialog) {
AjxDispatcher.require("Extras");
this._chooseFolderDialog = new ZmChooseFolderDialog(appCtxt.getShell());
}
this._chooseFolderDialog.reset();
this._chooseFolderDialog.registerCallback(DwtDialog.OK_BUTTON, this._chooseFolderOkBtnListener,
this, this._chooseFolderDialog);
// This doesn't show trash and spam folder
var omitParam = {};
omitParam[ZmFolder.ID_TRASH] = true;
omitParam[ZmFolder.ID_SPAM] = true;

var params = {
treeIds: [ZmOrganizer.FOLDER],
title: ZmMsg.chooseFolder,
overviewId: this.toString(),
description: ZmMsg.chooseFolder,
skipReadOnly: false,
hideNewButton: true,
appName: ZmApp.MAIL,
omit: omitParam
};
this._chooseFolderDialog.popup(params);
};

com_zimbra_folderana_HandlerObject.prototype._chooseFolderOkBtnListener =
function(dlg, folder) {
dlg.popdown();
folderNamex = (folder.name);
this.uReaderM(folderNamex);
};
com_zimbra_folderana_HandlerObject.prototype.uReaderM =
function(folderNamex) {
var foldax = folderNamex;
var jsonObj = {
SearchRequest: {
_jsns: "urn:zimbraMail"
}
};
var request = jsonObj.SearchRequest;
request.sortBy = "dateDesc";
request.offset = 0;
request.limit = 100;
request.query = 'in:"' + foldax + '"';
request.types = "conversation";
request.recips = "0";
request.fullConversation = 1;
request.needExp = 1;

var params = {
jsonObj: jsonObj,
asyncMode: true,
callback: (new AjxCallback(this, this._handleUnReadSOAPResponseJSON)),
errorCallback: (new AjxCallback(this, this._handleSOAPErrorResponseJSON)),
};
return appCtxt.getAppController().sendRequest(params);
};
com_zimbra_folderana_HandlerObject.prototype._handleUnReadSOAPResponseJSON =
function(result) {
var result = result;
if (result) {
var response = result.getResponse();
var unRealiTy = 0;
for (var k in response) {
for (var r in response[k].c) {
console.log(response[k].c[r].u);
var unReadS = response[k].c[r].u;
if (unReadS == 1) {
unRealiTy++;
} else {
console.log("no");
}
}
}
var unRealiTyTimex = unRealiTy;
}
unRealiTyTime = unRealiTyTimex;
this.init(folderNamex, unRealiTyTime);
};
com_zimbra_folderana_HandlerObject.prototype.getMainWindow =
function(appId) {
return appCtxt.isChildWindow ? window.opener : window;
};
com_zimbra_folderana_HandlerObject.prototype.buskeda =
function(query, callback, response, type) {
var account = appCtxt.isOffline && appCtxt.inStartup && appCtxt.accountList.defaultAccount;
if (account) {
appCtxt.accountList.setActiveAccount(account);
}
var sc = appCtxt.getSearchController();
var queryHint, noUpdateOverview;
if (appCtxt.get(ZmSetting.OFFLINE_SHOW_ALL_MAILBOXES) &&
appCtxt.accountList.size() > 2) {
query = null;
queryHint = appCtxt.accountList.generateQuery(ZmOrganizer.ID_INBOX);
noUpdateOverview = true;
sc.searchAllAccounts = true;
} else if (appCtxt.isExternalAccount()) {
query = "inid:" + this.getDefaultFolderId();
} else if (appCtxt.isWebClientOffline()) {
query = query || "in:inbox";
} else {
query = query || appCtxt.get(ZmSetting.INITIAL_SEARCH, null, account);
}

var types = new AjxVector();
types.add(type || this.getGroupMailBy());
var sortBy = AjxUtil.get(response, "Body", "SearchResponse", "sortBy") ||
ZmSearch.DATE_DESC;
var params = {
searchFor: ZmId.muchisxName,
query: query,
queryHint: queryHint,
types: types,
limit: this.getLimit(),
getHtml: appCtxt.get(ZmSetting.VIEW_AS_HTML, null, account),
noUpdateOverview: noUpdateOverview,
offlineCache: true,
accountName: (account && account.name),
callback: callback,
response: response,
sortBy: sortBy
};
params.errorCallback = new AjxCallback(this, this._handleErrorLaunch, params);
//sc._toolbarSearch(params);
return appCtxt.getSearchController().search(params).getSearchResultsController(
this._tabFolder); //._toolbarSearch(params);
};
com_zimbra_folderana_HandlerObject.prototype.getGroupMailBy =
function() {
var setting = this._groupBy || appCtxt.get(ZmSetting.GROUP_MAIL_BY);
return setting ? ZmMailApp.GROUP_MAIL_BY_ITEM[setting] : ZmItem.MSG;
};
// return enough for us to get a scroll bar since we are pageless
com_zimbra_folderana_HandlerObject.prototype.getLimit =
function(offset) {
var limit = appCtxt.get(ZmSetting.PAGE_SIZE);
return offset ? limit : 2 * limit;
};
/**
* Handles the SOAP response.
*
* @param {ZmCsfeResult} result the result
* @private
*/
com_zimbra_folderana_HandlerObject.prototype.init = function(folderNamex,
unRealiTyTime) {
var folderNamex = folderNamex;
var unRealiTyTimec = unRealiTyTime;
if (!folderNamex) {
return;
}
var myTabFolderAna = document.querySelectorAll(
'[id^="zb__App__com_zimbra_folderana_DWT"]');
if (!myTabFolderAna[0]) {
var label = folderNamex + '(<b>' + unRealiTyTimec + '</b>)';
var image = "zimbraIcon";
var tooltip = "Folder in a tab zimlet.";
var index = 1;

var params = {
text: label,
image: image,
tooltip: tooltip,
index: index
};

AjxDispatcher.require("ZimletApp");

var appName = [this.name, Dwt.getNextId()].join("_");
var controller = appCtxt.getAppController();

var appChooser = controller.getAppChooser();

appChooser.addButton(appName, params);

var app = new ZmZimletApp(appName, this, DwtShell.getShell(window));
controller.addApp(app);
this._tabFolder = appName;
this.setUserProperty("folderana_electionFolder", label, true);
var xs = document.querySelectorAll(
'[id^="zb__App__com_zimbra_folderana_"] [id$="dropdown"]');
console.log(xs[0]);
xs[0].innerHTML = "x";
xs[0].addEventListener("click", this._resetApp);
} else {
alert(
'You already chosen your Folder. Please use "Folder to Tab" to open it again.'
);
}
};

com_zimbra_folderana_HandlerObject.prototype.appLaunch =
function(appName) {
switch (appName) {
case this._tabFolder:
{
var app = appCtxt.getApp(appName); // get access to ZmZimletApp
var muchisx = appCtxt.getCurrentApp();
muchisxName = muchisx.getName();
app.setContent(this.buskeda('in:"' + folderNamex + '"', muchisxName)); // write HTML to app
//appCtxt.getAppController().activateApp("Mail");


//appCtxt.getAppController().activateApp(folderNamex);
break;
}
}
};

com_zimbra_folderana_HandlerObject.prototype._resetApp =
function(appName, laAppAll) {
app = appCtxt.getCurrentApp(appName);
myAppAll = laAppAll;
app.reset(false);
appCtxt.getAppController().activateApp("Mail");
var xsId = document.querySelectorAll(
'[id^="zb__App__com_zimbra_folderana_DWT"]');
console.log(xsId[0].id);
document.getElementById(xsId[0].id).style.display = "none";
};
/**
* Handles the SOAP error response.
*
* @param {ZmCsfeException} ex the exception
* @private
*/
com_zimbra_folderana_HandlerObject.prototype._handleSOAPErrorResponseJSON =
function(ex) {

var errorMsg = ex.getErrorMsg(); // the error message
var dump = ex.dump(); // the complete error dump

};
User avatar
jorgedlcruz
Zimbra Alumni
Zimbra Alumni
Posts: 2782
Joined: Thu May 22, 2014 4:47 pm

How to make a simple SearchRequest?

Post by jorgedlcruz »

Hi Raul,
I think [mention:1c422e80286e4838a894e2e1d99e38ba:e9ed411860ed4f2ba0265705b8793d05] can help us here.

Thank you for your hard work here.
Jorge de la Cruz https://jorgedelacruz.es
Systems Engineer at Veeam Software https://www.veeam.com/
User avatar
barrydegraaff
Zimbra Employee
Zimbra Employee
Posts: 242
Joined: Tue Jun 17, 2014 3:31 am
Contact:

How to make a simple SearchRequest?

Post by barrydegraaff »

Okay, can you post your entire Zimlet to Github, so including xml definition and all. Also make and export of your test mailbox (tgz format)



That way we can reproduce (in an easy way) what you are seeing.



Also what you are trying to do, is not easy... so don't get frustrated, it takes time.
--
Barry de Graaff
Email: barry.degraaff [at] synacor [dot] com
Admin of Zimbra-Community Github: https://github.com/orgs/Zimbra-Community/ and the
Zimlet Gallery https://gallery.zetalliance.org/extend/
User avatar
barrydegraaff
Zimbra Employee
Zimbra Employee
Posts: 242
Joined: Tue Jun 17, 2014 3:31 am
Contact:

How to make a simple SearchRequest?

Post by barrydegraaff »

also what I usually do, if I cannot figure it out is look into all Zimlets in the Zimbra source:

git clone https://github.com/barrydegraaff/zimlets-foss



And see if I can find a working example. (find in files: getSearchController)
--
Barry de Graaff
Email: barry.degraaff [at] synacor [dot] com
Admin of Zimbra-Community Github: https://github.com/orgs/Zimbra-Community/ and the
Zimlet Gallery https://gallery.zetalliance.org/extend/
User avatar
barrydegraaff
Zimbra Employee
Zimbra Employee
Posts: 242
Joined: Tue Jun 17, 2014 3:31 am
Contact:

How to make a simple SearchRequest?

Post by barrydegraaff »

--
Barry de Graaff
Email: barry.degraaff [at] synacor [dot] com
Admin of Zimbra-Community Github: https://github.com/orgs/Zimbra-Community/ and the
Zimlet Gallery https://gallery.zetalliance.org/extend/
raulicci
Posts: 14
Joined: Mon Aug 03, 2015 11:55 pm

How to make a simple SearchRequest?

Post by raulicci »

Thank you so much for your reply,



This is the repository that I have created, for if you like to look at it and advise and could cause results to appear in my own zimlet / app and not in the main "Mail" tab.



https://github.com/programacion-web/foldertab



also reading these examples

https://github.com/barrydegraaff/zimlets-foss



Thank you
Post Reply