claws-mail/src/mh.c

1387 lines
34 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
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#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>
2001-04-19 14:21:46 +02:00
#include <dirent.h>
#include <sys/stat.h>
2001-05-17 15:25:31 +02:00
#include <unistd.h>
#include <string.h>
2001-04-19 14:21:46 +02:00
#include <errno.h>
#undef MEASURE_TIME
#ifdef MEASURE_TIME
# include <sys/time.h>
#endif
#include "folder.h"
#include "mh.h"
#include "procmsg.h"
#include "procheader.h"
#include "utils.h"
2003-10-05 12:10:30 +02:00
#include "codeconv.h"
#include "statusbar.h"
#include "gtkutils.h"
2001-04-19 14:21:46 +02:00
2005-12-20 [colin] 1.9.100cvs97 * ABOUT-NLS * Makefile.am * autogen.sh * configure.ac * config/config.rpath * config/mkinstalldirs * m4/Makefile.am * m4/glibc2.m4 * m4/gnupg.m4 * m4/gpgme.m4 * m4/intmax.m4 * m4/longdouble.m4 * m4/longlong.m4 * m4/printf-posix.m4 * m4/signed.m4 * m4/size_max.m4 * m4/ulonglong.m4 * m4/wchar_t.m4 * m4/wint_t.m4 * m4/xsize.m4 * po/Makefile.in.in * po/Makevars * po/bg.po * po/ca.po * po/cs.po * po/de.po * po/el.po * po/en_GB.po * po/es.po * po/fi.po * po/fr.po * po/hr.po * po/hu.po * po/it.po * po/ja.po * po/ko.po * po/nb.po * po/nl.po * po/pl.po * po/pt_BR.po * po/ru.po * po/sk.po * po/sr.po * po/stamp-po * po/sv.po * po/zh_CN.po * po/zh_TW.po * src/Makefile.am * src/codeconv.c * src/compose.c * src/exporthtml.c * src/exportldif.c * src/folder.c * src/main.c * src/manual.c * src/mh.c * src/mimeview.c * src/send_message.c * src/common/Makefile.am * src/common/fnmatch.c * src/common/fnmatch.h * src/common/fnmatch_loop.c * src/common/nntp.c * src/common/plugin.c * src/common/smtp.c * src/common/socket.c * src/common/string_match.c * src/common/sylpheed.c * src/common/utils.c * src/common/utils.h * src/common/w32_dirent.c * src/common/w32_reg.c * src/common/w32_signal.c * src/common/w32_stat.c * src/common/w32_stdio.c * src/common/w32_stdlib.c * src/common/w32_string.c * src/common/w32_time.c * src/common/w32_unistd.c * src/common/w32_wait.c * src/common/w32lib.h * src/etpan/Makefile.am * src/gtk/Makefile.am * src/plugins/clamav/Makefile.am * src/plugins/demo/Makefile.am * src/plugins/dillo_viewer/Makefile.am * src/plugins/pgpcore/Makefile.am * src/plugins/pgpcore/passphrase.c * src/plugins/pgpcore/plugin.def * src/plugins/pgpcore/sgpgme.c * src/plugins/pgpcore/sylpheed.def * src/plugins/pgpcore/version.rc * src/plugins/pgpinline/Makefile.am * src/plugins/pgpinline/plugin.def * src/plugins/pgpinline/sylpheed.def * src/plugins/pgpinline/version.rc * src/plugins/pgpmime/Makefile.am * src/plugins/pgpmime/mypgpcore.def * src/plugins/pgpmime/plugin.def * src/plugins/pgpmime/sylpheed.def * src/plugins/pgpmime/version.rc * src/plugins/spamassassin/Makefile.am Very little ;-) patch from Werner Koch, providing infrastructure for cross-compiling to Win32
2005-12-20 18:43:40 +01:00
/* Define possible missing constants for Windows. */
#ifdef G_OS_WIN32
# ifndef S_IRGRP
# define S_IRGRP 0
# define S_IWGRP 0
# endif
# ifndef S_IROTH
# define S_IROTH 0
# define S_IWOTH 0
# endif
#endif
2004-01-12 22:28:31 +01:00
static void mh_folder_init (Folder *folder,
const gchar *name,
const gchar *path);
static Folder *mh_folder_new (const gchar *name,
const gchar *path);
static void mh_folder_destroy (Folder *folder);
static gchar *mh_fetch_msg (Folder *folder,
FolderItem *item,
gint num);
static MsgInfo *mh_get_msginfo (Folder *folder,
FolderItem *item,
gint num);
static gint mh_add_msg (Folder *folder,
FolderItem *dest,
const gchar *file,
MsgFlags *flags);
static gint mh_add_msgs (Folder *folder,
FolderItem *dest,
GSList *file_list,
GRelation *relation);
static gint mh_copy_msg (Folder *folder,
FolderItem *dest,
MsgInfo *msginfo);
static gint mh_copy_msgs (Folder *folder,
FolderItem *dest,
MsgInfoList *msglist,
GRelation *relation);
2004-01-12 22:28:31 +01:00
static gint mh_remove_msg (Folder *folder,
FolderItem *item,
gint num);
static gint mh_remove_msgs (Folder *folder,
FolderItem *item,
MsgInfoList *msglist,
GRelation *relation);
2004-01-12 22:28:31 +01:00
static gint mh_remove_all_msg (Folder *folder,
FolderItem *item);
static gboolean mh_is_msg_changed (Folder *folder,
FolderItem *item,
MsgInfo *msginfo);
static gint mh_get_num_list (Folder *folder,
FolderItem *item,
GSList **list,
gboolean *old_uids_valid);
static gint mh_scan_tree (Folder *folder);
static gint mh_create_tree (Folder *folder);
static FolderItem *mh_create_folder (Folder *folder,
FolderItem *parent,
const gchar *name);
static gint mh_rename_folder (Folder *folder,
FolderItem *item,
const gchar *name);
static gint mh_remove_folder (Folder *folder,
FolderItem *item);
static gchar *mh_get_new_msg_filename (FolderItem *dest);
static MsgInfo *mh_parse_msg (const gchar *file,
FolderItem *item);
2003-08-25 16:14:47 +02:00
static void mh_remove_missing_folder_items (Folder *folder);
2003-10-05 12:10:30 +02:00
static gchar *mh_filename_from_utf8 (const gchar *path);
static gchar *mh_filename_to_utf8 (const gchar *path);
2004-01-12 22:28:31 +01:00
static void mh_scan_tree_recursive (FolderItem *item);
2004-01-12 22:28:31 +01:00
static gboolean mh_rename_folder_func (GNode *node,
gpointer data);
static gchar *mh_item_get_path (Folder *folder,
FolderItem *item);
2001-04-19 14:21:46 +02:00
static gboolean mh_scan_required (Folder *folder,
FolderItem *item);
static int mh_item_close (Folder *folder,
FolderItem *item);
static gint mh_get_flags (Folder *folder, FolderItem *item,
MsgInfoList *msginfo_list, GRelation *msgflags);
static void mh_write_sequences (FolderItem *item, gboolean remove_unseen);
2004-05-10 12:22:28 +02:00
static FolderClass mh_class;
FolderClass *mh_get_class(void)
{
2004-05-10 12:22:28 +02:00
if (mh_class.idstr == NULL) {
mh_class.type = F_MH;
mh_class.idstr = "mh";
mh_class.uistr = "MH";
/* Folder functions */
mh_class.new_folder = mh_folder_new;
mh_class.destroy_folder = mh_folder_destroy;
mh_class.set_xml = folder_local_set_xml;
mh_class.get_xml = folder_local_get_xml;
mh_class.scan_tree = mh_scan_tree;
mh_class.create_tree = mh_create_tree;
/* FolderItem functions */
mh_class.item_get_path = mh_item_get_path;
mh_class.create_folder = mh_create_folder;
mh_class.rename_folder = mh_rename_folder;
mh_class.remove_folder = mh_remove_folder;
mh_class.get_num_list = mh_get_num_list;
mh_class.scan_required = mh_scan_required;
mh_class.close = mh_item_close;
mh_class.get_flags = NULL; /*mh_get_flags */;
2004-05-10 12:22:28 +02:00
/* Message functions */
mh_class.get_msginfo = mh_get_msginfo;
mh_class.fetch_msg = mh_fetch_msg;
mh_class.add_msg = mh_add_msg;
mh_class.add_msgs = mh_add_msgs;
mh_class.copy_msg = mh_copy_msg;
mh_class.copy_msgs = mh_copy_msgs;
2004-05-10 12:22:28 +02:00
mh_class.remove_msg = mh_remove_msg;
mh_class.remove_msgs = mh_remove_msgs;
2004-05-10 12:22:28 +02:00
mh_class.remove_all_msg = mh_remove_all_msg;
mh_class.is_msg_changed = mh_is_msg_changed;
}
return &mh_class;
}
2004-01-12 22:28:31 +01:00
static Folder *mh_folder_new(const gchar *name, const gchar *path)
2002-01-16 12:48:36 +01:00
{
Folder *folder;
folder = (Folder *)g_new0(MHFolder, 1);
folder->klass = &mh_class;
2002-01-16 12:48:36 +01:00
mh_folder_init(folder, name, path);
return folder;
}
static void mh_folder_destroy(Folder *folder)
2002-01-16 12:48:36 +01:00
{
folder_local_folder_destroy(LOCAL_FOLDER(folder));
}
static void mh_folder_init(Folder *folder, const gchar *name, const gchar *path)
{
folder_local_folder_init(folder, name, path);
2002-01-16 12:48:36 +01:00
}
gboolean mh_scan_required(Folder *folder, FolderItem *item)
{
gchar *path;
struct stat s;
path = folder_item_get_path(item);
g_return_val_if_fail(path != NULL, FALSE);
if (stat(path, &s) < 0) {
FILE_OP_ERROR(path, "stat");
g_free(path);
return FALSE;
}
if ((s.st_mtime > item->mtime) &&
(s.st_mtime - 3600 != item->mtime)) {
debug_print("MH scan required, folder updated: %s (%ld > %ld)\n",
path,
(long int) s.st_mtime,
(long int) item->mtime);
g_free(path);
return TRUE;
}
debug_print("MH scan not required: %s (%ld <= %ld)\n",
path,
(long int) s.st_mtime,
(long int) item->mtime);
g_free(path);
return FALSE;
}
2002-06-30 01:33:42 +02:00
void mh_get_last_num(Folder *folder, FolderItem *item)
{
gchar *path;
DIR *dp;
struct dirent *d;
gint max = 0;
gint num;
g_return_if_fail(item != NULL);
debug_print("mh_get_last_num(): Scanning %s ...\n", item->path);
path = folder_item_get_path(item);
g_return_if_fail(path != NULL);
if (change_dir(path) < 0) {
g_free(path);
return;
}
g_free(path);
if ((dp = opendir(".")) == NULL) {
FILE_OP_ERROR(item->path, "opendir");
return;
}
while ((d = readdir(dp)) != NULL) {
if ((num = to_number(d->d_name)) > 0 &&
2004-01-12 22:28:31 +01:00
dirent_is_regular_file(d)) {
2002-06-30 01:33:42 +02:00
if (max < num)
max = num;
}
}
closedir(dp);
2002-08-15 09:38:17 +02:00
debug_print("Last number in dir %s = %d\n", item->path, max);
2002-06-30 01:33:42 +02:00
item->last_num = max;
}
gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list, gboolean *old_uids_valid)
2002-06-30 01:33:42 +02:00
{
gchar *path;
DIR *dp;
struct dirent *d;
gint num, nummsgs = 0;
2002-06-30 01:33:42 +02:00
g_return_val_if_fail(item != NULL, -1);
2002-06-30 01:33:42 +02:00
debug_print("mh_get_num_list(): Scanning %s ...\n", item->path);
2002-06-30 01:33:42 +02:00
*old_uids_valid = TRUE;
2002-06-30 01:33:42 +02:00
path = folder_item_get_path(item);
g_return_val_if_fail(path != NULL, -1);
2002-06-30 01:33:42 +02:00
if (change_dir(path) < 0) {
g_free(path);
return -1;
2002-06-30 01:33:42 +02:00
}
g_free(path);
if ((dp = opendir(".")) == NULL) {
FILE_OP_ERROR(item->path, "opendir");
return -1;
2002-06-30 01:33:42 +02:00
}
while ((d = readdir(dp)) != NULL) {
if ((num = to_number(d->d_name)) > 0) {
*list = g_slist_prepend(*list, GINT_TO_POINTER(num));
2004-01-12 22:28:31 +01:00
nummsgs++;
2002-06-30 01:33:42 +02:00
}
}
closedir(dp);
item->mtime = time(NULL);
return nummsgs;
2002-06-30 01:33:42 +02:00
}
2004-01-12 22:28:31 +01:00
static gchar *mh_fetch_msg(Folder *folder, FolderItem *item, gint num)
2001-04-19 14:21:46 +02:00
{
gchar *path;
gchar *file;
g_return_val_if_fail(item != NULL, NULL);
2002-06-30 01:33:42 +02:00
g_return_val_if_fail(num > 0, NULL);
2001-04-19 14:21:46 +02:00
path = folder_item_get_path(item);
file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
2003-10-05 12:10:30 +02:00
2001-04-19 14:21:46 +02:00
if (!is_file_exist(file)) {
g_free(file);
g_free(path);
2001-04-19 14:21:46 +02:00
return NULL;
}
g_free(path);
2001-04-19 14:21:46 +02:00
return file;
}
2004-01-12 22:28:31 +01:00
static MsgInfo *mh_get_msginfo(Folder *folder, FolderItem *item, gint num)
2002-06-30 01:33:42 +02:00
{
MsgInfo *msginfo;
gchar *file;
2002-06-30 01:33:42 +02:00
g_return_val_if_fail(item != NULL, NULL);
if (num <= 0)
return NULL;
2002-06-30 01:33:42 +02:00
file = mh_fetch_msg(folder, item, num);
if (!file) return NULL;
msginfo = mh_parse_msg(file, item);
if (msginfo)
msginfo->msgnum = num;
2002-06-30 01:33:42 +02:00
g_free(file);
2002-06-30 01:33:42 +02:00
return msginfo;
}
2004-01-12 22:28:31 +01:00
static gchar *mh_get_new_msg_filename(FolderItem *dest)
{
gchar *destfile;
gchar *destpath;
destpath = folder_item_get_path(dest);
g_return_val_if_fail(destpath != NULL, NULL);
2002-04-21 11:24:27 +02:00
if (!is_dir_exist(destpath))
make_dir_hier(destpath);
2002-04-21 11:24:27 +02:00
for (;;) {
destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
dest->last_num + 1);
2002-04-21 11:24:27 +02:00
if (is_file_entry_exist(destfile)) {
dest->last_num++;
g_free(destfile);
2002-04-21 11:24:27 +02:00
} else
break;
}
g_free(destpath);
return destfile;
}
2004-01-12 22:28:31 +01:00
static gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file, MsgFlags *flags)
2001-04-19 14:21:46 +02:00
{
gint ret;
GSList file_list;
MsgFileInfo fileinfo;
g_return_val_if_fail(file != NULL, -1);
fileinfo.msginfo = NULL;
fileinfo.file = (gchar *)file;
fileinfo.flags = flags;
file_list.data = &fileinfo;
file_list.next = NULL;
ret = mh_add_msgs(folder, dest, &file_list, NULL);
return ret;
}
2004-01-12 22:28:31 +01:00
static gint mh_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
GRelation *relation)
{
2001-04-19 14:21:46 +02:00
gchar *destfile;
GSList *cur;
MsgFileInfo *fileinfo;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(file_list != NULL, -1);
2001-04-19 14:21:46 +02:00
if (dest->last_num < 0) {
2002-06-30 01:33:42 +02:00
mh_get_last_num(folder, dest);
2001-04-19 14:21:46 +02:00
if (dest->last_num < 0) return -1;
}
for (cur = file_list; cur != NULL; cur = cur->next) {
fileinfo = (MsgFileInfo *)cur->data;
destfile = mh_get_new_msg_filename(dest);
if (destfile == NULL) return -1;
#ifdef G_OS_UNIX
if (link(fileinfo->file, destfile) < 0) {
#endif
if (copy_file(fileinfo->file, destfile, TRUE) < 0) {
g_warning(_("can't copy message %s to %s\n"),
fileinfo->file, destfile);
g_free(destfile);
return -1;
}
#ifdef G_OS_UNIX
2001-05-17 15:25:31 +02:00
}
#endif
if (relation != NULL)
g_relation_insert(relation, fileinfo, GINT_TO_POINTER(dest->last_num + 1));
g_free(destfile);
dest->last_num++;
2001-05-17 15:25:31 +02:00
}
mh_write_sequences(dest, TRUE);
return dest->last_num;
2001-04-19 14:21:46 +02:00
}
2004-01-12 22:28:31 +01:00
static gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
{
GSList msglist;
g_return_val_if_fail(msginfo != NULL, -1);
msglist.data = msginfo;
msglist.next = NULL;
return mh_copy_msgs(folder, dest, &msglist, NULL);
}
static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
GRelation *relation)
2001-04-19 14:21:46 +02:00
{
gboolean dest_need_scan = FALSE;
2001-04-19 14:21:46 +02:00
gchar *srcfile;
gchar *destfile;
2001-07-30 07:49:36 +02:00
gint filemode = 0;
FolderItemPrefs *prefs;
MsgInfo *msginfo = NULL;
gboolean remove_special_headers = FALSE;
MsgInfoList *cur = NULL;
gint curnum = 0, total = 0;
gchar *srcpath = NULL;
gboolean full_fetch = FALSE;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(msglist != NULL, -1);
msginfo = (MsgInfo *)msglist->data;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(msginfo != NULL, -1);
if (msginfo->folder == dest) {
g_warning("the src folder is identical to the dest.\n");
2001-04-19 14:21:46 +02:00
return -1;
}
if (msginfo->folder->folder != dest->folder)
full_fetch = TRUE;
2001-04-19 14:21:46 +02:00
if (dest->last_num < 0) {
2002-06-30 01:33:42 +02:00
mh_get_last_num(folder, dest);
2001-04-19 14:21:46 +02:00
if (dest->last_num < 0) return -1;
}
if ((MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags))
&& !folder_has_parent_of_type(dest, F_QUEUE)
&& !folder_has_parent_of_type(dest, F_DRAFT)) {
/* as every msginfo comes from the same folder, it is supposed they
* will either match the preceding condition either all or none.
*/
remove_special_headers = TRUE;
} else if (!(MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags))
&& (folder_has_parent_of_type(dest, F_QUEUE)
|| folder_has_parent_of_type(dest, F_DRAFT))) {
return -1;
}
prefs = dest->prefs;
srcpath = folder_item_get_path(msginfo->folder);
total = g_slist_length(msglist);
if (total > 100) {
if (MSG_IS_MOVE(msginfo->flags))
statusbar_print_all(_("Moving messages..."));
else
statusbar_print_all(_("Copying messages..."));
}
for (cur = msglist; cur; cur = cur->next) {
gboolean moved = FALSE;
msginfo = (MsgInfo *)cur->data;
if (!msginfo) {
goto err_reset_status;
}
if (!full_fetch) {
srcfile = g_strconcat(srcpath,
G_DIR_SEPARATOR_S,
itos(msginfo->msgnum), NULL);
} else {
srcfile = procmsg_get_message_file(msginfo);
}
if (!srcfile) {
goto err_reset_status;
}
destfile = mh_get_new_msg_filename(dest);
if (!destfile) {
g_free(srcfile);
goto err_reset_status;
}
if (total > 100) {
statusbar_progress_all(curnum, total, 100);
if (curnum % 100 == 0)
GTK_EVENTS_FLUSH();
curnum++;
}
debug_print("Copying message %s%c%d to %s ...\n",
msginfo->folder->path, G_DIR_SEPARATOR,
msginfo->msgnum, dest->path);
if (remove_special_headers) {
if (procmsg_remove_special_headers(srcfile, destfile) !=0) {
g_free(srcfile);
g_free(destfile);
goto err_reset_status;
}
} else if (MSG_IS_MOVE(msginfo->flags)) {
if (move_file(srcfile, destfile, TRUE) < 0) {
FILE_OP_ERROR(srcfile, "move");
if (copy_file(srcfile, destfile, TRUE) < 0) {
FILE_OP_ERROR(srcfile, "copy");
g_free(srcfile);
g_free(destfile);
goto err_reset_status;
}
}
} else if (copy_file(srcfile, destfile, TRUE) < 0) {
FILE_OP_ERROR(srcfile, "copy");
g_free(srcfile);
g_free(destfile);
goto err_reset_status;
}
if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
if (chmod(destfile, prefs->folder_chmod) < 0)
FILE_OP_ERROR(destfile, "chmod");
/* for mark file */
filemode = prefs->folder_chmod;
if (filemode & S_IRGRP) filemode |= S_IWGRP;
if (filemode & S_IROTH) filemode |= S_IWOTH;
}
if (relation)
g_relation_insert(relation, msginfo, GINT_TO_POINTER(dest->last_num+1));
2001-04-19 14:21:46 +02:00
g_free(srcfile);
g_free(destfile);
dest->last_num++;
2001-04-19 14:21:46 +02:00
}
g_free(srcpath);
mh_write_sequences(dest, TRUE);
dest_need_scan = mh_scan_required(dest->folder, dest);
if (!dest_need_scan)
dest->mtime = time(NULL);
if (total > 100) {
statusbar_progress_all(0,0,0);
statusbar_pop_all();
}
2001-04-19 14:21:46 +02:00
return dest->last_num;
err_reset_status:
g_free(srcpath);
mh_write_sequences(dest, TRUE);
if (total > 100) {
statusbar_progress_all(0,0,0);
statusbar_pop_all();
}
return -1;
2001-04-19 14:21:46 +02:00
}
2001-05-28 00:40:29 +02:00
2004-01-12 22:28:31 +01:00
static gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
2001-04-19 14:21:46 +02:00
{
gboolean need_scan = FALSE;
2001-04-19 14:21:46 +02:00
gchar *file;
g_return_val_if_fail(item != NULL, -1);
file = mh_fetch_msg(folder, item, num);
g_return_val_if_fail(file != NULL, -1);
need_scan = mh_scan_required(folder, item);
if (g_unlink(file) < 0) {
2001-04-19 14:21:46 +02:00
FILE_OP_ERROR(file, "unlink");
g_free(file);
return -1;
}
if (!need_scan)
item->mtime = time(NULL);
2001-04-19 14:21:46 +02:00
g_free(file);
return 0;
}
static gint mh_remove_msgs(Folder *folder, FolderItem *item,
MsgInfoList *msglist, GRelation *relation)
{
gboolean need_scan = FALSE;
gchar *path, *file;
MsgInfoList *cur;
g_return_val_if_fail(item != NULL, -1);
path = folder_item_get_path(item);
for (cur = msglist; cur; cur = cur->next) {
MsgInfo *msginfo = (MsgInfo *)cur->data;
if (msginfo == NULL)
continue;
file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
if (file == NULL)
continue;
if (g_unlink(file) < 0) {
g_free(file);
continue;
}
g_free(file);
}
need_scan = mh_scan_required(folder, item);
if (!need_scan)
item->mtime = time(NULL);
g_free(path);
return 0;
}
2004-01-12 22:28:31 +01:00
static gint mh_remove_all_msg(Folder *folder, FolderItem *item)
2001-04-19 14:21:46 +02:00
{
gchar *path;
2001-06-06 15:05:23 +02:00
gint val;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(item != NULL, -1);
path = folder_item_get_path(item);
g_return_val_if_fail(path != NULL, -1);
2001-06-06 15:05:23 +02:00
val = remove_all_numbered_files(path);
2001-04-19 14:21:46 +02:00
g_free(path);
mh_write_sequences(item, TRUE);
2001-06-06 15:05:23 +02:00
return val;
2001-04-19 14:21:46 +02:00
}
2004-01-12 22:28:31 +01:00
static gboolean mh_is_msg_changed(Folder *folder, FolderItem *item,
MsgInfo *msginfo)
2001-04-19 14:21:46 +02:00
{
struct stat s;
if (g_stat(itos(msginfo->msgnum), &s) < 0 ||
msginfo->size != s.st_size || (
(msginfo->mtime - s.st_mtime != 0) &&
(msginfo->mtime - s.st_mtime != 3600) &&
(msginfo->mtime - s.st_mtime != -3600)))
2001-04-19 14:21:46 +02:00
return TRUE;
return FALSE;
}
2004-01-12 22:28:31 +01:00
static gint mh_scan_tree(Folder *folder)
2001-04-19 14:21:46 +02:00
{
FolderItem *item;
gchar *rootpath;
2004-01-12 22:28:31 +01:00
g_return_val_if_fail(folder != NULL, -1);
2001-04-19 14:21:46 +02:00
2003-08-25 16:14:47 +02:00
if (!folder->node) {
item = folder_item_new(folder, folder->name, NULL);
item->folder = folder;
folder->node = item->node = g_node_new(item);
} else
item = FOLDER_ITEM(folder->node->data);
2001-04-19 14:21:46 +02:00
rootpath = folder_item_get_path(item);
if (change_dir(rootpath) < 0) {
g_free(rootpath);
2004-01-12 22:28:31 +01:00
return -1;
2001-04-19 14:21:46 +02:00
}
g_free(rootpath);
2002-03-19 09:37:53 +01:00
mh_create_tree(folder);
2003-08-25 16:14:47 +02:00
mh_remove_missing_folder_items(folder);
mh_scan_tree_recursive(item);
2004-01-12 22:28:31 +01:00
return 0;
2001-04-19 14:21:46 +02:00
}
#define MAKE_DIR_IF_NOT_EXIST(dir) \
{ \
if (!is_dir_exist(dir)) { \
if (is_file_exist(dir)) { \
g_warning("File `%s' already exists.\n" \
"Can't create folder.", dir); \
2001-04-19 14:21:46 +02:00
return -1; \
} \
2002-05-28 08:42:48 +02:00
if (make_dir(dir) < 0) \
2001-04-19 14:21:46 +02:00
return -1; \
} \
}
2004-01-12 22:28:31 +01:00
static gint mh_create_tree(Folder *folder)
2001-04-19 14:21:46 +02:00
{
gchar *rootpath;
g_return_val_if_fail(folder != NULL, -1);
CHDIR_RETURN_VAL_IF_FAIL(get_mail_base_dir(), -1);
2001-04-19 14:21:46 +02:00
rootpath = LOCAL_FOLDER(folder)->rootpath;
MAKE_DIR_IF_NOT_EXIST(rootpath);
CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
MAKE_DIR_IF_NOT_EXIST(INBOX_DIR);
MAKE_DIR_IF_NOT_EXIST(OUTBOX_DIR);
MAKE_DIR_IF_NOT_EXIST(QUEUE_DIR);
MAKE_DIR_IF_NOT_EXIST(DRAFT_DIR);
MAKE_DIR_IF_NOT_EXIST(TRASH_DIR);
return 0;
}
#undef MAKE_DIR_IF_NOT_EXIST
2004-01-12 22:28:31 +01:00
static gchar *mh_item_get_path(Folder *folder, FolderItem *item)
{
gchar *folder_path, *path;
gchar *real_path;
g_return_val_if_fail(folder != NULL, NULL);
g_return_val_if_fail(item != NULL, NULL);
folder_path = g_strdup(LOCAL_FOLDER(folder)->rootpath);
g_return_val_if_fail(folder_path != NULL, NULL);
/* FIXME: [W32] The code below does not correctly merge
relative filenames; there should be a function to handle
this. */
if ( !is_relative_filename (folder_path) ) {
if (item->path)
path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
item->path, NULL);
else
path = g_strdup(folder_path);
} else {
if (item->path)
path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
folder_path, G_DIR_SEPARATOR_S,
item->path, NULL);
else
path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
folder_path, NULL);
}
g_free(folder_path);
real_path = mh_filename_from_utf8(path);
if (!is_dir_exist(real_path) && is_dir_exist(path)) {
/* mmh, older version did put utf8 filenames instead of
* the correct encoding */
rename(path, real_path);
folder_item_scan(item);
}
g_free(path);
return real_path;
}
2004-01-12 22:28:31 +01:00
static FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
const gchar *name)
2001-04-19 14:21:46 +02:00
{
2003-10-05 12:10:30 +02:00
gchar *path, *real_name;
2001-04-19 14:21:46 +02:00
gchar *fullpath;
FolderItem *new_item;
gchar *mh_sequences_filename;
FILE *mh_sequences_file;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(folder != NULL, NULL);
g_return_val_if_fail(parent != NULL, NULL);
g_return_val_if_fail(name != NULL, NULL);
path = folder_item_get_path(parent);
2002-11-06 23:32:44 +01:00
if (!is_dir_exist(path))
if (make_dir_hier(path) != 0)
return NULL;
2003-10-05 12:10:30 +02:00
real_name = mh_filename_from_utf8(name);
fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, real_name, NULL);
g_free(real_name);
2001-04-19 14:21:46 +02:00
g_free(path);
2002-05-28 08:42:48 +02:00
if (make_dir(fullpath) < 0) {
2001-04-19 14:21:46 +02:00
g_free(fullpath);
return NULL;
}
g_free(fullpath);
if (parent->path)
path = g_strconcat(parent->path, G_DIR_SEPARATOR_S, name,
NULL);
else
path = g_strdup(name);
new_item = folder_item_new(folder, name, path);
2001-04-19 14:21:46 +02:00
folder_item_append(parent, new_item);
2001-04-19 14:21:46 +02:00
g_free(path);
path = folder_item_get_path(new_item);
mh_sequences_filename = g_strconcat(path, G_DIR_SEPARATOR_S,
".mh_sequences", NULL);
if ((mh_sequences_file = g_fopen(mh_sequences_filename, "a+b")) != NULL) {
fclose(mh_sequences_file);
}
g_free(mh_sequences_filename);
g_free(path);
2001-04-19 14:21:46 +02:00
return new_item;
}
2004-01-12 22:28:31 +01:00
static gint mh_rename_folder(Folder *folder, FolderItem *item,
const gchar *name)
2001-04-19 14:21:46 +02:00
{
2003-10-05 12:10:30 +02:00
gchar *real_name;
2001-04-19 14:21:46 +02:00
gchar *oldpath;
gchar *dirname;
2003-10-05 12:10:30 +02:00
gchar *newpath, *utf8newpath;
2001-04-19 14:21:46 +02:00
gchar *paths[2];
g_return_val_if_fail(folder != NULL, -1);
g_return_val_if_fail(item != NULL, -1);
g_return_val_if_fail(item->path != NULL, -1);
g_return_val_if_fail(name != NULL, -1);
oldpath = folder_item_get_path(item);
if (!is_dir_exist(oldpath))
make_dir_hier(oldpath);
dirname = g_path_get_dirname(oldpath);
2003-10-05 12:10:30 +02:00
real_name = mh_filename_from_utf8(name);
newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, real_name, NULL);
g_free(real_name);
2001-04-19 14:21:46 +02:00
if (g_rename(oldpath, newpath) < 0) {
2001-04-19 14:21:46 +02:00
FILE_OP_ERROR(oldpath, "rename");
g_free(oldpath);
g_free(newpath);
return -1;
}
g_free(oldpath);
g_free(newpath);
if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
dirname = g_path_get_dirname(item->path);
2003-10-05 12:10:30 +02:00
utf8newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S,
name, NULL);
2001-04-19 14:21:46 +02:00
g_free(dirname);
} else
2003-10-05 12:10:30 +02:00
utf8newpath = g_strdup(name);
2001-04-19 14:21:46 +02:00
g_free(item->name);
item->name = g_strdup(name);
paths[0] = g_strdup(item->path);
2003-10-05 12:10:30 +02:00
paths[1] = utf8newpath;
2003-08-25 16:14:47 +02:00
g_node_traverse(item->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
2001-04-19 14:21:46 +02:00
mh_rename_folder_func, paths);
g_free(paths[0]);
g_free(paths[1]);
return 0;
}
2004-01-12 22:28:31 +01:00
static gint mh_remove_folder(Folder *folder, FolderItem *item)
2001-04-19 14:21:46 +02:00
{
gchar *path;
g_return_val_if_fail(folder != NULL, -1);
g_return_val_if_fail(item != NULL, -1);
g_return_val_if_fail(item->path != NULL, -1);
path = folder_item_get_path(item);
if (remove_dir_recursive(path) < 0) {
g_warning("can't remove directory `%s'\n", path);
g_free(path);
return -1;
}
g_free(path);
folder_item_remove(item);
return 0;
}
static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
{
MsgInfo *msginfo;
MsgFlags flags;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(item != NULL, NULL);
g_return_val_if_fail(file != NULL, NULL);
2004-01-12 22:28:31 +01:00
flags.perm_flags = MSG_NEW|MSG_UNREAD;
flags.tmp_flags = 0;
if (folder_has_parent_of_type(item, F_QUEUE)) {
MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
} else if (folder_has_parent_of_type(item, F_DRAFT)) {
MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
2001-04-19 14:21:46 +02:00
}
2002-06-19 09:31:13 +02:00
msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2001-04-19 14:21:46 +02:00
if (!msginfo) return NULL;
msginfo->msgnum = atoi(file);
msginfo->folder = item;
return msginfo;
}
2003-08-25 16:14:47 +02:00
static gboolean mh_remove_missing_folder_items_func(GNode *node, gpointer data)
{
FolderItem *item;
gchar *path;
g_return_val_if_fail(node->data != NULL, FALSE);
if (G_NODE_IS_ROOT(node))
return FALSE;
item = FOLDER_ITEM(node->data);
path = folder_item_get_path(item);
if (!is_dir_exist(path)) {
debug_print("folder '%s' not found. removing...\n", path);
folder_item_remove(item);
}
g_free(path);
return FALSE;
}
static void mh_remove_missing_folder_items(Folder *folder)
{
g_return_if_fail(folder != NULL);
debug_print("searching missing folders...\n");
g_node_traverse(folder->node, G_POST_ORDER, G_TRAVERSE_ALL, -1,
mh_remove_missing_folder_items_func, folder);
}
static void mh_scan_tree_recursive(FolderItem *item)
2001-04-19 14:21:46 +02:00
{
2003-08-25 16:14:47 +02:00
Folder *folder;
#ifdef G_OS_WIN32
GDir *dir;
#else
2001-04-19 14:21:46 +02:00
DIR *dp;
struct dirent *d;
#endif
const gchar *dir_name;
2001-04-19 14:21:46 +02:00
struct stat s;
2003-10-05 12:10:30 +02:00
gchar *real_path, *entry, *utf8entry, *utf8name;
2001-04-19 14:21:46 +02:00
gint n_msg = 0;
g_return_if_fail(item != NULL);
g_return_if_fail(item->folder != NULL);
2003-08-25 16:14:47 +02:00
folder = item->folder;
2003-10-05 12:10:30 +02:00
real_path = item->path ? mh_filename_from_utf8(item->path) : g_strdup(".");
#ifdef G_OS_WIN32
dir = g_dir_open(real_path, 0, NULL);
if (!dir) {
g_warning("failed to open directory: %s\n", real_path);
g_free(real_path);
return;
}
#else
2003-10-05 12:10:30 +02:00
dp = opendir(real_path);
2001-04-19 14:21:46 +02:00
if (!dp) {
2003-10-05 12:10:30 +02:00
FILE_OP_ERROR(real_path, "opendir");
2001-04-19 14:21:46 +02:00
return;
}
#endif
2003-10-05 12:10:30 +02:00
g_free(real_path);
2001-04-19 14:21:46 +02:00
debug_print("scanning %s ...\n",
item->path ? item->path
: LOCAL_FOLDER(item->folder)->rootpath);
2003-08-25 16:14:47 +02:00
if (folder->ui_func)
folder->ui_func(folder, item, folder->ui_func_data);
2001-04-19 14:21:46 +02:00
#ifdef G_OS_WIN32
while ((dir_name = g_dir_read_name(dir)) != NULL) {
#else
2001-04-19 14:21:46 +02:00
while ((d = readdir(dp)) != NULL) {
dir_name = d->d_name;
#endif
if (dir_name[0] == '.') continue;
2001-04-19 14:21:46 +02:00
utf8name = mh_filename_to_utf8(dir_name);
2001-04-19 14:21:46 +02:00
if (item->path)
2003-10-05 12:10:30 +02:00
utf8entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
utf8name, NULL);
2001-04-19 14:21:46 +02:00
else
2003-10-05 12:10:30 +02:00
utf8entry = g_strdup(utf8name);
entry = mh_filename_from_utf8(utf8entry);
2001-04-19 14:21:46 +02:00
2004-01-12 22:28:31 +01:00
if (
#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
2004-01-12 22:28:31 +01:00
d->d_type == DT_DIR ||
(d->d_type == DT_UNKNOWN &&
#endif
g_stat(entry, &s) == 0 && S_ISDIR(s.st_mode)
#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
2004-01-12 22:28:31 +01:00
)
#endif
) {
2003-08-25 16:14:47 +02:00
FolderItem *new_item = NULL;
GNode *node;
2001-04-19 14:21:46 +02:00
2003-08-25 16:14:47 +02:00
node = item->node;
for (node = node->children; node != NULL; node = node->next) {
FolderItem *cur_item = FOLDER_ITEM(node->data);
if (!strcmp2(cur_item->path, entry)) {
new_item = cur_item;
break;
}
}
if (!new_item) {
debug_print("new folder '%s' found.\n", entry);
2003-10-05 12:10:30 +02:00
new_item = folder_item_new(folder, utf8name, utf8entry);
2003-08-25 16:14:47 +02:00
folder_item_append(item, new_item);
}
2001-04-19 14:21:46 +02:00
if (!item->path) {
2003-08-25 16:14:47 +02:00
if (!folder->inbox &&
!strcmp(dir_name, INBOX_DIR)) {
2001-04-19 14:21:46 +02:00
new_item->stype = F_INBOX;
2003-08-25 16:14:47 +02:00
folder->inbox = new_item;
} else if (!folder->outbox &&
!strcmp(dir_name, OUTBOX_DIR)) {
2001-04-19 14:21:46 +02:00
new_item->stype = F_OUTBOX;
2003-08-25 16:14:47 +02:00
folder->outbox = new_item;
} else if (!folder->draft &&
!strcmp(dir_name, DRAFT_DIR)) {
2001-04-19 14:21:46 +02:00
new_item->stype = F_DRAFT;
2003-08-25 16:14:47 +02:00
folder->draft = new_item;
} else if (!folder->queue &&
!strcmp(dir_name, QUEUE_DIR)) {
2001-04-19 14:21:46 +02:00
new_item->stype = F_QUEUE;
2003-08-25 16:14:47 +02:00
folder->queue = new_item;
} else if (!folder->trash &&
!strcmp(dir_name, TRASH_DIR)) {
2001-04-19 14:21:46 +02:00
new_item->stype = F_TRASH;
2003-08-25 16:14:47 +02:00
folder->trash = new_item;
2001-04-19 14:21:46 +02:00
}
}
2003-08-25 16:14:47 +02:00
mh_scan_tree_recursive(new_item);
} else if (to_number(dir_name) > 0) n_msg++;
2001-04-19 14:21:46 +02:00
g_free(entry);
2003-10-05 12:10:30 +02:00
g_free(utf8entry);
g_free(utf8name);
2001-04-19 14:21:46 +02:00
}
#ifdef G_OS_WIN32
g_dir_close(dir);
#else
2001-04-19 14:21:46 +02:00
closedir(dp);
#endif
2001-04-19 14:21:46 +02:00
item->mtime = time(NULL);
2001-04-19 14:21:46 +02:00
}
static gboolean mh_rename_folder_func(GNode *node, gpointer data)
{
FolderItem *item = node->data;
gchar **paths = data;
const gchar *oldpath = paths[0];
const gchar *newpath = paths[1];
gchar *base;
gchar *new_itempath;
gint oldpathlen;
oldpathlen = strlen(oldpath);
if (strncmp(oldpath, item->path, oldpathlen) != 0) {
g_warning("path doesn't match: %s, %s\n", oldpath, item->path);
return TRUE;
}
base = item->path + oldpathlen;
while (*base == G_DIR_SEPARATOR) base++;
if (*base == '\0')
new_itempath = g_strdup(newpath);
else
new_itempath = g_strconcat(newpath, G_DIR_SEPARATOR_S, base,
NULL);
g_free(item->path);
item->path = new_itempath;
return FALSE;
}
2003-10-05 12:10:30 +02:00
static gchar *mh_filename_from_utf8(const gchar *path)
{
gchar *real_path = g_filename_from_utf8(path, -1, NULL, NULL, NULL);
2003-10-05 12:10:30 +02:00
if (!real_path) {
g_warning("mh_filename_from_utf8: faild to convert character set\n");
real_path = g_strdup(path);
}
return real_path;
}
static gchar *mh_filename_to_utf8(const gchar *path)
{
gchar *utf8path = g_filename_to_utf8(path, -1, NULL, NULL, NULL);
2003-10-05 12:10:30 +02:00
if (!utf8path) {
g_warning("mh_filename_to_utf8: faild to convert character set\n");
utf8path = g_strdup(path);
}
return utf8path;
}
static gint sort_cache_list_by_msgnum(gconstpointer a, gconstpointer b)
{
MsgInfo *msginfo_a = (MsgInfo *) a;
MsgInfo *msginfo_b = (MsgInfo *) b;
return (msginfo_a->msgnum - msginfo_b->msgnum);
}
static gchar *get_unseen_seq_name(void)
{
static gchar *seq_name = NULL;
if (!seq_name) {
gchar buf[BUFFSIZE];
gchar *tmp;
gchar *profile_path = g_strconcat(
get_home_dir(), G_DIR_SEPARATOR_S,
".mh_profile", NULL);
FILE *fp = g_fopen(profile_path, "r");
if (fp) {
while (fgets(buf, sizeof(buf), fp) != NULL) {
if (!strncmp(buf, "Unseen-Sequence:", strlen("Unseen-Sequence:"))) {
gchar *seq_tmp = buf+strlen("Unseen-Sequence:");
while (*seq_tmp == ' ')
seq_tmp++;
seq_name = g_strdup(seq_tmp);
seq_name = strretchomp(seq_name);
break;
}
}
fclose(fp);
}
if (!seq_name)
seq_name = g_strdup("unseen");
tmp = g_strdup_printf("%s:", seq_name);
g_free(seq_name);
seq_name = tmp;
}
return seq_name;
}
static gint mh_get_flags(Folder *folder, FolderItem *item,
MsgInfoList *msginfo_list, GRelation *msgflags)
{
gchar *mh_sequences_filename;
FILE *mh_sequences_file;
gchar buf[BUFFSIZE];
gchar *unseen_list = NULL;
gchar *path;
MsgInfoList *mcur = NULL;
/*
GTimer *timer = g_timer_new();
g_timer_start(timer);
*/
if (!item)
return 0;
/* don't update from .mh_sequences if the item's opened: mails may have
* been marked read/unread and it's not yet written in the file. */
if (item->opened)
return 0;
path = folder_item_get_path(item);
mh_sequences_filename = g_strconcat(path, G_DIR_SEPARATOR_S,
".mh_sequences", NULL);
g_free(path);
if ((mh_sequences_file = g_fopen(mh_sequences_filename, "r+b")) != NULL) {
while (fgets(buf, sizeof(buf), mh_sequences_file) != NULL) {
if (!strncmp(buf, get_unseen_seq_name(), strlen(get_unseen_seq_name()))) {
unseen_list = g_strdup(buf+strlen(get_unseen_seq_name()));
break;
}
}
fclose(mh_sequences_file);
}
g_free(mh_sequences_filename);
if (unseen_list) {
gchar *cur = NULL;
gchar *token = NULL, *next = NULL, *boundary = NULL;
gint num = 0;
GHashTable *unseen_table = g_hash_table_new(g_direct_hash, g_direct_equal);
cur = unseen_list = strretchomp(unseen_list);
debug_print("found unseen list in .mh_sequences: %s\n", unseen_list);
next_token:
while (*cur && *cur == ' ')
cur++;
if ((next = strchr(cur, ' ')) != NULL) {
token = cur;
cur = next+1;
*next = '\0';
} else {
token = cur;
cur = NULL;
}
if ((boundary = strchr(token, '-')) != NULL) {
gchar *start, *end;
int i;
start = token;
end = boundary+1;
*boundary='\0';
for (i = atoi(start); i <= atoi(end); i++) {
g_hash_table_insert(unseen_table, GINT_TO_POINTER(i), GINT_TO_POINTER(1));
}
} else if ((num = atoi(token)) > 0) {
g_hash_table_insert(unseen_table, GINT_TO_POINTER(num), GINT_TO_POINTER(1));
}
if (cur)
goto next_token;
for (mcur = msginfo_list; mcur; mcur = mcur->next) {
MsgInfo *msginfo = (MsgInfo *)mcur->data;
MsgPermFlags flags = msginfo->flags.perm_flags;
if (g_hash_table_lookup(unseen_table, GINT_TO_POINTER(msginfo->msgnum))) {
flags |= MSG_UNREAD;
} else if (!(flags & MSG_NEW)) { /* don't mark new msgs as read */
flags &= ~(MSG_UNREAD);
}
if (flags != msginfo->flags.perm_flags)
g_relation_insert(msgflags, msginfo, GINT_TO_POINTER(flags));
}
g_hash_table_destroy(unseen_table);
g_free(unseen_list);
}
/*
g_timer_stop(timer);
printf("mh_get_flags: %f secs\n", g_timer_elapsed(timer, NULL));
g_timer_destroy(timer);
*/
return 0;
}
static void mh_write_sequences(FolderItem *item, gboolean remove_unseen)
{
gchar *mh_sequences_old, *mh_sequences_new;
FILE *mh_sequences_old_fp, *mh_sequences_new_fp;
gchar buf[BUFFSIZE];
gchar *path = NULL;
/*
GTimer *timer = g_timer_new();
g_timer_start(timer);
*/
if (!item)
return;
path = folder_item_get_path(item);
mh_sequences_old = g_strconcat(path, G_DIR_SEPARATOR_S,
".mh_sequences", NULL);
mh_sequences_new = g_strconcat(path, G_DIR_SEPARATOR_S,
".mh_sequences.new", NULL);
if ((mh_sequences_new_fp = g_fopen(mh_sequences_new, "w+b")) != NULL) {
GSList *msglist = folder_item_get_msg_list(item);
GSList *cur;
MsgInfo *info = NULL;
gint start = -1, end = -1;
gchar *sequence = g_strdup("");
msglist = g_slist_sort(msglist, sort_cache_list_by_msgnum);
cur = msglist;
/* write the unseen sequence if we don't have to scrap it */
if (!remove_unseen) do {
info = (MsgInfo *)(cur ? cur->data:NULL);
if (info && (MSG_IS_UNREAD(info->flags) || MSG_IS_NEW(info->flags))) {
if (start < 0)
start = end = info->msgnum;
else
end = info->msgnum;
} else {
if (start > 0 && end > 0) {
gchar *tmp = sequence;
if (start != end)
sequence = g_strdup_printf("%s %d-%d ", tmp, start, end);
else
sequence = g_strdup_printf("%s %d ", tmp, start);
g_free(tmp);
start = end = -1;
}
}
cur = cur ? cur->next:NULL;
} while (cur || (start > 0 && end > 0));
if (sequence && strlen(sequence)) {
fprintf(mh_sequences_new_fp, "%s%s\n",
get_unseen_seq_name(), sequence);
debug_print("wrote unseen sequence: '%s%s'\n",
get_unseen_seq_name(), sequence);
}
/* rewrite the rest of the file */
if ((mh_sequences_old_fp = g_fopen(mh_sequences_old, "r+b")) != NULL) {
while (fgets(buf, sizeof(buf), mh_sequences_old_fp) != NULL) {
if (strncmp(buf, get_unseen_seq_name(), strlen(get_unseen_seq_name())))
fprintf(mh_sequences_new_fp, "%s", buf);
}
fclose(mh_sequences_old_fp);
}
fclose(mh_sequences_new_fp);
g_rename(mh_sequences_new, mh_sequences_old);
g_free(sequence);
procmsg_msg_list_free(msglist);
}
g_free(mh_sequences_old);
g_free(mh_sequences_new);
g_free(path);
/*
g_timer_stop(timer);
printf("mh_get_flags: %f secs\n", g_timer_elapsed(timer, NULL));
g_timer_destroy(timer);
*/
}
static int mh_item_close(Folder *folder, FolderItem *item)
{
mh_write_sequences(item, FALSE);
return 0;
}