[balsa/gtk3] Check charset of attached file correctly.
- From: Peter Bloomfield <PeterB src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/gtk3] Check charset of attached file correctly.
- Date: Wed, 31 Aug 2011 22:33:39 +0000 (UTC)
commit 3768263234ce1aaae7746e58b7455dea6114fa09
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Wed Aug 31 18:32:18 2011 -0400
Check charset of attached file correctly.
* libbalsa/misc.c (libbalsa_text_attr_file): use GFile methods.
* src/sendmsg-window.c (sw_set_charset): check for error return.
ChangeLog | 5 +++++
libbalsa/misc.c | 46 +++++++++++++++++++++++++++++-----------------
src/sendmsg-window.c | 12 +++++++-----
3 files changed, 41 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 85e6579..5c5fbf5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-08-31 Peter Bloomfield
+
+ * libbalsa/misc.c (libbalsa_text_attr_file): use GFile methods.
+ * src/sendmsg-window.c (sw_set_charset): check for error return.
+
2011-08-30 Peter Bloomfield
* src/main-window.c: call gtk_container_resize_children after
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index 24088d6..e385597 100644
--- a/libbalsa/misc.c
+++ b/libbalsa/misc.c
@@ -1,23 +1,21 @@
/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
/* Balsa E-Mail Client
*
- * Copyright (C) 1997-2003 Stuart Parmenter and others,
+ * Copyright (C) 1997-2011 Stuart Parmenter and others,
* See the file AUTHORS for a list.
*
* 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
- * the Free Software Foundation; either version 2, or (at your option)
+ * the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* The routines that go here should depend only on common libraries - so that
@@ -736,12 +734,16 @@ libbalsa_text_attr_string(const gchar * string)
return attr;
}
-/* Return text attributes of the contents of a file. */
+/* Return text attributes of the contents of a file;
+ * filename is in URI form;
+ * returns -1 on error. */
LibBalsaTextAttribute
libbalsa_text_attr_file(const gchar * filename)
{
+ GFile *file;
+ GFileInputStream *stream;
+ gssize bytes;
LibBalsaTextAttribute attr;
- FILE *fp;
gchar buf[80];
gchar *new_chars = buf;
gboolean has_esc = FALSE;
@@ -749,16 +751,23 @@ libbalsa_text_attr_file(const gchar * filename)
gboolean has_hi_ctrl = FALSE;
gboolean is_utf8 = TRUE;
- fp = fopen(filename, "r");
- if (!fp)
- return 0;
+ file = g_file_new_for_uri(filename);
+ stream = g_file_read(file, NULL, NULL);
+ g_object_unref(file);
+ if (!stream)
+ return -1;
- while (fgets(new_chars, (sizeof buf) - (new_chars - buf), fp)) {
- gboolean test_bits = !has_esc || !has_hi_bit || !has_hi_ctrl;
+ while ((bytes = g_input_stream_read(G_INPUT_STREAM(stream), new_chars,
+ (sizeof buf) - (new_chars - buf), NULL,
+ NULL)) > 0) {
+ gboolean test_bits;
+ test_bits = !has_esc || !has_hi_bit || !has_hi_ctrl;
if (!test_bits && !is_utf8)
break;
+ new_chars[bytes] = 0;
+
if (test_bits)
lb_text_attr(new_chars, &has_esc, &has_hi_bit, &has_hi_ctrl);
@@ -778,7 +787,10 @@ libbalsa_text_attr_file(const gchar * filename)
}
}
- fclose(fp);
+ g_object_unref(stream);
+
+ if (bytes < 0)
+ return -1;
attr = 0;
if (has_esc)
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index b10c40b..6f9bc0a 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -1,6 +1,6 @@
/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
/* Balsa E-Mail Client
- * Copyright (C) 1998-2010 Stuart Parmenter and others, see AUTHORS file.
+ * Copyright (C) 1998-2011 Stuart Parmenter and others, see AUTHORS file.
*
* 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
@@ -13,9 +13,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* FONT SELECTION DISCUSSION:
@@ -1923,7 +1921,11 @@ sw_set_charset(BalsaSendmsg * bsmsg, const gchar * filename,
gchar ** attach_charset)
{
const gchar *charset;
- LibBalsaTextAttribute attr = libbalsa_text_attr_file(filename);
+ LibBalsaTextAttribute attr;
+
+ attr = libbalsa_text_attr_file(filename);
+ if ((gint) attr < 0)
+ return FALSE;
if (attr == 0)
charset = "us-ascii";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]