[balsa] Simplify handling "mailto:" URLs



commit 7696091936370c07421e9a6243847b1194cf42c0
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu Feb 28 10:54:05 2019 -0500

    Simplify handling "mailto:"; URLs
    
    * src/sendmsg-window.c (decode_and_strdup): simplify;
    (sendmsg_window_process_url): drop the "field_setter func"
    argument; it's always "sendmsg_window_set_field";
    (set_list_post_rfc2369): use new API;
    * src/sendmsg-window.h: export new API;
    * src/balsa-mime-widget-text.c (handle_url): use new API;
    * src/main.c (balsa_check_open_compose_window): ditto.

 ChangeLog                    | 12 ++++++++
 src/balsa-mime-widget-text.c |  2 +-
 src/main.c                   |  3 +-
 src/sendmsg-window.c         | 73 ++++++++++++++++++++++++--------------------
 src/sendmsg-window.h         |  5 +--
 5 files changed, 55 insertions(+), 40 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e4c68c6bc..aca14c2dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2019-02-28  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Simplify handling "mailto:"; URLs
+
+       * src/sendmsg-window.c (decode_and_strdup): simplify;
+       (sendmsg_window_process_url): drop the "field_setter func"
+       argument; it's always "sendmsg_window_set_field";
+       (set_list_post_rfc2369): use new API;
+       * src/sendmsg-window.h: export new API;
+       * src/balsa-mime-widget-text.c (handle_url): use new API;
+       * src/main.c (balsa_check_open_compose_window): ditto.
+
 2019-02-24  Pawel Salek  <pawsa0 gmail com>
 
        Fix some issues raised by scan-build, the clang static analyzer
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index 179658e72..0159796c2 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -786,7 +786,7 @@ handle_url(const gchar * url)
 {
     if (!g_ascii_strncasecmp(url, "mailto:";, 7)) {
         BalsaSendmsg *snd = sendmsg_window_compose();
-        sendmsg_window_process_url(url + 7, sendmsg_window_set_field, snd);
+        sendmsg_window_process_url(url + 7, snd);
     } else {
         GtkStatusbar *statusbar;
         guint context_id;
diff --git a/src/main.c b/src/main.c
index 1b5e570ae..aed859345 100644
--- a/src/main.c
+++ b/src/main.c
@@ -444,8 +444,7 @@ balsa_check_open_compose_window(void)
 
         if (opt_compose_email) {
             if (g_ascii_strncasecmp(opt_compose_email, "mailto:";, 7) == 0)
-                sendmsg_window_process_url(opt_compose_email + 7,
-                                           sendmsg_window_set_field, snd);
+                sendmsg_window_process_url(opt_compose_email + 7, snd);
             else
                 sendmsg_window_set_field(snd, "to", opt_compose_email);
             g_free(opt_compose_email);
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index b757e2cfe..936360d69 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -4375,36 +4375,39 @@ sw_grab_focus_to_text(GtkWidget * text)
    decodes given URL string up to the delimiter and places the
    eos pointer in newstr if supplied (eos==NULL if end of string was reached)
 */
-static gchar*
-decode_and_strdup(const gchar*str, int delim, gchar** newstr)
+static gchar *
+decode_and_strdup(const gchar * str, int delim, const gchar ** newstr)
 {
-    gchar num[3];
     GString *s = g_string_new(NULL);
     /* eos points to the character after the last to parse */
-    gchar *eos = strchr(str, delim);
-
-    if(!eos) eos = (gchar*)str + strlen(str);
-    while(str<eos) {
-       switch(*str) {
-       case '+':
-           g_string_append_c(s, ' ');
-           str++;
-           break;
-       case '%':
-           if(str+2<eos) {
-               strncpy(num, str+1, 2); num[2] = 0;
-               g_string_append_c(s, strtol(num,NULL,16));
-           }
-           str+=3;
-           break;
-       default:
-           g_string_append_c(s, *str++);
-       }
+    const gchar *eos = strchr(str, delim);
+
+    if (eos == NULL)
+        eos = str + strlen(str);
+
+    while (str < eos) {
+        switch (*str) {
+        case '+':
+            g_string_append_c(s, ' ');
+            str++;
+            break;
+        case '%':
+            if (str + 2 < eos) {
+                gchar num[3] = {str[1], str[2], '\0'};
+
+                g_string_append_c(s, strtol(num, NULL, 16));
+            }
+            str += 3;
+            break;
+        default:
+            g_string_append_c(s, *str++);
+        }
     }
-    if(newstr) *newstr = *eos ? eos+1 : NULL;
-    eos = s->str;
-    g_string_free(s,FALSE);
-    return eos;
+
+    if (newstr != NULL)
+        *newstr = *eos != '\0' ? eos + 1 : NULL;
+
+    return g_string_free(s, FALSE);
 }
 
 /* process_url:
@@ -4412,18 +4415,19 @@ decode_and_strdup(const gchar*str, int delim, gchar** newstr)
    of format 'key'='value' with ampersands as separators.
 */
 void
-sendmsg_window_process_url(const char *url, field_setter func, void *data)
+sendmsg_window_process_url(const char *url, void *data)
 {
-    gchar * ptr, *to, *key, *val;
+    const gchar *ptr;
+    gchar *to, *key, *val;
 
     to = decode_and_strdup(url,'?', &ptr);
-    func(data, "to", to);
+    sendmsg_window_set_field(data, "to", to);
     g_free(to);
     while(ptr) {
        key = decode_and_strdup(ptr,'=', &ptr);
        if(ptr) {
            val = decode_and_strdup(ptr,'&', &ptr);
-           func(data, key, val);
+           sendmsg_window_set_field(data, key, val);
            g_free(val);
        }
        g_free(key);
@@ -6461,10 +6465,13 @@ set_list_post_rfc2369(BalsaSendmsg * bsmsg, const gchar * url)
            break;
        if (g_ascii_strncasecmp(url, "mailto:";, 7) == 0) {
            /* we support mailto! */
-            gchar *field = g_strndup(&url[7], close - &url[7]);
-           sendmsg_window_process_url(field, sendmsg_window_set_field,
-                                       bsmsg);
+            gchar *field;
+
+            url += 7;
+            field = g_strndup(url, close - url);
+            sendmsg_window_process_url(field, bsmsg);
             g_free(field);
+
            return TRUE;
        }
        if (!(*++close && *(close = rfc2822_skip_comments(close)) == ','))
diff --git a/src/sendmsg-window.h b/src/sendmsg-window.h
index e77aa4a28..1780751eb 100644
--- a/src/sendmsg-window.h
+++ b/src/sendmsg-window.h
@@ -130,10 +130,7 @@ G_BEGIN_DECLS
                             gboolean is_a_tmp_file, 
                             const gchar *forced_mime_type);
 
-    typedef void (*field_setter)(BalsaSendmsg *d, const gchar*, const gchar*);
-
-    void sendmsg_window_process_url(const char *url, field_setter func,
-                                   void *data);
+    void sendmsg_window_process_url(const char *url, void *data);
     BalsaSendmsg *sendmsg_window_new_from_list(LibBalsaMailbox * mailbox,
                                                GArray * selected,
                                                SendType type);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]