-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle Thunderbird as a special case for mail with attachment. #447
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,66 +34,123 @@ compose_mail_mailto (GAppInfo *info, | |
{ | ||
g_autofree char *enc_subject = NULL; | ||
g_autofree char *enc_body = NULL; | ||
g_autofree char *arg = NULL; | ||
g_autoptr(GString) url = NULL; | ||
g_autoptr(GList) uris = NULL; | ||
g_autoptr(GString) tb_arg = NULL; | ||
int i; | ||
gboolean success; | ||
const char *sep; | ||
const char *is_tb_snap; | ||
const char *old_cmdline; | ||
|
||
enc_subject = g_uri_escape_string (subject ? subject : "", NULL, FALSE); | ||
enc_body = g_uri_escape_string (body ? body : "", NULL, FALSE); | ||
|
||
url = g_string_new ("mailto:"); | ||
|
||
sep = "?"; | ||
|
||
if (addrs) | ||
{ | ||
for (i = 0; addrs[i]; i++) | ||
{ | ||
if (i > 0) | ||
g_string_append (url, ","); | ||
g_string_append_printf (url, "%s", addrs[i]); | ||
/* The commandline can be complicated, e.g. | ||
* env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/.../thunderbird_thunderbird.desktop /snap/bin/thunderbird %u | ||
* so just match for thunderbird. | ||
*/ | ||
old_cmdline = g_app_info_get_commandline(info); | ||
if(strstr(old_cmdline, "thunderbird")) { | ||
/* Construct the argument to -compose. */ | ||
tb_arg = g_string_new(""); | ||
if (addrs) { | ||
g_string_append_printf(tb_arg, "to='"); | ||
for (i = 0; addrs[i]; i++){ | ||
g_string_append_printf(tb_arg, "%s,", addrs[i]); | ||
} | ||
g_string_append_printf(tb_arg, "',"); | ||
} | ||
if (cc) { | ||
g_string_append_printf(tb_arg, "cc='"); | ||
for (i = 0; cc[i]; i++){ | ||
g_string_append_printf(tb_arg, "%s,", cc[i]); | ||
} | ||
g_string_append_printf(tb_arg, "',"); | ||
} | ||
if (bcc) { | ||
g_string_append_printf(tb_arg, "bcc='"); | ||
for (i = 0; bcc[i]; i++){ | ||
g_string_append_printf(tb_arg, "%s,", bcc[i]); | ||
} | ||
g_string_append_printf(tb_arg, "',"); | ||
} | ||
g_string_append_printf (tb_arg, "subject='%s',", enc_subject); | ||
g_string_append_printf (tb_arg, "body='%s',", enc_body); | ||
if (attachments) { | ||
g_string_append_printf(tb_arg, "attachment='"); | ||
for (i = 0; attachments[i]; i++){ | ||
if (i != 0) g_string_append_printf (tb_arg, ","); | ||
gchar *enc_att = (g_uri_escape_string(attachments[i], "/", 1)); | ||
g_string_append_printf (tb_arg, "file://%s", enc_att); | ||
} | ||
g_string_append_printf(tb_arg, "',"); | ||
} | ||
|
||
if (cc) | ||
{ | ||
g_string_append_printf (url, "%scc=", sep); | ||
sep = "&"; | ||
|
||
for (i = 0; cc[i]; i++) | ||
is_tb_snap = strstr(old_cmdline, "/snap/bin/thunderbird"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check this from the application type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, what is that? Does it have something to do with "content type" as in https://docs.gtk.org/gio/iface.AppInfo.html? |
||
gchar *cmdline[] = { | ||
is_tb_snap ? "/snap/bin/thunderbird" : "thunderbird", | ||
"-compose", | ||
tb_arg->str, | ||
NULL | ||
}; | ||
g_debug("Launching: %s %s %s", cmdline[0], cmdline[1], cmdline[2]); | ||
success = g_spawn_async(NULL, cmdline, NULL, G_SPAWN_SEARCH_PATH, NULL, | ||
NULL, NULL, error); | ||
} else { | ||
url = g_string_new ("mailto:"); | ||
|
||
sep = "?"; | ||
|
||
if (addrs) | ||
{ | ||
for (i = 0; addrs[i]; i++) | ||
{ | ||
if (i > 0) | ||
g_string_append (url, ","); | ||
g_string_append_printf (url, "%s", cc[i]); | ||
g_string_append_printf (url, "%s", addrs[i]); | ||
} | ||
} | ||
} | ||
|
||
if (bcc) | ||
{ | ||
g_string_append_printf (url, "%sbcc=", sep); | ||
sep = "&"; | ||
if (cc) | ||
{ | ||
g_string_append_printf (url, "%scc=", sep); | ||
sep = "&"; | ||
|
||
for (i = 0; cc[i]; i++) | ||
{ | ||
if (i > 0) | ||
g_string_append (url, ","); | ||
g_string_append_printf (url, "%s", cc[i]); | ||
} | ||
} | ||
|
||
for (i = 0; bcc[i]; i++) | ||
{ | ||
if (i > 0) | ||
g_string_append (url, ","); | ||
g_string_append_printf (url, "%s", bcc[i]); | ||
} | ||
} | ||
if (bcc) | ||
{ | ||
g_string_append_printf (url, "%sbcc=", sep); | ||
sep = "&"; | ||
|
||
for (i = 0; bcc[i]; i++) | ||
{ | ||
if (i > 0) | ||
g_string_append (url, ","); | ||
g_string_append_printf (url, "%s", bcc[i]); | ||
} | ||
} | ||
|
||
g_string_append_printf (url, "%ssubject=%s", sep, enc_subject); | ||
g_string_append_printf (url, "&body=%s", enc_body); | ||
g_string_append_printf (url, "%ssubject=%s", sep, enc_subject); | ||
g_string_append_printf (url, "&body=%s", enc_body); | ||
|
||
for (i = 0; attachments[i]; i++) | ||
g_string_append_printf (url, "&attachment=%s", attachments[i]); | ||
for (i = 0; attachments[i]; i++) | ||
g_string_append_printf (url, "&attachment=%s", attachments[i]); | ||
|
||
uris = g_list_append (uris, url->str); | ||
uris = g_list_append (uris, url->str); | ||
|
||
g_debug ("Launching: %s\n", url->str); | ||
g_debug ("Launching: %s\n", url->str); | ||
|
||
success = g_app_info_launch_uris (info, uris, NULL, error); | ||
success = g_app_info_launch_uris (info, uris, NULL, error); | ||
} | ||
|
||
return success; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't use
g_app_info_get_executable
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that in the example command line commented above, that would be
env
.