aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2002-07-23 07:10:00 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2002-07-23 07:10:00 +0800
commit22a346a7e4314788bdaa54f930c5b6737d598cd2 (patch)
treea3026f57ebdd24c2cb1278c1a3345a2821c1f03f
parent9df96068c2509185c9ddcc3115828a673cda949e (diff)
downloadgsoc2013-evolution-22a346a7e4314788bdaa54f930c5b6737d598cd2.tar
gsoc2013-evolution-22a346a7e4314788bdaa54f930c5b6737d598cd2.tar.gz
gsoc2013-evolution-22a346a7e4314788bdaa54f930c5b6737d598cd2.tar.bz2
gsoc2013-evolution-22a346a7e4314788bdaa54f930c5b6737d598cd2.tar.lz
gsoc2013-evolution-22a346a7e4314788bdaa54f930c5b6737d598cd2.tar.xz
gsoc2013-evolution-22a346a7e4314788bdaa54f930c5b6737d598cd2.tar.zst
gsoc2013-evolution-22a346a7e4314788bdaa54f930c5b6737d598cd2.zip
Check to make sure the script output is valid UTF-8, if not then attempt
2002-07-22 Jeffrey Stedfast <fejj@ximian.com> * mail-config.c (mail_config_signature_run_script): Check to make sure the script output is valid UTF-8, if not then attempt to convert it into UTF-8. Fixes bug #28086. svn path=/trunk/; revision=17536
-rw-r--r--mail/ChangeLog6
-rw-r--r--mail/mail-config.c70
2 files changed, 58 insertions, 18 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 819301769a..18b383cc3d 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,9 @@
+2002-07-22 Jeffrey Stedfast <fejj@ximian.com>
+
+ * mail-config.c (mail_config_signature_run_script): Check to make
+ sure the script output is valid UTF-8, if not then attempt to
+ convert it into UTF-8. Fixes bug #28086.
+
2002-07-22 Not Zed <NotZed@Ximian.com>
* message-list.c (regen_list_regened): Remove the assert, and
diff --git a/mail/mail-config.c b/mail/mail-config.c
index 0cef4dc0fa..9e639ee2a5 100644
--- a/mail/mail-config.c
+++ b/mail/mail-config.c
@@ -2921,7 +2921,7 @@ mail_config_signature_run_script (gchar *script)
if (!(pid = fork ())) {
/* child process */
int maxfd, i;
-
+
close (in_fds [0]);
if (dup2 (in_fds[1], STDOUT_FILENO) < 0)
_exit (255);
@@ -2945,22 +2945,59 @@ mail_config_signature_run_script (gchar *script)
g_warning ("Failed to create create child process '%s': %s", script, g_strerror (errno));
return NULL;
} else {
-#define BUFFER_SIZE 4096
- GString *str = g_string_new (NULL);
- gchar *rv;
- gchar buffer [BUFFER_SIZE];
- ssize_t rb;
-
+ CamelStreamFilter *filtered_stream;
+ CamelStreamMem *memstream;
+ CamelMimeFilter *charenc;
+ CamelStream *stream;
+ GByteArray *buffer;
+ const char *charset;
+ char *content;
+
/* parent process */
close (in_fds[1]);
- while ((rb = read (in_fds [0], buffer, BUFFER_SIZE - 1)) > 0) {
- buffer [rb] = 0;
- g_string_append (str, buffer);
+
+ stream = camel_stream_fs_new_with_fd (in_fds[0]);
+
+ memstream = (CamelStreamMem *) camel_stream_mem_new ();
+ buffer = g_byte_array_new ();
+ camel_stream_mem_set_byte_array (memstream, buffer);
+
+ camel_stream_write_to_stream (stream, (CamelStream *) memstream);
+ camel_object_unref (stream);
+
+ /* signature scripts are supposed to generate UTF-8 content, but because users
+ are known to not ever read the manual... we try to do our best if the
+ content isn't valid UTF-8 by assuming that the content is in the user's
+ preferred charset. */
+ if (!g_utf8_validate (buffer->data, buffer->len, NULL)) {
+ stream = (CamelStream *) memstream;
+ memstream = (CamelStreamMem *) camel_stream_mem_new ();
+ camel_stream_mem_set_byte_array (memstream, g_byte_array_new ());
+
+ filtered_stream = camel_stream_filter_new_with_stream (stream);
+ camel_object_unref (stream);
+
+ charset = mail_config_get_default_charset ();
+ charenc = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "utf-8");
+ camel_stream_filter_add (filtered_stream, charenc);
+ camel_object_unref (charenc);
+
+ camel_stream_write_to_stream ((CamelStream *) filtered_stream, (CamelStream *) memstream);
+ camel_object_unref (filtered_stream);
+ g_byte_array_free (buffer, TRUE);
+
+ buffer = memstream->buffer;
}
-
- close (in_fds [0]);
+
+ camel_object_unref (memstream);
+
+ g_byte_array_append (buffer, "", 1);
+ content = buffer->data;
+ g_byte_array_free (buffer, FALSE);
+
+ /* wait for the script process to terminate */
result = waitpid (pid, &status, 0);
-
+
if (result == -1 && errno == EINTR) {
/* child process is hanging... */
kill (pid, SIGTERM);
@@ -2973,11 +3010,8 @@ mail_config_signature_run_script (gchar *script)
result = waitpid (pid, &status, WNOHANG);
}
}
-
- rv = str->str;
- g_string_free (str, FALSE);
-
- return rv;
+
+ return content;
}
}