sync with 0.8.11cvs5
authorPaul Mangan <paul@claws-mail.org>
Thu, 13 Mar 2003 11:12:58 +0000 (11:12 +0000)
committerPaul Mangan <paul@claws-mail.org>
Thu, 13 Mar 2003 11:12:58 +0000 (11:12 +0000)
ChangeLog
ChangeLog.claws
ChangeLog.jp
configure.ac
src/compose.c
src/html.c
src/html.h
src/textview.c

index 079b9e2..5f92961 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2003-03-12
+
+       * src/textview.c: textview_button_pressed(): corrected the range of
+         URI link.
+       * src/compose.c: compose_wrap_line_all_full(): treat UTF-8 characters
+         represented with more than 2 bytes as 2 character width and 2 bytes
+         one as a single character width as a workaround for wrapping problem.
+
+2003-03-12
+
+       * src/utils.c: subject_compare_for_sort(): allow null strings (fixes
+         summary sorting).
+
+2003-03-11
+
+       * implemented HTML link correctly.
+       * src/html.[ch]: HTMLAttr, HTMLTag: new structure for attributes /
+         tags.
+         html_get_tag(): new. It parses tag and returns HTMLTag object.
+         html_parse_tag(): also parses <a> tags and 'href' attributes.
+       * src/textview.c: textview_write_link(): new. It creates link string.
+
+2003-03-10
+
+       * src/compose.c: compose_wrap_line_all_full(): fixed an infinite
+         loop / crash bug (thanks to Darko Koruga).
+         compose_write_to_file(): put correct charset element when
+         conversion failed but want to send anyway.
+
 2003-03-10
 
        * src/headerview.c: headerview_show()
index a5a83e3..ffcd265 100644 (file)
@@ -1,3 +1,8 @@
+2003-03-13 [paul]      0.8.11claws5
+
+       * sync with 0.8.11cvs5
+               see ChangeLog 2003-03-11, 2003-03-12
+
 2003-03-12 [christoph] 0.8.11claws4
 
        * src/folder.c
index 93ffc30..ec5e378 100644 (file)
@@ -1,3 +1,31 @@
+2003-03-12
+
+       * src/textview.c: textview_button_pressed(): URI ¤Î¥ê¥ó¥¯¤ÎÈϰϤò
+         ÄûÀµ¡£
+       * src/compose.c: compose_wrap_line_all_full(): ÀÞ¤êÊÖ¤·¤ÎÌäÂê¤Ø¤Î
+         Âнè¤Î¤¿¤á¡¢ UTF-8 ¤Î3¥Ð¥¤¥È°Ê¾å¤Çɽ¸½¤µ¤ì¤ëʸ»ú¤ò2ʸ»úÉý¡¢2
+         ¥Ð¥¤¥Èʸ»ú¤ò1ʸ»úÉý¤È¤·¤Æ°·¤¦¤è¤¦¤Ë¤·¤¿¡£
+
+2003-03-12
+
+       * src/utils.c: subject_compare_for_sort(): ¥Ì¥ëʸ»úÎó¤òµö²Ä(¥µ¥Þ¥ê¤Î
+         ¥½¡¼¥È¤ò½¤Àµ)¡£
+
+2003-03-11
+
+       * HTML ¥ê¥ó¥¯¤òÀµ¤·¤¯¼ÂÁõ¡£
+       * src/html.[ch]: HTMLAttr, HTMLTag: Â°À­ / ¥¿¥°¤Î¤¿¤á¤Î¿·µ¬¹½Â¤ÂΡ£
+         html_get_tag(): ¿·µ¬¡£¥¿¥°¤ò²òÀϤ·¤Æ HTMLTag ¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤¹¡£
+         html_parse_tag(): <a> ¥¿¥°¤È 'href' Â°À­¤â¥Ñ¡¼¥¹¡£
+       * src/textview.c: textview_write_link(): ¿·µ¬¡£¥ê¥ó¥¯Ê¸»úÎó¤òºîÀ®¡£
+
+2003-03-10
+
+       * src/compose.c: compose_wrap_line_all_full(): Ìµ¸Â¥ë¡¼¥× /
+         ¥¯¥é¥Ã¥·¥å¥Ð¥°¤ò½¤Àµ(Darko Koruga ¤µ¤ó thanks)¡£
+         compose_write_to_file(): ÊÑ´¹¤Ë¼ºÇÔ¤·¤¿¤¬¤È¤Ë¤«¤¯Á÷¿®¤·¤¿¤¤¤È¤­
+         ¤ËÀµ¤·¤¤ charset Í×ÁǤò½ÐÎϤ¹¤ë¤è¤¦¤Ë¤·¤¿¡£
+
 2003-03-10
 
        * src/headerview.c: headerview_show()
