[Commits] [SCM] claws branch, master, updated. 3.11.1-17-ga206800

ticho at claws-mail.org ticho at claws-mail.org
Sat Nov 15 20:01:58 CET 2014


The branch, master has been updated
       via  a2068001ee3f0a797968d8db474aca447cc22015 (commit)
      from  5aae1530df967ed180f42673042c62214dd604f7 (commit)

Summary of changes:
 doc/src/maintainer_guide.txt          |    2 -
 src/codeconv.c                        |    9 +-
 src/common/Makefile.am                |    2 -
 src/common/base64.c                   |  171 ---------------------------------
 src/common/base64.h                   |   49 ----------
 src/common/smtp.c                     |   93 ++++++++----------
 src/compose.c                         |    1 -
 src/gtk/gtkutils.c                    |    9 +-
 src/headerview.c                      |    1 -
 src/imap.c                            |    1 -
 src/ldif.c                            |   15 ++-
 src/plugins/pgpinline/pgpinline.c     |    1 -
 src/plugins/spam_report/spam_report.c |    4 +-
 src/prefs_account.c                   |   17 ++--
 src/prefs_customheader.c              |    9 +-
 src/prefs_gtk.c                       |   21 ++--
 src/procmime.c                        |   20 ++--
 src/textview.c                        |    1 -
 src/unmime.c                          |   11 +--
 19 files changed, 102 insertions(+), 335 deletions(-)
 delete mode 100644 src/common/base64.c
 delete mode 100644 src/common/base64.h


- Log -----------------------------------------------------------------
commit a2068001ee3f0a797968d8db474aca447cc22015
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Sat Nov 15 12:22:03 2014 +0100

    Use GLib's implementation of Base64 instead of our own.

diff --git a/doc/src/maintainer_guide.txt b/doc/src/maintainer_guide.txt
index 9eb3fec..0e2db96 100644
--- a/doc/src/maintainer_guide.txt
+++ b/doc/src/maintainer_guide.txt
@@ -254,8 +254,6 @@ vcard.c
 ------------------------------------------------------------------------------
 2. Files in src/common/
 
-base64.c
-   handles the base64 conversion
 hooks.c
    functions for handling hooks
 log.c
diff --git a/src/codeconv.c b/src/codeconv.c
index c9c8500..98b41b3 100644
--- a/src/codeconv.c
+++ b/src/codeconv.c
@@ -37,7 +37,6 @@
 
 #include "codeconv.h"
 #include "unmime.h"
-#include "base64.h"
 #include "quoted-printable.h"
 #include "utils.h"
 #include "prefs_common.h"
@@ -1573,6 +1572,8 @@ gchar *conv_unmime_header(const gchar *str, const gchar *default_encoding,
 	}								\
 }
 
+#define B64LEN(len) ((len) / 3 * 4 + ((len) % 3 ? 4 : 0))
+
 void conv_encode_header_full(gchar *dest, gint len, const gchar *src,
 			gint header_len, gboolean addr_field,
 			const gchar *out_encoding_)
