Merge branch 'master' of ssh://git.citadel.org/var/www/gitroot/citadel
authorArt Cancro <ajc@citadel.org>
Thu, 22 Sep 2022 19:19:07 +0000 (15:19 -0400)
committerArt Cancro <ajc@citadel.org>
Thu, 22 Sep 2022 19:19:07 +0000 (15:19 -0400)
citadel/server/msgbase.c
libcitadel/lib/html_to_ascii.c
libcitadel/lib/libcitadel.h
textclient/commands.c
textclient/messages.c
webcit/messages.c

index 0da39fc875e87db8a0541258210c2cf0f7e1022d..4ddd9aa4228b2b66685538ca699a3126a6f0ba0e 100644 (file)
@@ -1254,7 +1254,7 @@ void fixed_output(char *name, char *filename, char *partnum, char *disp,
        }
 
        if (!strcasecmp(cbtype, "text/html")) {
-               ptr = html_to_ascii(content, length, 80);
+               ptr = html_to_ascii(content, length, 80, 0);
                wlen = strlen(ptr);
                client_write(ptr, wlen);
                if ((wlen > 0) && (ptr[wlen-1] != '\n')) {
index d325e4a896c0523a3d3ba61293445cd9705e4fd7..33373c19d3c44cd4f75a28d2a457f09ba3d3e12c 100644 (file)
@@ -1,10 +1,8 @@
-/*
- * Functions which handle translation between HTML and plain text
- * Copyright (c) 2000-2018 by the citadel.org team
- *
+// Functions which handle translation between HTML and plain text
+// Copyright (c) 2000-2022 by the citadel.org team
+//
 // This program is open source software.  Use, duplication, or disclosure
 // is subject to the terms of the GNU General Public License, version 3.
- */
 
 #include <stdlib.h>
 #include <unistd.h>
 #include "libcitadel.h"
  
 
-/*
- * Convert HTML to plain text.
- *
- * inputmsg      = pointer to raw HTML message
- * screenwidth   = desired output screenwidth
- */
-char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) {
+// Convert HTML to plain text.
+//
+// inputmsg    = pointer to raw HTML message
+// msglen      = stop reading after this many bytes
+// screenwidth = desired output screenwidth
+// ansi                = if nonzero, assume output is to a terminal that supports ANSI escape codes
+//
+char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int ansi) {
        char inbuf[SIZ];
        int inbuf_len = 0;
        char outbuf[SIZ];
@@ -48,9 +47,9 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) {
        size_t outptr_buffer_size;
        size_t output_len = 0;
        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 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];
@@ -186,34 +185,52 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) {
                                        strcat(outbuf, nl);
                                }
 
-#if 0
-       These seemed like a good idea at the time, but it just makes a mess.
-
                                else if (
                                        (!strcasecmp(tag, "B"))
-                                       || (!strcasecmp(tag, "/B"))
                                        || (!strcasecmp(tag, "STRONG"))
+                               ) {
+                                       if (ansi) {
+                                               strcat(outbuf, "\033[1m");
+                                       }
+                               }
+                               else if (
+                                       (!strcasecmp(tag, "/B"))
                                        || (!strcasecmp(tag, "/STRONG"))
                                ) {
-                                       strcat(outbuf, "*");
+                                       if (ansi) {
+                                               strcat(outbuf, "\033[22m");
+                                       }
                                }
 
                                else if (
                                        (!strcasecmp(tag, "I"))
-                                       || (!strcasecmp(tag, "/I"))
                                        || (!strcasecmp(tag, "EM"))
-                                       || (!strcasecmp(tag, "/EM"))
                                ) {
-                                       strcat(outbuf, "/");
+                                       if (ansi) {
+                                               strcat(outbuf, "\033[3m");
+                                       }
                                }
 
                                else if (
-                                       (!strcasecmp(tag, "U"))
-                                       || (!strcasecmp(tag, "/U"))
+                                       (!strcasecmp(tag, "/I"))
+                                       || (!strcasecmp(tag, "/EM"))
                                ) {
-                                       strcat(outbuf, "_");
+                                       if (ansi) {
+                                               strcat(outbuf, "\033[23m");
+                                       }
+                               }
+
+                               else if (!strcasecmp(tag, "U")) {
+                                       if (ansi) {
+                                               strcat(outbuf, "\033[4m");
+                                       }
+                               }
+
+                               else if (!strcasecmp(tag, "/U")) {
+                                       if (ansi) {
+                                               strcat(outbuf, "\033[24m");
+                                       }
                                }
