aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2007-05-15 04:34:58 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2007-05-15 04:34:58 +0000
commitc5575f297c9e68bb0eaad671b4afb25ebe441186 (patch)
tree29b6cc0aa03f452f8ef3f5bf2e40a88449910293
parent017021009d0c7d9c6812834bb952edfd5411d3a5 (diff)
use quoted-printable or base64 to protect trailing spaces on PGP/MIME signing except for ISO-2022-JP.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1693 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog7
-rw-r--r--ChangeLog.ja7
-rw-r--r--libsylph/procmime.c37
-rw-r--r--libsylph/procmime.h3
-rw-r--r--src/compose.c25
5 files changed, 66 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index a93ff6e4..0a241109 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-05-15
+
+ * libsylph/procmime.[ch]: procmime_get_encoding_for_str(): added.
+ * src/compose.c: compose_write_to_file(): chomp all trailing spaces
+ only if body charset is ISO-2022-JP. Use quoted-printable or
+ base64 in other case.
+
2007-05-14
* src/summaryview.c: the quick search key now persists on refresh.
diff --git a/ChangeLog.ja b/ChangeLog.ja
index 5978fe2d..4c79739a 100644
--- a/ChangeLog.ja
+++ b/ChangeLog.ja
@@ -1,3 +1,10 @@
+2007-05-15
+
+ * libsylph/procmime.[ch]: procmime_get_encoding_for_str(): 追加。
+ * src/compose.c: compose_write_to_file(): 本文の文字コードが
+ ISO-2022-JP の場合のみ行末の空白を削除するようにした。その他の
+ 場合は quoted-printable または base64 を使用。
+
2007-05-14
* src/summaryview.c: クイック検索のキーがリフレッシュ時に保持される
diff --git a/libsylph/procmime.c b/libsylph/procmime.c
index de5c92ba..24fa4441 100644
--- a/libsylph/procmime.c
+++ b/libsylph/procmime.c
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1671,6 +1671,41 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file)
}
}
+EncodingType procmime_get_encoding_for_str(const gchar *str)
+{
+ const guchar *p;
+ size_t octet_chars = 0;
+ size_t total_len = 0;
+ gfloat octet_percentage;
+
+ total_len = strlen(str);
+
+ for (p = str; *p != '\0'; ++p) {
+ if (*p & 0x80)
+ ++octet_chars;
+ }
+
+ if (total_len > 0)
+ octet_percentage = (gfloat)octet_chars / (gfloat)total_len;
+ else
+ octet_percentage = 0.0;
+
+ debug_print("procmime_get_encoding_for_str(): "
+ "8bit chars: %d / %d (%f%%)\n", octet_chars, total_len,
+ 100.0 * octet_percentage);
+
+ if (octet_percentage > 0.20) {
+ debug_print("using BASE64\n");
+ return ENC_BASE64;
+ } else if (octet_chars > 0) {
+ debug_print("using quoted-printable\n");
+ return ENC_QUOTED_PRINTABLE;
+ } else {
+ debug_print("using 7bit\n");
+ return ENC_7BIT;
+ }
+}
+
const gchar *procmime_get_encoding_str(EncodingType encoding)
{
static const gchar *encoding_str[] = {
diff --git a/libsylph/procmime.h b/libsylph/procmime.h
index 735cef68..8d5b1855 100644
--- a/libsylph/procmime.h
+++ b/libsylph/procmime.h
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -197,6 +197,7 @@ gint procmime_execute_open_file (const gchar *file,
EncodingType procmime_get_encoding_for_charset (const gchar *charset);
EncodingType procmime_get_encoding_for_text_file(const gchar *file);
+EncodingType procmime_get_encoding_for_str (const gchar *str);
const gchar *procmime_get_encoding_str (EncodingType encoding);
#endif /* __PROCMIME_H__ */
diff --git a/src/compose.c b/src/compose.c
index f3772c2d..b0b32bb4 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -3075,19 +3075,22 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
buf = canon_buf;
#if USE_GPGME
- /* chomp all trailing spaces */
+ /* protect trailing spaces */
if (rfc2015_is_available() && !is_draft &&
compose->use_signing && !compose->account->clearsign) {
- gchar *tmp;
- tmp = strchomp_all(buf);
- g_free(buf);
- buf = tmp;
-#if 0
- if (encoding == ENC_7BIT)
- encoding = ENC_QUOTED_PRINTABLE;
- else if (encoding == ENC_8BIT)
- encoding = ENC_BASE64;
-#endif
+ if (encoding == ENC_7BIT) {
+ if (!g_ascii_strcasecmp(body_charset, CS_ISO_2022_JP)) {
+ gchar *tmp;
+ tmp = strchomp_all(buf);
+ g_free(buf);
+ buf = tmp;
+ } else
+ encoding = ENC_QUOTED_PRINTABLE;
+ } else if (encoding == ENC_8BIT) {
+ encoding = procmime_get_encoding_for_str(buf);
+ if (encoding == ENC_7BIT)
+ encoding = ENC_QUOTED_PRINTABLE;
+ }
}
if (rfc2015_is_available() && !is_draft &&