* Holy war on strlen: use IsEmptyStr where apropriate.
[citadel.git] / citadel / html.c
index a0d2e112c3e8525359667c039c30e71ec41e0607..1bb6cd4e2bb8c29dc8a54b0c0076815291ba982e 100644 (file)
@@ -30,7 +30,6 @@
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include "serv_extensions.h"
 #include "control.h"
 #include "sysdep_decls.h"
 #include "support.h"
@@ -60,6 +59,8 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
        int i, j, ch, did_out, rb, scanch;
        int nest = 0;           /* Bracket nesting level */
        int blockquote = 0;     /* BLOCKQUOTE nesting level */
+       int styletag = 0;       /* STYLE tag nesting level */
+       int styletag_start = 0;
        int bytes_processed = 0;
        char nl[128];
 
@@ -96,7 +97,7 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                }
 
                /* Do some parsing */
-               if (strlen(inbuf)>0) {
+               if (!IsEmptyStr(inbuf)) {
 
                    /* Fold in all the spacing */
                    for (i=0; i<strlen(inbuf); ++i) {
@@ -221,6 +222,20 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                                        strcat(outbuf, nl);
                                }
 
+                               else if (!strcasecmp(tag, "STYLE")) {
+                                       ++styletag;
+                                       if (styletag == 1) {
+                                               styletag_start = strlen(outbuf);
+                                       }
+                               }
+
+                               else if (!strcasecmp(tag, "/STYLE")) {
+                                       --styletag;
+                                       if (styletag == 0) {
+                                               outbuf[styletag_start] = 0;
+                                       }
+                               }
+
                        }
 
                        else if ((nest > 0) && (strlen(tag)<(sizeof(tag)-1))) {
@@ -237,7 +252,7 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                }
 
                /* Convert &; tags to the forbidden characters */
-               if (strlen(outbuf)>0) for (i=0; i<strlen(outbuf); ++i) {
+               if (!IsEmptyStr(outbuf)) for (i=0; i<strlen(outbuf); ++i) {
 
                        /* Character entity references */
                        if (!strncasecmp(&outbuf[i], "&nbsp;", 6)) {
@@ -402,6 +417,16 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                                strcpy(&outbuf[i+1], &outbuf[i+8]);
                        }
 
+                       else if (!strncasecmp(&outbuf[i], "&ldquo;", 7)) {
+                               outbuf[i] = '\"';
+                               strcpy(&outbuf[i+1], &outbuf[i+7]);
+                       }
+
+                       else if (!strncasecmp(&outbuf[i], "&rdquo;", 7)) {
+                               outbuf[i] = '\"';
+                               strcpy(&outbuf[i+1], &outbuf[i+7]);
+                       }
+
                        /* two-digit decimal equivalents */
                        else if ((!strncmp(&outbuf[i], "&#", 2))
                              && (outbuf[i+4] == ';') ) {
@@ -432,7 +457,7 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                /* Output any lines terminated with hard line breaks */
                do {
                        did_out = 0;
-                       if (strlen(outbuf)>0) {
+                       if (!IsEmptyStr(outbuf)) {
                            for (i = 0; i<strlen(outbuf); ++i) {
                                if ( (i<(screenwidth-2)) && (outbuf[i]=='\n')) {