-#endif
 
                                else if (!strcasecmp(tag, "BR")) {
                                        strcat(outbuf, nl);
@@ -230,6 +247,9 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) {
                                else if (!strcasecmp(tag, "BLOCKQUOTE")) {
                                        ++blockquote;
                                        strcpy(nl, "\n");
+                                       if ( (blockquote == 1) && (ansi) ) {
+                                               strcat(nl, "\033[2m\033[3m");
+                                       }
                                        for (j=0; j<blockquote; ++j) strcat(nl, ">");
                                        strcat(outbuf, nl);
                                }
@@ -237,6 +257,9 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) {
                                else if (!strcasecmp(tag, "/BLOCKQUOTE")) {
                                        strcat(outbuf, "\n");
                                        --blockquote;
+                                       if ( (blockquote == 0) && (ansi) ) {
+                                               strcat(outbuf, "\033[22m\033[23m");
+                                       }
                                        strcpy(nl, "\n");
                                        for (j=0; j<blockquote; ++j) strcat(nl, ">");
                                        strcat(outbuf, nl);
index 5f50539c275b7629eca53cb6c0627e80765996e4..891941c138ef1d892fb756d52beac5eab24e6fdb 100644 (file)
@@ -1,13 +1,11 @@
-/*
- * Header file for libcitadel
- *
- * Copyright (c) 1987-2022 by the citadel.org team
- *
+// Header file for libcitadel
+//
+// Copyright (c) 1987-2022 by the citadel.org team
+//
 // This program is open source software.  Use, duplication, or disclosure
 // is subject to the terms of the GNU General Public License, version 3.
- */
 
-/* protect against double includes */
+// protect against double includes
 #ifndef LIBCITADEL_H
 #define LIBCITADEL_H
 
@@ -433,7 +431,7 @@ char *rfc2047encode(const char *line, long length);
 int is_msg_in_mset(const char *mset, long msgnum);
 int pattern2(char *search, char *patn);
 void stripltlen(char *, int *);
-char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth);
+char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int ansi);
 void LoadEntityList(char *FileName);
 void utf8ify_rfc822_string(char *buf);
 
index 880d3ebc08139eb20e366683073d66ad63856cd1..197fe1a9d58dca65c9759838b33bac880fbdb766 100644 (file)
@@ -1406,6 +1406,7 @@ int fmout(int width,              // screen width to use
        char old = 0;           // The previous character
        int column = 0;         // Current column
        size_t i;               // Generic counter
+       int in_quote = 0;
 
        // Space for a single word, which can be at most screenwidth
        word = (char *) calloc(1, width);
@@ -1429,11 +1430,18 @@ int fmout(int width,            // screen width to use
 
        // Run the message body
        while (*e) {
+
                // Catch characters that shouldn't be there at all
                if (*e == '\r') {
                        e++;
                        continue;
                }
+
+               if ( (in_quote) && (*e == '\n') && (enable_color) ) {
+                       in_quote = 0;
+                       scr_printf("\033[22m\033[23m");
+               }
+
                if (*e == '\n') {       // newline?
                        e++;
                        if (*e == ' ') {        // paragraph?
@@ -1458,6 +1466,11 @@ int fmout(int width,             // screen width to use
                        continue;
                }
 
+               if ( (*e == '>') && (column <= 1) && (!fpout) && (enable_color) ) {
+                       in_quote = 1;
+                       scr_printf("\033[2m\033[3m");
+               }
+
                // Or are we looking at a space?
                if (*e == ' ') {
                        e++;
index 34e1882282f12aae1295b5b57688bde9c5462b7d..93641b723f77e828b174a7a2c702121f14fe78af 100644 (file)
@@ -611,7 +611,7 @@ int read_message(CtdlIPC * ipc, long num,   /* message number */
         * of the client screen.
         */
        if (!strcasecmp(message->content_type, "text/html")) {
-               converted_text = html_to_ascii(message->text, 0, screenwidth);
+               converted_text = html_to_ascii(message->text, 0, screenwidth, (enable_color ? 1 : 0));
                if (converted_text != NULL) {
                        free(message->text);
                        message->text = converted_text;
index d0ad4d67c9451f927af3835e41af3ba421def87c..78533171248a814fd0f665e47ed1e360030b9706 100644 (file)
@@ -905,7 +905,7 @@ void post_mime_to_server(void) {
                serv_puts("Content-type: text/plain; charset=utf-8");
                serv_puts("Content-Transfer-Encoding: quoted-printable");
                serv_puts("");
-               txtmail = html_to_ascii(bstr("msgtext"), 0, 80);
+               txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
                Buf = NewStrBufPlain(txtmail, -1);
                free(txtmail);