2005-11-08 [colin] 1.9.100cvs4
authorColin Leroy <colin@colino.net>
Tue, 8 Nov 2005 18:08:15 +0000 (18:08 +0000)
committerColin Leroy <colin@colino.net>
Tue, 8 Nov 2005 18:08:15 +0000 (18:08 +0000)
        * src/compose.c
        * src/textview.c
        * src/common/utils.c
        * src/common/utils.h
                Enhance the email parser

ChangeLog
PATCHSETS
configure.ac
src/common/utils.c
src/common/utils.h
src/compose.c
src/textview.c

index 85a26cf..2644204 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-11-08 [colin]     1.9.100cvs4
+
+       * src/compose.c
+       * src/textview.c
+       * src/common/utils.c
+       * src/common/utils.h
+               Enhance the email parser
+
 2005-11-08 [colin]     1.9.100cvs3
 
        * src/procmime.c
index 025eb13..164f632 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.115.2.65 -r 1.115.2.66 src/main.c;  ) > 1.9.100cvs1.patchset
 ( cvs diff -u -r 1.115.2.66 -r 1.115.2.67 src/main.c;  ) > 1.9.100cvs2.patchset
 ( cvs diff -u -r 1.49.2.67 -r 1.49.2.68 src/procmime.c;  ) > 1.9.100cvs3.patchset
+( cvs diff -u -r 1.382.2.192 -r 1.382.2.193 src/compose.c;  cvs diff -u -r 1.96.2.83 -r 1.96.2.84 src/textview.c;  cvs diff -u -r 1.36.2.47 -r 1.36.2.48 src/common/utils.c;  cvs diff -u -r 1.20.2.26 -r 1.20.2.27 src/common/utils.h;  ) > 1.9.100cvs4.patchset
index 1703acb..1ecde63 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=100
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=3
+EXTRA_VERSION=4
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index ec086a1..2f88adc 100644 (file)
@@ -4064,7 +4064,7 @@ void replace_returns(gchar *str)
 /* get_uri_part() - retrieves a URI starting from scanpos.
                    Returns TRUE if succesful */
 gboolean get_uri_part(const gchar *start, const gchar *scanpos,
-                            const gchar **bp, const gchar **ep)
+                            const gchar **bp, const gchar **ep, gboolean hdr)
 {
        const gchar *ep_;
 
@@ -4179,7 +4179,7 @@ static gboolean is_toplvl_domain(GHashTable *tab, const gchar *first, const gcha
 
 /* get_email_part() - retrieves an email address. Returns TRUE if succesful */
 gboolean get_email_part(const gchar *start, const gchar *scanpos,
-                              const gchar **bp, const gchar **ep)
+                              const gchar **bp, const gchar **ep, gboolean hdr)
 {
        /* more complex than the uri part because we need to scan back and forward starting from
         * the scan position. */
@@ -4202,6 +4202,40 @@ gboolean get_email_part(const gchar *start, const gchar *scanpos,
        g_return_val_if_fail(bp != NULL, FALSE);
        g_return_val_if_fail(ep != NULL, FALSE);
 
+       if (hdr) {
+search_again:
+               /* go to the real start */
+               if (start[0] == ',')
+                       start++;
+               if (start[0] == ';')
+                       start++;
+               while (start[0] == ' ' || start[0] == '\t')
+                       start++;
+
+               *bp = start;
+               
+               /* find end (either , or ; or end of line) */
+               if (strstr(start, ",") && strstr(start, ";"))
+                       *ep = strstr(start,",") < strstr(start, ";")
+                               ? strstr(start, ",") : strstr(start, ";");
+               else if (strstr(start, ","))
+                       *ep = strstr(start, ",");
+               else if (strstr(start, ";"))
+                       *ep = strstr(start, ";");
+               else
+                       *ep = start+strlen(start);
+               
+               /* check there's still an @ in that, or search 
+                * further if possible */
+               if (strstr(start, "@") && strstr(start, "@") < *ep)
+                       return TRUE;
+               else if (*ep < start+strlen(start)) {
+                       start = *ep;
+                       goto search_again;
+               } else
+                       return FALSE;
+       }
+
        if (!dom_tab)
                dom_tab = create_domain_tab();
        g_return_val_if_fail(dom_tab, FALSE);   
@@ -4321,7 +4355,7 @@ gboolean get_email_part(const gchar *start, const gchar *scanpos,
                        && (((bp_ + 1) < ep_)    && isalnum(*(bp_ + 1)))) {
                                /* hyphens are allowed, but only in
                                   between alnums */
-                       } else if (!strchr(",;:=?./+<>!&\r\n\t", *bp_)) {
+                       } else if (strchr(" \"'", *bp_)) {
                                /* but anything not being a punctiation
                                   is ok */
                        } else {
@@ -4332,18 +4366,18 @@ gboolean get_email_part(const gchar *start, const gchar *scanpos,
 
        bp_++;
 
+       /* scan forward (should start with an alnum) */
+       for (; *bp_ != '<' && isspace(*bp_) && *bp_ != '"'; bp_++)
+               ;
 #undef PEEK_STACK
 #undef PUSH_STACK
 #undef POP_STACK
 #undef IN_STACK
 #undef FULL_STACK
 
-       /* scan forward (should start with an alnum) */
-       for (; *bp_ != '<' && isspace(*bp_) && *bp_ != '"'; bp_++)
-               ;
 
-       *ep = ep_;
        *bp = bp_;
+       *ep = ep_;
        
        return result;
 }
index 85247dc..718e052 100644 (file)
@@ -542,10 +542,10 @@ void g_auto_pointer_free          (GAuto *auto_ptr);
 void replace_returns                   (gchar *str);
 
 gboolean get_uri_part(const gchar *start, const gchar *scanpos,
-                            const gchar **bp, const gchar **ep);
+                            const gchar **bp, const gchar **ep, gboolean hdr);
 gchar *make_uri_string(const gchar *bp, const gchar *ep);
 gboolean get_email_part(const gchar *start, const gchar *scanpos,
-                              const gchar **bp, const gchar **ep);
+                              const gchar **bp, const gchar **ep, gboolean hdr);
 gchar *make_email_string(const gchar *bp, const gchar *ep);
 gchar *make_http_string(const gchar *bp, const gchar *ep);
 gchar *mailcap_get_command_for_type(const gchar *type);
index 7d23ad4..ecb03c0 100644 (file)
@@ -3258,7 +3258,8 @@ static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter,
                        gboolean  (*parse)      (const gchar *start,
                                                 const gchar *scanpos,
                                                 const gchar **bp_,
-                                                const gchar **ep_);
+                                                const gchar **ep_,
+                                                gboolean hdr);
                        /* part to URI function */
                        gchar    *(*build_uri)  (const gchar *bp,
                                                 const gchar *ep);
@@ -3374,7 +3375,8 @@ colorize:
                bp = ep = 0;
                if (scanpos) {
                        /* check if URI can be parsed */
-                       if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,(const gchar **)&ep)
+                       if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
+                                       (const gchar **)&ep, FALSE)
                            && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
                                        walk = ep;
                        } else