index b8ce4e2..50d9120 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=11
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws4
+EXTRA_VERSION=claws5
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 0df7d5c..6e766b4 100644 (file)
@@ -2140,6 +2140,10 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        }                                                                    \
 }
 
+#define DISP_WIDTH(len) \
+       ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
+        (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
+
 #define INDENT_CHARS   ">|#"
 #define SPACE_CHARS    " \t"
 
@@ -2267,7 +2271,7 @@ static void compose_wrap_line(Compose *compose)
                        line_len = cur_len + ch_len;
                }
 
-               if (cur_len + ch_len > prefs_common.linewrap_len &&
+               if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
                    line_len > 0) {
                        gint tlen = ch_len;
 
@@ -2288,16 +2292,16 @@ static void compose_wrap_line(Compose *compose)
                        p_end++;
                        cur_pos++;
                        line_pos++;
-                       cur_len = cur_len - line_len + ch_len;
+                       cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
                        line_len = 0;
                        continue;
                }
 
                if (ch_len > 1) {
                        line_pos = cur_pos + 1;
-                       line_len = cur_len + ch_len;
+                       line_len = cur_len + DISP_WIDTH(ch_len);
                }
-               cur_len += ch_len;
+               cur_len += DISP_WIDTH(ch_len);
        }
 
 compose_end:
@@ -2602,7 +2606,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                }
 
                /* are we over wrapping length set in preferences ? */
-               if (cur_len + ch_len > linewrap_len) {
+               if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
                        gint clen;
 
 #ifdef WRAP_DEBUG
@@ -2700,10 +2704,10 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
 
                if (ch_len > 1) {
                        line_pos = cur_pos + 1;
-                       line_len = cur_len + ch_len;
+                       line_len = cur_len + DISP_WIDTH(ch_len);
                }
                /* advance to next character in buffer */
-               cur_len += ch_len;
+               cur_len += DISP_WIDTH(ch_len);
        }
 
        if (frozen)
index fdba4f7..da489b9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -338,6 +338,8 @@ HTMLParser *html_parser_new(FILE *fp, CodeConverter *conv)
        parser->str = g_string_new(NULL);
        parser->buf = g_string_new(NULL);
        parser->bufp = parser->buf->str;
+       parser->state = HTML_NORMAL;
+       parser->href = NULL;
        parser->newline = TRUE;
        parser->empty_line = TRUE;
        parser->space = FALSE;
@@ -390,6 +392,7 @@ void html_parser_destroy(HTMLParser *parser)
 {
        g_string_free(parser->str, TRUE);
        g_string_free(parser->buf, TRUE);
+       g_free(parser->href);
        g_free(parser);
 }
 
@@ -517,59 +520,128 @@ static void html_append_str(HTMLParser *parser, const gchar *str, gint len)
                parser->newline = FALSE;
 }
 
