From 4e9da56d81a0bf3977a37640e0db30112d37e7c5 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 21 May 2022 17:55:44 +0100 Subject: [PATCH] Committing all of my little comment syntax changes and getting them out of the way because I'm about to rip out a big chunk of code and rewrite it. --- citadel/msgbase.c | 92 +++++++++++++------------- libcitadel/lib/mime_parser.c | 123 ++++++++++++++--------------------- 2 files changed, 95 insertions(+), 120 deletions(-) diff --git a/citadel/msgbase.c b/citadel/msgbase.c index b33d904ab..406107e1c 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -1052,6 +1052,7 @@ void mime_spew_section(char *name, char *filename, char *partnum, char *disp, (!IsEmptyStr(partnum) && (!strcasecmp(CC->download_desired_section, partnum))) || (!IsEmptyStr(cbid) && (!strcasecmp(CC->download_desired_section, cbid))) ) { + syslog(LOG_DEBUG, "\033[32mYES part %s len %d\033[0m" , partnum, (int)length); *found_it = 1; cprintf("%d %d|-1|%s|%s|%s\n", BINARY_FOLLOWS, @@ -1062,6 +1063,9 @@ void mime_spew_section(char *name, char *filename, char *partnum, char *disp, ); client_write(content, length); } + else { + syslog(LOG_DEBUG, "\033[31m NO part %s\033[0m", partnum); + } } @@ -2033,44 +2037,41 @@ int CtdlOutputPreLoadedMsg( return((CC->download_fp != NULL) ? om_ok : om_mime_error); } - /* MT_SPEW_SECTION is like MT_DOWNLOAD except it outputs the whole MIME part - * in a single server operation instead of opening a download file. - */ + // MT_SPEW_SECTION is like MT_DOWNLOAD except it outputs the whole MIME part + // in a single server operation instead of opening a download file. if (mode == MT_SPEW_SECTION) { if (TheMessage->cm_format_type != FMT_RFC822) { if (do_proto) cprintf("%d This is not a MIME message.\n", ERROR + ILLEGAL_VALUE); - } else { - /* Parse the message text component */ + } + else { + // Locate and parse the component specified by the caller int found_it = 0; + mime_parser(CM_RANGE(TheMessage, eMesageText), *mime_spew_section, NULL, NULL, (void *)&found_it, 0); - mime_parser(CM_RANGE(TheMessage, eMesageText), - *mime_spew_section, NULL, NULL, (void *)&found_it, 0); - /* If section wasn't found, print an error - */ + // If section wasn't found, print an error if (!found_it) { - if (do_proto) cprintf( - "%d Section %s not found.\n", - ERROR + FILE_NOT_FOUND, - CC->download_desired_section); + if (do_proto) { + cprintf( "%d Section %s not found.\n", ERROR + FILE_NOT_FOUND, CC->download_desired_section); + } } } return((CC->download_fp != NULL) ? om_ok : om_mime_error); } - /* now for the user-mode message reading loops */ + // now for the user-mode message reading loops if (do_proto) cprintf("%d msg:\n", LISTING_FOLLOWS); - /* Does the caller want to skip the headers? */ + // Does the caller want to skip the headers? if (headers_only == HEADERS_NONE) goto START_TEXT; - /* Tell the client which format type we're using. */ + // Tell the client which format type we're using. if ( (mode == MT_CITADEL) && (do_proto) ) { cprintf("type=%d\n", TheMessage->cm_format_type); // Tell the client which format type we're using. } - /* nhdr=yes means that we're only displaying headers, no body */ + // nhdr=yes means that we're only displaying headers, no body if ( (TheMessage->cm_anon_type == MES_ANONONLY) && ((mode == MT_CITADEL) || (mode == MT_MIME)) && (do_proto) @@ -2082,7 +2083,7 @@ int CtdlOutputPreLoadedMsg( OutputCtdlMsgHeaders(TheMessage, do_proto); } - /* begin header processing loop for RFC822 transfer format */ + // begin header processing loop for RFC822 transfer format strcpy(suser, ""); strcpy(luser, ""); strcpy(fuser, ""); @@ -2132,11 +2133,11 @@ int CtdlOutputPreLoadedMsg( } } - /* end header processing loop ... at this point, we're in the text */ + // end header processing loop ... at this point, we're in the text START_TEXT: if (headers_only == HEADERS_FAST) goto DONE; - /* Tell the client about the MIME parts in this message */ + // Tell the client about the MIME parts in this message if (TheMessage->cm_format_type == FMT_RFC822) { if ( (mode == MT_CITADEL) || (mode == MT_MIME) ) { memset(&ma, 0, sizeof(struct ma_info)); @@ -2146,7 +2147,7 @@ START_TEXT: (do_proto ? *list_this_suff : NULL), (void *)&ma, 1); } - else if (mode == MT_RFC822) { /* unparsed RFC822 dump */ + else if (mode == MT_RFC822) { // unparsed RFC822 dump Dump_RFC822HeadersBody( TheMessage, headers_only, @@ -2160,7 +2161,7 @@ START_TEXT: goto DONE; } - /* signify start of msg text */ + // signify start of msg text if ( (mode == MT_CITADEL) || (mode == MT_MIME) ) { if (do_proto) cprintf("text\n"); } @@ -2168,16 +2169,16 @@ START_TEXT: if (TheMessage->cm_format_type == FMT_FIXED) DumpFormatFixed( TheMessage, - mode, /* how would you like that message? */ + mode, // how would you like that message? nl, nlen); - /* If the message on disk is format 0 (Citadel vari-format), we - * output using the formatter at 80 columns. This is the final output - * form if the transfer format is RFC822, but if the transfer format - * is Citadel proprietary, it'll still work, because the indentation - * for new paragraphs is correct and the client will reformat the - * message to the reader's screen width. - */ + // If the message on disk is format 0 (Citadel vari-format), we + // output using the formatter at 80 columns. This is the final output + // form if the transfer format is RFC822, but if the transfer format + // is Citadel proprietary, it'll still work, because the indentation + // for new paragraphs is correct and the client will reformat the + // message to the reader's screen width. + // if (TheMessage->cm_format_type == FMT_CITADEL) { if (mode == MT_MIME) { cprintf("Content-type: text/x-citadel-variformat\n\n"); @@ -2185,11 +2186,11 @@ START_TEXT: memfmout(TheMessage->cm_fields[eMesageText], nl); } - /* If the message on disk is format 4 (MIME), we've gotta hand it - * off to the MIME parser. The client has already been told that - * this message is format 1 (fixed format), so the callback function - * we use will display those parts as-is. - */ + // If the message on disk is format 4 (MIME), we've gotta hand it + // off to the MIME parser. The client has already been told that + // this message is format 1 (fixed format), so the callback function + // we use will display those parts as-is. + // if (TheMessage->cm_format_type == FMT_RFC822) { memset(&ma, 0, sizeof(struct ma_info)); @@ -2218,17 +2219,16 @@ DONE: /* now we're done */ return(om_ok); } -/* - * Save one or more message pointers into a specified room - * (Returns 0 for success, nonzero for failure) - * roomname may be NULL to use the current room - * - * Note that the 'supplied_msg' field may be set to NULL, in which case - * the message will be fetched from disk, by number, if we need to perform - * replication checks. This adds an additional database read, so if the - * caller already has the message in memory then it should be supplied. (Obviously - * this mode of operation only works if we're saving a single message.) - */ +// Save one or more message pointers into a specified room +// (Returns 0 for success, nonzero for failure) +// roomname may be NULL to use the current room +// +// Note that the 'supplied_msg' field may be set to NULL, in which case +// the message will be fetched from disk, by number, if we need to perform +// replication checks. This adds an additional database read, so if the +// caller already has the message in memory then it should be supplied. (Obviously +// this mode of operation only works if we're saving a single message.) +// int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs, int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj ) { diff --git a/libcitadel/lib/mime_parser.c b/libcitadel/lib/mime_parser.c index 2e81fe8b0..303bb54e0 100644 --- a/libcitadel/lib/mime_parser.c +++ b/libcitadel/lib/mime_parser.c @@ -1,22 +1,20 @@ -/* - * This is the MIME parser for Citadel. - * - * Copyright (c) 1998-2010 by the citadel.org development team. - * - * This program is open source software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ +// This is the MIME parser for Citadel. +// +// Copyright (c) 1998-2022 by the citadel.org development team. +// +// This program is open source software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include @@ -64,29 +62,23 @@ const unsigned char FromHexTable [256] = { }; -long extract_key(char *target, char *source, long sourcelen, char *key, long keylen, char KeyEnd) -{ +long extract_key(char *target, char *source, long sourcelen, char *key, long keylen, char KeyEnd) { char *sptr, *ptr = NULL; int double_quotes = 0; long RealKeyLen = keylen; sptr = source; - while (sptr != NULL) - { - ptr = bmstrcasestr_len(sptr, sourcelen - (sptr - source), - key, keylen); - if(ptr != NULL) - { + while (sptr != NULL) { + ptr = bmstrcasestr_len(sptr, sourcelen - (sptr - source), key, keylen); + if (ptr != NULL) { while (isspace(*(ptr + RealKeyLen))) RealKeyLen ++; - if (*(ptr + RealKeyLen) == KeyEnd) - { + if (*(ptr + RealKeyLen) == KeyEnd) { sptr = NULL; RealKeyLen ++; } - else - { + else { sptr = ptr + RealKeyLen + 1; } } @@ -133,8 +125,7 @@ char *fixed_partnum(char *supplied_partnum) { } -static inline unsigned int _decode_hex(const char *Source) -{ +static inline unsigned int _decode_hex(const char *Source) { unsigned int ret = '?'; unsigned char LO_NIBBLE; unsigned char HI_NIBBLE; @@ -161,30 +152,24 @@ int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) { int decoded_length = 0; int pos = 0; - while (pos < sourcelen) - { - if (*(encoded + pos) == '=') - { + while (pos < sourcelen) { + if (*(encoded + pos) == '=') { pos ++; - if (*(encoded + pos) == '\n') - { + if (*(encoded + pos) == '\n') { pos ++; } - else if (*(encoded + pos) == '\r') - { + else if (*(encoded + pos) == '\r') { pos ++; if (*(encoded + pos) == '\n') pos++; } - else - { + else { ch = _decode_hex(&encoded[pos]); pos += 2; decoded[decoded_length++] = ch; } } - else - { + else { decoded[decoded_length++] = encoded[pos]; pos += 1; } @@ -208,13 +193,12 @@ void mime_decode(char *partnum, MimeParserCallBackType PreMultiPartCallBack, MimeParserCallBackType PostMultiPartCallBack, void *userdata, - int dont_decode) -{ - + int dont_decode +) { char *decoded; size_t bytes_decoded = 0; - /* Some encodings aren't really encodings */ + // Some encodings aren't really encodings if (!strcasecmp(encoding, "7bit")) *encoding = '\0'; if (!strcasecmp(encoding, "8bit")) @@ -224,7 +208,7 @@ void mime_decode(char *partnum, if (!strcasecmp(encoding, "ISO-8859-1")) *encoding = '\0'; - /* If this part is not encoded, send as-is */ + // If this part is not encoded, send as-is if ( (strlen(encoding) == 0) || (dont_decode)) { if (CallBack != NULL) { CallBack(name, @@ -242,18 +226,16 @@ void mime_decode(char *partnum, return; } - /* Fail silently if we hit an unknown encoding. */ - if ((strcasecmp(encoding, "base64")) - && (strcasecmp(encoding, "quoted-printable"))) { + // Fail silently if we hit an unknown encoding. + if ((strcasecmp(encoding, "base64")) && (strcasecmp(encoding, "quoted-printable"))) { return; } + fprintf(stderr, "\033[33mSource encoded length: %d\033[0m\n", length); - /* - * Allocate a buffer for the decoded data. The output buffer is slightly - * larger than the input buffer; this assumes that the decoded data - * will never be significantly larger than the encoded data. This is a - * safe assumption with base64, uuencode, and quoted-printable. - */ + // Allocate a buffer for the decoded data. The output buffer is slightly + // larger than the input buffer; this assumes that the decoded data + // will never be significantly larger than the encoded data. This is a + // safe assumption with base64, uuencode, and quoted-printable. decoded = malloc(length + 32768); if (decoded == NULL) { return; @@ -265,6 +247,7 @@ void mime_decode(char *partnum, else if (!strcasecmp(encoding, "quoted-printable")) { bytes_decoded = CtdlDecodeQuotedPrintable(decoded, part_start, length); } + fprintf(stderr, "\033[33mTarget decoded length: %d\033[0m\n", bytes_decoded); if (bytes_decoded > 0) if (CallBack != NULL) { char encoding_buf[SIZ]; @@ -640,20 +623,15 @@ static void recurseable_mime_parser(char *partnum, optr = ptr; if (parse_MimeHeaders(SubMimeHeaders, &ptr, content_end) != 0) break; - if ((ptr - optr > 2) && - (*(ptr - 2) == '\r')) + if ((ptr - optr > 2) && (*(ptr - 2) == '\r')) { crlf_in_use = 1; + } part_start = ptr; - next_boundary = FindNextContent(ptr, - content_end, - SubMimeHeaders, - m); - if ((next_boundary != NULL) && - (next_boundary - part_start < 3)) { + next_boundary = FindNextContent(ptr, content_end, SubMimeHeaders, m); + if ((next_boundary != NULL) && (next_boundary - part_start < 3)) { FlushInterestingMimes(SubMimeHeaders); - continue; } @@ -700,9 +678,7 @@ static void recurseable_mime_parser(char *partnum, /* Determine whether newlines are LF or CRLF */ evaluate_crlf_ptr = part_start; --evaluate_crlf_ptr; - if ((*evaluate_crlf_ptr == '\r') && - (*(evaluate_crlf_ptr + 1) == '\n')) - { + if ((*evaluate_crlf_ptr == '\r') && (*(evaluate_crlf_ptr + 1) == '\n')) { crlf_in_use = 1; } else { @@ -743,7 +719,6 @@ static void recurseable_mime_parser(char *partnum, length = content_end - part_start; ptr = part_end = content_end; - /* The following code will truncate the MIME part to the size * specified by the Content-length: header. We have commented it * out because these headers have a tendency to be wrong. @@ -764,8 +739,7 @@ static void recurseable_mime_parser(char *partnum, chosen_name = &m->b[content_type_name]; } - /* Ok, we've got a non-multipart part here, so do something with it. - */ + // Ok, we've got a non-multipart part here, so do something with it. mime_decode(partnum, part_start, length, @@ -881,6 +855,7 @@ void the_mime_parser(char *partnum, free(m); } + /* * Entry point for the MIME parser. * (This function expects to be fed HEADERS + CONTENT) -- 2.30.2