sync with sylpheed 0.6.5cvs18
[claws.git] / src / textview.c
index f0e7f4253ff7b7bb8b95caf8076bd947c8e80a2e..0dff13fceaae574c65aecb720b9a9a26a57e527b 100644 (file)
@@ -297,11 +297,19 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
        } else {
                if (mimeinfo->mime_type == MIME_TEXT && mimeinfo->parent) {
                        glong fpos;
+                       MimeInfo *parent = mimeinfo->parent;
+
+                       while (parent->parent) {
+                               if (parent->main &&
+                                   parent->main->mime_type ==
+                                       MIME_MESSAGE_RFC822)
+                                       break;
+                               parent = parent->parent;
+                       }
 
                        if ((fpos = ftell(fp)) < 0)
                                perror("ftell");
-                       else if (fseek(fp, mimeinfo->parent->fpos, SEEK_SET)
-                                < 0)
+                       else if (fseek(fp, parent->fpos, SEEK_SET) < 0)
                                perror("fseek");
                        else {
                                headers = textview_scan_header(textview, fp);
@@ -309,6 +317,7 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
                                        perror("fseek");
                        }
                }
+               /* skip MIME part headers */
                while (fgets(buf, sizeof(buf), fp) != NULL)
                        if (buf[0] == '\r' || buf[0] == '\n') break;
        }
@@ -433,10 +442,15 @@ static void textview_show_html(TextView *textview, FILE *fp,
                if (parser->state == HTML_HREF) {
                        /* first time : get and copy the URL */
                        if (url == NULL) {
-                               url = strdup(strtok(str, " "));
-                               /* the URL may (or not) be followed by the
-                                * referenced text */
-                               str = strtok(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);
+                                       /* the URL may (or not) be followed by the
+                                        * referenced text */
+                                       str = strtok(NULL, "");
+                               }       
                        }
                        if (str != NULL) {
                                textview_write_link(textview, url, str, NULL);
@@ -478,8 +492,7 @@ static gboolean get_uri_part(const gchar *start, const gchar *scanpos,
         * should pass some URI type to this function and decide on that whether
         * to perform punctuation stripping */
 
-#define IS_REAL_PUNCT(ch) \
-       (ispunct(ch) && ((ch) != '/')) 
+#define IS_REAL_PUNCT(ch)      (ispunct(ch) && ((ch) != '/')) 
 
        for (; ep_ - 1 > scanpos + 1 && IS_REAL_PUNCT(*(ep_ - 1)); ep_--)
                ;
@@ -504,6 +517,8 @@ static gchar *make_uri_string(const gchar *bp, const gchar *ep)
         !isspace(ch) && \
         !strchr("()<>\"", (ch)))
 
+/* alphabet and number within 7bit ASCII */
+#define IS_ASCII_ALNUM(ch)     (isascii(ch) && isalnum(ch))
 #define IS_QUOTE(ch) ((ch) == '\'' || (ch) == '"')
 
 /* get_email_part() - retrieves an email address. Returns TRUE if succesful */
@@ -533,7 +548,7 @@ static gboolean get_email_part(const gchar *start, const gchar *scanpos,
 
        /* TODO: should start with an alnum? */
        bp_++;
-       for (; bp_ < scanpos && !isalnum(*bp_); bp_++)
+       for (; bp_ < scanpos && !IS_ASCII_ALNUM(*bp_); bp_++)
                ;
 
        if (bp_ != scanpos) {
@@ -542,7 +557,7 @@ static gboolean get_email_part(const gchar *start, const gchar *scanpos,
                        ;
 
                /* TODO: really should terminate with an alnum? */
-               for (; ep_ > scanpos  && !isalnum(*ep_); --ep_)
+               for (; ep_ > scanpos && !IS_ASCII_ALNUM(*ep_); --ep_)
                        ;
                ep_++;
 
@@ -801,7 +816,6 @@ static void textview_write_line(TextView *textview, const gchar *str,
 {
        GtkText *text = GTK_TEXT(textview->text);
        gchar buf[BUFFSIZE];
-       size_t len;
        GdkColor *fg_color;
        gint quotelevel = -1;
 
@@ -816,11 +830,7 @@ static void textview_write_line(TextView *textview, const gchar *str,
                return;
        }
 
-       len = strlen(buf);
-       if (len > 1 && buf[len - 1] == '\n' && buf[len - 2] == '\r') {
-               buf[len - 2] = '\n';
-               buf[len - 1] = '\0';
-       }
+       strcrchomp(buf);
        if (prefs_common.conv_mb_alnum) conv_mb_alnum(buf);
        fg_color = NULL;
 
@@ -1392,7 +1402,6 @@ static void textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                        textview_scroll_page(textview, FALSE);
                break;
        case GDK_BackSpace:
-       case GDK_Delete:
                textview_scroll_page(textview, TRUE);
                break;
        case GDK_Return: