claws-mail/src/msgcache.c

892 lines
23 KiB
C
Raw Normal View History

2002-06-30 01:48:43 +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 & The Sylpheed Claws Team
2002-06-30 01:48:43 +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.
2002-06-30 01:48:43 +02:00
*/
#include "defs.h"
#include <glib.h>
2005-02-10 [paul] 1.0.1cvs3.2 * AUTHORS * Makefile.am * autogen.sh * configure.ac * config/mkinstalldirs * intl/.cvsignore * intl/ChangeLog * intl/VERSION * intl/bindtextdom.c * intl/config.charset * intl/dcgettext.c * intl/dcigettext.c * intl/dcngettext.c * intl/dgettext.c * intl/dngettext.c * intl/eval-plural.h * intl/explodename.c * intl/finddomain.c * intl/gettext.c * intl/gettextP.h * intl/gmo.h * intl/hash-string.h * intl/intl-compat.c * intl/l10nflist.c * intl/libgnuintl.h.in * intl/loadinfo.h * intl/loadmsgcat.c * intl/localcharset.c * intl/localcharset.h * intl/locale.alias * intl/localealias.c * intl/localename.c * intl/log.c * intl/ngettext.c * intl/os2compat.c * intl/os2compat.h * intl/osdep.c * intl/plural-exp.c * intl/plural-exp.h * intl/plural.c * intl/plural.y * intl/ref-add.sin * intl/ref-del.sin * intl/relocatable.c * intl/relocatable.h * intl/textdomain.c * m4/Makefile.am * po/Makefile.in.in * src/Makefile.am * src/account.c * src/action.c * src/addr_compl.c * src/addressadd.c * src/addressbook.c * src/addrgather.c * src/addrindex.c * src/alertpanel.c * src/browseldap.c * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/crash.c * src/editaddress.c * src/editbook.c * src/editgroup.c * src/editjpilot.c * src/editldap.c * src/editldap_basedn.c * src/editvcard.c * src/exphtmldlg.c * src/expldifdlg.c * src/export.c * src/exporthtml.c * src/filtering.c * src/folder.c * src/folder_item_prefs.c * src/foldersel.c * src/folderview.c * src/grouplistdialog.c * src/headerview.c * src/imap.c * src/imap_gtk.c * src/import.c * src/importldif.c * src/importmutt.c * src/importpine.c * src/inc.c * src/ldif.c * src/main.c * src/mainwindow.c * src/matcher.c * src/mbox.c * src/message_search.c * src/messageview.c * src/mh.c * src/mh_gtk.c * src/mimeview.c * src/msgcache.c * src/news.c * src/news_gtk.c * src/noticeview.c * src/partial_download.c * src/pop.c * src/prefs_account.c * src/prefs_actions.c * src/prefs_common.c * src/prefs_customheader.c * src/prefs_display_header.c * src/prefs_ext_prog.c * src/prefs_filtering.c * src/prefs_filtering_action.c * src/prefs_folder_item.c * src/prefs_fonts.c * src/prefs_gtk.c * src/prefs_matcher.c * src/prefs_msg_colors.c * src/prefs_spelling.c * src/prefs_summary_column.c * src/prefs_template.c * src/prefs_themes.c * src/prefs_toolbar.c * src/prefs_wrapping.c * src/privacy.c * src/procheader.c * src/procmime.c * src/procmsg.c * src/quote_fmt.c * src/recv.c * src/send_message.c * src/setup.c * src/sourcewindow.c * src/ssl_manager.c * src/statusbar.c * src/summary_search.c * src/summaryview.c * src/textview.c * src/toolbar.c * src/wizard.c * src/common/nntp.c * src/common/plugin.c * src/common/smtp.c * src/common/ssl.c * src/common/ssl_certificate.c * src/common/string_match.c * src/common/sylpheed.c * src/common/template.c * src/common/utils.c * src/gtk/about.c * src/gtk/colorlabel.c * src/gtk/description_window.c * src/gtk/filesel.c * src/gtk/foldersort.c * src/gtk/gtkaspell.c * src/gtk/gtkutils.c * src/gtk/inputdialog.c * src/gtk/logwindow.c * src/gtk/menu.c * src/gtk/pluginwindow.c * src/gtk/prefswindow.c * src/gtk/progressdialog.c * src/gtk/quicksearch.c * src/gtk/sslcertwindow.c * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/image_viewer/plugin.c * src/plugins/image_viewer/viewer.c * src/plugins/image_viewer/viewerprefs.c * src/plugins/mathml_viewer/mathml_viewer.c * src/plugins/pgpmime/passphrase.c * src/plugins/pgpmime/plugin.c * src/plugins/pgpmime/prefs_gpg.c * src/plugins/pgpmime/select-keys.c * src/plugins/pgpmime/sgpgme.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c sync with main (revision 104)
2005-02-10 13:06:07 +01:00
#include <glib/gi18n.h>
#include <sys/mman.h>
2002-06-30 01:48:43 +02:00
#include <time.h>
#include "msgcache.h"
#include "utils.h"
#include "procmsg.h"
#include "codeconv.h"
#include "timing.h"
2002-06-30 01:48:43 +02:00
#if G_BYTE_ORDER == G_BIG_ENDIAN
#define bswap_32(x) \
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
static gboolean msgcache_use_mmap = FALSE;
#else
#define bswap_32(x) (x)
static gboolean msgcache_use_mmap = TRUE;
#endif
#define MMAP_TO_GUINT32(x) \
(((x[0]&0xff)) | \
((x[1]&0xff) << 8) | \
((x[2]&0xff) << 16) | \
((x[3]&0xff) << 24))
static gboolean swapping = TRUE;
2004-02-21 12:01:01 +01:00
typedef enum
{
DATA_READ,
DATA_WRITE,
DATA_APPEND
} DataOpenMode;
2002-06-30 01:48:43 +02:00
struct _MsgCache {
GHashTable *msgnum_table;
GHashTable *msgid_table;
2002-06-30 01:48:43 +02:00
guint memusage;
time_t last_access;
};
typedef struct _StringConverter StringConverter;
struct _StringConverter {
gchar *(*convert) (StringConverter *converter, gchar *srcstr);
void (*free) (StringConverter *converter);
};
typedef struct _StrdupConverter StrdupConverter;
struct _StrdupConverter {
StringConverter converter;
};
typedef struct _CharsetConverter CharsetConverter;
struct _CharsetConverter {
StringConverter converter;
gchar *srccharset;
gchar *dstcharset;
};
MsgCache *msgcache_new(void)
2002-06-30 01:48:43 +02:00
{
MsgCache *cache;
cache = g_new0(MsgCache, 1),
cache->msgnum_table = g_hash_table_new(g_int_hash, g_int_equal);
cache->msgid_table = g_hash_table_new(g_str_hash, g_str_equal);
2002-06-30 01:48:43 +02:00
cache->last_access = time(NULL);
return cache;
}
static gboolean msgcache_msginfo_free_func(gpointer num, gpointer msginfo, gpointer user_data)
{
procmsg_msginfo_free((MsgInfo *)msginfo);
return TRUE;
}
void msgcache_destroy(MsgCache *cache)
{
g_return_if_fail(cache != NULL);
g_hash_table_foreach_remove(cache->msgnum_table, msgcache_msginfo_free_func, NULL);
g_hash_table_destroy(cache->msgid_table);
2002-06-30 01:48:43 +02:00
g_hash_table_destroy(cache->msgnum_table);
g_free(cache);
}
void msgcache_add_msg(MsgCache *cache, MsgInfo *msginfo)
{
MsgInfo *newmsginfo;
g_return_if_fail(cache != NULL);
g_return_if_fail(msginfo != NULL);
newmsginfo = procmsg_msginfo_new_ref(msginfo);
g_hash_table_insert(cache->msgnum_table, &newmsginfo->msgnum, newmsginfo);
if(newmsginfo->msgid != NULL)
g_hash_table_insert(cache->msgid_table, newmsginfo->msgid, newmsginfo);
2002-06-30 01:48:43 +02:00
cache->memusage += procmsg_msginfo_memusage(msginfo);
cache->last_access = time(NULL);
2004-05-10 12:22:28 +02:00
debug_print("Cache size: %d messages, %d bytes\n", g_hash_table_size(cache->msgnum_table), cache->memusage);
2002-06-30 01:48:43 +02:00
}
void msgcache_remove_msg(MsgCache *cache, guint msgnum)
{
MsgInfo *msginfo;
g_return_if_fail(cache != NULL);
g_return_if_fail(msgnum > 0);
msginfo = (MsgInfo *) g_hash_table_lookup(cache->msgnum_table, &msgnum);
2002-06-30 01:48:43 +02:00
if(!msginfo)
return;
cache->memusage -= procmsg_msginfo_memusage(msginfo);
if(msginfo->msgid)
g_hash_table_remove(cache->msgid_table, msginfo->msgid);
g_hash_table_remove(cache->msgnum_table, &msginfo->msgnum);
2002-06-30 01:48:43 +02:00
procmsg_msginfo_free(msginfo);
cache->last_access = time(NULL);
2002-08-15 09:38:17 +02:00
debug_print("Cache size: %d messages, %d byte\n", g_hash_table_size(cache->msgnum_table), cache->memusage);
2002-06-30 01:48:43 +02:00
}
void msgcache_update_msg(MsgCache *cache, MsgInfo *msginfo)
{
MsgInfo *oldmsginfo, *newmsginfo;
g_return_if_fail(cache != NULL);
g_return_if_fail(msginfo != NULL);
oldmsginfo = g_hash_table_lookup(cache->msgnum_table, &msginfo->msgnum);
if(oldmsginfo && oldmsginfo->msgid)
g_hash_table_remove(cache->msgid_table, oldmsginfo->msgid);
2004-07-27 21:57:57 +02:00
if (oldmsginfo) {
g_hash_table_remove(cache->msgnum_table, &oldmsginfo->msgnum);
2004-07-27 21:57:57 +02:00
cache->memusage -= procmsg_msginfo_memusage(oldmsginfo);
procmsg_msginfo_free(oldmsginfo);
2004-07-27 21:57:57 +02:00
}
2002-06-30 01:48:43 +02:00
newmsginfo = procmsg_msginfo_new_ref(msginfo);
g_hash_table_insert(cache->msgnum_table, &newmsginfo->msgnum, newmsginfo);
if(newmsginfo->msgid)
g_hash_table_insert(cache->msgid_table, newmsginfo->msgid, newmsginfo);
2002-06-30 01:48:43 +02:00
cache->memusage += procmsg_msginfo_memusage(newmsginfo);
cache->last_access = time(NULL);
2002-08-15 09:38:17 +02:00
debug_print("Cache size: %d messages, %d byte\n", g_hash_table_size(cache->msgnum_table), cache->memusage);
2002-06-30 01:48:43 +02:00
return;
}
2004-02-21 12:01:01 +01:00
MsgInfo *msgcache_get_msg(MsgCache *cache, guint num)
{
MsgInfo *msginfo;
g_return_val_if_fail(cache != NULL, NULL);
msginfo = g_hash_table_lookup(cache->msgnum_table, &num);
if(!msginfo)
return NULL;
cache->last_access = time(NULL);
return procmsg_msginfo_new_ref(msginfo);
}
MsgInfo *msgcache_get_msg_by_id(MsgCache *cache, const gchar *msgid)
{
MsgInfo *msginfo;
g_return_val_if_fail(cache != NULL, NULL);
g_return_val_if_fail(msgid != NULL, NULL);
msginfo = g_hash_table_lookup(cache->msgid_table, msgid);
if(!msginfo)
return NULL;
cache->last_access = time(NULL);
return procmsg_msginfo_new_ref(msginfo);
}
static void msgcache_get_msg_list_func(gpointer key, gpointer value, gpointer user_data)
{
MsgInfoList **listptr = user_data;
MsgInfo *msginfo = value;
*listptr = g_slist_prepend(*listptr, procmsg_msginfo_new_ref(msginfo));
}
MsgInfoList *msgcache_get_msg_list(MsgCache *cache)
{
MsgInfoList *msg_list = NULL;
START_TIMING("msgcache_get_msg_list");
2004-02-21 12:01:01 +01:00
g_return_val_if_fail(cache != NULL, NULL);
g_hash_table_foreach((GHashTable *)cache->msgnum_table, msgcache_get_msg_list_func, (gpointer)&msg_list);
cache->last_access = time(NULL);
msg_list = g_slist_reverse(msg_list);
END_TIMING();
2004-02-21 12:01:01 +01:00
return msg_list;
}
time_t msgcache_get_last_access_time(MsgCache *cache)
{
g_return_val_if_fail(cache != NULL, 0);
return cache->last_access;
}
gint msgcache_get_memory_usage(MsgCache *cache)
{
g_return_val_if_fail(cache != NULL, 0);
return cache->memusage;
}
/*
* Cache saving functions
*/
#define READ_CACHE_DATA(data, fp, total_len) \
2004-02-21 12:01:01 +01:00
{ \
if ((tmp_len = msgcache_read_cache_data_str(fp, &data, conv)) < 0) { \
2004-02-21 12:01:01 +01:00
procmsg_msginfo_free(msginfo); \
error = TRUE; \
goto bail_err; \
2004-02-21 12:01:01 +01:00
} \
total_len += tmp_len; \
2004-02-21 12:01:01 +01:00
}
#define READ_CACHE_DATA_INT(n, fp) \
{ \
2004-05-22 09:27:30 +02:00
guint32 idata; \
size_t ni; \
2004-05-22 09:27:30 +02:00
\
if ((ni = fread(&idata, sizeof(idata), 1, fp)) != 1) { \
g_warning("read_int: Cache data corrupted, read %d of %d at " \
"offset %ld\n", ni, sizeof(idata), ftell(fp)); \
2004-02-21 12:01:01 +01:00
procmsg_msginfo_free(msginfo); \
error = TRUE; \
goto bail_err; \
2004-05-22 09:27:30 +02:00
} else \
n = swapping ? bswap_32(idata) : (idata);\
2004-02-21 12:01:01 +01:00
}
#define GET_CACHE_DATA_INT(n) \
{ \
guint32 idata = MMAP_TO_GUINT32(walk_data); \
n = swapping ? bswap_32(idata) : (idata);\
walk_data += 4; rem_len -= 4; \
}
#define GET_CACHE_DATA(data, total_len) \
{ \
GET_CACHE_DATA_INT(tmp_len); \
if ((tmp_len = msgcache_get_cache_data_str(walk_data, &data, tmp_len, conv)) < 0) { \
printf("error at rem_len:%d\n", rem_len);\
procmsg_msginfo_free(msginfo); \
error = TRUE; \
goto bail_err; \
} \
total_len += tmp_len; \
walk_data += tmp_len; rem_len -= tmp_len; \
}
2004-05-22 09:27:30 +02:00
#define WRITE_CACHE_DATA_INT(n, fp) \
{ \
guint32 idata; \
\
idata = (guint32)bswap_32(n); \
if (fwrite(&idata, sizeof(idata), 1, fp) != 1) \
w_err = 1; \
2004-05-22 09:27:30 +02:00
}
2004-02-21 12:01:01 +01:00
#define WRITE_CACHE_DATA(data, fp) \
{ \
2004-05-22 09:27:30 +02:00
size_t len; \
2004-02-21 12:01:01 +01:00
if (data == NULL) \
len = 0; \
else \
len = strlen(data); \
WRITE_CACHE_DATA_INT(len, fp); \
if (w_err == 0 && len > 0) { \
if (fwrite(data, 1, len, fp) != len) \
w_err = 1; \
2004-02-21 12:01:01 +01:00
} \
}
static FILE *msgcache_open_data_file(const gchar *file, guint version,
2004-02-21 12:01:01 +01:00
DataOpenMode mode,
gchar *buf, size_t buf_size)
{
FILE *fp;
gint32 data_ver;
2004-02-21 12:01:01 +01:00
g_return_val_if_fail(file != NULL, NULL);
if (mode == DATA_WRITE) {
int w_err = 0;
if ((fp = g_fopen(file, "wb")) == NULL) {
2004-02-21 12:01:01 +01:00
FILE_OP_ERROR(file, "fopen");
return NULL;
}
if (change_file_mode_rw(fp, file) < 0)
FILE_OP_ERROR(file, "chmod");
WRITE_CACHE_DATA_INT(version, fp);
if (w_err != 0) {
g_warning("failed to write int\n");
fclose(fp);
return NULL;
}
2004-02-21 12:01:01 +01:00
return fp;
}
/* check version */
if ((fp = g_fopen(file, "rb")) == NULL)
debug_print("Mark/Cache file '%s' not found\n", file);
2004-02-21 12:01:01 +01:00
else {
if (buf && buf_size > 0)
setvbuf(fp, buf, _IOFBF, buf_size);
if (fread(&data_ver, sizeof(data_ver), 1, fp) != 1 ||
version != bswap_32(data_ver)) {
g_message("%s: Mark/Cache version is different (%u != %u).\n",
file, bswap_32(data_ver), version);
2004-02-21 12:01:01 +01:00
fclose(fp);
fp = NULL;
}
data_ver = bswap_32(data_ver);
2004-02-21 12:01:01 +01:00
}
2004-02-21 12:01:01 +01:00
if (mode == DATA_READ)
return fp;
if (fp) {
/* reopen with append mode */
fclose(fp);
if ((fp = g_fopen(file, "ab")) == NULL)
2004-02-21 12:01:01 +01:00
FILE_OP_ERROR(file, "fopen");
} else {
/* open with overwrite mode if mark file doesn't exist or
version is different */
fp = msgcache_open_data_file(file, version, DATA_WRITE, buf,
buf_size);
}
return fp;
}
static gint msgcache_read_cache_data_str(FILE *fp, gchar **str,
StringConverter *conv)
2002-06-30 01:48:43 +02:00
{
gchar *tmpstr = NULL;
size_t ni;
guint32 len;
*str = NULL;
if (!swapping) {
if ((ni = fread(&len, sizeof(len), 1, fp) != 1) ||
len > G_MAXINT) {
g_warning("read_data_str: Cache data (len) corrupted, read %d "
"of %d bytes at offset %ld\n", ni, sizeof(len),
ftell(fp));
return -1;
}
} else {
if ((ni = fread(&len, sizeof(len), 1, fp) != 1) ||
bswap_32(len) > G_MAXINT) {
g_warning("read_data_str: Cache data (len) corrupted, read %d "
"of %d bytes at offset %ld\n", ni, sizeof(len),
ftell(fp));
return -1;
}
len = bswap_32(len);
}
if (len == 0)
return 0;
tmpstr = g_try_malloc(len + 1);
if(tmpstr == NULL) {
g_warning("read_data_str: can't g_malloc %d bytes - cache data probably corrupted.\n", len);
return -1;
}
if ((ni = fread(tmpstr, 1, len, fp)) != len) {
g_warning("read_data_str: Cache data corrupted, read %d of %d "
"bytes at offset %ld\n",
ni, len, ftell(fp));
g_free(tmpstr);
return -1;
}
tmpstr[len] = 0;
if (conv != NULL) {
*str = conv->convert(conv, tmpstr);
g_free(tmpstr);
} else
*str = tmpstr;
return len;
2002-06-30 01:48:43 +02:00
}
static gint msgcache_get_cache_data_str(gchar *src, gchar **str, gint len,
StringConverter *conv)
{
gchar *tmpstr = NULL;
*str = NULL;
if (len == 0)
return 0;
tmpstr = g_try_malloc(len + 1);
if(tmpstr == NULL) {
g_warning("read_data_str: can't g_malloc %d bytes - cache data probably corrupted.\n", len);
return -1;
}
strncpy(tmpstr, src, len);
tmpstr[len] = 0;
if (conv != NULL) {
*str = conv->convert(conv, tmpstr);
g_free(tmpstr);
} else
*str = tmpstr;
return len;
}
gchar *strconv_strdup_convert(StringConverter *conv, gchar *srcstr)
{
return g_strdup(srcstr);
}
gchar *strconv_charset_convert(StringConverter *conv, gchar *srcstr)
{
CharsetConverter *charsetconv = (CharsetConverter *) conv;
return conv_codeset_strdup(srcstr, charsetconv->srccharset, charsetconv->dstcharset);
}
void strconv_charset_free(StringConverter *conv)
{
CharsetConverter *charsetconv = (CharsetConverter *) conv;
g_free(charsetconv->srccharset);
g_free(charsetconv->dstcharset);
}
2002-06-30 01:48:43 +02:00
MsgCache *msgcache_read_cache(FolderItem *item, const gchar *cache_file)
{
MsgCache *cache;
FILE *fp;
MsgInfo *msginfo;
MsgTmpFlags tmp_flags = 0;
2002-06-30 01:48:43 +02:00
gchar file_buf[BUFFSIZE];
guint32 num;
guint refnum;
2002-06-30 01:48:43 +02:00
gboolean error = FALSE;
StringConverter *conv = NULL;
gchar *srccharset = NULL;
const gchar *dstcharset = NULL;
gchar *ref = NULL;
guint memusage = 0;
gint tmp_len = 0, map_len = -1;
char *cache_data = NULL;
struct stat st;
2002-06-30 01:48:43 +02:00
g_return_val_if_fail(cache_file != NULL, NULL);
g_return_val_if_fail(item != NULL, NULL);
swapping = TRUE;
/* In case we can't open the mark file with MARK_VERSION, check if we can open it with the
* swapped MARK_VERSION. As msgcache_open_data_file swaps it too, if this succeeds,
* it means it's the old version (not little-endian) on a big-endian machine. The code has
* no effect on x86 as their file doesn't change. */
2004-02-21 12:01:01 +01:00
if ((fp = msgcache_open_data_file
(cache_file, CACHE_VERSION, DATA_READ, file_buf, sizeof(file_buf))) == NULL) {
if ((fp = msgcache_open_data_file
(cache_file, bswap_32(CACHE_VERSION), DATA_READ, file_buf, sizeof(file_buf))) == NULL)
return NULL;
else
swapping = FALSE;
}
2002-06-30 01:48:43 +02:00
debug_print("\tReading %sswapped message cache from %s...\n", swapping?"":"un", cache_file);
2002-06-30 01:48:43 +02:00
if (folder_has_parent_of_type(item, F_QUEUE)) {
tmp_flags |= MSG_QUEUED;
} else if (folder_has_parent_of_type(item, F_DRAFT)) {
tmp_flags |= MSG_DRAFT;
}
if (msgcache_read_cache_data_str(fp, &srccharset, NULL) < 0)
return NULL;
dstcharset = CS_UTF_8;
if (srccharset == NULL || dstcharset == NULL) {
conv = NULL;
} else if (strcmp(srccharset, dstcharset) == 0) {
debug_print("using Noop Converter\n");
conv = NULL;
} else {
CharsetConverter *charsetconv;
debug_print("using CharsetConverter\n");
charsetconv = g_new0(CharsetConverter, 1);
charsetconv->converter.convert = strconv_charset_convert;
charsetconv->converter.free = strconv_charset_free;
charsetconv->srccharset = g_strdup(srccharset);
charsetconv->dstcharset = g_strdup(dstcharset);
conv = (StringConverter *) charsetconv;
}
g_free(srccharset);
cache = msgcache_new();
2002-06-30 01:48:43 +02:00
if (msgcache_use_mmap == TRUE) {
if (fstat(fileno(fp), &st) >= 0)
map_len = st.st_size;
else
map_len = -1;
if (map_len > 0)
cache_data = mmap(NULL, map_len, PROT_READ, MAP_PRIVATE, fileno(fp), 0);
} else {
cache_data = NULL;
}
if (cache_data != NULL && cache_data != MAP_FAILED) {
int rem_len = map_len-ftell(fp);
char *walk_data = cache_data+ftell(fp);
while(rem_len > 0) {
GET_CACHE_DATA_INT(num);
msginfo = procmsg_msginfo_new();
msginfo->msgnum = num;
memusage += sizeof(MsgInfo);
GET_CACHE_DATA_INT(msginfo->size);
GET_CACHE_DATA_INT(msginfo->mtime);
GET_CACHE_DATA_INT(msginfo->date_t);
GET_CACHE_DATA_INT(msginfo->flags.tmp_flags);
GET_CACHE_DATA(msginfo->fromname, memusage);
GET_CACHE_DATA(msginfo->date, memusage);
GET_CACHE_DATA(msginfo->from, memusage);
GET_CACHE_DATA(msginfo->to, memusage);
GET_CACHE_DATA(msginfo->cc, memusage);
GET_CACHE_DATA(msginfo->newsgroups, memusage);
GET_CACHE_DATA(msginfo->subject, memusage);
GET_CACHE_DATA(msginfo->msgid, memusage);
GET_CACHE_DATA(msginfo->inreplyto, memusage);
GET_CACHE_DATA(msginfo->xref, memusage);
GET_CACHE_DATA_INT(msginfo->planned_download);
GET_CACHE_DATA_INT(msginfo->total_size);
GET_CACHE_DATA_INT(refnum);
for (; refnum != 0; refnum--) {
ref = NULL;
GET_CACHE_DATA(ref, memusage);
if (ref && *ref)
msginfo->references =
g_slist_prepend(msginfo->references, ref);
}
if (msginfo->references)
msginfo->references =
g_slist_reverse(msginfo->references);
msginfo->folder = item;
msginfo->flags.tmp_flags |= tmp_flags;
g_hash_table_insert(cache->msgnum_table, &msginfo->msgnum, msginfo);
if(msginfo->msgid)
g_hash_table_insert(cache->msgid_table, msginfo->msgid, msginfo);
}
munmap(cache_data, map_len);
} else {
while (fread(&num, sizeof(num), 1, fp) == 1) {
if (swapping)
num = bswap_32(num);
msginfo = procmsg_msginfo_new();
msginfo->msgnum = num;
memusage += sizeof(MsgInfo);
READ_CACHE_DATA_INT(msginfo->size, fp);
READ_CACHE_DATA_INT(msginfo->mtime, fp);
READ_CACHE_DATA_INT(msginfo->date_t, fp);
READ_CACHE_DATA_INT(msginfo->flags.tmp_flags, fp);
READ_CACHE_DATA(msginfo->fromname, fp, memusage);
READ_CACHE_DATA(msginfo->date, fp, memusage);
READ_CACHE_DATA(msginfo->from, fp, memusage);
READ_CACHE_DATA(msginfo->to, fp, memusage);
READ_CACHE_DATA(msginfo->cc, fp, memusage);
READ_CACHE_DATA(msginfo->newsgroups, fp, memusage);
READ_CACHE_DATA(msginfo->subject, fp, memusage);
READ_CACHE_DATA(msginfo->msgid, fp, memusage);
READ_CACHE_DATA(msginfo->inreplyto, fp, memusage);
READ_CACHE_DATA(msginfo->xref, fp, memusage);
READ_CACHE_DATA_INT(msginfo->planned_download, fp);
READ_CACHE_DATA_INT(msginfo->total_size, fp);
READ_CACHE_DATA_INT(refnum, fp);
for (; refnum != 0; refnum--) {
ref = NULL;
READ_CACHE_DATA(ref, fp, memusage);
if (ref && *ref)
msginfo->references =
g_slist_prepend(msginfo->references, ref);
}
if (msginfo->references)
msginfo->references =
g_slist_reverse(msginfo->references);
msginfo->folder = item;
msginfo->flags.tmp_flags |= tmp_flags;
2002-06-30 01:48:43 +02:00
g_hash_table_insert(cache->msgnum_table, &msginfo->msgnum, msginfo);
if(msginfo->msgid)
g_hash_table_insert(cache->msgid_table, msginfo->msgid, msginfo);
}
2002-06-30 01:48:43 +02:00
}
bail_err:
2002-06-30 01:48:43 +02:00
fclose(fp);
if (conv != NULL) {
if (conv->free != NULL)
conv->free(conv);
g_free(conv);
}
if(error) {
msgcache_destroy(cache);
return NULL;
}
2002-06-30 01:48:43 +02:00
cache->last_access = time(NULL);
cache->memusage = memusage;
2002-06-30 01:48:43 +02:00
2002-08-15 09:38:17 +02:00
debug_print("done. (%d items read)\n", g_hash_table_size(cache->msgnum_table));
debug_print("Cache size: %d messages, %d byte\n", g_hash_table_size(cache->msgnum_table), cache->memusage);
2002-06-30 01:48:43 +02:00
return cache;
}
void msgcache_read_mark(MsgCache *cache, const gchar *mark_file)
{
FILE *fp;
MsgInfo *msginfo;
MsgPermFlags perm_flags;
guint32 num;
gint map_len = -1;
char *cache_data = NULL;
struct stat st;
swapping = TRUE;
/* In case we can't open the mark file with MARK_VERSION, check if we can open it with the
* swapped MARK_VERSION. As msgcache_open_data_file swaps it too, if this succeeds,
* it means it's the old version (not little-endian) on a big-endian machine. The code has
* no effect on x86 as their file doesn't change. */
if ((fp = msgcache_open_data_file(mark_file, MARK_VERSION, DATA_READ, NULL, 0)) == NULL) {
/* see if it isn't swapped ? */
if ((fp = msgcache_open_data_file(mark_file, bswap_32(MARK_VERSION), DATA_READ, NULL, 0)) == NULL)
return;
else
swapping = FALSE; /* yay */
}
debug_print("reading %sswapped mark file.\n", swapping?"":"un");
if (msgcache_use_mmap) {
if (fstat(fileno(fp), &st) >= 0)
map_len = st.st_size;
else
map_len = -1;
if (map_len > 0)
cache_data = mmap(NULL, map_len, PROT_READ, MAP_PRIVATE, fileno(fp), 0);
} else {
cache_data = NULL;
}
if (cache_data != NULL && cache_data != MAP_FAILED) {
int rem_len = map_len-ftell(fp);
char *walk_data = cache_data+ftell(fp);
while(rem_len > 0) {
GET_CACHE_DATA_INT(num);
GET_CACHE_DATA_INT(perm_flags);
msginfo = g_hash_table_lookup(cache->msgnum_table, &num);
if(msginfo) {
msginfo->flags.perm_flags = perm_flags;
}
2002-06-30 01:48:43 +02:00
}
munmap(cache_data, map_len);
} else {
while (fread(&num, sizeof(num), 1, fp) == 1) {
if (swapping)
num = bswap_32(num);
if (fread(&perm_flags, sizeof(perm_flags), 1, fp) != 1) break;
if (swapping)
perm_flags = bswap_32(perm_flags);
msginfo = g_hash_table_lookup(cache->msgnum_table, &num);
if(msginfo) {
msginfo->flags.perm_flags = perm_flags;
}
}
}
2002-06-30 01:48:43 +02:00
fclose(fp);
}
static int msgcache_write_cache(MsgInfo *msginfo, FILE *fp)
2002-06-30 01:48:43 +02:00
{
MsgTmpFlags flags = msginfo->flags.tmp_flags & MSG_CACHED_FLAG_MASK;
GSList *cur;
int w_err = 0;
2002-06-30 01:48:43 +02:00
WRITE_CACHE_DATA_INT(msginfo->msgnum, fp);
WRITE_CACHE_DATA_INT(msginfo->size, fp);
WRITE_CACHE_DATA_INT(msginfo->mtime, fp);
WRITE_CACHE_DATA_INT(msginfo->date_t, fp);
WRITE_CACHE_DATA_INT(flags, fp);
WRITE_CACHE_DATA(msginfo->fromname, fp);
WRITE_CACHE_DATA(msginfo->date, fp);
WRITE_CACHE_DATA(msginfo->from, fp);
WRITE_CACHE_DATA(msginfo->to, fp);
WRITE_CACHE_DATA(msginfo->cc, fp);
WRITE_CACHE_DATA(msginfo->newsgroups, fp);
WRITE_CACHE_DATA(msginfo->subject, fp);
WRITE_CACHE_DATA(msginfo->msgid, fp);
WRITE_CACHE_DATA(msginfo->inreplyto, fp);
WRITE_CACHE_DATA(msginfo->xref, fp);
WRITE_CACHE_DATA_INT(msginfo->planned_download, fp);
WRITE_CACHE_DATA_INT(msginfo->total_size, fp);
WRITE_CACHE_DATA_INT(g_slist_length(msginfo->references), fp);
for (cur = msginfo->references; cur != NULL; cur = cur->next) {
WRITE_CACHE_DATA((gchar *)cur->data, fp);
}
return w_err;
2002-06-30 01:48:43 +02:00
}
static int msgcache_write_flags(MsgInfo *msginfo, FILE *fp)
2002-06-30 01:48:43 +02:00
{
MsgPermFlags flags = msginfo->flags.perm_flags;
int w_err = 0;
2002-06-30 01:48:43 +02:00
WRITE_CACHE_DATA_INT(msginfo->msgnum, fp);
WRITE_CACHE_DATA_INT(flags, fp);
return w_err;
2002-06-30 01:48:43 +02:00
}
struct write_fps
{
FILE *cache_fp;
FILE *mark_fp;
int error;
2002-06-30 01:48:43 +02:00
};
static void msgcache_write_func(gpointer key, gpointer value, gpointer user_data)
{
MsgInfo *msginfo;
struct write_fps *write_fps;
2002-06-30 01:48:43 +02:00
msginfo = (MsgInfo *)value;
write_fps = user_data;
write_fps->error |= msgcache_write_cache(msginfo, write_fps->cache_fp);
write_fps->error |= msgcache_write_flags(msginfo, write_fps->mark_fp);
2002-06-30 01:48:43 +02:00
}
gint msgcache_write(const gchar *cache_file, const gchar *mark_file, MsgCache *cache)
{
struct write_fps write_fps;
gchar *new_cache, *new_mark;
int w_err = 0;
2002-06-30 01:48:43 +02:00
g_return_val_if_fail(cache_file != NULL, -1);
g_return_val_if_fail(mark_file != NULL, -1);
g_return_val_if_fail(cache != NULL, -1);
new_cache = g_strconcat(cache_file, ".new", NULL);
new_mark = g_strconcat(mark_file, ".new", NULL);
write_fps.error = 0;
write_fps.cache_fp = msgcache_open_data_file(new_cache, CACHE_VERSION,
2004-02-21 12:01:01 +01:00
DATA_WRITE, NULL, 0);
if (write_fps.cache_fp == NULL) {
g_free(new_cache);
g_free(new_mark);
2002-06-30 01:48:43 +02:00
return -1;
}
2002-06-30 01:48:43 +02:00
WRITE_CACHE_DATA(CS_UTF_8, write_fps.cache_fp);
if (w_err != 0) {
g_warning("failed to write charset\n");
fclose(write_fps.cache_fp);
g_unlink(new_cache);
g_free(new_cache);
g_free(new_mark);
return -1;
}
write_fps.mark_fp = msgcache_open_data_file(new_mark, MARK_VERSION,
2004-02-21 12:01:01 +01:00
DATA_WRITE, NULL, 0);
if (write_fps.mark_fp == NULL) {
2002-06-30 01:48:43 +02:00
fclose(write_fps.cache_fp);
g_unlink(new_cache);
g_free(new_cache);
g_free(new_mark);
2002-06-30 01:48:43 +02:00
return -1;
}
debug_print("\tWriting message cache to %s and %s...\n", new_cache, new_mark);
2004-02-21 12:01:01 +01:00
if (change_file_mode_rw(write_fps.cache_fp, new_cache) < 0)
FILE_OP_ERROR(new_cache, "chmod");
2002-06-30 01:48:43 +02:00
g_hash_table_foreach(cache->msgnum_table, msgcache_write_func, (gpointer)&write_fps);
fclose(write_fps.cache_fp);
fclose(write_fps.mark_fp);
if (write_fps.error != 0) {
g_unlink(new_cache);
g_unlink(new_mark);
g_free(new_cache);
g_free(new_mark);
return -1;
} else {
move_file(new_cache, cache_file, TRUE);
move_file(new_mark, mark_file, TRUE);
cache->last_access = time(NULL);
}
g_free(new_cache);
g_free(new_mark);
2002-08-15 09:38:17 +02:00
debug_print("done.\n");
return 0;
2002-06-30 01:48:43 +02:00
}