New function StrBufDecodeQP() to decode a quoted-printable StrBuf in-place without...
authorArt Cancro <ajc@citadel.org>
Wed, 1 Feb 2017 03:47:57 +0000 (22:47 -0500)
committerArt Cancro <ajc@citadel.org>
Wed, 1 Feb 2017 03:47:57 +0000 (22:47 -0500)
libcitadel/configure.in
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index 2be9c363d79af1acb024c64fb369637f6f6881a2..21c0636d0afde3781938327a2db56e1bb5e51604 100755 (executable)
@@ -5,7 +5,7 @@ dnl
 dnl Ensure that libcitadel is configured with autoconf 2.52 or newer
 AC_PREREQ(2.52)
 
-AC_INIT(libcitadel, 903, http://uncensored.citadel.org)
+AC_INIT(libcitadel, 904, http://uncensored.citadel.org)
 
 AC_CONFIG_SRCDIR(Makefile.in)
 AC_CONFIG_AUX_DIR(conftools)
@@ -20,7 +20,7 @@ dnl Set LIBAGE to 0.
 dnl
 
 LIBCURRENT=4
-LIBREVISION=903
+LIBREVISION=904
 LIBAGE=0
 
 sinclude(conftools/libtool.m4)
index eb02470013c866b80eeb5a9d57bf1cbfdb71799a..87ab9f21c8caf92937c6f7ec9fa06f9ebcb9353b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Header file for libcitadel
  *
- * Copyright (c) 1987-2016 by the citadel.org team
+ * Copyright (c) 1987-2017 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.
@@ -28,7 +28,7 @@
 #include <sys/types.h>
 #include <netinet/in.h>
 
-#define LIBCITADEL_VERSION_NUMBER      903
+#define LIBCITADEL_VERSION_NUMBER      904
 
 /*
  * Here's a bunch of stupid magic to make the MIME parser portable.
@@ -353,6 +353,7 @@ int StrBufDestroyStreamContext(eStreamType type, vStreamT **Stream, const char *
 int StrBufStreamTranscode(eStreamType type, IOBuffer *Target, IOBuffer *In, const char* pIn, long pInLen, vStreamT *Stream, int LastChunk, const char **Err);
 
 int StrBufDecodeBase64(StrBuf *Buf);
+void StrBufDecodeQP(StrBuf *Buf);
 int StrBufDecodeBase64To(const StrBuf *BufIn, StrBuf *BufOut);
 int StrBufDecodeHex(StrBuf *Buf);
 StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe);
index 12fd259e4582ef93d9da48158582d4a0ca0bca40..8398757ded3a2c2a71c4960195029372b2609c3c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1987-2013 by the citadel.org team
+ * Copyright (c) 1987-2017 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
@@ -5622,3 +5622,44 @@ void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash)
 }
 
 
+/*
+ * Decode a quoted-printable encoded StrBuf buffer "in place"
+ * This is possible because the decoded will always be shorter than the encoded
+ * so we don't have to worry about the buffer being to small.
+ */
+void StrBufDecodeQP(StrBuf *Buf)
+{
+       if (!Buf) {                             // sanity check #1
+               return;
+       }
+
+       int source_len = StrLength(Buf);
+       if (source_len < 1) {                   // sanity check #2
+               return;
+       }
+
+       int spos = 0;                           // source position
+       int tpos = 0;                           // target position
+
+       while (spos < source_len) {
+               if (!strncmp(&Buf->buf[spos], "=\r\n", 3)) {
+                       spos += 3;
+               }
+               else if (!strncmp(&Buf->buf[spos], "=\n", 2)) {
+                       spos += 2;
+               }
+               else if (Buf->buf[spos] == '=') {
+                       ++spos;
+                       int ch;
+                       sscanf(&Buf->buf[spos], "%02x", &ch);
+                       Buf->buf[tpos++] = ch;
+                       spos +=2;
+               }
+               else {
+                       Buf->buf[tpos++] = Buf->buf[spos++];
+               }
+       }
+
+       Buf->buf[tpos] = 0;
+       Buf->BufUsed = tpos;
+}