index 0ed29a8..a19a1f3 100644 (file)
@@ -887,7 +887,8 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
 static void textview_make_clickable_parts(TextView *textview,
                                          const gchar *fg_tag,
                                          const gchar *uri_tag,
-                                         const gchar *linebuf)
+                                         const gchar *linebuf,
+                                         gboolean hdr)
 {
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
        GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
@@ -905,7 +906,8 @@ static void textview_make_clickable_parts(TextView *textview,
                gboolean  (*parse)      (const gchar *start,
                                         const gchar *scanpos,
                                         const gchar **bp_,
-                                        const gchar **ep_);
+                                        const gchar **ep_,
+                                        gboolean hdr);
                /* part to URI function */
                gchar    *(*build_uri)  (const gchar *bp,
                                         const gchar *ep);
@@ -957,7 +959,7 @@ static void textview_make_clickable_parts(TextView *textview,
 
                if (scanpos) {
                        /* check if URI can be parsed */
-                       if (parser[last_index].parse(walk, scanpos, &bp, &ep)
+                       if (parser[last_index].parse(walk, scanpos, &bp, &ep, hdr)
                            && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
                                        ADD_TXT_POS(bp, ep, last_index);
                                        walk = ep;
@@ -1062,7 +1064,7 @@ static void textview_write_line(TextView *textview, const gchar *str,
                textview->is_in_signature = TRUE;
        }
 
-       textview_make_clickable_parts(textview, fg_color, "link", buf);
+       textview_make_clickable_parts(textview, fg_color, "link", buf, FALSE);
 }
 
 void textview_write_link(TextView *textview, const gchar *str,
@@ -1401,8 +1403,14 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                                (buffer, &iter, header->body, -1,
                                 "header", "emphasis", NULL);
                } else {
-                       textview_make_clickable_parts(textview, "header", "link",
-                                                     header->body);
+                       gboolean hdr = 
+                         procheader_headername_equal(header->name, "From") ||
+                         procheader_headername_equal(header->name, "To") ||
+                         procheader_headername_equal(header->name, "Cc") ||
+                         procheader_headername_equal(header->name, "Bcc");
+                       textview_make_clickable_parts(textview, "header", 
+                                                     "link", header->body, 
+                                                     hdr);
                }
                gtk_text_buffer_get_end_iter (buffer, &iter);
                gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "\n", 1,