X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=textclient%2Fmessages.c;h=3fc71730040495f947ffa3acc3c0a29dcf1f71c2;hb=e0258a233ad97497b9bfa27442549e12cd84a36b;hp=7fd9502df3831326b3c2afff2563fada38dc121b;hpb=7427b76904be76426c2a84c9de80fa48a0e022c8;p=citadel.git diff --git a/textclient/messages.c b/textclient/messages.c index 7fd9502df..3fc717300 100644 --- a/textclient/messages.c +++ b/textclient/messages.c @@ -1,16 +1,14 @@ -/* - * Text client functions for reading and writing of messages - * - * Copyright (c) 1987-2020 by the citadel.org team - * - * This program is open source software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ +// Text client functions for reading and writing of messages +// +// Copyright (c) 1987-2020 by the citadel.org team +// +// This program is open source software. Use, duplication, and/or +// disclosure are subject to the GNU General Purpose License version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. #include "textclient.h" @@ -139,7 +137,6 @@ void add_newline(struct cittext *textlist) while (ptr->text[strlen(ptr->text) - 1] == 32) ptr->text[strlen(ptr->text) - 1] = 0; - /* strcat(ptr->text,"\n"); */ ptr->next = (struct cittext *) malloc(sizeof(struct cittext)); @@ -340,50 +337,60 @@ void free_parts(struct parts *p) /* * This is a mini RFC2047 decoder. * It only handles strings encoded from UTF-8 as Quoted-printable. + * We can do this "in place" because the converted string will always be smaller than the source string. */ void mini_2047_decode(char *s) { - if (!s) + if (!s) { // no null strings allowed! return; + } - char *qstart = strstr(s, "=?UTF-8?Q?"); - if (!qstart) + char *qstart = strstr(s, "=?UTF-8?Q?"); // Must start with this string + if (!qstart) { return; + } - char *qend = strstr(s, "?="); - if (!qend) + char *qend = strstr(qstart+10, "?="); // Must end with this string + if (!qend) { return; + } - if (qend <= qstart) + if (qend <= qstart) { // And there must be something in between them. return; + } - strcpy(qstart, &qstart[10]); - qend -= 10; + // The string has qualified for conversion. - char *p = qstart; - while (p < qend) { + strcpy(qend, ""); // Strip the trailer + strcpy(qstart, &qstart[10]); // Strip the header - if (p[0] == '=') { + char *r = qstart; // Pointer to where in the string we're reading + char *w = s; // Pointer to where in the string we're writing + while(*r) { // Loop through the source string + if (r[0] == '=') { // "=" means read a hex character char ch[3]; - ch[0] = p[1]; - ch[1] = p[2]; - ch[2] = p[3]; + ch[0] = r[1]; + ch[1] = r[2]; + ch[2] = r[3]; int c; sscanf(ch, "%02x", &c); - p[0] = c; - strcpy(&p[1], &p[3]); - qend -= 2; + w[0] = c; + r += 3; + ++w; } - - if (p[0] == '_') { - p[0] = ' '; + else if (r[0] == '_') { // "_" is a space + w[0] = ' '; + ++r; + ++w; + } + else { // anything else pass through literally + w[0] = r[0]; + ++r; + ++w; } - - ++p; } - - strcpy(qend, &qend[2]); + w[0] = 0; // null terminate } @@ -410,8 +417,6 @@ int read_message(CtdlIPC *ipc, char ch; int linelen; int final_line_is_blank = 0; - int is_local = 0; - has_images = 0; sigcaught = 0; @@ -445,18 +450,6 @@ int read_message(CtdlIPC *ipc, color(BRIGHT_CYAN); } - /* Determine if the message originated here on the local system. If it did we will suppress printing of email addresses */ - is_local = 0; - char *at = !IsEmptyStr(message->email) ? strchr(message->email,'@') : NULL; - if (at) { - if (!strcasecmp(++at, ipc->ServInfo.fqdn)) { - is_local = 1; - } - } - else { - is_local = 1; // no address means it couldn't have originated anywhere else - } - /* View headers only */ if (pagin == 2) { scr_printf("nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n", @@ -513,7 +506,7 @@ int read_message(CtdlIPC *ipc, strftime(now, sizeof now, "%F %R", &thetime); if (dest) { fprintf(dest, "%s from %s ", now, message->author); - if (!is_local) { + if (!message->is_local) { fprintf(dest, "<%s> ", message->email); } } @@ -524,7 +517,7 @@ int read_message(CtdlIPC *ipc, scr_printf("from "); color(BRIGHT_CYAN); scr_printf("%s ", message->author); - if (!is_local) { + if (!message->is_local) { color(DIM_WHITE); scr_printf("<"); color(BRIGHT_BLUE); @@ -557,7 +550,8 @@ int read_message(CtdlIPC *ipc, if (dest) { fprintf(dest, "\n"); - } else { + } + else { scr_printf("\n"); } @@ -566,7 +560,8 @@ int read_message(CtdlIPC *ipc, if ((message->email != NULL) && (!IsEmptyStr(message->email))) { if (!IsEmptyStr(message->author)) { snprintf(reply_to, sizeof reply_to, "%s <%s>", message->author, message->email); - } else { + } + else { safestrncpy(reply_to, message->email, sizeof reply_to); } } @@ -581,10 +576,11 @@ int read_message(CtdlIPC *ipc, safestrncpy(reply_inreplyto, message->msgid, sizeof reply_inreplyto); } - if (message->references != NULL) + if (message->references != NULL) { if (!IsEmptyStr(message->references)) { safestrncpy(reply_references, message->references, sizeof reply_references); } + } if (message->subject != NULL) { safestrncpy(reply_subject, message->subject, sizeof reply_subject); @@ -597,6 +593,7 @@ int read_message(CtdlIPC *ipc, color(BRIGHT_CYAN); mini_2047_decode(message->subject); scr_printf("%s\n", message->subject); + } } } @@ -662,7 +659,8 @@ int read_message(CtdlIPC *ipc, */ if (format_type == 0) { fr = fmout(screenwidth, NULL, message->text, dest, 1); - } else { + } + else { /* renderer for text/plain */ lineptr = message->text; @@ -1088,7 +1086,8 @@ int entmsg(CtdlIPC * ipc, int is_reply, /* nonzero if this was a eply command if (c > 0) { mode = 1; - } else { + } + else { mode = 0; }