Modified webpage: now tinymail repository is in gitorious.
[modest] / tests / dbus_api / test_get_unread_msgs.c
1 #include <libmodest-dbus-client/libmodest-dbus-client.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <glib.h>
5
6 int main (int argc, char *argv[])
7 {
8         osso_context_t *osso_context;
9         gboolean res;
10         GList *hits, *iter;
11         gint number;
12
13         osso_context = osso_initialize ("test_search",
14                                         "0.0.1",
15                                         TRUE,
16                                         NULL);
17
18
19         /* Check that initialization was ok */
20         if (osso_context == NULL) {
21                 g_printerr ("osso_initialize() failed.\n");
22                 return OSSO_ERROR;
23         }
24
25         hits = NULL;
26
27         if (argc == 2) {
28           number = strtol (argv[1], NULL, 10);
29         } else {
30                 number = 10;
31         }
32
33         g_print ("Starting get_unread_messages)...\n");
34
35         res = libmodest_dbus_client_get_unread_messages (osso_context,
36                                                          number,
37                                                          &hits);
38
39         g_print ("Search done. (success: %s)\n", res ? "yes" : "no");
40
41         for (iter = hits; iter; iter = iter->next) {
42                 ModestAccountHits *hits = (ModestAccountHits *) iter->data;
43                 GList *header_node;
44
45                 g_print ("Account: id: %s name: %s protocol: %s unread: %d\n", hits->account_id, hits->account_name, 
46                          hits->store_protocol, (gint32) hits->unread_count);
47                 for (header_node = hits->hits; header_node != NULL; header_node = g_list_next (header_node)) {
48                         ModestGetUnreadMessagesHit *hit = (ModestGetUnreadMessagesHit *) header_node->data;
49
50                         g_print ("    %s\n    %s\n", hit->subject, ctime (&(hit->timestamp)));
51                 }
52         }
53         modest_account_hits_list_free (hits);
54
55         return res ? 0 : -1;
56 }