[evolution] Bug 788192 - Support mid: URI scheme
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 788192 - Support mid: URI scheme
- Date: Thu, 29 Oct 2020 12:02:10 +0000 (UTC)
commit fbaee67b32f717b4fb251edb2102f00428189021
Author: Milan Crha <mcrha redhat com>
Date: Thu Oct 29 13:00:34 2020 +0100
Bug 788192 - Support mid: URI scheme
Closes https://bugzilla.gnome.org/show_bug.cgi?id=788192
src/mail/e-mail-free-form-exp.c | 22 +++++++
src/modules/mail/e-mail-shell-backend.c | 92 +++++++++++++++++++++++++++-
src/modules/mail/e-mail-shell-view-actions.h | 2 +
3 files changed, 114 insertions(+), 2 deletions(-)
---
diff --git a/src/mail/e-mail-free-form-exp.c b/src/mail/e-mail-free-form-exp.c
index 1b8416f269..ec8f18fcb0 100644
--- a/src/mail/e-mail-free-form-exp.c
+++ b/src/mail/e-mail-free-form-exp.c
@@ -535,6 +535,27 @@ mail_ffe_location (const gchar *word,
return sexp;
}
+static gchar *
+mail_ffe_message_id (const gchar *word,
+ const gchar *options,
+ const gchar *hint)
+{
+ GString *encoded_mid;
+ gchar *sexp;
+
+ if (!word)
+ return NULL;
+
+ encoded_mid = g_string_new ("");
+ camel_sexp_encode_string (encoded_mid, word);
+
+ sexp = g_strdup_printf ("(header-matches \"MESSAGE-ID\" %s)", encoded_mid->str);
+
+ g_string_free (encoded_mid, TRUE);
+
+ return sexp;
+}
+
static const EFreeFormExpSymbol mail_ffe_symbols[] = {
{ "", "1", mail_ffe_recips },
{ "from:f", NULL, mail_ffe_from },
@@ -555,6 +576,7 @@ static const EFreeFormExpSymbol mail_ffe_symbols[] = {
{ "received:rcv", NULL, mail_ffe_received },
{ "attachment:a", NULL, mail_ffe_attachment },
{ "location:m", NULL, mail_ffe_location },
+ { "mid", NULL, mail_ffe_message_id },
{ NULL, NULL, NULL}
};
diff --git a/src/modules/mail/e-mail-shell-backend.c b/src/modules/mail/e-mail-shell-backend.c
index 4b31c7385b..570be148d1 100644
--- a/src/modules/mail/e-mail-shell-backend.c
+++ b/src/modules/mail/e-mail-shell-backend.c
@@ -24,8 +24,11 @@
#include <glib/gi18n.h>
-#include <shell/e-shell.h>
-#include <shell/e-shell-window.h>
+#include "shell/e-shell.h"
+#include "shell/e-shell-content.h"
+#include "shell/e-shell-searchbar.h"
+#include "shell/e-shell-view.h"
+#include "shell/e-shell-window.h"
#include <composer/e-msg-composer.h>
@@ -46,8 +49,10 @@
#include <em-format/e-mail-formatter.h>
#include <em-format/e-mail-part-utils.h>
+#include "e-mail-shell-content.h"
#include "e-mail-shell-sidebar.h"
#include "e-mail-shell-view.h"
+#include "e-mail-shell-view-private.h"
#include "em-account-prefs.h"
#include "em-composer-prefs.h"
#include "em-mailer-prefs.h"
@@ -582,6 +587,87 @@ mail_shell_backend_select_folder_uri (EMailShellBackend *mail_shell_backend,
g_free (folder_uri);
}
+static void
+mail_shell_backend_search_mid (EMailShellBackend *mail_shell_backend,
+ const gchar *in_uri)
+{
+ EShellWindow *window;
+ EShell *shell;
+ gchar *decoded_uri = NULL;
+ const gchar *uri = in_uri, *message_id;
+
+ g_return_if_fail (E_IS_MAIL_SHELL_BACKEND (mail_shell_backend));
+ g_return_if_fail (uri != NULL);
+ g_return_if_fail (g_str_has_prefix (uri, "mid:"));
+
+ if (strchr (uri, '%')) {
+ decoded_uri = g_uri_unescape_string (uri, NULL);
+
+ if (decoded_uri)
+ uri = decoded_uri;
+ }
+
+ message_id = uri + 4; /* strlen ("mid:") */
+
+ if (!*message_id) {
+ g_free (decoded_uri);
+ return;
+ }
+
+ shell = e_shell_backend_get_shell (E_SHELL_BACKEND (mail_shell_backend));
+ window = mail_shell_backend_get_mail_window (shell);
+
+ if (window) {
+ EShellView *shell_view;
+
+ shell_view = e_shell_window_get_shell_view (window, "mail");
+
+ if (shell_view) {
+ EShellSearchbar *shell_searchbar;
+ EShellWindow *shell_window = E_SHELL_WINDOW (window);
+ GString *expr;
+ GtkAction *action;
+ gint ii;
+
+ shell_searchbar = e_mail_shell_content_get_searchbar (E_MAIL_SHELL_CONTENT
(e_shell_view_get_shell_content (shell_view)));
+
+ expr = g_string_sized_new (strlen (message_id) + 4 + 2 + 1); /* strlen ("mid:") + 2 *
strlen ("\"") + NUL-terminator */
+ g_string_append (expr, "mid:\"");
+
+ for (ii = 0; message_id[ii]; ii++) {
+ /* skip white-spaces and double-quotes */
+ if (!g_ascii_isspace (message_id[ii]) && message_id[ii] != '\"')
+ g_string_append_c (expr, message_id[ii]);
+ }
+
+ g_string_append_c (expr, '\"');
+
+ e_shell_view_block_execute_search (shell_view);
+
+ action = ACTION (MAIL_FILTER_ALL_MESSAGES);
+ gtk_action_activate (action);
+
+ action = ACTION (MAIL_SEARCH_FREE_FORM_EXPR);
+ gtk_action_activate (action);
+
+ action = ACTION (MAIL_SCOPE_ALL_ACCOUNTS);
+ gtk_action_activate (action);
+
+ e_shell_view_set_search_rule (shell_view, NULL);
+ e_shell_searchbar_set_search_text (shell_searchbar, expr->str);
+
+ e_shell_view_unblock_execute_search (shell_view);
+ e_shell_view_execute_search (shell_view);
+
+ g_string_free (expr, TRUE);
+ }
+
+ gtk_window_present (GTK_WINDOW (window));
+ }
+
+ g_free (decoded_uri);
+}
+
static gboolean
mail_shell_backend_handle_uri_cb (EShell *shell,
const gchar *uri,
@@ -593,6 +679,8 @@ mail_shell_backend_handle_uri_cb (EShell *shell,
em_utils_compose_new_message_with_mailto (shell, uri, NULL);
} else if (g_str_has_prefix (uri, "folder:")) {
mail_shell_backend_select_folder_uri (mail_shell_backend, uri);
+ } else if (g_str_has_prefix (uri, "mid:")) {
+ mail_shell_backend_search_mid (mail_shell_backend, uri);
} else {
handled = FALSE;
}
diff --git a/src/modules/mail/e-mail-shell-view-actions.h b/src/modules/mail/e-mail-shell-view-actions.h
index ccd16ae015..1104d5bff2 100644
--- a/src/modules/mail/e-mail-shell-view-actions.h
+++ b/src/modules/mail/e-mail-shell-view-actions.h
@@ -172,6 +172,8 @@
E_SHELL_WINDOW_ACTION ((window), "mail-search-folder-from-sender")
#define E_SHELL_WINDOW_ACTION_MAIL_SEARCH_FOLDER_FROM_SUBJECT(window) \
E_SHELL_WINDOW_ACTION ((window), "mail-search-folder-from-subject")
+#define E_SHELL_WINDOW_ACTION_MAIL_SEARCH_FREE_FORM_EXPR(window) \
+ E_SHELL_WINDOW_ACTION ((window), "mail-search-free-form-expr")
#define E_SHELL_WINDOW_ACTION_MAIL_SELECT_ALL(window) \
E_SHELL_WINDOW_ACTION ((window), "mail-select-all")
#define E_SHELL_WINDOW_ACTION_MAIL_SEND_RECEIVE(window) \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]