From 99a7382d8fc0b91c98475ec8c92c9a86975accc7 Mon Sep 17 00:00:00 2001 From: Paul Mangan Date: Fri, 17 Jan 2003 09:59:47 +0000 Subject: [PATCH 1/1] sycn with 0.8.8cvs11 --- ChangeLog | 19 ++++++ ChangeLog.claws | 5 ++ ChangeLog.jp | 19 ++++++ configure.ac | 2 +- src/common/quoted-printable.c | 2 + src/common/utils.c | 110 +++++++++++++++++++++++++++++++++- src/common/utils.h | 8 ++- src/compose.c | 42 ++++--------- src/procmime.c | 2 +- src/procmsg.c | 2 +- 10 files changed, 174 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 046092eac..2e469adcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2003-01-17 + + * src/quoted-printable.c: qp_encode_line(): fixed linebreak + duplication bug if the source string has CRLF. + * src/utils.[ch]: + canonicalize_str(): new. Returns newly allocated canonicalized + string. + uncanonicalize_file(): new. Uncanonicalize (CRLF -> LF) text. + uncanonicalize_file_replace(): new. + * src/compose.c: always canonicalize body before processing, and + uncanonicalize before returning. + +2003-01-17 + + * src/procmime.c: procmime_get_encoding_for_charset(): prefer + ENC_8BIT for Russian charsets. + * src/compose.c: compose_write_to_file(): use base64 when signing + 8bit message. + 2003-01-16 * src/prefs_common.c: prefs_send_create(): added a description for diff --git a/ChangeLog.claws b/ChangeLog.claws index bb485f8c2..5f4733371 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,8 @@ +2003-01-17 [paul] 0.8.8claws108 + + * sync with 0.8.8cvs11 + see ChangeLog 2003-01-17 + 2003-01-16 [colin] 0.8.8claws107 * src/procmsg.c diff --git a/ChangeLog.jp b/ChangeLog.jp index 5c726fa27..ae2e4e84d 100644 --- a/ChangeLog.jp +++ b/ChangeLog.jp @@ -1,3 +1,22 @@ +2003-01-17 + + * src/quoted-printable.c: qp_encode_line(): ¸µ¤Îʸ»úÎó¤Ë CRLF ¤¬ + ¤¢¤Ã¤¿¾ì¹ç¤Ë²þ¹Ô¤¬½ÅÊ£¤¹¤ë¥Ð¥°¤ò½¤Àµ¡£ + * src/utils.[ch] + canonicalize_str(): ¿·µ¬¡£¿·µ¬¤Ë³ÎÊݤµ¤ì¤¿Àµµ¬²½¤µ¤ì¤¿Ê¸»úÎó¤ò + ÊÖ¤¹¡£ + uncanonicalize_file(): ¿·µ¬¡£Àµµ¬²½¤ò²ò½ü¤¹¤ë(CRLF -> LF)¡£ + uncanonicalize_file_replace(): ¿·µ¬¡£ + * src/compose.c: ½èÍý¤ÎÁ°¤Ë¾ï¤ËËÜʸ¤òÀµµ¬²½¤·¡¢Ìá¤ëÁ°¤ËÀµµ¬²½¤ò + ²ò½ü¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£ + +2003-01-17 + + * src/procmime.c: procmime_get_encoding_for_charset(): ¥í¥·¥¢¸ì + charset ¤Î¾ì¹ç¤Ï ENC_8BIT ¤òÁª¤Ö¤è¤¦¤Ë¤·¤¿¡£ + * src/compose.c: compose_write_to_file(): 8bit ¥á¥Ã¥»¡¼¥¸¤ò½ð̾¤¹¤ë + ¾ì¹ç¤Ï base64 ¤ò»ÈÍѤ¹¤ë¤è¤¦¤Ë¤·¤¿¡£ + 2003-01-16 * src/prefs_common.c: prefs_send_create(): Content-Transfer-Encoding diff --git a/configure.ac b/configure.ac index 8a32fe967..47a7470cb 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=claws107 +EXTRA_VERSION=claws108 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 515641bca..7e8da23e4 100644 --- a/src/common/quoted-printable.c +++ b/src/common/quoted-printable.c @@ -49,6 +49,8 @@ void qp_encode_line(gchar *out, const guchar *in) if (IS_LBREAK(inp)) { *outp++ = '\n'; len = 0; + if (*inp == '\r') + inp++; inp++; } else if (ch == '\t' || ch == ' ') { if (IS_LBREAK(inp + 1)) { diff --git a/src/common/utils.c b/src/common/utils.c index 4e5d79e3a..ab112f240 100644 --- a/src/common/utils.c +++ b/src/common/utils.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 @@ -2321,6 +2321,39 @@ gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest) /* convert line endings into CRLF. If the last line doesn't end with * linebreak, add it. */ +gchar *canonicalize_str(const gchar *str) +{ + const gchar *p; + guint new_len = 0; + gchar *out, *outp; + + for (p = str; *p != '\0'; ++p) { + if (*p != '\r') { + ++new_len; + if (*p == '\n') + ++new_len; + } + } + if (p == str || *(p - 1) != '\n') + new_len += 2; + + out = outp = g_malloc(new_len + 1); + for (p = str; *p != '\0'; ++p) { + if (*p != '\r') { + if (*p == '\n') + *outp++ = '\r'; + *outp++ = *p; + } + } + if (p == str || *(p - 1) != '\n') { + *outp++ = '\r'; + *outp++ = '\n'; + } + *outp = '\0'; + + return out; +} + gint canonicalize_file(const gchar *src, const gchar *dest) { FILE *src_fp, *dest_fp; @@ -2382,7 +2415,7 @@ gint canonicalize_file(const gchar *src, const gchar *dest) } if (ferror(src_fp)) { - FILE_OP_ERROR(src, "fread"); + FILE_OP_ERROR(src, "fgets"); err = TRUE; } fclose(src_fp); @@ -2421,6 +2454,79 @@ gint canonicalize_file_replace(const gchar *file) return 0; } +gint uncanonicalize_file(const gchar *src, const gchar *dest) +{ + FILE *src_fp, *dest_fp; + gchar buf[BUFFSIZE]; + gboolean err = FALSE; + + if ((src_fp = fopen(src, "rb")) == NULL) { + FILE_OP_ERROR(src, "fopen"); + return -1; + } + + if ((dest_fp = fopen(dest, "wb")) == NULL) { + FILE_OP_ERROR(dest, "fopen"); + fclose(src_fp); + return -1; + } + + if (change_file_mode_rw(dest_fp, dest) < 0) { + FILE_OP_ERROR(dest, "chmod"); + g_warning("can't change file mode\n"); + } + + while (fgets(buf, sizeof(buf), src_fp) != NULL) { + strcrchomp(buf); + if (fputs(buf, dest_fp) == EOF) { + g_warning("writing to %s failed.\n", dest); + fclose(dest_fp); + fclose(src_fp); + unlink(dest); + return -1; + } + } + + if (ferror(src_fp)) { + FILE_OP_ERROR(src, "fgets"); + err = TRUE; + } + fclose(src_fp); + if (fclose(dest_fp) == EOF) { + FILE_OP_ERROR(dest, "fclose"); + err = TRUE; + } + + if (err) { + unlink(dest); + return -1; + } + + return 0; +} + +gint uncanonicalize_file_replace(const gchar *file) +{ + gchar *tmp_file; + + tmp_file = get_tmp_file(); + + if (uncanonicalize_file(file, tmp_file) < 0) { + g_free(tmp_file); + return -1; + } + + if (move_file(tmp_file, file, TRUE) < 0) { + g_warning("can't replace %s .\n", file); + unlink(tmp_file); + g_free(tmp_file); + return -1; + } + + g_free(tmp_file); + return 0; +} + gint change_file_mode_rw(FILE *fp, const gchar *file) { #if HAVE_FCHMOD diff --git a/src/common/utils.h b/src/common/utils.h index 2c77192fa..dcb59ded4 100644 --- a/src/common/utils.h +++ b/src/common/utils.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 @@ -356,9 +356,15 @@ gint copy_file_part (FILE *fp, off_t offset, size_t length, const gchar *dest); + +gchar *canonicalize_str (const gchar *str); gint canonicalize_file (const gchar *src, const gchar *dest); gint canonicalize_file_replace (const gchar *file); +gint uncanonicalize_file (const gchar *src, + const gchar *dest); +gint uncanonicalize_file_replace(const gchar *file); + gint change_file_mode_rw (FILE *fp, const gchar *file); FILE *my_tmpfile (void); diff --git a/src/compose.c b/src/compose.c index 40cf24d62..165519e34 100644 --- a/src/compose.c +++ b/src/compose.c @@ -3180,8 +3180,7 @@ static gint compose_clearsign_text(Compose *compose, gchar **text) return -1; } - if (canonicalize_file_replace(tmp_file) < 0 || - compose_create_signers_list(compose, &key_list) < 0 || + if (compose_create_signers_list(compose, &key_list) < 0 || rfc2015_clearsign(tmp_file, key_list) < 0) { unlink(tmp_file); g_free(tmp_file); @@ -3206,6 +3205,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, size_t len; gchar *chars; gchar *buf; + gchar *canon_buf; const gchar *out_codeset; EncodingType encoding; @@ -3248,7 +3248,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_QUOTED_PRINTABLE; + encoding = ENC_BASE64; #endif src_codeset = conv_get_current_charset_str(); @@ -3281,33 +3281,9 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, } g_free(chars); - /* Canonicalize line endings in the message text */ - { - gchar *canon_buf, *out; - const gchar *p; - guint new_len = 0; - - for (p = buf ; *p; ++p) { - if (*p != '\r') { - ++new_len; - if (*p == '\n') - ++new_len; - } - } - - out = canon_buf = g_new(gchar, new_len + 1); - for (p = buf; *p; ++p) { - if (*p != '\r') { - if (*p == '\n') - *out++ = '\r'; - *out++ = *p; - } - } - *out = '\0'; - - free(buf); - buf = canon_buf; - } + canon_buf = canonicalize_str(buf); + g_free(buf); + buf = canon_buf; #if USE_GPGME if (!is_draft && compose->use_signing && compose->gnupg_mode) { @@ -3395,8 +3371,10 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, } #if USE_GPGME - if (is_draft) + if (is_draft) { + uncanonicalize_file_replace(file); return 0; + } if ((compose->use_signing && !compose->gnupg_mode) || compose->use_encryption) { @@ -3424,6 +3402,8 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, } #endif /* USE_GPGME */ + uncanonicalize_file_replace(file); + return 0; } diff --git a/src/procmime.c b/src/procmime.c index 7aedcc3ad..97585cc3c 100644 --- a/src/procmime.c +++ b/src/procmime.c @@ -1241,7 +1241,7 @@ EncodingType procmime_get_encoding_for_charset(const gchar *charset) else if (!strcasecmp(charset, "ISO-8859-5") || !strncasecmp(charset, "KOI8-", 5) || !strcasecmp(charset, "Windows-1251")) - return ENC_BASE64; + return ENC_8BIT; else if (!strncasecmp(charset, "ISO-8859-", 9)) return ENC_QUOTED_PRINTABLE; else diff --git a/src/procmsg.c b/src/procmsg.c index 50278cf37..11180f2b4 100644 --- a/src/procmsg.c +++ b/src/procmsg.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 -- 2.25.1