aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mail-remote/mail-remote.c
blob: 6ee41f6c9dae9aa29026ef6e9a4d2f35368ca8b3 (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

#include <stdio.h>
#include <unistd.h>

#include "evolution-mail-session.h"
#include <bonobo/bonobo-main.h>

#define MAIL_SESSION_ID  "OAFIID:GNOME_Evolution_Mail_Session:" BASE_VERSION

int e_plugin_lib_enable(int enable);

int e_plugin_lib_enable(int enable)
{
    static EvolutionMailSession *sess;
    char *path;
    FILE *fp;

    if (enable) {
        static PortableServer_POA poa = NULL;
        CORBA_string ior;
        CORBA_Environment ev = { 0 };

        if (sess != NULL)
            return 0;

        if (poa == NULL)
            poa = bonobo_poa_get_threaded (ORBIT_THREAD_HINT_PER_REQUEST, NULL);

        sess = g_object_new(evolution_mail_session_get_type(), "poa", poa, NULL);
        ior = CORBA_ORB_object_to_string(bonobo_orb(), bonobo_object_corba_objref((BonoboObject *)sess), &ev);

        path = g_build_filename(g_get_home_dir(), ".evolution-mail-remote.ior", NULL);
        fp = fopen(path, "w");
        fprintf(fp, "%s", ior);
        fclose(fp);
        g_free(path);

        printf("Enable mail-remote: IOR=%s\n", ior);
    } else {
        if (sess == NULL)
            return 0;

        path = g_build_filename(g_get_home_dir(), ".evolution-mail-remote.ior", NULL);
        unlink(path);
        g_free(path);

        g_object_unref(sess);
        sess = NULL;
    }

    return 0;
}