claws-mail/src/html.c

656 lines
16 KiB
C
Raw Normal View History

2001-04-19 14:21:46 +02:00
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
2006-01-13 [paul] 1.9.100cvs142 * src/account.c * src/account.h * src/action.c * src/action.h * src/adbookbase.h * src/addr_compl.c * src/addr_compl.h * src/addrbook.c * src/addrcache.c * src/addrcache.h * src/addrcindex.c * src/addrcindex.h * src/addrclip.c * src/addrclip.h * src/addrdefs.h * src/addressadd.c * src/addressadd.h * src/addressbook.c * src/addressbook.h * src/addrgather.c * src/addrgather.h * src/addrharvest.c * src/addrharvest.h * src/addrindex.c * src/addrindex.h * src/addritem.c * src/addritem.h * src/addrquery.c * src/addrquery.h * src/addrselect.c * src/addrselect.h * src/alertpanel.c * src/alertpanel.h * src/browseldap.c * src/browseldap.h * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/customheader.c * src/customheader.h * src/displayheader.c * src/displayheader.h * src/editaddress.c * src/editaddress.h * src/editbook.c * src/editbook.h * src/editgroup.c * src/editgroup.h * src/editjpilot.c * src/editjpilot.h * src/editldap.c * src/editldap.h * src/editldap_basedn.c * src/editldap_basedn.h * src/editvcard.c * src/editvcard.h * src/exphtmldlg.c * src/exphtmldlg.h * src/expldifdlg.c * src/expldifdlg.h * src/export.h * src/exporthtml.c * src/exporthtml.h * src/exportldif.c * src/exportldif.h * src/filtering.c * src/filtering.h * src/folder.c * src/folder.h * src/folder_item_prefs.c * src/folder_item_prefs.h * src/foldersel.c * src/foldersel.h * src/folderutils.c * src/folderutils.h * src/folderview.c * src/folderview.h * src/grouplistdialog.c * src/grouplistdialog.h * src/headerview.c * src/html.c * src/html.h * src/image_viewer.c * src/image_viewer.h * src/imap.c * src/imap.h * src/imap_gtk.c * src/imap_gtk.h * src/import.h * src/importldif.c * src/importldif.h * src/importmutt.c * src/importmutt.h * src/importpine.c * src/importpine.h * src/inc.c * src/inc.h * src/jpilot.c * src/jpilot.h * src/ldapctrl.c * src/ldapctrl.h * src/ldaplocate.c * src/ldaplocate.h * src/ldapquery.c * src/ldapquery.h * src/ldapserver.c * src/ldapserver.h * src/ldaputil.c * src/ldaputil.h * src/ldif.c * src/ldif.h * src/main.c * src/main.h * src/mainwindow.c * src/mainwindow.h * src/manual.c * src/manual.h * src/mbox.c * src/mbox.h * src/message_search.c * src/message_search.h * src/messageview.c * src/messageview.h * src/mh.c * src/mh.h * src/mh_gtk.c * src/mh_gtk.h * src/mimeview.c * src/mimeview.h * src/msgcache.c * src/msgcache.h * src/mutt.c * src/mutt.h * src/news.c * src/news.h * src/news_gtk.c * src/news_gtk.h * src/partial_download.c * src/partial_download.h * src/pine.c * src/pine.h * src/pop.c * src/pop.h * src/prefs_account.c * src/prefs_account.h * src/prefs_actions.c * src/prefs_actions.h * src/prefs_common.c * src/prefs_common.h * src/prefs_compose_writing.c * src/prefs_compose_writing.h * src/prefs_customheader.c * src/prefs_customheader.h * src/prefs_display_header.c * src/prefs_display_header.h * src/prefs_filtering.c * src/prefs_filtering.h * src/prefs_filtering_action.c * src/prefs_filtering_action.h * src/prefs_folder_column.c * src/prefs_folder_column.h * src/prefs_folder_item.c * src/prefs_folder_item.h * src/prefs_fonts.c * src/prefs_fonts.h * src/prefs_gtk.c * src/prefs_gtk.h * src/prefs_image_viewer.c * src/prefs_image_viewer.h * src/prefs_matcher.c * src/prefs_matcher.h * src/prefs_message.c * src/prefs_msg_colors.c * src/prefs_msg_colors.h * src/prefs_other.c * src/prefs_quote.c * src/prefs_receive.c * src/prefs_send.c * src/prefs_spelling.c * src/prefs_spelling.h * src/prefs_summaries.c * src/prefs_summaries.h * src/prefs_summary_column.c * src/prefs_summary_column.h * src/prefs_template.c * src/prefs_template.h * src/prefs_themes.c * src/prefs_themes.h * src/prefs_toolbar.c * src/prefs_toolbar.h * src/prefs_wrapping.c * src/prefs_wrapping.h * src/privacy.c * src/privacy.h * src/procheader.c * src/procheader.h * src/procmime.c * src/procmime.h * src/procmsg.c * src/procmsg.h * src/quote_fmt.c * src/quote_fmt_parse.y * src/recv.c * src/recv.h * src/remotefolder.c * src/remotefolder.h * src/send_message.c * src/send_message.h * src/setup.c * src/setup.h * src/sourcewindow.c * src/sourcewindow.h * src/ssl_manager.c * src/ssl_manager.h * src/statusbar.c * src/statusbar.h * src/stock_pixmap.c * src/stock_pixmap.h * src/summary_search.c * src/summary_search.h * src/summaryview.c * src/summaryview.h * src/syldap.c * src/syldap.h * src/textview.c * src/textview.h * src/toolbar.c * src/toolbar.h * src/undo.c * src/undo.h * src/unmime.c * src/unmime.h * src/vcard.c * src/vcard.h * src/wizard.c * src/wizard.h * src/common/base64.c * src/common/base64.h * src/common/defs.h * src/common/hooks.c * src/common/hooks.h * src/common/log.c * src/common/log.h * src/common/mgutils.c * src/common/mgutils.h * src/common/nntp.c * src/common/nntp.h * src/common/passcrypt.c * src/common/passcrypt.h.in * src/common/plugin.c * src/common/plugin.h * src/common/prefs.c * src/common/prefs.h * src/common/progressindicator.c * src/common/progressindicator.h * src/common/quoted-printable.c * src/common/quoted-printable.h * src/common/session.c * src/common/session.h * src/common/smtp.c * src/common/smtp.h * src/common/socket.c * src/common/socket.h * src/common/ssl.c * src/common/ssl.h * src/common/ssl_certificate.c * src/common/ssl_certificate.h * src/common/stringtable.c * src/common/stringtable.h * src/common/sylpheed.c * src/common/sylpheed.h * src/common/template.c * src/common/template.h * src/common/timing.h * src/common/utils.c * src/common/utils.h * src/common/version.h.in * src/common/xml.c * src/common/xml.h * src/common/xmlprops.c * src/common/xmlprops.h * src/gtk/colorlabel.c * src/gtk/colorsel.c * src/gtk/colorsel.h * src/gtk/description_window.c * src/gtk/description_window.h * src/gtk/filesel.c * src/gtk/filesel.h * src/gtk/foldersort.c * src/gtk/foldersort.h * src/gtk/gtkutils.c * src/gtk/gtkutils.h * src/gtk/inputdialog.c * src/gtk/inputdialog.h * src/gtk/logwindow.c * src/gtk/logwindow.h * src/gtk/manage_window.c * src/gtk/manage_window.h * src/gtk/menu.c * src/gtk/menu.h * src/gtk/pluginwindow.c * src/gtk/pluginwindow.h * src/gtk/prefswindow.c * src/gtk/prefswindow.h * src/gtk/progressdialog.c * src/gtk/progressdialog.h * src/gtk/sslcertwindow.c * src/gtk/sslcertwindow.h * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin.h * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_prefs.h * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/pgpcore/passphrase.c * src/plugins/pgpcore/passphrase.h * src/plugins/pgpcore/plugin.c * src/plugins/pgpcore/select-keys.c * src/plugins/pgpcore/select-keys.h * src/plugins/pgpcore/sgpgme.c * src/plugins/pgpcore/sgpgme.h * src/plugins/pgpinline/pgpinline.c * src/plugins/pgpinline/pgpinline.h * src/plugins/pgpinline/plugin.c * src/plugins/pgpmime/pgpmime.c * src/plugins/pgpmime/pgpmime.h * src/plugins/pgpmime/plugin.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin.h * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c update copyright header
2006-01-13 18:24:38 +01:00
* Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
2001-04-19 14:21:46 +02:00
*
* 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 of the License, 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
* 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
2005-09-21 [paul] 1.9.14cvs47 * README * README.jp * configure.ac * config/config.rpath * doc/manual/en/sylpheed-20.html * doc/manual/es/sylpheed-20.html * po/bg.po * po/ca.po * po/de.po * po/es.po * po/fr.po * po/it.po * po/pt_BR.po * po/sk.po * po/zh_TW.po * src/account.c * src/account.h * src/action.c * src/action.h * src/adbookbase.h * src/addr_compl.c * src/addr_compl.h * src/addrbook.c * src/addrbook.h * src/addrcache.c * src/addrcache.h * src/addrcindex.c * src/addrcindex.h * src/addrclip.c * src/addrclip.h * src/addrdefs.h * src/addressadd.c * src/addressadd.h * src/addressbook.c * src/addressbook.h * src/addressitem.h * src/addrgather.c * src/addrgather.h * src/addrharvest.c * src/addrharvest.h * src/addrindex.c * src/addrindex.h * src/addritem.c * src/addritem.h * src/addrquery.c * src/addrquery.h * src/addrselect.c * src/addrselect.h * src/alertpanel.c * src/alertpanel.h * src/browseldap.c * src/browseldap.h * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/crash.c * src/crash.h * src/customheader.c * src/customheader.h * src/displayheader.c * src/displayheader.h * src/editaddress.c * src/editaddress.h * src/editbook.c * src/editbook.h * src/editgroup.c * src/editgroup.h * src/editjpilot.c * src/editjpilot.h * src/editldap.c * src/editldap.h * src/editldap_basedn.c * src/editldap_basedn.h * src/editvcard.c * src/editvcard.h * src/enriched.c * src/enriched.h * src/exphtmldlg.c * src/exphtmldlg.h * src/expldifdlg.c * src/expldifdlg.h * src/export.c * src/export.h * src/exporthtml.c * src/exporthtml.h * src/exportldif.c * src/exportldif.h * src/filtering.c * src/filtering.h * src/folder.c * src/folder.h * src/folder_item_prefs.c * src/folder_item_prefs.h * src/foldersel.c * src/foldersel.h * src/folderutils.c * src/folderutils.h * src/folderview.c * src/folderview.h * src/grouplistdialog.c * src/grouplistdialog.h * src/headerview.c * src/headerview.h * src/html.c * src/html.h * src/image_viewer.c * src/image_viewer.h * src/imap.c * src/imap.h * src/imap_gtk.c * src/imap_gtk.h * src/import.c * src/import.h * src/importldif.c * src/importldif.h * src/importmutt.c * src/importmutt.h * src/importpine.c * src/importpine.h * src/inc.c * src/inc.h * src/jpilot.c * src/jpilot.h * src/ldapctrl.c * src/ldapctrl.h * src/ldaplocate.c * src/ldaplocate.h * src/ldapquery.c * src/ldapquery.h * src/ldapserver.c * src/ldapserver.h * src/ldaputil.c * src/ldaputil.h * src/ldif.c * src/ldif.h * src/localfolder.c * src/localfolder.h * src/main.c * src/main.h * src/mainwindow.c * src/mainwindow.h * src/manual.c * src/manual.h * src/matcher.c * src/matcher.h * src/matcher_parser.h * src/matcher_parser_lex.l * src/matcher_parser_parse.y * src/mbox.c * src/mbox.h * src/message_search.c * src/message_search.h * src/messageview.c * src/messageview.h * src/mh.c * src/mh.h * src/mh_gtk.c * src/mh_gtk.h * src/mimeview.c * src/mimeview.h * src/msgcache.c * src/msgcache.h * src/mutt.c * src/mutt.h * src/news.c * src/news.h * src/news_gtk.c * src/news_gtk.h * src/noticeview.c * src/noticeview.h * src/partial_download.c * src/partial_download.h * src/pine.c * src/pine.h * src/pop.c * src/pop.h * src/prefs_account.c * src/prefs_account.h * src/prefs_actions.c * src/prefs_actions.h * src/prefs_common.c * src/prefs_common.h * src/prefs_compose_writing.c * src/prefs_compose_writing.h * src/prefs_customheader.c * src/prefs_customheader.h * src/prefs_display_header.c * src/prefs_display_header.h * src/prefs_ext_prog.c * src/prefs_ext_prog.h * src/prefs_filtering.c * src/prefs_filtering.h * src/prefs_filtering_action.c * src/prefs_filtering_action.h * src/prefs_folder_column.c * src/prefs_folder_column.h * src/prefs_folder_item.c * src/prefs_folder_item.h * src/prefs_fonts.c * src/prefs_fonts.h * src/prefs_gtk.c * src/prefs_gtk.h * src/prefs_image_viewer.c * src/prefs_image_viewer.h * src/prefs_matcher.c * src/prefs_matcher.h * src/prefs_message.c * src/prefs_message.h * src/prefs_msg_colors.c * src/prefs_msg_colors.h * src/prefs_other.c * src/prefs_other.h * src/prefs_quote.c * src/prefs_quote.h * src/prefs_receive.c * src/prefs_receive.h * src/prefs_send.c * src/prefs_send.h * src/prefs_spelling.c * src/prefs_spelling.h * src/prefs_summaries.c * src/prefs_summaries.h * src/prefs_summary_column.c * src/prefs_summary_column.h * src/prefs_template.c * src/prefs_template.h * src/prefs_themes.c * src/prefs_themes.h * src/prefs_toolbar.c * src/prefs_toolbar.h * src/prefs_wrapping.c * src/prefs_wrapping.h * src/privacy.c * src/privacy.h * src/procheader.c * src/procheader.h * src/procmime.c * src/procmime.h * src/procmsg.c * src/procmsg.h * src/quote_fmt.c * src/quote_fmt_parse.y * src/recv.c * src/recv.h * src/remotefolder.c * src/remotefolder.h * src/send_message.c * src/send_message.h * src/setup.c * src/setup.h * src/simple-gettext.c * src/sourcewindow.c * src/sourcewindow.h * src/ssl_manager.c * src/ssl_manager.h * src/statusbar.c * src/statusbar.h * src/stock_pixmap.c * src/stock_pixmap.h * src/summary_search.c * src/summary_search.h * src/summaryview.c * src/summaryview.h * src/syldap.c * src/syldap.h * src/textview.c * src/textview.h * src/toolbar.c * src/toolbar.h * src/undo.c * src/undo.h * src/unmime.c * src/unmime.h * src/vcard.c * src/vcard.h * src/wizard.c * src/wizard.h * src/common/base64.c * src/common/base64.h * src/common/defs.h * src/common/hooks.c * src/common/hooks.h * src/common/log.c * src/common/log.h * src/common/md5.c * src/common/md5.h * src/common/mgutils.c * src/common/mgutils.h * src/common/nntp.c * src/common/nntp.h * src/common/passcrypt.c * src/common/passcrypt.h.in * src/common/plugin.c * src/common/plugin.h * src/common/prefs.c * src/common/prefs.h * src/common/progressindicator.c * src/common/progressindicator.h * src/common/quoted-printable.c * src/common/quoted-printable.h * src/common/session.c * src/common/session.h * src/common/smtp.c * src/common/smtp.h * src/common/socket.c * src/common/socket.h * src/common/ssl.c * src/common/ssl.h * src/common/ssl_certificate.c * src/common/ssl_certificate.h * src/common/string_match.c * src/common/string_match.h * src/common/stringtable.c * src/common/sylpheed.c * src/common/sylpheed.h * src/common/template.c * src/common/template.h * src/common/timing.h * src/common/utils.c * src/common/utils.h * src/common/uuencode.c * src/common/uuencode.h * src/common/version.h.in * src/common/xml.c * src/common/xml.h * src/common/xmlprops.c * src/common/xmlprops.h * src/gtk/about.c * src/gtk/about.h * src/gtk/colorlabel.c * src/gtk/colorlabel.h * src/gtk/colorsel.c * src/gtk/colorsel.h * src/gtk/description_window.c * src/gtk/description_window.h * src/gtk/filesel.c * src/gtk/filesel.h * src/gtk/foldersort.c * src/gtk/foldersort.h * src/gtk/gtkutils.c * src/gtk/gtkutils.h * src/gtk/inputdialog.c * src/gtk/inputdialog.h * src/gtk/logwindow.c * src/gtk/logwindow.h * src/gtk/manage_window.c * src/gtk/manage_window.h * src/gtk/menu.c * src/gtk/menu.h * src/gtk/pluginwindow.c * src/gtk/pluginwindow.h * src/gtk/prefswindow.c * src/gtk/prefswindow.h * src/gtk/progressdialog.c * src/gtk/progressdialog.h * src/gtk/quicksearch.c * src/gtk/quicksearch.h * src/gtk/sslcertwindow.c * src/gtk/sslcertwindow.h * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin.h * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_prefs.h * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/mathml_viewer/mathml_viewer.c * src/plugins/pgpcore/passphrase.c * src/plugins/pgpcore/passphrase.h * src/plugins/pgpcore/plugin.c * src/plugins/pgpcore/prefs_gpg.c * src/plugins/pgpcore/prefs_gpg.h * src/plugins/pgpcore/select-keys.c * src/plugins/pgpcore/select-keys.h * src/plugins/pgpcore/sgpgme.c * src/plugins/pgpcore/sgpgme.h * src/plugins/pgpinline/pgpinline.c * src/plugins/pgpinline/pgpinline.h * src/plugins/pgpinline/plugin.c * src/plugins/pgpmime/pgpmime.c * src/plugins/pgpmime/pgpmime.h * src/plugins/pgpmime/plugin.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin.h * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c * tools/OOo2sylpheed.pl * tools/acroread2sylpheed.pl * tools/asus_mailled.sh * tools/filter_conv.pl * tools/freshmeat_search.pl * tools/google_search.pl * tools/kmail2sylpheed.pl * tools/kmail2sylpheed_v2.pl * tools/maildir2sylpheed.pl * tools/multiwebsearch.pl * tools/newscache_clean.pl * tools/outlook2sylpheed.pl * tools/sylpheed-switcher * tools/update-po * tools/vcard2xml.py * tools/kdeservicemenu/sylpheed-kdeservicemenu.pl update FSF address
2005-09-21 20:22:51 +02:00
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2001-04-19 14:21:46 +02:00
*/
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "html.h"
#include "codeconv.h"
#include "utils.h"
#define SC_HTMLBUFSIZE 8192
2001-04-19 14:21:46 +02:00
#define HR_STR "------------------------------------------------"
typedef struct _SC_HTMLSymbol SC_HTMLSymbol;
2001-04-19 14:21:46 +02:00
struct _SC_HTMLSymbol
2001-04-19 14:21:46 +02:00
{
gchar *const key;
gchar *const val;
};
static SC_HTMLSymbol symbol_list[] = {
2001-04-19 14:21:46 +02:00
{"&lt;" , "<"},
{"&gt;" , ">"},
{"&amp;" , "&"},
{"&quot;" , "\""},
{"&lsquo;", "'"},
{"&rsquo;", "'"},
{"&ldquo;", "\""},
{"&rdquo;", "\""},
2001-04-19 14:21:46 +02:00
{"&nbsp;" , " "},
{"&trade;" , "(TM)"},
{"&#153;", "(TM)"},
{"&hellip;", "..."},
2001-04-19 14:21:46 +02:00
};
static SC_HTMLSymbol ascii_symbol_list[] = {
2001-04-19 14:21:46 +02:00
{"&iexcl;" , "^!"},
{"&brvbar;", "|"},
{"&copy;" , "(C)"},
{"&laquo;" , "<<"},
{"&reg;" , "(R)"},
{"&sup2;" , "^2"},
{"&sup3;" , "^3"},
{"&acute;" , "'"},
{"&cedil;" , ","},
{"&sup1;" , "^1"},
{"&raquo;" , ">>"},
{"&frac14;", "1/4"},
{"&frac12;", "1/2"},
{"&frac34;", "3/4"},
{"&iquest;", "^?"},
{"&Agrave;", "A`"},
{"&Aacute;", "A'"},
{"&Acirc;" , "A^"},
{"&Atilde;", "A~"},
{"&AElig;" , "AE"},
{"&Egrave;", "E`"},
{"&Eacute;", "E'"},
{"&Ecirc;" , "E^"},
{"&Igrave;", "I`"},
{"&Iacute;", "I'"},
{"&Icirc;" , "I^"},
{"&Ntilde;", "N~"},
{"&Ograve;", "O`"},
{"&Oacute;", "O'"},
{"&Ocirc;" , "O^"},
{"&Otilde;", "O~"},
{"&Ugrave;", "U`"},
{"&Uacute;", "U'"},
{"&Ucirc;" , "U^"},
{"&Yacute;", "Y'"},
{"&agrave;", "a`"},
{"&aacute;", "a'"},
{"&acirc;" , "a^"},
{"&atilde;", "a~"},
{"&aelig;" , "ae"},
{"&egrave;", "e`"},
{"&eacute;", "e'"},
{"&ecirc;" , "e^"},
{"&igrave;", "i`"},
{"&iacute;", "i'"},
{"&icirc;" , "i^"},
{"&ntilde;", "n~"},
{"&ograve;", "o`"},
{"&oacute;", "o'"},
{"&ocirc;" , "o^"},
{"&otilde;", "o~"},
{"&ugrave;", "u`"},
{"&uacute;", "u'"},
{"&ucirc;" , "u^"},
{"&yacute;", "y'"},
};
static GHashTable *default_symbol_table;
static SC_HTMLState sc_html_read_line (SC_HTMLParser *parser);
static void sc_html_append_char (SC_HTMLParser *parser,
2001-04-19 14:21:46 +02:00
gchar ch);
static void sc_html_append_str (SC_HTMLParser *parser,
2001-04-19 14:21:46 +02:00
const gchar *str,
gint len);
static SC_HTMLState sc_html_parse_tag (SC_HTMLParser *parser);
static void sc_html_parse_special (SC_HTMLParser *parser);
static void sc_html_get_parenthesis (SC_HTMLParser *parser,
2001-04-19 14:21:46 +02:00
gchar *buf,
gint len);
SC_HTMLParser *sc_html_parser_new(FILE *fp, CodeConverter *conv)
2001-04-19 14:21:46 +02:00
{
SC_HTMLParser *parser;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(fp != NULL, NULL);
g_return_val_if_fail(conv != NULL, NULL);
parser = g_new0(SC_HTMLParser, 1);
2001-04-19 14:21:46 +02:00
parser->fp = fp;
parser->conv = conv;
parser->str = g_string_new(NULL);
parser->buf = g_string_new(NULL);
parser->bufp = parser->buf->str;
parser->state = SC_HTML_NORMAL;
2003-03-13 12:12:58 +01:00
parser->href = NULL;
2001-04-19 14:21:46 +02:00
parser->newline = TRUE;
parser->empty_line = TRUE;
parser->space = FALSE;
parser->pre = FALSE;
#define SYMBOL_TABLE_ADD(table, list) \
{ \
gint i; \
\
for (i = 0; i < sizeof(list) / sizeof(list[0]); i++) \
g_hash_table_insert(table, list[i].key, list[i].val); \
}
if (!default_symbol_table) {
default_symbol_table =
g_hash_table_new(g_str_hash, g_str_equal);
SYMBOL_TABLE_ADD(default_symbol_table, symbol_list);
SYMBOL_TABLE_ADD(default_symbol_table, ascii_symbol_list);
}
#undef SYMBOL_TABLE_ADD
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
parser->symbol_table = default_symbol_table;
2001-04-19 14:21:46 +02:00
return parser;
}
void sc_html_parser_destroy(SC_HTMLParser *parser)
2001-04-19 14:21:46 +02:00
{
g_string_free(parser->str, TRUE);
g_string_free(parser->buf, TRUE);
2003-03-13 12:12:58 +01:00
g_free(parser->href);
2001-04-19 14:21:46 +02:00
g_free(parser);
}
gchar *sc_html_parse(SC_HTMLParser *parser)
2001-04-19 14:21:46 +02:00
{
parser->state = SC_HTML_NORMAL;
2001-04-19 14:21:46 +02:00
g_string_truncate(parser->str, 0);
if (*parser->bufp == '\0') {
g_string_truncate(parser->buf, 0);
parser->bufp = parser->buf->str;
if (sc_html_read_line(parser) == SC_HTML_EOF)
2001-04-19 14:21:46 +02:00
return NULL;
}
while (*parser->bufp != '\0') {
switch (*parser->bufp) {
case '<': {
SC_HTMLState st;
st = sc_html_parse_tag(parser);
/* when we see an href, we need to flush the str
* buffer. Then collect all the chars until we
* see the end anchor tag
*/
if (SC_HTML_HREF_BEG == st || SC_HTML_HREF == st)
return parser->str->str;
}
break;
2001-04-19 14:21:46 +02:00
case '&':
sc_html_parse_special(parser);
2001-04-19 14:21:46 +02:00
break;
case ' ':
case '\t':
case '\r':
case '\n':
if (parser->bufp[0] == '\r' && parser->bufp[1] == '\n')
parser->bufp++;
if (!parser->pre) {
if (!parser->newline)
parser->space = TRUE;
parser->bufp++;
break;
}
/* fallthrough */
default:
sc_html_append_char(parser, *parser->bufp++);
2001-04-19 14:21:46 +02:00
}
}
return parser->str->str;
}
static SC_HTMLState sc_html_read_line(SC_HTMLParser *parser)
2001-04-19 14:21:46 +02:00
{
gchar buf[SC_HTMLBUFSIZE];
gchar buf2[SC_HTMLBUFSIZE];
2001-04-19 14:21:46 +02:00
gint index;
if (fgets(buf, sizeof(buf), parser->fp) == NULL) {
parser->state = SC_HTML_EOF;
return SC_HTML_EOF;
2001-04-19 14:21:46 +02:00
}
if (conv_convert(parser->conv, buf2, sizeof(buf2), buf) < 0) {
index = parser->bufp - parser->buf->str;
conv_utf8todisp(buf2, sizeof(buf2), buf);
2003-02-13 10:43:43 +01:00
g_string_append(parser->buf, buf2);
2001-04-19 14:21:46 +02:00
parser->bufp = parser->buf->str + index;
return SC_HTML_CONV_FAILED;
2001-04-19 14:21:46 +02:00
}
index = parser->bufp - parser->buf->str;
g_string_append(parser->buf, buf2);
parser->bufp = parser->buf->str + index;
return SC_HTML_NORMAL;
2001-04-19 14:21:46 +02:00
}
static void sc_html_append_char(SC_HTMLParser *parser, gchar ch)
2001-04-19 14:21:46 +02:00
{
GString *str = parser->str;
if (!parser->pre && parser->space) {
g_string_append_c(str, ' ');
parser->space = FALSE;
}
g_string_append_c(str, ch);
parser->empty_line = FALSE;
if (ch == '\n') {
parser->newline = TRUE;
if (str->len > 1 && str->str[str->len - 2] == '\n')
parser->empty_line = TRUE;
} else
parser->newline = FALSE;
}
static void sc_html_append_str(SC_HTMLParser *parser, const gchar *str, gint len)
2001-04-19 14:21:46 +02:00
{
GString *string = parser->str;
if (!parser->pre && parser->space) {
g_string_append_c(string, ' ');
parser->space = FALSE;
}
if (len == 0) return;
if (len < 0)
g_string_append(string, str);
else {
gchar *s;
Xstrndup_a(s, str, len, return);
g_string_append(string, s);
}
parser->empty_line = FALSE;
if (string->len > 0 && string->str[string->len - 1] == '\n') {
parser->newline = TRUE;
if (string->len > 1 && string->str[string->len - 2] == '\n')
parser->empty_line = TRUE;
} else
parser->newline = FALSE;
}
static SC_HTMLTag *sc_html_get_tag(const gchar *str)
2003-03-13 12:12:58 +01:00
{
SC_HTMLTag *tag;
2003-03-13 12:12:58 +01:00
gchar *tmp;
2004-02-21 12:01:01 +01:00
guchar *tmpp;
2003-03-13 12:12:58 +01:00
g_return_val_if_fail(str != NULL, NULL);
if (*str == '\0' || *str == '!') return NULL;
Xstrdup_a(tmp, str, return NULL);
tag = g_new0(SC_HTMLTag, 1);
2003-03-13 12:12:58 +01:00
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
for (tmpp = tmp; *tmpp != '\0' && !g_ascii_isspace(*tmpp); tmpp++)
2003-03-13 12:12:58 +01:00
;
if (*tmpp == '\0') {
g_strdown(tmp);
tag->name = g_strdup(tmp);
return tag;
} else {
*tmpp++ = '\0';
g_strdown(tmp);
tag->name = g_strdup(tmp);
}
while (*tmpp != '\0') {
SC_HTMLAttr *attr;
2003-03-13 12:12:58 +01:00
gchar *attr_name;
gchar *attr_value;
gchar *p;
gchar quote;
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
while (g_ascii_isspace(*tmpp)) tmpp++;
2003-03-13 12:12:58 +01:00
attr_name = tmpp;
2004-01-12 22:28:31 +01:00
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
while (*tmpp != '\0' && !g_ascii_isspace(*tmpp) &&
*tmpp != '=')
tmpp++;
2004-01-12 22:28:31 +01:00
if (*tmpp != '\0' && *tmpp != '=') {
*tmpp++ = '\0';
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
while (g_ascii_isspace(*tmpp)) tmpp++;
2003-03-13 12:12:58 +01:00
}
2004-01-12 22:28:31 +01:00
if (*tmpp == '=') {
2003-03-13 12:12:58 +01:00
*tmpp++ = '\0';
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
while (g_ascii_isspace(*tmpp)) tmpp++;
2004-01-12 22:28:31 +01:00
if (*tmpp == '"' || *tmpp == '\'') {
/* name="value" */
quote = *tmpp;
tmpp++;
attr_value = tmpp;
if ((p = strchr(attr_value, quote)) == NULL) {
g_warning("sc_html_get_tag(): syntax error in tag: '%s'\n", str);
2004-01-12 22:28:31 +01:00
return tag;
}
tmpp = p;
2003-03-13 12:12:58 +01:00
*tmpp++ = '\0';
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
while (g_ascii_isspace(*tmpp)) tmpp++;
2004-01-12 22:28:31 +01:00
} else {
/* name=value */
attr_value = tmpp;
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
while (*tmpp != '\0' && !g_ascii_isspace(*tmpp)) tmpp++;
2004-01-12 22:28:31 +01:00
if (*tmpp != '\0')
*tmpp++ = '\0';
}
} else
attr_value = "";
2003-03-13 12:12:58 +01:00
g_strchomp(attr_name);
g_strdown(attr_name);
attr = g_new(SC_HTMLAttr, 1);
2003-03-13 12:12:58 +01:00
attr->name = g_strdup(attr_name);
attr->value = g_strdup(attr_value);
tag->attr = g_list_append(tag->attr, attr);
}
return tag;
}
static void sc_html_free_tag(SC_HTMLTag *tag)
2003-03-13 12:12:58 +01:00
{
if (!tag) return;
g_free(tag->name);
while (tag->attr != NULL) {
SC_HTMLAttr *attr = (SC_HTMLAttr *)tag->attr->data;
2003-03-13 12:12:58 +01:00
g_free(attr->name);
g_free(attr->value);
g_free(attr);
tag->attr = g_list_remove(tag->attr, tag->attr->data);
}
g_free(tag);
}
static SC_HTMLState sc_html_parse_tag(SC_HTMLParser *parser)
2001-04-19 14:21:46 +02:00
{
gchar buf[SC_HTMLBUFSIZE];
SC_HTMLTag *tag;
2001-04-19 14:21:46 +02:00
sc_html_get_parenthesis(parser, buf, sizeof(buf));
2001-04-19 14:21:46 +02:00
tag = sc_html_get_tag(buf);
2001-04-19 14:21:46 +02:00
parser->state = SC_HTML_UNKNOWN;
if (!tag) return SC_HTML_UNKNOWN;
2001-04-19 14:21:46 +02:00
2003-03-13 12:12:58 +01:00
if (!strcmp(tag->name, "br")) {
2001-04-19 14:21:46 +02:00
parser->space = FALSE;
sc_html_append_char(parser, '\n');
parser->state = SC_HTML_BR;
2003-03-13 12:12:58 +01:00
} else if (!strcmp(tag->name, "a")) {
GList *cur;
for (cur = tag->attr; cur != NULL; cur = cur->next) {
if (cur->data && !strcmp(((SC_HTMLAttr *)cur->data)->name, "href")) {
g_free(parser->href);
parser->href = g_strdup(((SC_HTMLAttr *)cur->data)->value);
parser->state = SC_HTML_HREF_BEG;
break;
}
2001-10-29 16:42:21 +01:00
}
2003-03-13 12:12:58 +01:00
} else if (!strcmp(tag->name, "/a")) {
parser->state = SC_HTML_HREF;
2003-03-13 12:12:58 +01:00
} else if (!strcmp(tag->name, "p")) {
2001-04-19 14:21:46 +02:00
parser->space = FALSE;
if (!parser->empty_line) {
parser->space = FALSE;
if (!parser->newline) sc_html_append_char(parser, '\n');
sc_html_append_char(parser, '\n');
2001-04-19 14:21:46 +02:00
}
parser->state = SC_HTML_PAR;
2003-03-13 12:12:58 +01:00
} else if (!strcmp(tag->name, "pre")) {
2001-04-19 14:21:46 +02:00
parser->pre = TRUE;
parser->state = SC_HTML_PRE;
2003-03-13 12:12:58 +01:00
} else if (!strcmp(tag->name, "/pre")) {
2001-04-19 14:21:46 +02:00
parser->pre = FALSE;
parser->state = SC_HTML_NORMAL;
2003-03-13 12:12:58 +01:00
} else if (!strcmp(tag->name, "hr")) {
2001-04-19 14:21:46 +02:00
if (!parser->newline) {
parser->space = FALSE;
sc_html_append_char(parser, '\n');
2001-04-19 14:21:46 +02:00
}
sc_html_append_str(parser, HR_STR "\n", -1);
parser->state = SC_HTML_HR;
2003-03-13 12:12:58 +01:00
} else if (!strcmp(tag->name, "div") ||
!strcmp(tag->name, "ul") ||
!strcmp(tag->name, "li") ||
!strcmp(tag->name, "table") ||
!strcmp(tag->name, "tr") ||
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
(tag->name[0] == 'h' && g_ascii_isdigit(tag->name[1]))) {
2001-04-19 14:21:46 +02:00
if (!parser->newline) {
parser->space = FALSE;
sc_html_append_char(parser, '\n');
2001-04-19 14:21:46 +02:00
}
parser->state = SC_HTML_NORMAL;
2003-03-13 12:12:58 +01:00
} else if (!strcmp(tag->name, "/table") ||
(tag->name[0] == '/' &&
tag->name[1] == 'h' &&
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
g_ascii_isdigit(tag->name[1]))) {
2001-04-19 14:21:46 +02:00
if (!parser->empty_line) {
parser->space = FALSE;
if (!parser->newline) sc_html_append_char(parser, '\n');
sc_html_append_char(parser, '\n');
2001-04-19 14:21:46 +02:00
}
parser->state = SC_HTML_NORMAL;
2003-03-13 12:12:58 +01:00
} else if (!strcmp(tag->name, "/div") ||
!strcmp(tag->name, "/ul") ||
!strcmp(tag->name, "/li")) {
2001-04-19 14:21:46 +02:00
if (!parser->newline) {
parser->space = FALSE;
sc_html_append_char(parser, '\n');
2001-04-19 14:21:46 +02:00
}
parser->state = SC_HTML_NORMAL;
2003-03-13 12:12:58 +01:00
}
sc_html_free_tag(tag);
2001-04-19 14:21:46 +02:00
return parser->state;
}
static void sc_html_parse_special(SC_HTMLParser *parser)
2001-04-19 14:21:46 +02:00
{
gchar symbol_name[9];
gint n;
const gchar *val;
parser->state = SC_HTML_UNKNOWN;
2001-04-19 14:21:46 +02:00
g_return_if_fail(*parser->bufp == '&');
/* &foo; */
for (n = 0; parser->bufp[n] != '\0' && parser->bufp[n] != ';'; n++)
;
if (n > 7 || parser->bufp[n] != ';') {
/* output literal `&' */
sc_html_append_char(parser, *parser->bufp++);
parser->state = SC_HTML_NORMAL;
2001-04-19 14:21:46 +02:00
return;
}
strncpy2(symbol_name, parser->bufp, n + 2);
parser->bufp += n + 1;
if ((val = g_hash_table_lookup(parser->symbol_table, symbol_name))
!= NULL) {
sc_html_append_str(parser, val, -1);
parser->state = SC_HTML_NORMAL;
2001-04-19 14:21:46 +02:00
return;
2005-03-30 [paul] 1.9.6cvs12 partial sync with main: * src/action.c create_io_dialog(): use user-defined text font (thanks to Alfons), and modified its appearance. * src/addrgather.c * src/addrharvest.c * src/browseldap.c replace old code * src/compose.c don't join (presumably) itemized lines on line-wrapping fixed wrapping of quote when auto-wrapping is enabled compose_destroy(): destroy paned only if it's not attached to window. Fixed memory leak of popup menu. * src/exphtmldlg.c * src/expldifdlg.c replace old code * src/html.c * src/html.h * src/importmutt.c * src/importpine.c replace old code * src/main.c removed redundant code * src/mainwindow.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' main_window_set_widgets(): request size first to prevent window size becoming wrong fixed remembering of the state of the visibility of MessageView * src/messageview.c changed 'Code set' (which is rather incorrect) in the menu to 'Character encoding' * src/prefs_common.c * src/prefs_common.h added an option whether to render HTML as text or not added separators to outgoing encoding menu * src/procheader.c procheader_scan_date_string(): support header like: "[Tue,] 01 Feb 2005 09:57[:00]" * src/summaryview.c * src/summaryview.h minor code cleanup * src/textview.c textview_show_html(): force output of newline added an option whether to render HTML as text or not * src/common/utils.c strncpy2(): optimized based on Alfons' code * src/gtk/gtkutils.c * src/gtk/gtkutils.h removed non-used code * src/plugins/pgpmime/passphrase.c partially fixed grab input of passphrase dialog Confine pointer to window
2005-03-30 14:01:26 +02:00
} else if (symbol_name[1] == '#' && g_ascii_isdigit(symbol_name[2])) {
2001-04-19 14:21:46 +02:00
gint ch;
ch = atoi(symbol_name + 2);
if ((ch > 0 && ch <= 127) ||
(ch >= 128 && ch <= 255 &&
parser->conv->charset == C_ISO_8859_1)) {
sc_html_append_char(parser, ch);
parser->state = SC_HTML_NORMAL;
2001-04-19 14:21:46 +02:00
return;
} else {
char *symb = NULL;
switch (ch) {
/* http://www.w3schools.com/html/html_entitiesref.asp */
case 96: /* backtick */
symb = "`";
break;
case 338: /* capital ligature OE &OElig; */
symb = "OE";
break;
case 339: /* small ligature OE &oelig; */
symb = "oe";
break;
case 352: /* capital S w/caron &Scaron; */
case 353: /* small S w/caron &scaron; */
case 376: /* cap Y w/ diaeres &Yuml; */
break;
case 710: /* circumflex accent &circ; */
symb = "^";
break;
case 732: /* small tilde &tilde; */
symb = "~";
break;
case 8194: /* en space &ensp; */
case 8195: /* em space &emsp; */
case 8201: /* thin space &thinsp; */
symb = " ";
break;
case 8204: /* zero width non-joiner &zwnj; */
case 8205: /* zero width joiner &zwj; */
case 8206: /* l-t-r mark &lrm; */
case 8207: /* r-t-l mark &rlm */
break;
case 8211: /* en dash &ndash; */
symb = "-";
break;
case 8212: /* em dash &mdash; */
symb = "--";
break;
case 8216: /* l single quot mark &lsquo; */
case 8217: /* r single quot mark &rsquo; */
symb = "'";
break;
case 8218: /* single low-9 quot &sbquo; */
symb = ",";
break;
case 8220: /* l double quot mark &ldquo; */
case 8221: /* r double quot mark &rdquo; */
symb = "\"";
break;
case 8222: /* double low-9 quot &bdquo; */
symb = ",,";
break;
case 8224: /* dagger &dagger; */
case 8225: /* double dagger &Dagger; */
break;
case 8230: /* horizontal ellipsis &hellip; */
symb = "...";
break;
case 8240: /* per mile &permil; */
symb = "\%o";
break;
case 8249: /* l-pointing angle quot &lsaquo; */
symb = "<";
break;
case 8250: /* r-pointing angle quot &rsaquo; */
symb = ">";
break;
case 8364: /* euro &euro; */
symb = "EUR";
break;
case 8482: /* trademark &trade; */
symb = "(TM)";
break;
default:
break;
}
if (symb) {
sc_html_append_str(parser, symb, -1);
parser->state = SC_HTML_NORMAL;
return;
}
2001-04-19 14:21:46 +02:00
}
}
sc_html_append_str(parser, symbol_name, -1);
2001-04-19 14:21:46 +02:00
}
static void sc_html_get_parenthesis(SC_HTMLParser *parser, gchar *buf, gint len)
2001-04-19 14:21:46 +02:00
{
gchar *p;
buf[0] = '\0';
g_return_if_fail(*parser->bufp == '<');
2001-12-03 11:06:10 +01:00
/* ignore comment / CSS / script stuff */
2001-04-19 14:21:46 +02:00
if (!strncmp(parser->bufp, "<!--", 4)) {
parser->bufp += 4;
while ((p = strstr(parser->bufp, "-->")) == NULL)
if (sc_html_read_line(parser) == SC_HTML_EOF) return;
2001-04-19 14:21:46 +02:00
parser->bufp = p + 3;
return;
}
if (!g_ascii_strncasecmp(parser->bufp, "<style", 6)) {
2001-12-03 11:06:10 +01:00
parser->bufp += 6;
while ((p = strcasestr(parser->bufp, "</style>")) == NULL)
if (sc_html_read_line(parser) == SC_HTML_EOF) return;
2001-10-25 08:31:55 +02:00
parser->bufp = p + 8;
return;
}
if (!g_ascii_strncasecmp(parser->bufp, "<script", 7)) {
2001-12-03 11:06:10 +01:00
parser->bufp += 7;
while ((p = strcasestr(parser->bufp, "</script>")) == NULL)
if (sc_html_read_line(parser) == SC_HTML_EOF) return;
2001-12-03 11:06:10 +01:00
parser->bufp = p + 9;
2001-10-26 10:42:37 +02:00
return;
}
2001-04-19 14:21:46 +02:00
parser->bufp++;
while ((p = strchr(parser->bufp, '>')) == NULL)
if (sc_html_read_line(parser) == SC_HTML_EOF) return;
2001-04-19 14:21:46 +02:00
strncpy2(buf, parser->bufp, MIN(p - parser->bufp + 1, len));
2003-03-13 12:12:58 +01:00
g_strstrip(buf);
2001-04-19 14:21:46 +02:00
parser->bufp = p + 1;
}