[balsa] Check charset of attached file correctly.
- From: Peter Bloomfield <PeterB src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] Check charset of attached file correctly.
- Date: Thu, 1 Sep 2011 12:34:43 +0000 (UTC)
commit fa4b17166bbb25ee4618d58975afe26bb6cf7fdc
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 | 22 ++++++++++++----------
3 files changed, 46 insertions(+), 27 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7d0ff0c..07ad5d2 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-29 Pawel Salek
* libbalsa/filter-funcs.c: implement libbalsa_condition_to_string_user
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index 14f44db..6e05f32 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
@@ -744,12 +742,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;
@@ -757,16 +759,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);
@@ -786,7 +795,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 bf663b7..b3169ca 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -1,21 +1,19 @@
/* -*-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
- * 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/>.
*/
/* FONT SELECTION DISCUSSION:
@@ -1931,7 +1929,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]