]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/stringbuf.c
Rename StrBufRFC2047encodeMessage() to StrBufQuotedPrintableEncode()
[citadel.git] / libcitadel / lib / stringbuf.c
index 3d8b3010d914a096c893177f37eb7604153014b6..d31c227c53059edb6e74c4958b5c1b6d7e459a1e 100644 (file)
@@ -1,18 +1,7 @@
-// Copyright (c) 1987-2022 by the citadel.org team
+// Copyright (c) 1987-2023 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 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 program is open source software.  Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License, version 3.
 
 #define _GNU_SOURCE
 #include "sysdep.h"
@@ -44,8 +33,7 @@
 
 #ifdef HAVE_ZLIB
 #include <zlib.h>
-int ZEXPORT compress_gzip(Bytef * dest, size_t * destLen,
-                          const Bytef * source, uLong sourceLen, int level);
+int ZEXPORT compress_gzip(Bytef * dest, size_t * destLen, const Bytef * source, uLong sourceLen, int level);
 #endif
 int BaseStrBufSize = 64;
 int EnableSplice = 0;
@@ -528,7 +516,7 @@ int StrBufPlain(StrBuf *Buf, const char* ptr, int nChars) {
 }
 
 
-/**
+/*
  *  use strbuf as wrapper for a string constant for easy handling
  *  StringConstant a string to wrap
  *  SizeOfStrConstant should be sizeof(StringConstant)-1
@@ -551,7 +539,7 @@ StrBuf* _NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant)
 }
 
 
-/**
+/*
  *  flush the content of a Buf; keep its struct
  *  buf Buffer to flush
  */
@@ -566,7 +554,7 @@ int FlushStrBuf(StrBuf *buf)
        return 0;
 }
 
-/**
+/*
  *  wipe the content of a Buf thoroughly (overwrite it -> expensive); keep its struct
  *  buf Buffer to wipe
  */
@@ -586,7 +574,7 @@ int FLUSHStrBuf(StrBuf *buf)
 #ifdef SIZE_DEBUG
 int hFreeDbglog = -1;
 #endif
-/**
+/*
  *  Release a Buffer
  * Its a double pointer, so it can NULL your pointer
  * so fancy SIG11 appear instead of random results
@@ -650,7 +638,7 @@ void HFreeStrBuf (void *VFreeMe) {
  *                      Simple string transformations                          *
  *******************************************************************************/
 
-/**
+/*
  *  Wrapper around atol
  */
 long StrTol(const StrBuf *Buf)
@@ -663,7 +651,7 @@ long StrTol(const StrBuf *Buf)
                return 0;
 }
 
-/**
+/*
  *  Wrapper around atoi
  */
 int StrToi(const StrBuf *Buf)
@@ -676,7 +664,7 @@ int StrToi(const StrBuf *Buf)
                return 0;
 }
 
-/**
+/*
  *  Checks to see if the string is a pure number 
  *  Buf The buffer to inspect
  * @returns 1 if its a pure number, 0, if not.
@@ -3108,13 +3096,10 @@ int StrBufRFC2047encode(StrBuf **target, const StrBuf *source)
        return (*target)->BufUsed;;
 }
 
-/**
- *     Quoted-Printable encode a message; make it < 80 columns width.
- *     source          Source string to be encoded.
- * @returns     buffer with encoded message.
- */
-StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
-{
+// Quoted-Printable encode a message; make it < 80 columns width.
+// source      Source string to be encoded.
+// returns     buffer with encoded message.
+StrBuf *StrBufQuotedPrintableEncode(const StrBuf *EncodeMe) {
        StrBuf *OutBuf;
        char *Optr, *OEptr;
        const char *ptr, *eptr;
@@ -3128,10 +3113,8 @@ StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
        eptr = EncodeMe->buf + EncodeMe->BufUsed;
        LinePos = 0;
 
-       while (ptr < eptr)
-       {
-               if (Optr + 4 >= OEptr)
-               {
+       while (ptr < eptr) {
+               if (Optr + 4 >= OEptr) {
                        long Offset;
                        Offset = Optr - OutBuf->buf;
                        OutBuf->BufUsed = Optr - OutBuf->buf;
@@ -3139,21 +3122,16 @@ StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
                        Optr = OutBuf->buf + Offset;
                        OEptr = OutBuf->buf + OutBuf->BufSize;
                }
-               if (*ptr == '\r')
-               {
-                       /* ignore carriage returns */
+               if (*ptr == '\r') {             // ignore carriage returns
                        ptr ++;
                }
-               else if (*ptr == '\n') {
-                       /* hard line break */
+               else if (*ptr == '\n') {        // hard line break
                        memcpy(Optr, HKEY("=0A"));
                        Optr += 3;
                        LinePos += 3;
                        ptr ++;
                }
-               else if (( (*ptr >= 32) && (*ptr <= 60) ) ||
-                        ( (*ptr >= 62) && (*ptr <= 126) ))
-               {
+               else if (( (*ptr >= 32) && (*ptr <= 60) ) || ( (*ptr >= 62) && (*ptr <= 126) )) {
                        *Optr = *ptr;
                        Optr ++;
                        ptr ++;
@@ -3171,8 +3149,7 @@ StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
                        ptr ++;
                }
 
-               if (LinePos > 72) {
-                       /* soft line break */
+               if (LinePos > 72) {             // soft line break
                        if (isspace(*(Optr - 1))) {
                                ch = *(Optr - 1);
                                Optr --;
@@ -3198,11 +3175,7 @@ StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
 }
 
 
-static void AddRecipient(StrBuf *Target, 
-                        StrBuf *UserName, 
-                        StrBuf *EmailAddress, 
-                        StrBuf *EncBuf)
-{
+static void AddRecipient(StrBuf *Target, StrBuf *UserName, StrBuf *EmailAddress, StrBuf *EncBuf) {
        int QuoteMe = 0;
 
        if (StrLength(Target) > 0) StrBufAppendBufPlain(Target, HKEY(", "), 0);
@@ -3230,11 +3203,7 @@ static void AddRecipient(StrBuf *Target,
  * \param EncBuf Temporary buffer for internal use; Please provide valid buffer.
  * \returns encoded & sanitized buffer with the contents of Recp; Caller owns this memory.
  */
-StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp, 
-                                          StrBuf *UserName, 
-                                          StrBuf *EmailAddress,
-                                          StrBuf *EncBuf)
-{
+StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp, StrBuf *UserName, StrBuf *EmailAddress, StrBuf *EncBuf) {
        StrBuf *Target;
        const char *pch, *pche;
        const char *UserStart, *UserEnd, *EmailStart, *EmailEnd, *At;
@@ -3373,8 +3342,7 @@ StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp,
  *  search character to search
  *  replace character to replace search by
  */
-void StrBufReplaceChars(StrBuf *buf, char search, char replace)
-{
+void StrBufReplaceChars(StrBuf *buf, char search, char replace) {
        long i;
        if (buf == NULL)
                return;