@@ -1719,9 +1720,8 @@ void conv_encode_header_full(gchar *dest, gint len, const gchar *src,
 					out_enc_str_len =
 						qp_get_q_encoding_len(out_str);
 
-				Xalloca(enc_str, out_enc_str_len + 1, );
 				if (use_base64)
-					base64_encode(enc_str, out_str, out_str_len);
+					enc_str = g_base64_encode(out_str, out_str_len);
 				else
 					qp_q_encode(enc_str, out_str);
 
@@ -1732,6 +1732,7 @@ void conv_encode_header_full(gchar *dest, gint len, const gchar *src,
 				g_snprintf(destp, mime_block_len + 1,
 					   MIMESEP_BEGIN "%s%s%s" MIMESEP_END,
 					   out_encoding, mimesep_enc, enc_str);
+				g_free(enc_str);
 				destp += mime_block_len;
 				srcp += cur_len;
 
@@ -1755,6 +1756,8 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src,
 }
 
 #undef LBREAK_IF_REQUIRED
+#undef B64LEN
+
 gchar *conv_filename_from_utf8(const gchar *utf8_file)
 {
 	gchar *fs_file;
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 7597061..796fae3 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -20,7 +20,6 @@ arch_header =
 endif
 
 libclawscommon_la_SOURCES = $(arch_sources) \
-	base64.c \
 	hooks.c \
 	log.c \
 	md5.c \
@@ -47,7 +46,6 @@ libclawscommon_la_SOURCES = $(arch_sources) \
 
 clawscommonincludedir = $(pkgincludedir)/common
 clawscommoninclude_HEADERS = $(arch_headers) \
-	base64.h \
 	defs.h \
 	hooks.h \
 	log.h \
diff --git a/src/common/base64.c b/src/common/base64.c
deleted file mode 100644
index b524128..0000000
--- a/src/common/base64.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
- *
- * This program is free 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, see <http://www.gnu.org/licenses/>.
- * 
- */
-
-#include <glib.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "base64.h"
-#include "utils.h"
-
-static const gchar base64char[64] =
-	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-static const signed char base64val[128] = {
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
-	52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
-	-1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
-	15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
-	-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
-	41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
-};
-
-#define BASE64VAL(c)	(IS_ASCII(c) ? base64val[(gint) (c)] : -1)
-
-void base64_encode(gchar *out, const guchar *in, gint inlen)
-{
-	const guchar *inp = in;
-	gchar *outp = out;
-
-	while (inlen >= 3) {
-		*outp++ = base64char[(inp[0] >> 2) & 0x3f];
-		*outp++ = base64char[((inp[0] & 0x03) << 4) |
-				     ((inp[1] >> 4) & 0x0f)];
-		*outp++ = base64char[((inp[1] & 0x0f) << 2) |
-				     ((inp[2] >> 6) & 0x03)];
-		*outp++ = base64char[inp[2] & 0x3f];
-
-		inp += 3;
-		inlen -= 3;
-	}
-
-	if (inlen > 0) {
-		*outp++ = base64char[(inp[0] >> 2) & 0x3f];
-		if (inlen == 1) {
-			*outp++ = base64char[(inp[0] & 0x03) << 4];
-			*outp++ = '=';
-		} else {
-			*outp++ = base64char[((inp[0] & 0x03) << 4) |
-					     ((inp[1] >> 4) & 0x0f)];
-			*outp++ = base64char[((inp[1] & 0x0f) << 2)];
-		}
-		*outp++ = '=';
-	}
-
-	*outp = '\0';
-}
-
-gint base64_decode(guchar *out, const gchar *in, gint inlen)
-{
-	const gchar *inp = in;
-	guchar *outp = out;
-	gchar buf[4];
-
-	if (inlen < 0)
-		inlen = G_MAXINT;
-
-	while (inlen >= 4 && *inp != '\0') {
-		buf[0] = *inp++;
-		inlen--;
-		if (BASE64VAL(buf[0]) == -1) break;
-
-		buf[1] = *inp++;
-		inlen--;
-		if (BASE64VAL(buf[1]) == -1) break;
-
-		buf[2] = *inp++;
-		inlen--;
-		if (buf[2] != '=' && BASE64VAL(buf[2]) == -1) break;
-
-		buf[3] = *inp++;
-		inlen--;
-		if (buf[3] != '=' && BASE64VAL(buf[3]) == -1) break;
-
-		*outp++ = ((BASE64VAL(buf[0]) << 2) & 0xfc) |
-			  ((BASE64VAL(buf[1]) >> 4) & 0x03);
-		if (buf[2] != '=') {
-			*outp++ = ((BASE64VAL(buf[1]) & 0x0f) << 4) |
-				  ((BASE64VAL(buf[2]) >> 2) & 0x0f);
-			if (buf[3] != '=') {
-				*outp++ = ((BASE64VAL(buf[2]) & 0x03) << 6) |
-					   (BASE64VAL(buf[3]) & 0x3f);
-			}
-		}
-	}
-
-	return outp - out;
-}
-
-Base64Decoder *base64_decoder_new(void)
-{
-	Base64Decoder *decoder;
-
-	decoder = g_new0(Base64Decoder, 1);
-	return decoder;
-}
-
-void base64_decoder_free(Base64Decoder *decoder)
-{
-	g_free(decoder);
-}
-
-gint base64_decoder_decode(Base64Decoder *decoder,
-			   const gchar *in, guchar *out, gint inlen)
-{
-	const gchar *in_end = in + inlen;
-	gint len, total_len = 0;
-	gboolean in_more = inlen > 0;
-	gboolean got_eq = FALSE;
-	gint buf_len;
-	gchar buf[4];
-
-	cm_return_val_if_fail(decoder != NULL, -1);
-	cm_return_val_if_fail(in != NULL, -1);
-	cm_return_val_if_fail(out != NULL, -1);
-
-	/* Start with previous saved tail */	
-	buf_len = decoder->buf_len;
-	memcpy(buf, decoder->buf, sizeof(buf));
-
-	while (in_more) {
-		while (buf_len < 4 && in_more) {
-			gchar c = *in;
-
-			in++;
-			got_eq = (c == '=');
-			if (got_eq || BASE64VAL(c) >= 0)
-				buf[buf_len++] = c;
-			in_more = (in < in_end) && !(got_eq && (buf_len == 4));
-		}
-		if (buf_len == 4) {
-			len = base64_decode(out, buf, 4);
-			out += len;
-			total_len += len;
-			buf_len = 0;
-		}
-	}
-	if (buf_len < 4) { 
-		/* Save tail for next iteration call. It wll be ignored if ends here. */
-		decoder->buf_len = buf_len;
-		memcpy(decoder->buf, buf, buf_len);
-	}
-	return total_len;
-}
diff --git a/src/common/base64.h b/src/common/base64.h
deleted file mode 100644
index 3a38515..0000000
--- a/src/common/base64.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail teams
- *
- * This program is free 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, see <http://www.gnu.org/licenses/>.
- * 
- */
-
-#ifndef __BASE64_H__
-#define __BASE64_H__
-
-#include <glib.h>
-
-#define B64LEN(len)	((len) / 3 * 4 + ((len) % 3 ? 4 : 0))
-
-typedef struct _Base64Decoder	Base64Decoder;
-
-struct _Base64Decoder
-{
-	gint buf_len;
-	gchar buf[4];
-};
-
-void base64_encode	(gchar		*out,
-			 const guchar	*in,
-			 gint		 inlen);
-gint base64_decode	(guchar		*out,
-			 const gchar	*in,
-			 gint		 inlen);
-
-Base64Decoder *base64_decoder_new	(void);
-void	       base64_decoder_free	(Base64Decoder	*decoder);
-gint	       base64_decoder_decode	(Base64Decoder	*decoder,
-					 const gchar	*in,
-					 guchar		*out,
-					 gint           inlen);
-
-#endif /* __BASE64_H__ */
diff --git a/src/common/smtp.c b/src/common/smtp.c
index 888b0b2..3b94b47 100644
--- a/src/common/smtp.c
+++ b/src/common/smtp.c
@@ -34,7 +34,6 @@
 
 #include "smtp.h"
 #include "md5.h"
-#include "base64.h"
 #include "utils.h"
 #include "log.h"
 
@@ -189,18 +188,21 @@ static gint smtp_auth(SMTPSession *session)
 
 static gint smtp_auth_recv(SMTPSession *session, const gchar *msg)
 {
-	gchar buf[MESSAGEBUFSIZE];
+	gchar buf[MESSAGEBUFSIZE], *tmp;
 
 	switch (session->auth_type) {
 	case SMTPAUTH_LOGIN:
 		session->state = SMTP_AUTH_LOGIN_USER;
 
 		if (!strncmp(msg, "334 ", 4)) {
-			base64_encode(buf, session->user, strlen(session->user));
+			tmp = g_base64_encode(session->user, strlen(session->user));
 
 			if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
-					 buf) < 0)
+					 tmp) < 0) {
+				g_free(tmp);
 				return SM_ERROR;
+			}
+			g_free(tmp);
 			log_print(LOG_PROTOCOL, "ESMTP> [USERID]\n");
 		} else {
 			/* Server rejects AUTH */
@@ -216,13 +218,13 @@ static gint smtp_auth_recv(SMTPSession *session, const gchar *msg)
 		if (!strncmp(msg, "334 ", 4)) {
 			gchar *response;
 			gchar *response64;
-			gchar *challenge;
-			gint challengelen;
+			gchar *challenge, *tmp;
+			gsize challengelen;
 			guchar hexdigest[33];
 
-			challenge = g_malloc(strlen(msg + 4) + 1);
-			challengelen = base64_decode(challenge, msg + 4, -1);
-			challenge[challengelen] = '\0';
+			tmp = g_base64_decode(msg + 4, &challengelen);
+			challenge = g_strndup(tmp, challengelen);
+			g_free(tmp);
 			log_print(LOG_PROTOCOL, "ESMTP< [Decoded: %s]\n", challenge);
 
 			g_snprintf(buf, sizeof(buf), "%s", session->pass);
@@ -234,13 +236,14 @@ static gint smtp_auth_recv(SMTPSession *session, const gchar *msg)
 				("%s %s", session->user, hexdigest);
 			log_print(LOG_PROTOCOL, "ESMTP> [Encoded: %s]\n", response);
 
-			response64 = g_malloc((strlen(response) + 3) * 2 + 1);
-			base64_encode(response64, response, strlen(response));
+			response64 = g_base64_encode(response, strlen(response));
 			g_free(response);
 
 			if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
-					 response64) < 0)
+					 response64) < 0) {
+				g_free(response64);
 				return SM_ERROR;
+			}
 			log_print(LOG_PROTOCOL, "ESMTP> %s\n", response64);
 			g_free(response64);
 		} else {
@@ -265,15 +268,26 @@ static gint smtp_auth_recv(SMTPSession *session, const gchar *msg)
 
 static gint smtp_auth_login_user_recv(SMTPSession *session, const gchar *msg)
 {
-	gchar buf[MESSAGEBUFSIZE];
+	gchar buf[MESSAGEBUFSIZE], *tmp;
+	gsize len;
 
 	session->state = SMTP_AUTH_LOGIN_PASS;
 
-	if (!strncmp(msg, "334 ", 4))
-		base64_encode(buf, session->pass, strlen(session->pass));
-	else
+	if (!strncmp(msg, "334 ", 4)) {
+		tmp = g_base64_encode(session->pass, strlen(session->pass));
+		len = g_strlcat(buf, tmp, MESSAGEBUFSIZE);
+		if (len >= MESSAGEBUFSIZE) {
+			/* This should never happen, and even if it does, all it will do
+			 * is send an incorrect password so auth will fail. That's why
+			 * we're printing this debug message, so investigating user or dev
+			 * will know what's wrong. */
+			debug_print("Truncation of password occured in g_strlcat().\n");
+		}
+		g_free(tmp);
+	} else {
 		/* Server rejects AUTH */
 		g_snprintf(buf, sizeof(buf), "*");
+	}
 
 	if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, buf) < 0)
 		return SM_ERROR;
