aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mail-remote/client.c
blob: c2e242725075d1122f1260d928068d13f58f8904 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

#include <libbonobo.h>

#include "Evolution-DataServer-Mail.h"

#include "evolution-mail-listener.h"

static EvolutionMailListener *listener;

static GNOME_Evolution_Mail_Session
get_session(void)
{
    char *path, *ior;
    GNOME_Evolution_Mail_Session sess = NULL;
    CORBA_Environment ev = { 0 };

    /* The new-improved bonobo-activation ... */

    path = g_build_filename(g_get_home_dir(), ".evolution-mail-remote.ior", NULL);
    if (g_file_get_contents(path, &ior, NULL, NULL)) {
        sess = CORBA_ORB_string_to_object(bonobo_orb(), ior, &ev);
        g_free(ior);
    }

    if (sess != CORBA_OBJECT_NIL) {
        listener = evolution_mail_listener_new();
        GNOME_Evolution_Mail_Session_addListener(sess, bonobo_object_corba_objref((BonoboObject *)listener), &ev);
        if (ev._major != CORBA_NO_EXCEPTION) {
            printf("AddListener failed: %s\n", ev._id);
            CORBA_exception_free(&ev);
        }
    }

    return sess;
}

static int domain(void *data)
{
    GNOME_Evolution_Mail_Session sess;
    GNOME_Evolution_Mail_StoreInfos *stores;
    GNOME_Evolution_Mail_FolderInfos *folders;
    CORBA_Environment ev = { 0 };
    int i, j, f;


    sess = get_session();

    stores = GNOME_Evolution_Mail_Session_getStores(sess, "", &ev);
    if (ev._major != CORBA_NO_EXCEPTION) {
        printf("getStores failed\n");
        return 1;
    }

    printf("Got %d stores\n", stores->_length);
    for (i=0;i<stores->_length;i++) {
        GNOME_Evolution_Mail_PropertyName namesarray[] = {
            "name", "uid"
        };
        GNOME_Evolution_Mail_PropertyNames names = {
            2, 2,
            namesarray,
            FALSE,
        };
        GNOME_Evolution_Mail_Properties *props;
        GNOME_Evolution_Mail_Store store = stores->_buffer[i].store;
        
        printf("store %p '%s' uid '%s'\n", store, stores->_buffer[i].name, stores->_buffer[i].uid);
            
        GNOME_Evolution_Mail_Store_getProperties(store, &names, &props, &ev);
        if (ev._major != CORBA_NO_EXCEPTION) {
            printf("getProperties failed\n");
            return 1;
        }

        for (j=0;j<props->_length;j++) {
            printf(" %s = (%s)", props->_buffer[j].name, ORBit_tk_to_name(props->_buffer[j].value._type->kind));
            if (props->_buffer[j].value._type == TC_CORBA_string) {
                printf(" '%s'\n", props->_buffer[j].value._value);
            } else {
                printf(" '%s' ", BONOBO_ARG_GET_STRING(&props->_buffer[j].value));
                printf(" <unknonw type>\n");
            }
        }

        CORBA_free(props);
#if 0
        printf("attempt send mail to store\n");
        GNOME_Evolution_Mail_Store_sendMessage(store, NULL, "notzed@ximian.com", "notzed@novell.com, user@host", &ev);
        if (ev._major != CORBA_NO_EXCEPTION) {
            printf("sendmessage failed\n");
            /* FIXME:L leaks ex data? */
            CORBA_exception_init(&ev);
        }
#endif

        folders = GNOME_Evolution_Mail_Store_getFolders(store, "", &ev);
        if (ev._major != CORBA_NO_EXCEPTION) {
            printf("getfolders failed\n");
            /* FIXME: leaks ex data? */
            CORBA_exception_free(&ev);
        } else {
            for (f = 0; f<folders->_length;f++) {
                printf("folder %p full:'%s' name:'%s'\n", folders->_buffer[f].folder, folders->_buffer[f].full_name, folders->_buffer[f].name);
            }
        }
    }

    CORBA_free(stores);

    return 0;
}

int main(int argc, char **argv)
{
    bonobo_init(&argc, argv);

    g_idle_add(domain, NULL);

    bonobo_main();

    return 0;
}