--- libbalsa/mime.c.html_internal	Tue Aug 21 14:31:38 2001
+++ libbalsa/mime.c	Tue Aug 21 15:11:07 2001
@@ -27,6 +27,9 @@
 #include "libbalsa.h"
 #include "mailbackend.h"
 
+#define HTML_TO_TEXT "lynx -force_html -dump file:%s > %s" /* *** FIXME: Set via ./configure */
+
+
 /* FIXME: The content of this file could go to message.c */
 
 static GString *process_mime_multipart(LibBalsaMessage * message,
@@ -83,9 +86,9 @@
     return tag;
 }
 
-gchar *convert_html(const gchar *html)
-/* Remarks: This is just a quick hack - look for external library routine 
-            that will do this */
+static gchar *convert_html_internal(const gchar *html)
+/* Remarks: Fall-back used when no real HTML converter was configured, or 
+            call failed. */
 {
     gchar *txt=calloc(strlen(html)+1, sizeof(gchar));
 
@@ -161,6 +164,47 @@
 	}
     }
     return txt;
+}
+
+gchar *convert_html(const gchar *html)
+{
+#ifdef HTML_TO_TEXT
+    gchar html_file[PATH_MAX + 1], txt_file[PATH_MAX + 1];
+    gchar *txt=NULL;
+    FILE *fp;
+
+    libbalsa_lock_mutt();
+    mutt_mktemp(html_file);
+    mutt_mktemp(txt_file);
+    libbalsa_unlock_mutt();
+
+    fp=safe_fopen(html_file, "w");
+    
+    if(fp) {
+	char cmd[PATH_MAX + 1];
+
+	fprintf(fp, "%s", html);
+	fclose(fp);
+
+	snprintf(cmd, sizeof(cmd), HTML_TO_TEXT, html_file, txt_file);
+	/*** FIXME: Use gnome_execute_shell - but not directly, as we need to
+ 	            wait for result. */
+	if(system(cmd)>=0) {
+	    fp=fopen(txt_file, "r");
+	    if(fp) {
+		libbalsa_readfile(fp, &txt);
+		fclose(fp);
+	    }
+	}
+    }
+    unlink(txt_file);
+    unlink(html_file);
+
+    if(txt)
+	return txt;
+
+#endif
+    return convert_html_internal(html);
 }
 
 