@@ -364,49 +378,26 @@ static gint smtp_auth_cram_md5(SMTPSession *session)
 
 static gint smtp_auth_plain(SMTPSession *session)
 {
-	gchar buf[MESSAGEBUFSIZE];
-
-	/* 
- 	 * +1      +1      +1
-	 * \0<user>\0<pass>\0 
-	 */
-	int b64len = (1 + strlen(session->user) + 1 + strlen(session->pass) + 1);
-	gchar *b64buf = g_malloc(b64len);
-
-	/* use the char *ptr to walk the base64 string with embedded \0 */
-	char  *a = b64buf;
-	int  b64cnt = 0;
+	gchar buf[MESSAGEBUFSIZE], *b64buf, *out;
+	gint len;
 
 	session->state = SMTP_AUTH_PLAIN;
 	session->auth_type = SMTPAUTH_PLAIN;
 
 	memset(buf, 0, sizeof buf);
 
-	/*
-	 * have to construct the string bit by bit. sprintf can't do it in one.
-	 * first field is null, so string is \0<user>\0<password>
-	 */
-	*a = 0;
-	a++;
-
-	g_snprintf (a, b64len - 1, "%s", session->user);
-
-	b64cnt = strlen(session->user)+1;
-	a += b64cnt;
-
-	g_snprintf (a, b64len - b64cnt - 1, "%s", session->pass);
-	b64cnt += strlen(session->pass) + 1;	
-
-	/*
-	 * reuse the char *ptr to offset into the textbuf to meld
-	 * the plaintext ESMTP message and the base64 string value
-	 */
-	strcpy(buf, "AUTH PLAIN ");
-	a = buf + strlen(buf);
-	base64_encode(a, b64buf, b64cnt);
+	/* "\0user\0password" */
+	len = sprintf(buf, "%c%s%c%s", '\0', session->user, '\0', session->pass);
+	b64buf = g_base64_encode(buf, len);
+	out = g_strconcat("AUTH PLAIN ", b64buf, NULL);
+	g_free(b64buf);
 
-	if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, buf) < 0)
+	if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, out) < 0) {
+		g_free(out);
 		return SM_ERROR;
+	}
+
+	g_free(out);
 
 	log_print(LOG_PROTOCOL, "ESMTP> [AUTH PLAIN]\n");
 
