From 81a8190f4d157d2be6414f28108c449c8a76b6c8 Mon Sep 17 00:00:00 2001
From: "Dr. Werner Fink" <werner@suse.com>
Date: Mon, 22 Apr 2013 09:36:06 +0000
Subject: [PATCH] .

OBS-URL: https://build.opensuse.org/package/show/server:mail/mutt?expand=0&rev=91
---
 mutt.changes         |  4 +--
 mutt.spec            | 38 ++++++++++++++++++++++++++---
 widechar.sidebar.dif | 58 +++++++++++++++++++++++++++++---------------
 3 files changed, 74 insertions(+), 26 deletions(-)

diff --git a/mutt.changes b/mutt.changes
index dd848b9..31d0bf7 100644
--- a/mutt.changes
+++ b/mutt.changes
@@ -1,8 +1,8 @@
 -------------------------------------------------------------------
 Thu Apr 18 12:54:39 UTC 2013 - werner@suse.de
 
-- Add widechar.sidebar.dif: bnc#813498 - mutt crashes in fgetwc in
-  text_enriched_handler
+- Add widechar.sidebar.dif as workaround: bnc#813498 - mutt crashes
+  in fgetwc in text_enriched_handler
 
 -------------------------------------------------------------------
 Mon Jan 14 09:11:05 UTC 2013 - werner@suse.de
diff --git a/mutt.spec b/mutt.spec
index 4970356..28e94b6 100644
--- a/mutt.spec
+++ b/mutt.spec
@@ -133,12 +133,42 @@ cp %{S:2} .
 %if 0%{?suse_version} > 1100
 autoreconf -fi
 %endif
+  cflags ()
+  {
+    local flag=$1; shift
+    local var=$1; shift
+    test -n "${flag}" -a -n "${var}" || return
+    case "${!var}" in
+    *${flag}*) return
+    esac
+    set -o noclobber
+    case "$flag" in
+    -Wl,*)
+	if echo 'int main () { return 0; }' | \
+	    ${CC:-gcc} -Werror $flag -o /dev/null -xc - > /dev/null 2>&1 ; then
+	    eval $var=\${$var:+\$$var\ }$flag
+	fi
+	;;
+    *)
+	if ${CC:-gcc} -Werror $flag -S -o /dev/null -xc /dev/null > /dev/null 2>&1 ; then
+	    eval $var=\${$var:+\$$var\ }$flag
+	fi
+    esac
+    set +o noclobber
+  }
 CC=gcc
-CFLAGS="-Wall $RPM_OPT_FLAGS -I. -D_GNU_SOURCE -fno-strict-aliasing"
-CFLAGS="$CFLAGS -fstack-protector"
-#CFLAGS="$CFLAGS -DSUSE_IMAP_FORCE_SSL"
+CFLAGS="-Wall $RPM_OPT_FLAGS -I. -D_GNU_SOURCE"
+#cflags -DSUSE_IMAP_FORCE_SSL		CFLAGS
+cflags -std=gnu99			CFLAGS
+cflags -fno-strict-aliasing		CFLAGS
+cflags -fstack-protector		CFLAGS
+cflags -g3				CFLAGS
+cflags -pipe				CFLAGS
+cflags -Wl,--as-needed			LDFLAGS
+cflags -Wl,-O2				LDFLAGS
+cflags -Wl,--hash-size=8599		LDFLAGS
 KRB5CFGPATH=%{S:6}
-export CC CFLAGS KRB5CFGPATH
+export CC CFLAGS LDFLAGS KRB5CFGPATH
 chmod 755 $KRB5CFGPATH
 ./configure $RPM_ARCH-suse-linux \
 	--prefix=%{_prefix} \
diff --git a/widechar.sidebar.dif b/widechar.sidebar.dif
index ec4bc99..34e3cc7 100644
--- a/widechar.sidebar.dif
+++ b/widechar.sidebar.dif
@@ -1,22 +1,40 @@
 --- handler.c
-+++ handler.c	2013-04-18 12:51:41.414000078 +0000
-@@ -1650,7 +1650,7 @@ int mutt_body_handler (BODY *b, STATE *s
- 	/* decode to a tempfile, saving the original destination */
- 	fp = s->fpout;
- #ifdef HAVE_FMEMOPEN
--	if ((s->fpout = open_memstream(&temp, &tempsize)) == NULL)
-+	if ((s->fpout = open_wmemstream(&temp, &tempsize)) == NULL)
++++ handler.c
+@@ -778,7 +778,7 @@ static void enriched_set_flags (const wchar_t *tag, struct enriched_state *stte)
+ static int text_enriched_handler (BODY *a, STATE *s)
+ {
+   enum {
+-    TEXT, LANGLE, TAG, BOGUS_TAG, NEWLINE, ST_EOF, DONE
++    TEXT, TEXT_GOTWC, LANGLE, TAG, BOGUS_TAG, NEWLINE, ST_EOF, DONE
+   } state = TEXT;
+ 
+   long bytes = a->length;
+@@ -807,7 +807,7 @@ static int text_enriched_handler (BODY *a, STATE *s)
+   {
+     if (state != ST_EOF)
+     {
+-      if (!bytes || (wc = fgetwc (s->fpin)) == WEOF)
++      if (state != TEXT_GOTWC && (!bytes || (fscanf (s->fpin, "%lc", &wc)) == EOF))
+ 	state = ST_EOF;
+       else
+ 	bytes--;
+@@ -815,6 +815,8 @@ static int text_enriched_handler (BODY *a, STATE *s)
+ 
+     switch (state)
+     {
++      case TEXT_GOTWC:
++	state = TEXT;
+       case TEXT :
+ 	switch (wc)
  	{
- 	  mutt_error _("Unable to open memory stream!");
- 	  dprint (1, (debugfile, "Can't open memory stream.\n"));
---- pattern.c
-+++ pattern.c	2013-04-18 12:52:06.573939217 +0000
-@@ -168,7 +168,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat
-       s.fpin = msg->fp;
-       s.flags = M_CHARCONV;
- #ifdef HAVE_FMEMOPEN
--      if((s.fpout = open_memstream(&temp, &tempsize)) == NULL)
-+      if((s.fpout = open_wmemstream(&temp, &tempsize)) == NULL)
-       {
- 	mutt_perror ("Error opening memstream");
- 	return (0);
+@@ -875,9 +877,8 @@ static int text_enriched_handler (BODY *a, STATE *s)
+ 	  enriched_flush (&stte, 1);
+ 	else
+ 	{
+-	  ungetwc (wc, s->fpin);
+ 	  bytes++;
+-	  state = TEXT;
++	  state = TEXT_GOTWC;
+ 	}
+ 	break;
+