diff -Nru ../kannel-snapshot-cvs-20040226/gw/wap-appl.c gw/wap-appl.c
--- ../kannel-snapshot-cvs-20040226/gw/wap-appl.c	2004-01-22 16:08:24.000000000 +0200
+++ gw/wap-appl.c	2004-03-04 20:26:44.000000000 +0200
@@ -732,7 +732,7 @@
 
     /* ensure we pass only the orginal headers to the convertion routine */
     device_headers = (orig_event->type == S_MethodInvoke_Ind) ?
-        orig_event->u.S_MethodInvoke_Ind.request_headers :
+        orig_event->u.S_MethodInvoke_Ind.session_headers :
         orig_event->u.S_Unit_MethodInvoke_Ind.request_headers;
     if (device_headers == NULL)
         device_headers = list_create();
@@ -844,14 +844,18 @@
             octstr_search(content.type, octstr_imm("application/vnd.wap.xhtml+xml"), 0) >= 0) {
             Octstr *charset;
             
-            /* get charset used in content body, default to utf-8 if not present */
+            /* get charset used in content body or http header, default to utf-8 if not present */
             if ((charset = find_charset_encoding(content.body)) == NULL)
-                charset = octstr_imm("UTF-8"); 
+		if (octstr_len(content.charset) > 0) {
+			charset = octstr_duplicate(content.charset);
+		} else {
+			charset = octstr_create("UTF-8");
+		}
 
             /* convert to utf-8 if original charset is not utf-8 
              * and device supports it */
 
-            if (octstr_case_compare(charset, octstr_imm("UTF-8")) < 0 &&
+            if (octstr_case_compare(charset, octstr_imm("UTF-8")) != 0 &&
                 !http_charset_accepted(device_headers, octstr_get_cstr(charset))) {
                 if (!http_charset_accepted(device_headers, "UTF-8")) {
                     warning(0, "WSP: Device doesn't support charset <%s> neither UTF-8", 
@@ -865,13 +869,16 @@
                         octstr_destroy(content.charset);
                         content.charset = octstr_create("UTF-8");
                         /* XXX it might be good idea to change <?xml...encoding?> */
+			if (delete_charset_encoding(content.body))
+				debug("wsp",0,"Delete encoding=\"%s\" from <?xml ... ?> ",
+					octstr_get_cstr(charset));
                     }
                  }
             }
  
             /* convert to iso-8859-1 if original charset is not iso 
              * and device supports it */
-            else if (octstr_case_compare(charset, octstr_imm("ISO-8859-1")) < 0 &&
+            else if (octstr_case_compare(charset, octstr_imm("ISO-8859-1")) != 0 &&
                     !http_charset_accepted(device_headers, octstr_get_cstr(charset))) {
                 if (!http_charset_accepted(device_headers, "ISO-8859-1")) {
                     warning(0, "WSP: Device doesn't support charset <%s> neither ISO-8859-1", 
@@ -885,6 +892,9 @@
                         octstr_destroy(content.charset);
                         content.charset = octstr_create("ISO-8859-1");
                         /* XXX it might be good idea to change <?xml...encoding?> */
+			if (delete_charset_encoding(content.body))
+				debug("wsp",0,"Delete encoding=\"%s\" from <?xml ... ?> ",
+					octstr_get_cstr(charset));
                     }
                 }
             }
diff -Nru ../kannel-snapshot-cvs-20040226/gw/wml_compiler.c gw/wml_compiler.c
--- ../kannel-snapshot-cvs-20040226/gw/wml_compiler.c	2004-02-16 20:55:22.000000000 +0200
+++ gw/wml_compiler.c	2004-03-04 19:11:48.000000000 +0200
@@ -348,7 +348,7 @@
 
     /* transcode from charset to UTF-8 */
     if (charset && octstr_len(charset) && 
-        octstr_case_compare(charset, octstr_imm("UTF-8")) == -1) {
+        octstr_case_compare(charset, octstr_imm("UTF-8")) != 0) {
         debug("wml_compile", 0, "WML compiler: Transcoding from <%s> to UTF-8", 
               octstr_get_cstr(charset));
         set_charset(wml_text, charset);
diff -Nru ../kannel-snapshot-cvs-20040226/gw/xml_shared.c gw/xml_shared.c
--- ../kannel-snapshot-cvs-20040226/gw/xml_shared.c	2004-01-22 16:08:24.000000000 +0200
+++ gw/xml_shared.c	2004-03-04 20:44:11.000000000 +0200
@@ -153,6 +153,25 @@
     return encoding;
 }
 
+/*
+ * delete_charset_encoding -- parses for a encoding argument within
+ * the xml preabmle, ie. <?xml verion="xxx" encoding="ISO-8859-1"?> 
+ * and delete it.
+ */
+int delete_charset_encoding(Octstr *document)
+{
+    long gt = 0, enc = 0;
+
+    enc = octstr_search(document, octstr_imm(" encoding="), 0);
+    gt = octstr_search(document, octstr_imm("?>"), 0);
+
+    if (enc < 0 || enc + 10 > gt) 
+        return 0;
+
+    octstr_delete(document, enc, gt - enc );
+    return 1;
+}
+
 
 /*
  * only_blanks - checks if a text node contains only white space, when it can 
diff -Nru ../kannel-snapshot-cvs-20040226/gw/xml_shared.h gw/xml_shared.h
--- ../kannel-snapshot-cvs-20040226/gw/xml_shared.h	2004-01-22 16:08:24.000000000 +0200
+++ gw/xml_shared.h	2004-03-04 20:45:03.000000000 +0200
@@ -104,6 +104,13 @@
 Octstr *find_charset_encoding(Octstr *document);
 
 /*
+ * delete_charset_encoding -- parses for a encoding argument within
+ * the xml preabmle, ie. <?xml verion="xxx" encoding="ISO-8859-1"?> 
+ * and delete it.
+ */
+int delete_charset_encoding(Octstr *document);
+
+/*
  * element_check_content - a helper function for checking if an element has 
  * content or attributes. Returns status bit for attributes (0x80) and another
  * for content (0x40) added into one octet.