+static HTMLTag *html_get_tag(const gchar *str)
+{
+       HTMLTag *tag;
+       gchar *tmp;
+       gchar *tmpp;
+
+       g_return_val_if_fail(str != NULL, NULL);
+
+       if (*str == '\0' || *str == '!') return NULL;
+
+       Xstrdup_a(tmp, str, return NULL);
+
+       tag = g_new0(HTMLTag, 1);
+
+       for (tmpp = tmp; *tmpp != '\0' && !isspace(*tmpp); tmpp++)
+               ;
+
+       if (*tmpp == '\0') {
+               g_strdown(tmp);
+               tag->name = g_strdup(tmp);
+               return tag;
+       } else {
+               *tmpp++ = '\0';
+               g_strdown(tmp);
+               tag->name = g_strdup(tmp);
+       }
+
+       while (*tmpp != '\0') {
+               HTMLAttr *attr;
+               gchar *attr_name;
+               gchar *attr_value;
+               gchar *p;
+               gchar quote;
+
+               while (isspace(*tmpp)) tmpp++;
+               attr_name = tmpp;
+               if ((p = strchr(attr_name, '=')) == NULL) {
+                       g_warning("html_get_tag(): syntax error in tag: '%s'\n", str);
+                       return tag;
+               }
+               tmpp = p;
+               *tmpp++ = '\0';
+               while (isspace(*tmpp)) tmpp++;
+
+               if (*tmpp == '\0') {
+                       g_warning("html_get_tag(): syntax error in tag: '%s'\n", str);
+                       return tag;
+               } else if (*tmpp == '"' || *tmpp == '\'') {
+                       /* name="value" */
+                       quote = *tmpp;
+                       tmpp++;
+                       attr_value = tmpp;
+                       if ((p = strchr(attr_value, quote)) == NULL) {
+                               g_warning("html_get_tag(): syntax error in tag: '%s'\n", str);
+                               return tag;
+                       }
+                       tmpp = p;
+                       *tmpp++ = '\0';
+                       while (isspace(*tmpp)) tmpp++;
+               } else {
+                       /* name=value */
+                       attr_value = tmpp;
+                       while (*tmpp != '\0' && !isspace(*tmpp)) tmpp++;
+                       if (*tmpp != '\0')
+                               *tmpp++ = '\0';
+               }
+
+               g_strchomp(attr_name);
+               g_strdown(attr_name);
+               attr = g_new(HTMLAttr, 1);
+               attr->name = g_strdup(attr_name);
+               attr->value = g_strdup(attr_value);
+               tag->attr = g_list_append(tag->attr, attr);
+       }
+
+       return tag;
+}
+
+static void html_free_tag(HTMLTag *tag)
+{
+       if (!tag) return;
+
+       g_free(tag->name);
+       while (tag->attr != NULL) {
+               HTMLAttr *attr = (HTMLAttr *)tag->attr->data;
+               g_free(attr->name);
+               g_free(attr->value);
+               g_free(attr);
+               tag->attr = g_list_remove(tag->attr, tag->attr->data);
+       }
+       g_free(tag);
+}
+
 static HTMLState html_parse_tag(HTMLParser *parser)
 {
        gchar buf[HTMLBUFSIZE];
-       gchar *p;
-       static gboolean is_in_href = FALSE;
+       HTMLTag *tag;
 
        html_get_parenthesis(parser, buf, sizeof(buf));
 
-       for (p = buf; *p != '\0'; p++) {
-               if (isspace(*p)) {
-                       *p = '\0';
-                       break;
-               }
-       }
+       tag = html_get_tag(buf);
 
        parser->state = HTML_UNKNOWN;
-       if (buf[0] == '\0') return parser->state;
+       if (!tag) return HTML_UNKNOWN;
 
-       g_strdown(buf);
-
-       if (!strcmp(buf, "br")) {
+       if (!strcmp(tag->name, "br")) {
                parser->space = FALSE;
                html_append_char(parser, '\n');
                parser->state = HTML_BR;
-       } else if (!strcmp(buf, "a")) {
-               /* look for tokens separated by space or = */
-               char* href_token = strtok(++p, " =");
-               parser->state = HTML_NORMAL;
-               while (href_token != NULL) {
-                       /* look for href */
-                       if (!strcmp(href_token, "href")) {
-                               /* the next token is the url, between double
-                                        * quotes */
-                               char* url = strtok(NULL, "\"");
-                                       if (url && url[0] == '\'')
-                                         url = strtok(url,"\'");
-
-                               if (!url) break;
-                               html_append_str(parser, url, strlen(url));
-                               html_append_char(parser, ' ');
-                               /* start enforcing html link */
-                               parser->state = HTML_HREF;
-                               is_in_href = TRUE;
-                               break;
-                       }
-                       /* or get next token */
-                       href_token = strtok(NULL, " =");
+       } else if (!strcmp(tag->name, "a")) {
+               if (tag->attr && tag->attr->data &&
+                   !strcmp(((HTMLAttr *)tag->attr->data)->name, "href")) {
+                       g_free(parser->href);
+                       parser->href =
+                               g_strdup(((HTMLAttr *)tag->attr->data)->value);
+                       parser->state = HTML_HREF;
                }
-       } else if (!strcmp(buf, "/a")) {
-               /* stop enforcing html link */
-               parser->state = HTML_NORMAL;
-               is_in_href = FALSE;
-       } else if (!strcmp(buf, "p")) {
+       } else if (!strcmp(tag->name, "/a")) {
+               g_free(parser->href);
+               parser->href = NULL;
+               parser->state = HTML_NORMAL;
+       } else if (!strcmp(tag->name, "p")) {
                parser->space = FALSE;
                if (!parser->empty_line) {
                        parser->space = FALSE;
@@ -577,53 +649,51 @@ static HTMLState html_parse_tag(HTMLParser *parser)
                        html_append_char(parser, '\n');
                }
                parser->state = HTML_PAR;
-       } else if (!strcmp(buf, "pre")) {
+       } else if (!strcmp(tag->name, "pre")) {
                parser->pre = TRUE;
                parser->state = HTML_PRE;
-       } else if (!strcmp(buf, "/pre")) {
+       } else if (!strcmp(tag->name, "/pre")) {
                parser->pre = FALSE;
                parser->state = HTML_NORMAL;
-       } else if (!strcmp(buf, "hr")) {
+       } else if (!strcmp(tag->name, "hr")) {
                if (!parser->newline) {
                        parser->space = FALSE;
                        html_append_char(parser, '\n');
                }
                html_append_str(parser, HR_STR "\n", -1);
                parser->state = HTML_HR;
-       } else if (!strcmp(buf, "div")    ||
-                  !strcmp(buf, "ul")     ||
-                  !strcmp(buf, "li")     ||
-                  !strcmp(buf, "table")  ||
-                  !strcmp(buf, "tr")     ||
-                  (buf[0] == 'h' && isdigit(buf[1]))) {
+       } else if (!strcmp(tag->name, "div")    ||
+                  !strcmp(tag->name, "ul")     ||
+                  !strcmp(tag->name, "li")     ||
+                  !strcmp(tag->name, "table")  ||
+                  !strcmp(tag->name, "tr")     ||
+                  (tag->name[0] == 'h' && isdigit(tag->name[1]))) {
                if (!parser->newline) {
                        parser->space = FALSE;
                        html_append_char(parser, '\n');
                }
                parser->state = HTML_NORMAL;
-       } else if (!strcmp(buf, "/table") ||
-                  (buf[0] == '/' && buf[1] == 'h' && isdigit(buf[1]))) {
+       } else if (!strcmp(tag->name, "/table") ||
+                  (tag->name[0] == '/' &&
+                   tag->name[1] == 'h' &&
+                   isdigit(tag->name[1]))) {
                if (!parser->empty_line) {
                        parser->space = FALSE;
                        if (!parser->newline) html_append_char(parser, '\n');
                        html_append_char(parser, '\n');
                }
                parser->state = HTML_NORMAL;
-       } else if (!strcmp(buf, "/div")   ||
-                  !strcmp(buf, "/ul")    ||
-                  !strcmp(buf, "/li")) {
+       } else if (!strcmp(tag->name, "/div")   ||
+                  !strcmp(tag->name, "/ul")    ||
+                  !strcmp(tag->name, "/li")) {
                if (!parser->newline) {
                        parser->space = FALSE;
                        html_append_char(parser, '\n');
                }
                parser->state = HTML_NORMAL;
-       }
-       
-       if (is_in_href == TRUE) {
-               /* when inside a link, everything will be written as
-                * clickable (see textview_show_thml in textview.c) */
-               parser->state = HTML_HREF;
-       }
+                       }
+
+       html_free_tag(tag);
 
        return parser->state;
 }
@@ -705,6 +775,7 @@ static void html_get_parenthesis(HTMLParser *parser, gchar *buf, gint len)
                if (html_read_line(parser) == HTML_EOF) return;
 
        strncpy2(buf, parser->bufp, MIN(p - parser->bufp + 1, len));
+       g_strstrip(buf);
        parser->bufp = p + 1;
 }
 
