~ubuntu-branches/ubuntu/quantal/nautilus-sendto/quantal

« back to all changes in this revision

Viewing changes to src/plugins/evolution/evolution.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2011-07-27 23:43:01 UTC
  • Revision ID: james.westby@ubuntu.com-20110727234301-krhefa9ee45638qk
Tags: 3.0.0-1ubuntu3
* Fix LP: #757976 - Attachment paths are mangled when sending via Thunderbird.
  Thunderbird doesn't properyly unescape the attachment URI's specified
  on the command line, so just send the unescaped filenames rather than
  converting them to file:/// URI's
  - add debian/patches/no-uris-for-thunderbird.patch
  - update debian/patches/series 
* Use GIO for the default mailer check rather than the deprecated gconf, to
  ensure we pick up the correct preffered mail client
  - add debian/patches/use-gio-for-default-mailer.patch
  - update debian/patches/series
  - update debian/rules to run autoreconf

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include <e-contact-entry.h>
27
27
#include <glib/gi18n-lib.h>
 
28
#include <gio/gio.h>
28
29
#include <string.h>
29
30
#include "nautilus-sendto-plugin.h"
30
31
 
31
32
#define GCONF_COMPLETION "/apps/evolution/addressbook"
32
33
#define GCONF_COMPLETION_SOURCES GCONF_COMPLETION "/sources"
33
 
#define DEFAULT_MAILTO "/desktop/gnome/url-handlers/mailto/command"
34
34
 
35
35
#define CONTACT_FORMAT "%s <%s>"
36
36
 
47
47
static char *email = NULL;
48
48
static char *name = NULL;
49
49
 
50
 
static char *
51
 
get_evo_cmd (void)
52
 
{
53
 
        char *tmp = NULL;
54
 
        char *retval;
55
 
        char *cmds[] = {"evolution",
56
 
                "evolution-2.0",
57
 
                "evolution-2.2",
58
 
                "evolution-2.4",
59
 
                "evolution-2.6",
60
 
                "evolution-2.8", /* for the future */
61
 
                "evolution-3.0", /* but how far to go ? */
62
 
                NULL};
63
 
        guint i;
64
 
 
65
 
        
66
 
        for (i = 0; cmds[i] != NULL; i++) {
67
 
                tmp = g_find_program_in_path (cmds[i]);
68
 
                if (tmp != NULL)
69
 
                        break;
70
 
        }
71
 
 
72
 
        if (tmp == NULL)
73
 
                return NULL;
74
 
 
75
 
        retval = g_strdup_printf ("%s --component=mail %%s", tmp);
76
 
        g_free (tmp);
77
 
        return retval;
78
 
}
79
 
 
80
50
static gboolean
81
51
init (NstPlugin *plugin)
82
52
{
83
 
        GConfClient *client;
 
53
        GAppInfo *app = NULL;
84
54
 
85
55
        g_print ("Init evolution plugin\n");
86
56
        
87
57
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
88
58
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
89
59
 
90
 
        client = gconf_client_get_default ();
91
 
        mail_cmd = gconf_client_get_string (client, DEFAULT_MAILTO, NULL);
92
 
        g_object_unref (client);
 
60
        app = g_app_info_get_default_for_uri_scheme ("mailto");
 
61
        mail_cmd = g_strdup (g_app_info_get_executable (app));
 
62
        g_object_unref (app);
93
63
 
94
 
        if (mail_cmd == NULL || *mail_cmd == '\0') {
95
 
                g_free (mail_cmd);
96
 
                mail_cmd = get_evo_cmd ();
 
64
        /* Find what the default mailer is */
 
65
        if (strstr (mail_cmd, "balsa"))
 
66
                type = MAILER_BALSA;
 
67
        else if (strstr (mail_cmd, "thunder") || strstr (mail_cmd, "seamonkey"))
 
68
                type = MAILER_THUNDERBIRD;
 
69
        else if (strstr (mail_cmd, "sylpheed") || strstr (mail_cmd, "claws"))
 
70
                type = MAILER_SYLPHEED;
 
71
        else if (strstr (mail_cmd, "anjal"))
97
72
                type = MAILER_EVO;
98
 
        } else {
99
 
                /* Find what the default mailer is */
100
 
                if (strstr (mail_cmd, "balsa"))
101
 
                        type = MAILER_BALSA;
102
 
                else if (strstr (mail_cmd, "thunder") || strstr (mail_cmd, "seamonkey")) {
103
 
                        char **strv;
104
 
 
105
 
                        type = MAILER_THUNDERBIRD;
106
 
 
107
 
                        /* Thunderbird sucks, see
108
 
                         * https://bugzilla.gnome.org/show_bug.cgi?id=614222 */
109
 
                        strv = g_strsplit (mail_cmd, " ", -1);
110
 
                        g_free (mail_cmd);
111
 
                        mail_cmd = g_strdup_printf ("%s %%s", strv[0]);
112
 
                        g_strfreev (strv);
113
 
                } else if (strstr (mail_cmd, "sylpheed") || strstr (mail_cmd, "claws"))
114
 
                        type = MAILER_SYLPHEED;
115
 
                else if (strstr (mail_cmd, "anjal"))
116
 
                        type = MAILER_EVO;
117
 
        }
118
73
 
119
74
        if (mail_cmd == NULL)
120
75
                return FALSE;
251
206
{
252
207
        GList *l;
253
208
 
254
 
        if (strstr (mail_cmd, " -m ") == NULL && strstr (mail_cmd, " --compose=") == NULL)
255
 
                g_string_append (mailto, " --compose=");
 
209
        g_string_append (mailto, " --compose=");
256
210
        if (email != NULL) {
257
211
                if (name != NULL)
258
212
                        g_string_append_printf (mailto, "\""CONTACT_FORMAT"\"", name, email);
277
231
get_thunderbird_mailto (GtkWidget *contact_widget, GString *mailto, GList *file_list)
278
232
{
279
233
        GList *l;
 
234
        gchar *filename;
280
235
 
281
236
        g_string_append (mailto, "-compose \"");
282
237
        if (email != NULL) {
291
246
                if (text != NULL && *text != '\0')
292
247
                        g_string_append_printf (mailto, "to='%s',", text);
293
248
        }
294
 
        g_string_append_printf (mailto,"attachment='%s", (char *)file_list->data);
 
249
 
 
250
        /* XXX: Work around https://launchpad.net/bugs/757976 . Thunderbird
 
251
         * doesn't properly unescape the file URI's, so just convert them back
 
252
         * to filenames again */
 
253
        filename = g_filename_from_uri ((char *)file_list->data, NULL, NULL);
 
254
        g_string_append_printf (mailto,"attachment='%s", filename);
 
255
        g_free (filename);
295
256
        for (l = file_list->next ; l; l=l->next){
296
 
                g_string_append_printf (mailto,",%s", (char *)l->data);
 
257
                filename = g_filename_from_uri ((char *)l->data, NULL, NULL);
 
258
                g_string_append_printf (mailto,",%s", filename);
 
259
                g_free (filename);
297
260
        }
298
261
        g_string_append (mailto, "'\"");
299
262
}
348
311
                get_evo_mailto (contact_widget, mailto, file_list);
349
312
        }
350
313
 
351
 
        cmd = g_strdup_printf (mail_cmd, mailto->str);
 
314
        cmd = g_strconcat (mail_cmd, " ", mailto->str, NULL);
352
315
        g_string_free (mailto, TRUE);
353
316
 
354
317
        g_message ("Mailer type: %d", type);