diff --git a/src/compose.c b/src/compose.c
index c3ea943..0e3b9b6 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -84,7 +84,6 @@
 #include "procmime.h"
 #include "statusbar.h"
 #include "about.h"
-#include "base64.h"
 #include "quoted-printable.h"
 #include "codeconv.h"
 #include "utils.h"
diff --git a/src/gtk/gtkutils.c b/src/gtk/gtkutils.c
index 5bcea99..b98c93c 100644
--- a/src/gtk/gtkutils.c
+++ b/src/gtk/gtkutils.c
@@ -57,7 +57,6 @@
 #include "prefs_account.h"
 #include "prefs_common.h"
 #include "manage_window.h"
-#include "base64.h"
 #include "manual.h"
 #include "combobox.h"
 
@@ -1113,7 +1112,8 @@ GtkWidget *face_get_from_header(const gchar *o_face)
 {
 	gchar face[2048];
 	gchar face_png[2048];
-	gint pngsize;
+	gchar *tmp;
+	gsize pngsize;
 	GdkPixbuf *pixbuf;
 	GError *error = NULL;
 	GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();
@@ -1127,7 +1127,10 @@ GtkWidget *face_get_from_header(const gchar *o_face)
 	unfold_line(face); /* strip all whitespace and linebreaks */
 	remove_space(face);
 
-	pngsize = base64_decode(face_png, face, strlen(face));
+	tmp = g_base64_decode(face, &pngsize);
+	memcpy(face_png, tmp, pngsize);
+	face_png[pngsize] = '\0';
+	debug_print("---------------------- loaded face png\n");
 
 	if (!gdk_pixbuf_loader_write (loader, face_png, pngsize, &error) ||
 	    !gdk_pixbuf_loader_close (loader, &error)) {
diff --git a/src/headerview.c b/src/headerview.c
index d4db9bb..6ac0959 100644
--- a/src/headerview.c
+++ b/src/headerview.c
@@ -38,7 +38,6 @@
 #include "codeconv.h"
 #include "gtkutils.h"
 #include "utils.h"
-#include "base64.h"
 #include "headers.h"
 #include "addrindex.h"
 #include "hooks.h"
diff --git a/src/imap.c b/src/imap.c
index 8ef3ac4..32ecd38 100644
--- a/src/imap.c
+++ b/src/imap.c
@@ -59,7 +59,6 @@
 #include "prefs_account.h"
 #include "codeconv.h"
 #include "md5.h"
-#include "base64.h"
 #include "utils.h"
 #include "prefs_common.h"
 #include "inputdialog.h"
diff --git a/src/ldif.c b/src/ldif.c
index 54d90aa..89f750b 100644
--- a/src/ldif.c
+++ b/src/ldif.c
@@ -32,7 +32,6 @@
 #include "addritem.h"
 #include "addrcache.h"
 
-#include "base64.h"
 #include "utils.h"
 
 #define	LDIF_SEP_TAG    ':'
@@ -608,6 +607,8 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
 	long posEnd = 0L;
 	long posCur = 0L;
 	GHashTable *hashField;
+	gchar *out;
+	gsize len;
 
 	hashField = ldifFile->hashFields;
 	rec = g_new0( Ldif_ParsedRec, 1 );
@@ -641,10 +642,8 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
 				/* Save record */
 				fullValue = mgu_list_coalesce( listValue );
 				if (fullValue && last64) {
-					gchar *out = g_malloc(strlen(fullValue));
-					int len = 0;
-					if ((len = base64_decode(out, fullValue,
-							strlen(fullValue))) >= 0) {
+					out = g_base64_decode(fullValue, &len);
+					if (len >= 0) {
 						g_free(fullValue);
 						fullValue = out;
 						fullValue[len] = '\0';
@@ -692,10 +691,8 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
 							fullValue =
 								mgu_list_coalesce( listValue );
 							if (fullValue && last64) {
-								gchar *out = g_malloc(strlen(fullValue));
-								int len = 0;
-								if ((len = base64_decode(out, fullValue,
-										strlen(fullValue))) >= 0) {
+								out = g_base64_decode(fullValue, &len);
+								if (len >= 0) {
 									g_free(fullValue);
 									fullValue = out;
 									fullValue[len] = '\0';
diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c
index a5e2267..f6144b5 100644
--- a/src/plugins/pgpinline/pgpinline.c
+++ b/src/plugins/pgpinline/pgpinline.c
@@ -40,7 +40,6 @@
 #include <plugins/pgpcore/passphrase.h>
 #include <plugins/pgpcore/pgp_utils.h>
 #include "quoted-printable.h"
-#include "base64.h"
 #include "codeconv.h"
 #include "plugin.h"
 
diff --git a/src/plugins/spam_report/spam_report.c b/src/plugins/spam_report/spam_report.c
index e996607..9cb43d3 100644
--- a/src/plugins/spam_report/spam_report.c
+++ b/src/plugins/spam_report/spam_report.c
@@ -43,7 +43,6 @@
 #include "plugin.h"
 #include "menu.h"
 #include "defs.h"
-#include "base64.h"
 #include "procheader.h"
 
 #ifdef USE_PTHREAD
@@ -213,8 +212,7 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
 	debug_print("reporting via %s\n", intf->name);
 	tmp = spamreport_strreplace(intf->body, "%claws_mail_body%", contents);
 	len_contents = strlen(contents);
-	b64 = g_malloc0(B64LEN(len_contents) + 1);
-	base64_encode(b64, contents, len_contents);
+	b64 = g_base64_encode(contents, len_contents);
 	reqbody = spamreport_strreplace(tmp, "%claws_mail_body_b64%", b64);
 	geturl = spamreport_strreplace(intf->url, "%claws_mail_msgid%", msginfo->msgid);
 	g_free(b64);
diff --git a/src/prefs_account.c b/src/prefs_account.c
index bb9c07a..3db4b33 100644
--- a/src/prefs_account.c
+++ b/src/prefs_account.c
@@ -57,7 +57,6 @@
 #include "smtp.h"
 #include "imap.h"
 #include "remotefolder.h"
-#include "base64.h"
 #include "combobox.h"
 #include "setup.h"
 #include "quote_fmt.h"
@@ -3489,6 +3488,7 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
 	gchar *rcpath;
 	gint id;
 	gchar **strv, **cur;
+	gsize len;
 
 	cm_return_if_fail(ac_prefs != NULL);
 	cm_return_if_fail(label != NULL);
@@ -3522,7 +3522,8 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
 	if (privacy_prefs != NULL) {
 		strv = g_strsplit(privacy_prefs, ",", 0);
 		for (cur = strv; *cur != NULL; cur++) {
-			gchar *encvalue, *value;
+			gchar *encvalue, *tmp;
+			gchar value[1024];
 
 			encvalue = strchr(*cur, '=');
 			if (encvalue == NULL)
@@ -3530,10 +3531,13 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
 			encvalue[0] = '\0';
 			encvalue++;
 
-			value = g_malloc0(strlen(encvalue));
-			if (base64_decode(value, encvalue, strlen(encvalue)) > 0)
+			tmp = g_base64_decode(encvalue, &len);
+			if (len > 0) {
+				g_strlcat(value, tmp, 1024);
+				value[len] = '\0';
 				g_hash_table_insert(ac_prefs->privacy_prefs, g_strdup(*cur), g_strdup(value));
-			g_free(value);
+			}
+			g_free(tmp);
 		}
 		g_strfreev(strv);
 		g_free(privacy_prefs);
@@ -3554,8 +3558,7 @@ static void create_privacy_prefs(gpointer key, gpointer _value, gpointer user_da
 	if (str->len > 0)
 		g_string_append_c(str, ',');
 
-	encvalue = g_malloc0(B64LEN(strlen(value)) + 1);
-	base64_encode(encvalue, (gchar *) value, strlen(value));
+	encvalue = g_base64_encode(value, strlen(value));
 	g_string_append_printf(str, "%s=%s", (gchar *) key, encvalue);
 	g_free(encvalue);
 }
diff --git a/src/prefs_customheader.c b/src/prefs_customheader.c
index 3a84d7c..a82e0ec 100644
--- a/src/prefs_customheader.c
+++ b/src/prefs_customheader.c
@@ -46,7 +46,6 @@
 #include "utils.h"
 #include "gtkutils.h"
 #include "alertpanel.h"
-#include "base64.h"
 #include "filesel.h"
 #include "combobox.h"
 
@@ -571,7 +570,7 @@ static void prefs_custom_header_val_from_file_cb(void)
 		if (filename && is_file_exist(filename)) {
 			FILE *fp = NULL;
 			gint len;
-			gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
+			gchar inbuf[B64_LINE_SIZE], *outbuf;
 			gchar *tmp = NULL;
 			gint w, h;
 			GdkPixbufFormat *format = gdk_pixbuf_get_file_info(
@@ -649,16 +648,18 @@ static void prefs_custom_header_val_from_file_cb(void)
 			while ((len = fread(inbuf, sizeof(gchar),
 					    B64_LINE_SIZE, fp))
 			       == B64_LINE_SIZE) {
-				base64_encode(outbuf, inbuf, B64_LINE_SIZE);
+				outbuf = g_base64_encode(inbuf, B64_LINE_SIZE);
 
 				tmp = contents;
 				contents = g_strconcat(tmp?tmp:"",outbuf, NULL);
+				g_free(outbuf);
 				g_free(tmp);
 			}
 			if (len > 0 && feof(fp)) {
 				tmp = contents;
-				base64_encode(outbuf, inbuf, len);
+				outbuf = g_base64_encode(inbuf, len);
 				contents = g_strconcat(tmp?tmp:"",outbuf, NULL);
+				g_free(outbuf);
 				g_free(tmp);
 			}
 			fclose(fp);
diff --git a/src/prefs_gtk.c b/src/prefs_gtk.c
index 5045926..e141afd 100644
--- a/src/prefs_gtk.c
+++ b/src/prefs_gtk.c
@@ -41,7 +41,6 @@
 #include "utils.h"
 #include "gtkutils.h"
 #include "passcrypt.h"
-#include "base64.h"
 #include "codeconv.h"
 
 #define CL(x)	(((gulong) (x) >> (gulong) 8) & 0xFFUL)
@@ -220,14 +219,16 @@ static void prefs_config_parse_one_line(PrefParam *param, const gchar *buf)
 		case P_PASSWORD:
 			g_free(*((gchar **)param[i].data));
 			if (value[0] == '!') {
-				gchar tmp[1024];
-				gint len;
-
-				len = base64_decode(tmp, &value[1], strlen(value) - 1);
-				passcrypt_decrypt(tmp, len);
-				tmp[len] = '\0';
+				gchar *tmp, buf[1024];
+				gsize len;
+
+				tmp = g_base64_decode(&value[1], &len);
+				g_strlcat(buf, tmp, 1024);
+				g_free(tmp);
+				buf[len] = '\0';
+				passcrypt_decrypt(buf, len);
 				*((gchar **)param[i].data) =
-					*tmp ? g_strdup(tmp) : NULL;
+					*buf ? g_strdup(buf) : NULL;
 			} else {
 				*((gchar **)param[i].data) =
 					*value ? g_strdup(value) : NULL;
@@ -383,7 +384,7 @@ gint prefs_write_param(PrefParam *param, FILE *fp)
 			break;
 		case P_PASSWORD:
 			{
-				gchar *tmp = NULL, tmp2[1024] = {0};
+				gchar *tmp = NULL, *tmp2 = NULL;
 
 				tmp = *((gchar **)param[i].data);
 				if (tmp) {
@@ -392,7 +393,7 @@ gint prefs_write_param(PrefParam *param, FILE *fp)
 					tmp = g_strdup(tmp);
 					len = strlen(tmp);
 					passcrypt_encrypt(tmp, len);
-					base64_encode(tmp2, tmp, len);
+					tmp2 = g_base64_encode(tmp, len);
 					g_free(tmp);
 					tmp = tmp2;
 				}
diff --git a/src/procmime.c b/src/procmime.c
index 592f2d6..a463026 100644
--- a/src/procmime.c
+++ b/src/procmime.c
@@ -41,7 +41,6 @@
 
 #include "procmime.h"
 #include "procheader.h"
-#include "base64.h"
 #include "quoted-printable.h"
 #include "uuencode.h"
 #include "unmime.h"
@@ -320,6 +319,8 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 	gboolean flowed = FALSE;
 	gboolean delsp = FALSE; 
 	gboolean err = FALSE;
+	gint state = 0;
+	guint save = 0;
 
 	EncodingType encoding = forced_encoding 
 				? forced_encoding
@@ -395,7 +396,6 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 	} else if (encoding == ENC_BASE64) {
 		gchar outbuf[BUFFSIZE];
 		gint len, inlen, inread;
-		Base64Decoder *decoder;
 		gboolean got_error = FALSE;
 		gboolean uncanonicalize = FALSE;
 		FILE *tmpfp = NULL;
@@ -419,10 +419,9 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 		} else
 			tmpfp = outfp;
 
-		decoder = base64_decoder_new();
 		while ((inlen = MIN(readend - ftell(infp), sizeof(buf))) > 0 && !err) {
 			inread = SC_FREAD(buf, 1, inlen, infp);
-			len = base64_decoder_decode(decoder, buf, outbuf, inread);
+			len = g_base64_decode_step(buf, inlen, outbuf, &state, &save);
 			if (uncanonicalize == TRUE && strlen(outbuf) < len && starting) {
 				uncanonicalize = FALSE;
 				null_bytes = TRUE;
@@ -451,7 +450,6 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 				got_error = FALSE;
 			}
 		}
-		base64_decoder_free(decoder);
 
 		if (uncanonicalize) {
 			rewind(tmpfp);
@@ -573,7 +571,7 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
 	}
 
 	if (encoding == ENC_BASE64) {
-		gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
+		gchar inbuf[B64_LINE_SIZE], *out;
 		FILE *tmp_fp = infp;
 		gchar *tmp_file = NULL;
 
@@ -614,16 +612,18 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
 		while ((len = SC_FREAD(inbuf, sizeof(gchar),
 				    B64_LINE_SIZE, tmp_fp))
 		       == B64_LINE_SIZE) {
-			base64_encode(outbuf, inbuf, B64_LINE_SIZE);
-			if (SC_FPUTS(outbuf, outfp) == EOF)
+			out = g_base64_encode(inbuf, B64_LINE_SIZE);
+			if (SC_FPUTS(out, outfp) == EOF)
 				err = TRUE;
+			g_free(out);
 			if (SC_FPUTC('\n', outfp) == EOF)
 				err = TRUE;
 		}
 		if (len > 0 && SC_FEOF(tmp_fp)) {
-			base64_encode(outbuf, inbuf, len);
-			if (SC_FPUTS(outbuf, outfp) == EOF)
+			out = g_base64_encode(inbuf, len);
+			if (SC_FPUTS(out, outfp) == EOF)
 				err = TRUE;
+			g_free(out);
 			if (SC_FPUTC('\n', outfp) == EOF)
 				err = TRUE;
 		}
diff --git a/src/textview.c b/src/textview.c
index b2a0985..6f0027a 100644
--- a/src/textview.c
+++ b/src/textview.c
@@ -63,7 +63,6 @@
 #include "menu.h"
 #include "image_viewer.h"
 #include "filesel.h"
-#include "base64.h"
 #include "inputdialog.h"
 #include "timing.h"
 #include "tags.h"
diff --git a/src/unmime.c b/src/unmime.c
index 2054c14..aeda9e4 100644
--- a/src/unmime.c
+++ b/src/unmime.c
@@ -27,7 +27,6 @@
 #include <ctype.h>
 
 #include "codeconv.h"
-#include "base64.h"
 #include "quoted-printable.h"
 
 #define ENCODED_WORD_BEGIN	"=?"
@@ -112,11 +111,11 @@ gchar *unmime_header(const gchar *encoded_str, gboolean addr_field)
 		encoding = g_ascii_toupper(*(encoding_begin_p + 1));
 
 		if (encoding == 'B') {
-			decoded_text = g_malloc
-				(eword_end_p - (text_begin_p + 1) + 1);
-			len = base64_decode(decoded_text, text_begin_p + 1,
-					    eword_end_p - (text_begin_p + 1));
-			decoded_text[len] = '\0';
+			gchar *tmp;
+			tmp = g_strndup(text_begin_p + 1, eword_end_p - (text_begin_p + 1) + 1);
+			decoded_text = g_base64_decode(tmp, &out_len);
+			g_free(tmp);
+			decoded_text[out_len] = '\0';
 		} else if (encoding == 'Q') {
 			decoded_text = g_malloc
 				(eword_end_p - (text_begin_p + 1) + 1);

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list