]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add function to perform quoted-printable encoding
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 20 Dec 2016 16:46:28 +0000 (16:46 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 20 Dec 2016 17:14:17 +0000 (17:14 +0000)
src/libutil/str_util.c
src/libutil/str_util.h

index bccb0699fb056ac40c2768c37d8b708280b821d8..7a94a4df1e864667432b555e8c37ab2893e8349d 100644 (file)
@@ -1940,6 +1940,43 @@ decode:
        return (o - out);
 }
 
+gssize
+rspamd_encode_qp2047_buf (const gchar *in, gsize inlen,
+               gchar *out, gsize outlen)
+{
+       gchar *o = out, *end = out + outlen, c;
+       static const gchar hexdigests[16] = "0123456789ABCDEF";
+
+       while (inlen > 0 && o < end) {
+               c = *in;
+
+               if (g_ascii_isalnum (c)) {
+                       *o++ = c;
+               }
+               else if (c == ' ') {
+                       *o++ = "_";
+                       in++;
+               }
+               else if (end - o >= 3){
+                       *o++ = '=';
+                       *o++ = hexdigests[((c >> 4) & 0xF)];
+                       *o++ = hexdigests[(c & 0xF)];
+               }
+               else {
+                       return (-1);
+               }
+
+               in ++;
+               inlen --;
+       }
+
+       if (inlen != 0) {
+               return (-1);
+       }
+
+       return (o - out);
+}
+
 
 /*
  * GString ucl emitting functions
index 2c9905e139ffa2152e5ebc1aef7cc37eb68e764c..094a6498c657b4ee6c5404ecd937199a6269e5ca 100644 (file)
@@ -234,6 +234,17 @@ gssize rspamd_decode_qp_buf (const gchar *in, gsize inlen,
 gssize rspamd_decode_qp2047_buf (const gchar *in, gsize inlen,
                gchar *out, gsize outlen);
 
+/**
+ * Encode quoted-printable buffer using rfc2047 format, input and output must not overlap
+ * @param in
+ * @param inlen
+ * @param out
+ * @param outlen
+ * @return
+ */
+gssize rspamd_encode_qp2047_buf (const gchar *in, gsize inlen,
+               gchar *out, gsize outlen);
+
 #ifndef g_tolower
 #   define g_tolower(x) (((x) >= 'A' && (x) <= 'Z') ? (x) - 'A' + 'a' : (x))
 #endif