index 5b17dc2..7267c17 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -42,6 +42,8 @@ typedef enum
 } HTMLState;
 
 typedef struct _HTMLParser     HTMLParser;
+typedef struct _HTMLAttr       HTMLAttr;
+typedef struct _HTMLTag                HTMLTag;
 
 struct _HTMLParser
 {
@@ -57,12 +59,26 @@ struct _HTMLParser
 
        HTMLState state;
 
+       gchar *href;
+
        gboolean newline;
        gboolean empty_line;
        gboolean space;
        gboolean pre;
 };
 
+struct _HTMLAttr
+{
+       gchar *name;
+       gchar *value;
+};
+
+struct _HTMLTag
+{
+       gchar *name;
+       GList *attr;
+};
+
 HTMLParser *html_parser_new    (FILE           *fp,
                                 CodeConverter  *conv);
 void html_parser_destroy       (HTMLParser     *parser);
index fe24af8..235a7b9 100644 (file)
@@ -148,9 +148,9 @@ static void textview_show_html              (TextView       *textview,
 static void textview_write_line                (TextView       *textview,
                                         const gchar    *str,
                                         CodeConverter  *conv);
-static void textview_write_link         (TextView      *textview,
-                                         const gchar    *url,
+static void textview_write_link                (TextView       *textview,
                                         const gchar    *str,
+                                        const gchar    *uri,
                                         CodeConverter  *conv);
 static GPtrArray *textview_scan_header (TextView       *textview,
                                         FILE           *fp);
@@ -523,7 +523,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
                textview->msgfont = NULL;
 
                tmp = g_strconcat("pgp: ", _("Check signature"), NULL);
-               textview_write_link(textview, tmp, buf, NULL);
+               textview_write_link(textview, buf, tmp, NULL);
                
                /* put things back */
                textview->msgfont = (GdkFont *)oldfont;
@@ -557,7 +557,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
                        charset = mimeinfo->charset;
                textview_write_body(textview, mimeinfo, fp, charset);
        }
-       
+
        gtk_stext_thaw(text);
 }
 
