From ccacaf836acd56251763b3465ba23719b28319b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ho=C3=A0=20Vi=C3=AAt=20Dinh?= Date: Sun, 4 Nov 2001 12:51:37 +0000 Subject: [PATCH] newsgroups dialog / enhanced mailto --- ChangeLog.claws | 18 ++++++- configure.in | 2 +- src/compose.c | 97 ++++++++++++++++++++++++++++++++- src/grouplistdialog.c | 15 +++++- src/utils.c | 123 ++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 244 insertions(+), 11 deletions(-) diff --git a/ChangeLog.claws b/ChangeLog.claws index f8d130807..c5aa30e98 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,10 +1,24 @@ -2001-11-18 [hoa] 0.6.4claws21 +2001-11-04 [hoa] 0.6.4claws22 + + * src/grouplistdialog.c + change the names of the nodes in the tree + + * src/compose.c + enhanced mailto syntax as described in + http://developer.netscape.com/viewsource/husted_mailto/mailto.html + (thanks to Jonathan Ware ) + + * src/utils.c + encode and decode URI (useful when opening URL into + netscape). + +2001-11-03 [hoa] 0.6.4claws21 * src/grouplistdialog.c a new newsgroups list selection dialog box with a CTree instead of a CList -2001-11-18 [hoa] 0.6.4claws20 +2001-11-03 [hoa] 0.6.4claws20 * src/folderview.c enable property and scoring options when right diff --git a/configure.in b/configure.in index 26d60fc27..80f297306 100644 --- a/configure.in +++ b/configure.in @@ -8,7 +8,7 @@ MINOR_VERSION=6 MICRO_VERSION=4 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=claws21 +EXTRA_VERSION=claws22 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl diff --git a/src/compose.c b/src/compose.c index 0e4796aa3..4c51dc772 100644 --- a/src/compose.c +++ b/src/compose.c @@ -494,6 +494,86 @@ Compose * compose_new_with_folderitem(PrefsAccount *account, FolderItem *item) return compose_generic_new(account, NULL, item); } +static void set_compose_entries(Compose * compose, const gchar * mailto) +{ + gchar * subject = NULL; + gchar * to = NULL; + gchar * cc = NULL; + gchar * bcc = NULL; + gchar * body = NULL; + gchar * p; + gchar * tmp_mailto; + gchar * cur; + + Xstrdup_a(tmp_mailto, mailto, return); + + cur = tmp_mailto; + + p = strchr(cur, '?'); + if (p != NULL) { + * p = 0; + cur = p + 1; + } + to = tmp_mailto; + + while (p) { + char *field, *value; + + field = cur; + + p = strchr(cur, '='); + if (p == NULL) + break; + * p = 0; + cur = p + 1; + + value = cur; + + p = strchr(cur, '&'); + if (p != NULL) { + * p = 0; + cur = p + 1; + } + + if (value) { + if (g_strcasecmp(field, "subject")==0) { + Xstrdup_a(subject, value, ); + if (subject != NULL) + decode_uri(subject, value); + } + else if (g_strcasecmp(field, "cc")==0) + cc = value; + else if (g_strcasecmp(field, "bcc")==0) + bcc = value; + else if (g_strcasecmp(field, "body")==0) { + Xstrdup_a(body, value, ); + if (body != NULL) + decode_uri(body, value); + } + } + } + + if (to) { + compose_entry_append(compose, to, COMPOSE_TO); + /* + gtk_widget_grab_focus(compose->text); + */ + } + + if (subject) + gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject); + if (cc) + compose_entry_append(compose, cc, COMPOSE_CC); + if (bcc) + compose_entry_append(compose, bcc, COMPOSE_BCC); + if (body) { + gtk_text_insert(GTK_TEXT(compose->text), + NULL, NULL, NULL, body, -1); + gtk_text_insert(GTK_TEXT(compose->text), + NULL, NULL, NULL, "\n", 1); + } +} + Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem *item) { Compose *compose; @@ -501,7 +581,7 @@ Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem if (item && item->prefs && item->prefs->enable_default_account) account = account_find_from_id(item->prefs->default_account); - if (!account) account = cur_account; + if (!account) account = cur_account; g_return_val_if_fail(account != NULL, NULL); compose = compose_create(account, COMPOSE_NEW); @@ -514,7 +594,8 @@ Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem if (account->protocol != A_NNTP) { if (to) { - compose_entry_append(compose, to, COMPOSE_TO); + set_compose_entries(compose, to); + } else if(item && item->prefs->enable_default_to) { compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO); } @@ -1664,11 +1745,23 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo, : msginfo->from ? msginfo->from : ""), COMPOSE_TO); if (compose->account->protocol == A_NNTP) + if (ignore_replyto) + compose_entry_append(compose, + msginfo->from ? msginfo->from : "", + COMPOSE_TO); + else + compose_entry_append(compose, + compose->followup_to ? compose->followup_to + : compose->newsgroups ? compose->newsgroups + : "", + COMPOSE_NEWSGROUPS); + /* compose_entry_append(compose, compose->followup_to ? compose->followup_to : compose->newsgroups ? compose->newsgroups : "", COMPOSE_NEWSGROUPS); + */ if (msginfo->subject && *msginfo->subject) { gchar *buf, *buf2, *p; diff --git a/src/grouplistdialog.c b/src/grouplistdialog.c index fa29754a5..975e2d119 100644 --- a/src/grouplistdialog.c +++ b/src/grouplistdialog.c @@ -306,6 +306,17 @@ static gchar * get_parent_name(gchar * name) return g_strndup(name, p - name); } +static gchar * get_node_name(gchar * name) +{ + gchar * p; + + p = (gchar *) strrchr(name, '.'); + if (p == NULL) + return name; + + return p + 1; +} + static GtkCTreeNode * create_parent(GtkCTree * groups_tree, gchar * name) { gchar * cols[3]; @@ -319,7 +330,7 @@ static GtkCTreeNode * create_parent(GtkCTree * groups_tree, gchar * name) if (hash_news_get_branch_node(name) != NULL) return; - cols[0] = name; + cols[0] = get_node_name(name); cols[1] = ""; cols[2] = ""; @@ -357,7 +368,7 @@ static GtkCTreeNode * create_branch(GtkCTree * groups_tree, gchar * name, count = 0; snprintf(count_str, 10, "%i", count); - cols[0] = info->name; + cols[0] = get_node_name(info->name); cols[1] = count_str; if (info->type == 'y') cols[2] = ""; diff --git a/src/utils.c b/src/utils.c index c197163f3..1f4dc6abd 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1815,25 +1815,140 @@ gint execute_command_line(const gchar *cmdline, gboolean async) return ret; } +static gint is_unchanged_uri_char(char c) +{ + switch (c) { + case '(': + case ')': + case ',': + return 0; + default: + return 1; + } +} + +void encode_uri(gchar * encoded_uri, gint bufsize, const gchar * uri) +{ + int i; + int k; + + k = 0; + for(i = 0; i < strlen(uri) ; i++) { + if (is_unchanged_uri_char(uri[i])) { + if (k + 2 >= bufsize) + break; + encoded_uri[k++] = uri[i]; + } + else { + char * hexa = "0123456789ABCDEF"; + + if (k + 4 >= bufsize) + break; + encoded_uri[k++] = '%'; + encoded_uri[k++] = hexa[uri[i] / 16]; + encoded_uri[k++] = hexa[uri[i] % 16]; + } + } + encoded_uri[k] = 0; +} + +/* Converts two-digit hexadecimal to decimal. Used for unescaping escaped + * characters + */ +static gint axtoi(const gchar *hexstr) +{ + gint Hi, Lo, Result; + + Hi = hexstr[0]; + if ('0' <= Hi && Hi <= '9') { + Hi -= '0'; + } else + if ('a' <= Hi && Hi <= 'f') { + Hi -=('a'-10); + } else + if ('A' <= Hi && Hi <= 'F') { + Hi -= ('A'-10); + } + + Lo = hexstr[1]; + if ('0' <= Lo && Lo <='9') { + Lo -= '0'; + } else + if ('a' <= Lo && Lo <= 'f') { + Lo -= ('a'-10); + } else + if ('A' <= Lo && Lo <= 'F') { + Lo -= ('A'-10); + } + Result = Lo + (16 * Hi); + return (Result); +} + + +/* Decodes URL-Encoded strings (i.e. strings in which spaces are replaced by + * plusses, and escape characters are used) + */ + +void decode_uri(gchar * decoded_uri, const gchar * encoded_uri) +{ + const gchar * encoded; + gchar * decoded; + + // strcpy(decoded_uri, encoded_uri); + // subst_char(decoded_uri, '+', ' '); + + encoded = encoded_uri; + decoded = decoded_uri; + + while (* encoded) { + if (* encoded == '%') { + encoded ++; + if (isxdigit(encoded[0]) + && isxdigit(encoded[1])) { + * decoded = (gchar) axtoi(encoded); + decoded ++; + encoded += 2; + } + } + else if (* encoded == '+') { + * decoded = ' '; + decoded ++; + encoded ++; + } + else { + * decoded = * encoded; + decoded ++; + encoded ++; + } + } + + * decoded = '\0'; +} + + gint open_uri(const gchar *uri, const gchar *cmdline) { static gchar *default_cmdline = "netscape -remote openURL(%s,raise)"; gchar buf[BUFFSIZE]; gchar *p; - + gchar encoded_uri[BUFFSIZE]; + g_return_val_if_fail(uri != NULL, -1); + /* an option to choose whether to use encode_uri or not ? */ + encode_uri(encoded_uri, BUFFSIZE, uri); + if (cmdline && (p = strchr(cmdline, '%')) && *(p + 1) == 's' && !strchr(p + 2, '%')) - g_snprintf(buf, sizeof(buf), cmdline, uri); + g_snprintf(buf, sizeof(buf), cmdline, encoded_uri); else { if (cmdline) g_warning(_("Open URI command line is invalid: `%s'"), cmdline); - g_snprintf(buf, sizeof(buf), default_cmdline, uri); + g_snprintf(buf, sizeof(buf), default_cmdline, encoded_uri); } - + execute_command_line(buf, TRUE); return 0; -- 2.25.1