Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
 
Go Back   Zimbra - Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra - Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-22-2007, 08:34 AM
Moderator
 
Posts: 701
Question Get inbox count via rest or soap interface

Hi, can I get the number of messages in the inbox of an account using rest or soap?

Reason for this is I'm generating an info page that will be shown in the sales room on a large screen, it will show various info from various systems and is programmed in asp and ajax, I'd like to show the number of messages in the sales shared email account so people can see if they need to log into it to deal with messages. The messages are deleted or moved out of the inbox when actioned, so any messages in there, read or not will be something that needs actioning.

I've never used either rest or soap before, so any tips on how to intergrate that into the javascript or asp function would be apprecated.

Thanks.
Reply With Quote
  #2 (permalink)  
Old 02-22-2007, 11:13 AM
Zimbra Employee
 
Posts: 1,434
Default GetFolderRequest

Quote:
Originally Posted by Dirk View Post
Hi, can I get the number of messages in the inbox of an account using rest or soap?
Use SOAP. A <GetFolderRequest><folder l="2"/></GetFolderRequest> should give you what you want. Look at the "n" attribute on the topmost returned <folder> in the response.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #3 (permalink)  
Old 02-22-2007, 03:43 PM
Moderator
 
Posts: 701
Default

Ok, that's a starting point of sorts. I do appreciate the value of the "give a man a fish" addage, but the thing is, with that starting hint, the amount of research needed for me to work it out is likely to be too much for me to bother.

I will try, of course, and I'll post a working example of exactly how to do it so others may benefit, but I'm currently working on an Asterisk system, which will also be intergrated into this status display and that's taking a phenominal amount of time and research, so what I hoped would be a short diversion may be a weeks research and learning.

A working code snippet would point me towards a more concise field of research and I'd still learn how it all works in the end - dont get me wrong, I very much appreciate your response, and I know you have better things to do that to write my code for me, it's just frustrating at times that these things have such a steep learning curve.

I have good SQL skills, good asp skills, I can read php and ruby, I can do reasonable ajax coding and I understand linux, but I have absolutley zero experience of soap and rest (that sounds odd!). I will get there, I will know it, but if you could offer a little more, I could get there faster.

Looking at your post, it looks like some form of xml structure, but I dont see how to pass that request to zimbra, nor do I see how it would return the response.

Yes, I'm being petulant, I know. I apologise for that, but when they said it wasnt going to be easy, I didnt realise it would be this hard
Reply With Quote
  #4 (permalink)  
Old 02-22-2007, 04:20 PM
Zimbra Employee
 
Posts: 1,434
Default SOAP primer

SOAP is a standardized XML-based RPC mechanism. It's the mechanism by which the AJAX client communicates with the Zimbra server. To get a sense of what a SOAP request looks like, turn on the AJAX client's debug window (search the forums for details on how to do this) and do something in the client -- fetch a message, mark a message as read, move a contact to the Trash.

SOAP messages are sent to the SOAP servlet on the Zimbra server. I believe that the URL you want to send your SOAP requests to is http://example.com/service/soap . You should be able to find a SOAP library in the programming language of your choice to expedite this.

The AJAX client explcitly asks for a JSON response because it's a JavaScript app and that's much easier for it to handle. You probably don't want to do this. Make sure that you don't include the <format type="js"/> element in the SOAP header.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #5 (permalink)  
Old 02-22-2007, 04:35 PM
Zimbra Employee
 
Posts: 1,434
Default Sample SOAP request

Code:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header>
    <context xmlns="urn:zimbra">
      <nosession/>
      <authToken>auth token from AuthResponse goes here</authToken>
    </context>
  </soap:Header>
  <soap:Body>
    <SearchConvRequest xmlns="urn:zimbraMail" sortBy="dateDesc" offset="0" limit="25" cid="-560" fetch="1" read="1" html="1">
      <query>in:inbox</query>
    </SearchConvRequest>
  </soap:Body>
</soap:Envelope>
Your request replaces SearchConvRequest and its children.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #6 (permalink)  
Old 02-23-2007, 02:18 AM
Moderator
 
Posts: 701
Default

Looks interesting, thanks Dkarp. Needless to say, I'm still none the wiser, but lets see what a day of googling and test code does. I'll try to work out all the generic stuff like the html, xml, js and soap by myself, but I may still need some zimbra specific assistance.

The part about the auth token for instance, I've seen that mentioned in posts here before so I'm guessing I need to pass some code before this to specify the account I wish to read and send the response from that code into the soap header?

Phew, lots to learn!
Reply With Quote
  #7 (permalink)  
Old 02-23-2007, 06:01 AM
Moderator
 
Posts: 701
Unhappy

Well, a few hours in and I'm really beginning to think that the 's' in Soap should not stand for 'simple'

I'd expect to be able to throw a few lines of code together and get a response, but everything I'm seeing so far is insanely complicated considering I'm just trying to do the SQL equivalent of
Select Count(message) from account where account = 'thisone'

Time to checkout the zimbra source code I guess...
Reply With Quote
  #8 (permalink)  
Old 02-23-2007, 07:49 AM
Zimlet Guru & Moderator
 
Posts: 431
Default

Quote:
Originally Posted by Dirk View Post
Well, a few hours in and I'm really beginning to think that the 's' in Soap should not stand for 'simple'

I'd expect to be able to throw a few lines of code together and get a response, but everything I'm seeing so far is insanely complicated considering I'm just trying to do the SQL equivalent of
Select Count(message) from account where account = 'thisone'

Time to checkout the zimbra source code I guess...
There are a lot of people who think that, hence REST.

Something that I have found very useful is to get the latest version of Firebug for Firefox. Once you put it into debugging mode (click the icon in the lower status bar) you can see network traffic go back and forth. That includes the SOAP requests and the javascript responses. If you make your request look like their request, it will work.

Most of the API's are documented in the soap.txt file in the ZimbraServer/Doc directory. Take a look at the ZimbraWebClient, not at the backend server.
Reply With Quote
  #9 (permalink)  
Old 02-23-2007, 10:16 AM
Zimbra Employee
 
Posts: 1,434
Default zmmailbox option

What I should have asked was what language you're using and whether there's a Zimbra install on the box.

You can use the zmmailbox gf command to fetch this data, then just parse the results of executing the command.

If you're in Java, you can use the com.zimbra.cs.zclient.ZMailbox class to fetch this data: new ZMailbox(...).getFolderByPath("Inbox").getUnreadCo unt().
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #10 (permalink)  
Old 03-21-2007, 07:11 AM
Member
 
Posts: 10
Default

Quote:
Originally Posted by dkarp View Post
If you're in Java, you can use the com.zimbra.cs.zclient.ZMailbox class to fetch this data: new ZMailbox(...).getFolderByPath("Inbox").getUnreadCo unt().
so, can we get information about accounts without accesing the SOAP way? Which libraries should we use to access this classes? Can this be done remotely?

thanks in advance.
Reply With Quote
Reply


Thread Tools
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

Zimbrablog.com




 

Search Engine Optimization by vBSEO 3.1.0