From a29fc3c9815ca916af9267bc45aeea8e65f175f2 Mon Sep 17 00:00:00 2001 From: Paul Mangan Date: Wed, 15 Jan 2003 11:31:35 +0000 Subject: [PATCH] sync with 0.8.8cvs8 --- ChangeLog | 19 +++++++++++ ChangeLog.claws | 5 +++ ChangeLog.jp | 20 +++++++++++ configure.ac | 2 +- src/common/quoted-printable.c | 62 ++++++++++++++++++++++++++++++++++- src/common/quoted-printable.h | 5 ++- src/compose.c | 58 +++++++++++++++++++++----------- src/procmime.c | 7 ++-- 8 files changed, 152 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6098a2da1..14a7e67ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2003-01-15 + + * src/quoted-printable.[ch]: qp_encode_line(): fixed a bug if the + line doesn't end with linebreak. + +2003-01-15 + + * implemented quoted-printable encoding. + * src/quoted-printable.[ch]: qp_encode_line(): new. + * src/compose.c: + compose_write_to_file() + compose_write_attach(): implemented quoted-printable encoding. + compose_attach_property_create(): enabled quoted-printable menu + item. + * src/procmime.c: procmime_get_encoding_for_charset(): return + ENC_QUOTED_PRINTABLE for ISO-8859-* and CP125* charset. + * src/Makefile.am: added $(LIBICONV) to sylpheed_LDADD for libiconv + support. + 2003-01-14 * src/folderview.c diff --git a/ChangeLog.claws b/ChangeLog.claws index b2b8f6548..1d6024008 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,8 @@ +2003-01-15 [paul] 0.8.8claws102 + + * sync with 0.8.8cvs8 + see ChangeLog 2002-01-15 + 2003-01-15 [colin] 0.8.8claws101 * src/Makefile.am diff --git a/ChangeLog.jp b/ChangeLog.jp index eb3fe051d..e33516cc2 100644 --- a/ChangeLog.jp +++ b/ChangeLog.jp @@ -1,3 +1,23 @@ +2003-01-15 + + * src/quoted-printable.[ch]: qp_encode_line(): ¹Ô¤¬²þ¹Ô¤Ç½ª¤ï¤é¤Ê¤¤ + ¾ì¹ç¤Î¥Ð¥°¤ò½¤Àµ¡£ + +2003-01-15 + + * quoted-printable Éä¹æ²½¤ò¼ÂÁõ¡£ + * src/quoted-printable.[ch]: qp_encode_line(): ¿·µ¬¡£ + * src/compose.c: + compose_write_to_file() + compose_write_attach(): quoted-printable Éä¹æ²½¤ò¼ÂÁõ¡£ + compose_attach_property_create(): quoted-printable ¥á¥Ë¥å¡¼¹àÌܤò + Í­¸ú¤Ë¤·¤¿¡£ + * src/procmime.c: procmime_get_encoding_for_charset(): ISO-8859-* + ¤È CP125* ʸ»ú¥»¥Ã¥È¤Î¾ì¹ç¤Ï ENC_QUOTED_PRINTABLE ¤òÊÖ¤¹¤è¤¦¤Ë + ¤·¤¿¡£ + * src/Makefile.am: libiconv Âбþ¤Î¤¿¤á¤Ë sylpheed_LDADD ¤Ë + $(LIBICONV) ¤òÄɲᣠ+ 2003-01-14 * src/folderview.c diff --git a/configure.ac b/configure.ac index 1bdfacab4..588b0a66a 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=8 MICRO_VERSION=8 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=claws101 +EXTRA_VERSION=claws102 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl set $target diff --git a/src/common/quoted-printable.c b/src/common/quoted-printable.c index df6cca438..515641bca 100644 --- a/src/common/quoted-printable.c +++ b/src/common/quoted-printable.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2002 Hiroyuki Yamamoto + * Copyright (C) 1999-2003 Hiroyuki Yamamoto * * 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 @@ -23,6 +23,66 @@ static gboolean get_hex_value(guchar *out, gchar c1, gchar c2); static void get_hex_str(gchar *out, guchar ch); +#define MAX_LINELEN 76 + +#define IS_LBREAK(p) \ + (*(p) == '\0' || *(p) == '\n' || (*(p) == '\r' && *((p) + 1) == '\n')) + +#define SOFT_LBREAK_IF_REQUIRED(n) \ + if (len + (n) > MAX_LINELEN || \ + (len + (n) == MAX_LINELEN && (!IS_LBREAK(inp + 1)))) { \ + *outp++ = '='; \ + *outp++ = '\n'; \ + len = 0; \ + } + +void qp_encode_line(gchar *out, const guchar *in) +{ + const guchar *inp = in; + gchar *outp = out; + guchar ch; + gint len = 0; + + while (*inp != '\0') { + ch = *inp; + + if (IS_LBREAK(inp)) { + *outp++ = '\n'; + len = 0; + inp++; + } else if (ch == '\t' || ch == ' ') { + if (IS_LBREAK(inp + 1)) { + SOFT_LBREAK_IF_REQUIRED(3); + *outp++ = '='; + get_hex_str(outp, ch); + outp += 2; + len += 3; + inp++; + } else { + SOFT_LBREAK_IF_REQUIRED(1); + *outp++ = *inp++; + len++; + } + } else if ((ch >= 33 && ch <= 60) || (ch >= 62 && ch <= 126)) { + SOFT_LBREAK_IF_REQUIRED(1); + *outp++ = *inp++; + len++; + } else { + SOFT_LBREAK_IF_REQUIRED(3); + *outp++ = '='; + get_hex_str(outp, ch); + outp += 2; + len += 3; + inp++; + } + } + + if (len > 0) + *outp++ = '\n'; + + *outp = '\0'; +} + gint qp_decode_line(gchar *str) { gchar *inp = str, *outp = str; diff --git a/src/common/quoted-printable.h b/src/common/quoted-printable.h index 8c1ad0c3a..e5abf4f79 100644 --- a/src/common/quoted-printable.h +++ b/src/common/quoted-printable.h @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2002 Hiroyuki Yamamoto + * Copyright (C) 1999-2003 Hiroyuki Yamamoto * * 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 @@ -22,7 +22,10 @@ #include +void qp_encode_line (gchar *out, + const guchar *in); gint qp_decode_line (gchar *str); + gint qp_decode_q_encoding (guchar *out, const gchar *in, gint inlen); diff --git a/src/compose.c b/src/compose.c index 924bcf190..be28caac3 100644 --- a/src/compose.c +++ b/src/compose.c @@ -92,6 +92,7 @@ #include "statusbar.h" #include "about.h" #include "base64.h" +#include "quoted-printable.h" #include "codeconv.h" #include "utils.h" #include "gtkutils.h" @@ -3235,7 +3236,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, if (!is_draft && compose->use_signing && !compose->gnupg_mode && encoding == ENC_8BIT) - encoding = ENC_BASE64; + encoding = ENC_QUOTED_PRINTABLE; #endif src_codeset = conv_get_current_charset_str(); @@ -3347,6 +3348,22 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, fputs(outbuf, fp); fputc('\n', fp); } + } else if (encoding == ENC_QUOTED_PRINTABLE) { + gchar *outbuf; + size_t outlen; + + outbuf = g_malloc(len * 4); + qp_encode_line(outbuf, buf); + outlen = strlen(outbuf); + if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) { + FILE_OP_ERROR(file, "fwrite"); + fclose(fp); + unlink(file); + g_free(outbuf); + g_free(buf); + return -1; + } + g_free(outbuf); } else if (fwrite(buf, sizeof(gchar), len, fp) != len) { FILE_OP_ERROR(file, "fwrite"); fclose(fp); @@ -3723,19 +3740,8 @@ static void compose_write_attach(Compose *compose, FILE *fp) fprintf(fp, "Content-Transfer-Encoding: %s\n\n", procmime_get_encoding_str(ainfo->encoding)); - switch (ainfo->encoding) { - - case ENC_7BIT: - case ENC_8BIT: - /* if (ainfo->encoding == ENC_7BIT) { */ - - while (fgets(buf, sizeof(buf), attach_fp) != NULL) { - strcrchomp(buf); - fputs(buf, fp); - } - break; - /* } else { */ - case ENC_BASE64: + if (ainfo->encoding == ENC_BASE64) { + gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE]; while ((len = fread(inbuf, sizeof(gchar), B64_LINE_SIZE, attach_fp)) @@ -3749,10 +3755,20 @@ static void compose_write_attach(Compose *compose, FILE *fp) fputs(outbuf, fp); fputc('\n', fp); } - break; - default: - debug_print("Tried to write attachment in unsupported encoding type\n"); - break; + } else if (ainfo->encoding == ENC_QUOTED_PRINTABLE) { + gchar inbuf[BUFFSIZE], outbuf[BUFFSIZE * 4]; + + while (fgets(inbuf, sizeof(inbuf), attach_fp) != NULL) { + qp_encode_line(outbuf, inbuf); + fputs(outbuf, fp); + } + } else { + gchar buf[BUFFSIZE]; + + while (fgets(buf, sizeof(buf), attach_fp) != NULL) { + strcrchomp(buf); + fputs(buf, fp); + } } fclose(attach_fp); @@ -5498,8 +5514,10 @@ static void compose_attach_property_create(gboolean *cancelled) #if 0 gtk_widget_set_sensitive(menuitem, FALSE); #endif - MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE); - gtk_widget_set_sensitive(menuitem, FALSE); + MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", + ENC_QUOTED_PRINTABLE); + gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu); + MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64); gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu); diff --git a/src/procmime.c b/src/procmime.c index d5057e127..34856726a 100644 --- a/src/procmime.c +++ b/src/procmime.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2002 Hiroyuki Yamamoto + * Copyright (C) 1999-2003 Hiroyuki Yamamoto * * 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 @@ -1238,10 +1238,11 @@ EncodingType procmime_get_encoding_for_charset(const gchar *charset) else if (!strncasecmp(charset, "ISO-2022-", 9) || !strcasecmp(charset, "US-ASCII")) return ENC_7BIT; + else if (!strncasecmp(charset, "ISO-8859-", 9) || + !strncasecmp(charset, "CP125", 5)) + return ENC_QUOTED_PRINTABLE; else return ENC_8BIT; - /* return ENC_BASE64; */ - /* return ENC_QUOTED_PRINTABLE; */ } EncodingType procmime_get_encoding_for_file(const gchar *file) -- 2.25.1