@@ -595,7 +595,7 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        textview_set_font(textview, NULL);
        text = GTK_STEXT(textview->text);
        textview_clear(textview);
-       
+
        gtk_stext_freeze(text);
 
        TEXT_INSERT(_("To save this part, pop up the context menu with "));
@@ -636,7 +636,7 @@ void textview_show_signature_part(TextView *textview, MimeInfo *partinfo)
        } else {
                TEXT_INSERT(partinfo->sigstatus_full);
        }
-               
+
        gtk_stext_thaw(text);
 }
 #endif /* USE_GPGME */
@@ -657,7 +657,6 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo,
        textview->is_in_signature = FALSE;
 
        if (tmpfp) {
-               
                if (mimeinfo->mime_type == MIME_TEXT_HTML)
                        textview_show_html(textview, tmpfp, conv);
                else if (mimeinfo->mime_type == MIME_TEXT_ENRICHED)
@@ -676,7 +675,6 @@ static void textview_show_html(TextView *textview, FILE *fp,
 {
        HTMLParser *parser;
        gchar *str;
-       gchar* url = NULL;
 
        parser = html_parser_new(fp, conv);
        g_return_if_fail(parser != NULL);
@@ -684,29 +682,22 @@ static void textview_show_html(TextView *textview, FILE *fp,
        while ((str = html_parse(parser)) != NULL) {
                if (parser->state == HTML_HREF) {
                        /* first time : get and copy the URL */
-                       if (url == NULL) {
+                       if (parser->href == NULL) {
                                /* ALF - the sylpheed html parser returns an empty string,
                                 * if still inside an <a>, but already parsed past HREF */
                                str = strtok(str, " ");
                                if (str) { 
-                                       url = strdup(str);
+                                       parser->href = strdup(str);
                                        /* the URL may (or not) be followed by the
                                         * referenced text */
                                        str = strtok(NULL, "");
                                }       
                        }
-                       if (str != NULL) {
-                               textview_write_link(textview, url, str, NULL);
-                       }
-               } else {
-                       if (url != NULL) {
-                               free(url);
-                               url = NULL;
-                       }
+                       if (str != NULL)
+                               textview_write_link(textview, str, parser->href, NULL);
+               } else
                        textview_write_line(textview, str, NULL);
-               }
        }
-       
        html_parser_destroy(parser);
 }
 
@@ -1123,49 +1114,6 @@ static void textview_make_clickable_parts(TextView *textview,
 
 #undef ADD_TXT_POS
 
-/* This function writes str as a double-clickable link with the given url. */ 
-static void textview_write_link(TextView *textview, const gchar *url,
-                                const gchar *str, CodeConverter *conv)
-{
-    GdkColor *link_color = NULL;
-    RemoteURI* uri;
-    GtkSText *text = GTK_STEXT(textview->text);
-    gchar buf[BUFFSIZE];
-
-    /* this part is taken from textview_write_line. Right now the only place
-     * that calls this function passes NULL for conv, but you never know. */
-#if 0
-    if (!conv)
-           strncpy2(buf, str, sizeof(buf));
-    else if (conv_convert(conv, buf, sizeof(buf), str) < 0) {
-                   gtk_stext_insert(text, textview->msgfont,
-                           prefs_common.enable_color
-                           ? &error_color : NULL, NULL,
-                           "*** Warning: code conversion failed ***\n",
-                           -1);
-           return;
-    }
-#endif
-
-    if (!conv || conv_convert(conv, buf, sizeof(buf), str) < 0)
-       strncpy2(buf, str, sizeof(buf));
-
-    strcrchomp(buf);
-    gtk_stext_insert(text, textview->msgfont, NULL, NULL, " ", 1);
-    /* this part is based on the code in make_clickable_parts */
-    if (prefs_common.enable_color) {
-       link_color = &uri_color;
-    }
-    uri = g_new(RemoteURI, 1);
-    uri->uri = g_strdup(url);
-    uri->start = gtk_stext_get_point(text);
-    gtk_stext_insert(text, textview->msgfont, link_color, NULL, str,
-                   strlen(str));
-    uri->end = gtk_stext_get_point(text);
-    textview->uri_list = g_slist_append(textview->uri_list, uri);
-}
-
 static void textview_write_line(TextView *textview, const gchar *str,
                                CodeConverter *conv)
 {
@@ -1227,6 +1175,44 @@ static void textview_write_line(TextView *textview, const gchar *str,
                                              fg_color, NULL, buf);
 }
 
+void textview_write_link(TextView *textview, const gchar *str,
+                        const gchar *uri, CodeConverter *conv)
+{
+       GdkColor *link_color = NULL;
+       GtkSText *text = GTK_STEXT(textview->text);
+       gchar buf[BUFFSIZE];
+       gchar *bufp;
+       RemoteURI *r_uri;
+
+       if (*str == '\0')
+               return;
+
+       if (!conv) {
+               if (textview->text_is_mb)
+                       conv_localetodisp(buf, sizeof(buf), str);
+               else
+                       strncpy2(buf, str, sizeof(buf));
+       } else if (conv_convert(conv, buf, sizeof(buf), str) < 0)
+               conv_localetodisp(buf, sizeof(buf), str);
+       else if (textview->text_is_mb)
+               conv_unreadable_locale(buf);
+
+       strcrchomp(buf);
+
+       for (bufp = buf; isspace(*bufp); bufp++)
+               gtk_stext_insert(text, textview->msgfont, NULL, NULL, bufp, 1);
+
+       if (prefs_common.enable_color) {
+               link_color = &uri_color;
+       }
+       r_uri = g_new(RemoteURI, 1);
+       r_uri->uri = g_strdup(uri);
+       r_uri->start = gtk_stext_get_point(text);
+       gtk_stext_insert(text, textview->msgfont, link_color, NULL, bufp, -1);
+       r_uri->end = gtk_stext_get_point(text);
+       textview->uri_list = g_slist_append(textview->uri_list, r_uri);
+}
+
 void textview_clear(TextView *textview)
 {
        GtkSText *text = GTK_STEXT(textview->text);
@@ -1445,6 +1431,7 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        } else
                procheader_header_array_destroy(headers);
 
+
        return sorted_headers;
 }
 
@@ -1539,6 +1526,7 @@ gboolean textview_search_string(TextView *textview, const gchar *str,
                }
                if (text_len - pos == len) break;
        }
+
        g_free(wcs);
        return found;
 }
@@ -1878,7 +1866,7 @@ static gint textview_button_released(GtkWidget *widget, GdkEventButton *event,
                        RemoteURI *uri = (RemoteURI *)cur->data;
 
                        if (textview->cur_pos >= uri->start &&
-                           textview->cur_pos <  uri->end) {
+                           textview->cur_pos <= uri->end) {
                                /* single click: display url in statusbar */
                                if (event->button == 1 && textview->last_buttonpress != GDK_2BUTTON_PRESS) {
                                        if (textview->messageview->mainwin) {