Update Unread count via C++ API

Hi,

i’m trying to get, for a specific user, the mail unread count by a server agent. I get the unread count without problem but the number return is not up to date. It’s the number of unread count the last time the database was open…

Any idea to update this count ?

Here is my script :

Function GetUnreadCount(server As String,database As String,username As String) As Long

Dim rc As Integer

Dim hDB As Long

Dim hTable As Long

GetUnreadCount=-1

rc=NSFDbOpen(server+"!!"+database,hDB)

If rc=0 Then

	rc=NSFDbUpdateUnread(hDB,hTable)

	If rc=0 Then

		rc=NSFDbGetUnreadNoteTable(hDB,username,Len(username),0,hTable)

		If rc=0 Then

			GetUnreadCount=IDEntries(hTable)

			IDDestroyTable hTable

		End If

	End If

	NSFDbClose hDB

End If 

End Function