aboutsummaryrefslogtreecommitdiff
path: root/libsylph
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 /libsylph
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
Diffstat (limited to 'libsylph')
-rw-r--r--libsylph/procmime.c37
-rw-r--r--libsylph/procmime.h3
2 files changed, 38 insertions, 2 deletions
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__ */