claws-mail/src/folder.c

3993 lines
99 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 <stdio.h>
#include <string.h>
2002-06-30 01:33:42 +02:00
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
2002-06-19 09:31:13 +02:00
#include <stdlib.h>
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
#ifdef WIN32
#include <w32lib.h>
#endif
2001-04-19 14:21:46 +02:00
#include "folder.h"
#include "session.h"
#include "inc.h"
2001-04-19 14:21:46 +02:00
#include "imap.h"
#include "news.h"
#include "mh.h"
#include "utils.h"
#include "xml.h"
#include "codeconv.h"
#include "prefs_gtk.h"
2001-04-19 14:21:46 +02:00
#include "account.h"
#include "filtering.h"
2002-06-30 01:33:42 +02:00
#include "procheader.h"
#include "hooks.h"
#include "log.h"
#include "folder_item_prefs.h"
2004-01-12 22:28:31 +01:00
#include "remotefolder.h"
#include "partial_download.h"
#include "statusbar.h"
#include "gtkutils.h"
#include "timing.h"
#include "compose.h"
2001-04-19 14:21:46 +02:00
/* Dependecies to be removed ?! */
#include "prefs_common.h"
#include "prefs_account.h"
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
2001-04-19 14:21:46 +02:00
static GList *folder_list = NULL;
2004-02-21 12:01:01 +01:00
static GSList *class_list = NULL;
static GSList *folder_unloaded_list = NULL;
2001-04-19 14:21:46 +02:00
2004-01-12 22:28:31 +01:00
void folder_init (Folder *folder,
2001-04-19 14:21:46 +02:00
const gchar *name);
static gchar *folder_get_list_path (void);
2004-02-21 12:01:01 +01:00
static GNode *folder_get_xml_node (Folder *folder);
static Folder *folder_get_from_xml (GNode *node);
2001-07-31 08:17:48 +02:00
static void folder_update_op_count_rec (GNode *node);
2001-04-19 14:21:46 +02:00
static void folder_get_persist_prefs_recursive
(GNode *node, GHashTable *pptable);
static gboolean persist_prefs_free (gpointer key, gpointer val, gpointer data);
2002-06-30 01:33:42 +02:00
void folder_item_read_cache (FolderItem *item);
gint folder_item_scan_full (FolderItem *item, gboolean filtering);
2004-06-25 10:05:09 +02:00
static void folder_item_update_with_msg (FolderItem *item, FolderItemUpdateFlags update_flags,
MsgInfo *msg);
void folder_system_init(void)
{
folder_register_class(mh_get_class());
folder_register_class(imap_get_class());
folder_register_class(news_get_class());
}
GSList *folder_get_class_list(void)
{
2004-02-21 12:01:01 +01:00
return class_list;
}
void folder_register_class(FolderClass *klass)
{
2004-02-21 12:01:01 +01:00
GSList *xmllist, *cur;
debug_print("registering folder class %s\n", klass->idstr);
2004-02-21 12:01:01 +01:00
class_list = g_slist_append(class_list, klass);
xmllist = g_slist_copy(folder_unloaded_list);
for (cur = xmllist; cur != NULL; cur = g_slist_next(cur)) {
GNode *node = (GNode *) cur->data;
XMLNode *xmlnode = (XMLNode *) node->data;
GList *cur = xmlnode->tag->attr;
for (; cur != NULL; cur = g_list_next(cur)) {
XMLAttr *attr = (XMLAttr *) cur->data;
if (!attr || !attr->name || !attr->value) continue;
if (!strcmp(attr->name, "type") && !strcmp(attr->value, klass->idstr)) {
Folder *folder;
folder = folder_get_from_xml(node);
folder_add(folder);
folder_unloaded_list = g_slist_remove(folder_unloaded_list, node);
cur = NULL;
continue;
}
}
}
g_slist_free(xmllist);
}
void folder_unregister_class(FolderClass *klass)
{
GList *folderlist, *cur;
debug_print("unregistering folder class %s\n", klass->idstr);
class_list = g_slist_remove(class_list, klass);
folderlist = g_list_copy(folder_get_list());
for (cur = folderlist; cur != NULL; cur = g_list_next(cur)) {
Folder *folder = (Folder *) cur->data;
if (folder->klass == klass) {
GNode *xmlnode = folder_get_xml_node(folder);
folder_unloaded_list = g_slist_append(folder_unloaded_list, xmlnode);
folder_destroy(folder);
}
}
g_list_free(folderlist);
}
Folder *folder_new(FolderClass *klass, const gchar *name, const gchar *path)
2001-04-19 14:21:46 +02:00
{
Folder *folder = NULL;
FolderItem *item;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(klass != NULL, NULL);
2001-04-19 14:21:46 +02:00
name = name ? name : path;
folder = klass->new_folder(name, path);
2001-04-19 14:21:46 +02:00
/* Create root folder item */
item = folder_item_new(folder, name, NULL);
if (item == NULL) {
return NULL;
}
item->folder = folder;
2003-08-25 16:14:47 +02:00
folder->node = item->node = g_node_new(item);
folder->data = NULL;
2001-04-19 14:21:46 +02:00
return folder;
}
2004-01-12 22:28:31 +01:00
void folder_init(Folder *folder, const gchar *name)
2001-04-19 14:21:46 +02:00
{
2002-01-16 12:48:36 +01:00
g_return_if_fail(folder != NULL);
2001-04-19 14:21:46 +02:00
2002-01-16 12:48:36 +01:00
folder_set_name(folder, name);
2002-06-30 01:33:42 +02:00
/* Init folder data */
2002-01-16 12:48:36 +01:00
folder->account = NULL;
2004-05-10 12:22:28 +02:00
folder->sort = 0;
2002-01-16 12:48:36 +01:00
folder->inbox = NULL;
folder->outbox = NULL;
folder->draft = NULL;
folder->queue = NULL;
folder->trash = NULL;
2001-04-19 14:21:46 +02:00
}
static void reset_parent_type(FolderItem *item, gpointer data) {
item->parent_stype = -1;
}
void folder_item_change_type(FolderItem *item, SpecialFolderItemType newtype)
{
Folder *folder = NULL;
FolderUpdateData hookdata;
folder = item->folder;
/* unset previous root of newtype */
switch(newtype) {
case F_INBOX:
folder_item_change_type(folder->inbox, F_NORMAL);
folder->inbox = item;
break;
case F_OUTBOX:
folder_item_change_type(folder->outbox, F_NORMAL);
folder->outbox = item;
break;
case F_QUEUE:
folder_item_change_type(folder->queue, F_NORMAL);
folder->queue = item;
break;
case F_DRAFT:
folder_item_change_type(folder->draft, F_NORMAL);
folder->draft = item;
break;
case F_TRASH:
folder_item_change_type(folder->trash, F_NORMAL);
folder->trash = item;
break;
case F_NORMAL:
default:
break;
}
/* set new type for current folder and sons */
item->stype = newtype;
folder_func_to_all_folders(reset_parent_type, NULL);
hookdata.folder = folder;
hookdata.update_flags = FOLDER_TREE_CHANGED;
hookdata.item = NULL;
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
}
2002-01-16 12:48:36 +01:00
void folder_destroy(Folder *folder)
2001-04-19 14:21:46 +02:00
{
2002-01-16 12:48:36 +01:00
g_return_if_fail(folder != NULL);
g_return_if_fail(folder->klass->destroy_folder != NULL);
2001-04-19 14:21:46 +02:00
2004-05-10 12:22:28 +02:00
folder_remove(folder);
2004-02-21 12:01:01 +01:00
2002-01-16 12:48:36 +01:00
folder_tree_destroy(folder);
folder->klass->destroy_folder(folder);
2003-04-09 20:24:52 +02:00
g_free(folder->name);
g_free(folder);
2001-04-19 14:21:46 +02:00
}
2004-01-12 22:28:31 +01:00
void folder_set_xml(Folder *folder, XMLTag *tag)
2001-04-19 14:21:46 +02:00
{
2004-01-12 22:28:31 +01:00
GList *cur;
2004-02-21 12:01:01 +01:00
FolderItem *rootitem = NULL;
if ((folder->node != NULL) && (folder->node->data != NULL))
rootitem = (FolderItem *) folder->node->data;
2004-01-12 22:28:31 +01:00
for (cur = tag->attr; cur != NULL; cur = g_list_next(cur)) {
XMLAttr *attr = (XMLAttr *) cur->data;
if (!attr || !attr->name || !attr->value) continue;
if (!strcmp(attr->name, "name")) {
g_free(folder->name);
2004-01-12 22:28:31 +01:00
folder->name = g_strdup(attr->value);
2004-02-21 12:01:01 +01:00
if (rootitem != NULL) {
g_free(rootitem->name);
2004-02-21 12:01:01 +01:00
rootitem->name = g_strdup(attr->value);
}
2004-01-12 22:28:31 +01:00
} else if (!strcmp(attr->name, "account_id")) {
PrefsAccount *account;
2002-01-16 12:48:36 +01:00
2004-01-12 22:28:31 +01:00
account = account_find_from_id(atoi(attr->value));
if (!account)
g_warning("account_id: %s not found\n", attr->value);
else {
folder->account = account;
account->folder = folder;
}
2004-02-21 12:01:01 +01:00
} else if (!strcmp(attr->name, "collapsed")) {
if (rootitem != NULL)
rootitem->collapsed = *attr->value == '1' ? TRUE : FALSE;
2004-05-10 12:22:28 +02:00
} else if (!strcmp(attr->name, "sort")) {
folder->sort = atoi(attr->value);
2004-01-12 22:28:31 +01:00
}
}
2002-01-16 12:48:36 +01:00
}
2001-04-19 14:21:46 +02:00
2004-01-12 22:28:31 +01:00
XMLTag *folder_get_xml(Folder *folder)
2002-01-16 12:48:36 +01:00
{
2004-01-12 22:28:31 +01:00
XMLTag *tag;
2001-04-19 14:21:46 +02:00
tag = xml_tag_new("folder");
2004-01-12 22:28:31 +01:00
if (folder->name)
xml_tag_add_attr(tag, xml_attr_new("name", folder->name));
2004-01-12 22:28:31 +01:00
if (folder->account)
xml_tag_add_attr(tag, xml_attr_new_int("account_id", folder->account->account_id));
2004-02-21 12:01:01 +01:00
if (folder->node && folder->node->data) {
FolderItem *rootitem = (FolderItem *) folder->node->data;
xml_tag_add_attr(tag, xml_attr_new("collapsed", rootitem->collapsed ? "1" : "0"));
2004-02-21 12:01:01 +01:00
}
xml_tag_add_attr(tag, xml_attr_new_int("sort", folder->sort));
2004-01-12 22:28:31 +01:00
return tag;
2001-04-19 14:21:46 +02:00
}
FolderItem *folder_item_new(Folder *folder, const gchar *name, const gchar *path)
2001-04-19 14:21:46 +02:00
{
FolderItem *item = NULL;
g_return_val_if_fail(folder != NULL, NULL);
if (folder->klass->item_new) {
item = folder->klass->item_new(folder);
} else {
item = g_new0(FolderItem, 1);
}
g_return_val_if_fail(item != NULL, NULL);
2001-04-19 14:21:46 +02:00
item->stype = F_NORMAL;
item->name = g_strdup(name);
item->path = g_strdup(path);
item->mtime = 0;
item->new_msgs = 0;
item->unread_msgs = 0;
item->unreadmarked_msgs = 0;
item->marked_msgs = 0;
item->total_msgs = 0;
2001-04-19 14:21:46 +02:00
item->last_num = -1;
2002-06-30 01:33:42 +02:00
item->cache = NULL;
2001-06-28 10:44:31 +02:00
item->no_sub = FALSE;
item->no_select = FALSE;
2001-07-14 19:21:51 +02:00
item->collapsed = FALSE;
item->thread_collapsed = FALSE;
2001-09-25 11:12:39 +02:00
item->threaded = TRUE;
item->ret_rcpt = FALSE;
2002-04-03 10:58:44 +02:00
item->opened = FALSE;
2004-05-10 12:22:28 +02:00
item->node = g_node_new(item);
2001-04-19 14:21:46 +02:00
item->folder = NULL;
item->account = NULL;
item->apply_sub = FALSE;
2002-04-03 10:58:44 +02:00
item->mark_queue = NULL;
2001-04-19 14:21:46 +02:00
item->data = NULL;
item->parent_stype = -1;
2001-04-19 14:21:46 +02:00
item->sort_key = SORT_BY_DATE;
item->sort_type = SORT_ASCENDING;
item->prefs = folder_item_prefs_new();
2001-05-06 06:27:28 +02:00
2001-04-19 14:21:46 +02:00
return item;
}
void folder_item_append(FolderItem *parent, FolderItem *item)
{
g_return_if_fail(parent != NULL);
g_return_if_fail(parent->folder != NULL);
2003-08-25 16:14:47 +02:00
g_return_if_fail(parent->node != NULL);
2001-04-19 14:21:46 +02:00
g_return_if_fail(item != NULL);
item->folder = parent->folder;
2004-05-10 12:22:28 +02:00
g_node_append(parent->node, item->node);
2003-08-25 16:14:47 +02:00
}
void folder_item_remove(FolderItem *item)
2003-08-25 16:14:47 +02:00
{
GNode *node, *start_node;
FolderUpdateData hookdata;
2003-08-25 16:14:47 +02:00
g_return_if_fail(item != NULL);
g_return_if_fail(item->folder != NULL);
g_return_if_fail(item->folder->node != NULL);
start_node = node = item->node;
node = item->folder->node;
node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
node = node->children;
/* remove my children */
while (node != NULL) {
if (node && node->data) {
FolderItem *sub_item = (FolderItem*) node->data;
node = node->next;
folder_item_remove(sub_item);
}
}
/* remove myself */
if (item->cache != NULL) {
msgcache_destroy(item->cache);
item->cache = NULL;
}
hookdata.folder = item->folder;
hookdata.update_flags = FOLDER_TREE_CHANGED | FOLDER_REMOVE_FOLDERITEM;
hookdata.item = item;
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
node = start_node;
2001-04-19 14:21:46 +02:00
if (item->folder->node == node)
item->folder->node = NULL;
2003-08-25 16:14:47 +02:00
folder_item_destroy(item);
2001-04-19 14:21:46 +02:00
g_node_destroy(node);
}
2003-08-26 09:13:40 +02:00
void folder_item_remove_children(FolderItem *item)
{
GNode *node, *next;
g_return_if_fail(item != NULL);
g_return_if_fail(item->folder != NULL);
g_return_if_fail(item->node != NULL);
node = item->node->children;
while (node != NULL) {
next = node->next;
folder_item_remove(FOLDER_ITEM(node->data));
node = next;
}
}
2001-07-01 10:37:50 +02:00
void folder_item_destroy(FolderItem *item)
{
2003-08-25 16:14:47 +02:00
Folder *folder;
2001-07-01 10:37:50 +02:00
g_return_if_fail(item != NULL);
2003-08-25 16:14:47 +02:00
folder = item->folder;
if (folder) {
if (folder->inbox == item)
folder->inbox = NULL;
else if (folder->outbox == item)
folder->outbox = NULL;
else if (folder->draft == item)
folder->draft = NULL;
else if (folder->queue == item)
folder->queue = NULL;
else if (folder->trash == item)
folder->trash = NULL;
}
if (item->cache)
folder_item_free_cache(item, TRUE);
if (item->prefs)
folder_item_prefs_free(item->prefs);
2001-07-01 10:37:50 +02:00
g_free(item->name);
g_free(item->path);
if (item->folder != NULL) {
if(item->folder->klass->item_destroy) {
item->folder->klass->item_destroy(item->folder, item);
} else {
g_free(item);
}
}
2001-07-01 10:37:50 +02:00
}
2004-02-21 12:01:01 +01:00
FolderItem *folder_item_parent(FolderItem *item)
{
g_return_val_if_fail(item != NULL, NULL);
g_return_val_if_fail(item->node != NULL, NULL);
if (item->node->parent == NULL)
return NULL;
return (FolderItem *) item->node->parent->data;
}
2004-01-12 22:28:31 +01:00
void folder_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag)
{
GList *cur;
for (cur = tag->attr; cur != NULL; cur = g_list_next(cur)) {
XMLAttr *attr = (XMLAttr *) cur->data;
if (!attr || !attr->name || !attr->value) continue;
if (!strcmp(attr->name, "type")) {
if (!g_ascii_strcasecmp(attr->value, "normal"))
2004-01-12 22:28:31 +01:00
item->stype = F_NORMAL;
else if (!g_ascii_strcasecmp(attr->value, "inbox"))
2004-01-12 22:28:31 +01:00
item->stype = F_INBOX;
else if (!g_ascii_strcasecmp(attr->value, "outbox"))
2004-01-12 22:28:31 +01:00
item->stype = F_OUTBOX;
else if (!g_ascii_strcasecmp(attr->value, "draft"))
2004-01-12 22:28:31 +01:00
item->stype = F_DRAFT;
else if (!g_ascii_strcasecmp(attr->value, "queue"))
2004-01-12 22:28:31 +01:00
item->stype = F_QUEUE;
else if (!g_ascii_strcasecmp(attr->value, "trash"))
2004-01-12 22:28:31 +01:00
item->stype = F_TRASH;
} else if (!strcmp(attr->name, "name")) {
g_free(item->name);
2004-01-12 22:28:31 +01:00
item->name = g_strdup(attr->value);
} else if (!strcmp(attr->name, "path")) {
g_free(item->path);
2004-01-12 22:28:31 +01:00
item->path = g_strdup(attr->value);
} else if (!strcmp(attr->name, "mtime"))
item->mtime = strtoul(attr->value, NULL, 10);
else if (!strcmp(attr->name, "new"))
item->new_msgs = atoi(attr->value);
else if (!strcmp(attr->name, "unread"))
item->unread_msgs = atoi(attr->value);
else if (!strcmp(attr->name, "unreadmarked"))
item->unreadmarked_msgs = atoi(attr->value);
else if (!strcmp(attr->name, "marked"))
item->marked_msgs = atoi(attr->value);
2004-01-12 22:28:31 +01:00
else if (!strcmp(attr->name, "total"))
item->total_msgs = atoi(attr->value);
else if (!strcmp(attr->name, "no_sub"))
item->no_sub = *attr->value == '1' ? TRUE : FALSE;
else if (!strcmp(attr->name, "no_select"))
item->no_select = *attr->value == '1' ? TRUE : FALSE;
else if (!strcmp(attr->name, "collapsed"))
item->collapsed = *attr->value == '1' ? TRUE : FALSE;
else if (!strcmp(attr->name, "thread_collapsed"))
item->thread_collapsed = *attr->value == '1' ? TRUE : FALSE;
else if (!strcmp(attr->name, "threaded"))
item->threaded = *attr->value == '1' ? TRUE : FALSE;
else if (!strcmp(attr->name, "hidereadmsgs"))
item->hide_read_msgs = *attr->value == '1' ? TRUE : FALSE;
else if (!strcmp(attr->name, "reqretrcpt"))
item->ret_rcpt = *attr->value == '1' ? TRUE : FALSE;
else if (!strcmp(attr->name, "sort_key")) {
if (!strcmp(attr->value, "none"))
item->sort_key = SORT_BY_NONE;
else if (!strcmp(attr->value, "number"))
item->sort_key = SORT_BY_NUMBER;
else if (!strcmp(attr->value, "size"))
item->sort_key = SORT_BY_SIZE;
else if (!strcmp(attr->value, "date"))
item->sort_key = SORT_BY_DATE;
else if (!strcmp(attr->value, "from"))
item->sort_key = SORT_BY_FROM;
else if (!strcmp(attr->value, "subject"))
item->sort_key = SORT_BY_SUBJECT;
else if (!strcmp(attr->value, "score"))
item->sort_key = SORT_BY_SCORE;
else if (!strcmp(attr->value, "label"))
item->sort_key = SORT_BY_LABEL;
else if (!strcmp(attr->value, "mark"))
item->sort_key = SORT_BY_MARK;
else if (!strcmp(attr->value, "unread"))
item->sort_key = SORT_BY_STATUS;
else if (!strcmp(attr->value, "mime"))
item->sort_key = SORT_BY_MIME;
else if (!strcmp(attr->value, "to"))
item->sort_key = SORT_BY_TO;
else if (!strcmp(attr->value, "locked"))
item->sort_key = SORT_BY_LOCKED;
} else if (!strcmp(attr->name, "sort_type")) {
if (!strcmp(attr->value, "ascending"))
item->sort_type = SORT_ASCENDING;
else
item->sort_type = SORT_DESCENDING;
} else if (!strcmp(attr->name, "account_id")) {
PrefsAccount *account;
account = account_find_from_id(atoi(attr->value));
if (!account)
g_warning("account_id: %s not found\n", attr->value);
else
item->account = account;
} else if (!strcmp(attr->name, "apply_sub"))
item->apply_sub = *attr->value == '1' ? TRUE : FALSE;
}
}
XMLTag *folder_item_get_xml(Folder *folder, FolderItem *item)
{
static gchar *folder_item_stype_str[] = {"normal", "inbox", "outbox",
"draft", "queue", "trash"};
static gchar *sort_key_str[] = {"none", "number", "size", "date",
"from", "subject", "score", "label",
"mark", "unread", "mime", "to",
"locked"};
XMLTag *tag;
gchar *value;
2004-01-12 22:28:31 +01:00
tag = xml_tag_new("folderitem");
2004-01-12 22:28:31 +01:00
xml_tag_add_attr(tag, xml_attr_new("type", folder_item_stype_str[item->stype]));
2004-01-12 22:28:31 +01:00
if (item->name)
xml_tag_add_attr(tag, xml_attr_new("name", item->name));
2004-01-12 22:28:31 +01:00
if (item->path)
xml_tag_add_attr(tag, xml_attr_new("path", item->path));
2004-01-12 22:28:31 +01:00
if (item->no_sub)
xml_tag_add_attr(tag, xml_attr_new("no_sub", "1"));
2004-01-12 22:28:31 +01:00
if (item->no_select)
xml_tag_add_attr(tag, xml_attr_new("no_select", "1"));
xml_tag_add_attr(tag, xml_attr_new("collapsed", item->collapsed && item->node->children ? "1" : "0"));
xml_tag_add_attr(tag, xml_attr_new("thread_collapsed", item->thread_collapsed ? "1" : "0"));
xml_tag_add_attr(tag, xml_attr_new("threaded", item->threaded ? "1" : "0"));
xml_tag_add_attr(tag, xml_attr_new("hidereadmsgs", item->hide_read_msgs ? "1" : "0"));
2004-01-12 22:28:31 +01:00
if (item->ret_rcpt)
xml_tag_add_attr(tag, xml_attr_new("reqretrcpt", "1"));
2004-01-12 22:28:31 +01:00
if (item->sort_key != SORT_BY_NONE) {
xml_tag_add_attr(tag, xml_attr_new("sort_key", sort_key_str[item->sort_key]));
xml_tag_add_attr(tag, xml_attr_new("sort_type", item->sort_type == SORT_ASCENDING ? "ascending" : "descending"));
2004-01-12 22:28:31 +01:00
}
value = g_strdup_printf("%ld", (unsigned long int) item->mtime);
xml_tag_add_attr(tag, xml_attr_new("mtime", value));
g_free(value);
xml_tag_add_attr(tag, xml_attr_new_int("new", item->new_msgs));
xml_tag_add_attr(tag, xml_attr_new_int("unread", item->unread_msgs));
xml_tag_add_attr(tag, xml_attr_new_int("unreadmarked", item->unreadmarked_msgs));
xml_tag_add_attr(tag, xml_attr_new_int("marked", item->marked_msgs));
xml_tag_add_attr(tag, xml_attr_new_int("total", item->total_msgs));
2004-01-12 22:28:31 +01:00
if (item->account)
xml_tag_add_attr(tag, xml_attr_new_int("account_id", item->account->account_id));
2004-01-12 22:28:31 +01:00
if (item->apply_sub)
xml_tag_add_attr(tag, xml_attr_new("apply_sub", "1"));
2004-01-12 22:28:31 +01:00
return tag;
}
2001-04-19 14:21:46 +02:00
void folder_set_ui_func(Folder *folder, FolderUIFunc func, gpointer data)
{
g_return_if_fail(folder != NULL);
folder->ui_func = func;
folder->ui_func_data = data;
}
void folder_set_name(Folder *folder, const gchar *name)
{
g_return_if_fail(folder != NULL);
g_free(folder->name);
folder->name = name ? g_strdup(name) : NULL;
if (folder->node && folder->node->data) {
FolderItem *item = (FolderItem *)folder->node->data;
g_free(item->name);
item->name = name ? g_strdup(name) : NULL;
}
}
2004-05-10 12:22:28 +02:00
void folder_set_sort(Folder *folder, guint sort)
{
g_return_if_fail(folder != NULL);
if (folder->sort != sort) {
folder_remove(folder);
folder->sort = sort;
folder_add(folder);
}
}
gboolean folder_tree_destroy_func(GNode *node, gpointer data) {
FolderItem *item = (FolderItem *) node->data;
folder_item_destroy(item);
return FALSE;
}
2001-04-19 14:21:46 +02:00
void folder_tree_destroy(Folder *folder)
{
GNode *node;
g_return_if_fail(folder != NULL);
node = folder->node;
prefs_filtering_clear_folder(folder);
if (node != NULL) {
g_node_traverse(node, G_POST_ORDER, G_TRAVERSE_ALL, -1,
folder_tree_destroy_func, NULL);
g_node_destroy(node);
folder->node = NULL;
}
2001-04-19 14:21:46 +02:00
}
void folder_add(Folder *folder)
{
Folder *cur_folder;
GList *cur;
gint i;
2004-02-21 12:01:01 +01:00
FolderUpdateData hookdata;
2001-04-19 14:21:46 +02:00
g_return_if_fail(folder != NULL);
for (i = 0, cur = folder_list; cur != NULL; cur = cur->next, i++) {
cur_folder = FOLDER(cur->data);
2004-05-10 12:22:28 +02:00
if (cur_folder->sort < folder->sort)
break;
2001-04-19 14:21:46 +02:00
}
folder_list = g_list_insert(folder_list, folder, i);
2004-02-21 12:01:01 +01:00
hookdata.folder = folder;
2004-05-10 12:22:28 +02:00
hookdata.update_flags = FOLDER_ADD_FOLDER;
hookdata.item = NULL;
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
}
void folder_remove(Folder *folder)
{
FolderUpdateData hookdata;
g_return_if_fail(folder != NULL);
folder_list = g_list_remove(folder_list, folder);
hookdata.folder = folder;
hookdata.update_flags = FOLDER_REMOVE_FOLDER;
2004-02-21 12:01:01 +01:00
hookdata.item = NULL;
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
2001-04-19 14:21:46 +02:00
}
GList *folder_get_list(void)
{
return folder_list;
}
gint folder_read_list(void)
{
2004-02-21 12:01:01 +01:00
GNode *node, *cur;
2001-04-19 14:21:46 +02:00
XMLNode *xmlnode;
2001-08-01 09:22:54 +02:00
gchar *path;
2001-04-19 14:21:46 +02:00
2001-08-01 09:22:54 +02:00
path = folder_get_list_path();
if (!is_file_exist(path)) return -1;
node = xml_parse_file(path);
2001-04-19 14:21:46 +02:00
if (!node) return -1;
xmlnode = node->data;
if (strcmp2(xmlnode->tag->tag, "folderlist") != 0) {
g_warning("wrong folder list\n");
xml_free_tree(node);
return -1;
}
2004-02-21 12:01:01 +01:00
cur = node->children;
while (cur != NULL) {
Folder *folder;
folder = folder_get_from_xml(cur);
if (folder != NULL)
folder_add(folder);
else
folder_unloaded_list = g_slist_append(folder_unloaded_list,
(gpointer) xml_copy_tree(cur));
cur = cur->next;
}
2001-04-19 14:21:46 +02:00
xml_free_tree(node);
if (folder_list || folder_unloaded_list)
2001-04-19 14:21:46 +02:00
return 0;
else
return -1;
}
void folder_write_list(void)
{
GList *list;
2004-02-21 12:01:01 +01:00
GSList *slist;
2001-04-19 14:21:46 +02:00
Folder *folder;
gchar *path;
PrefFile *pfile;
2004-02-21 12:01:01 +01:00
GNode *rootnode;
XMLNode *xmlnode;
XMLTag *tag;
2001-04-19 14:21:46 +02:00
path = folder_get_list_path();
if ((pfile = prefs_write_open(path)) == NULL) return;
xml_file_put_xml_decl(pfile->fp);
tag = xml_tag_new("folderlist");
2004-02-21 12:01:01 +01:00
xmlnode = xml_node_new(tag, NULL);
2004-02-21 12:01:01 +01:00
rootnode = g_node_new(xmlnode);
2001-04-19 14:21:46 +02:00
for (list = folder_list; list != NULL; list = list->next) {
2004-02-21 12:01:01 +01:00
GNode *node;
2001-04-19 14:21:46 +02:00
folder = list->data;
2004-02-21 12:01:01 +01:00
node = folder_get_xml_node(folder);
if (node != NULL)
g_node_append(rootnode, node);
2001-04-19 14:21:46 +02:00
}
2004-02-21 12:01:01 +01:00
for (slist = folder_unloaded_list; slist != NULL; slist = g_slist_next(slist)) {
GNode *node = (GNode *) slist->data;
g_node_append(rootnode, (gpointer) xml_copy_tree(node));
}
xml_write_tree(rootnode, pfile->fp);
2001-04-19 14:21:46 +02:00
if (prefs_file_close(pfile) < 0)
2001-04-19 14:21:46 +02:00
g_warning("failed to write folder list.\n");
2004-02-21 12:01:01 +01:00
xml_free_tree(rootnode);
2001-04-19 14:21:46 +02:00
}
gboolean folder_scan_tree_func(GNode *node, gpointer data)
{
GHashTable *pptable = (GHashTable *)data;
FolderItem *item = (FolderItem *)node->data;
folder_item_restore_persist_prefs(item, pptable);
folder_item_scan_full(item, FALSE);
return FALSE;
}
void folder_scan_tree(Folder *folder, gboolean rebuild)
{
GHashTable *pptable;
FolderUpdateData hookdata;
Folder *old_folder = folder;
if (!folder->klass->scan_tree)
return;
pptable = folder_persist_prefs_new(folder);
if (rebuild)
folder_remove(folder);
if (folder->klass->scan_tree(folder) < 0) {
if (rebuild)
folder_add(old_folder);
return;
} else if (rebuild)
folder_add(folder);
hookdata.folder = folder;
hookdata.update_flags = FOLDER_TREE_CHANGED;
hookdata.item = NULL;
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
g_node_traverse(folder->node, G_POST_ORDER, G_TRAVERSE_ALL, -1, folder_scan_tree_func, pptable);
folder_persist_prefs_free(pptable);
prefs_matcher_read_config();
folder_write_list();
}
FolderItem *folder_create_folder(FolderItem *parent, const gchar *name)
{
FolderItem *new_item;
new_item = parent->folder->klass->create_folder(parent->folder, parent, name);
if (new_item) {
2004-05-10 12:22:28 +02:00
FolderUpdateData hookdata;
2002-11-07 00:56:26 +01:00
new_item->cache = msgcache_new();
hookdata.folder = new_item->folder;
2004-05-10 12:22:28 +02:00
hookdata.update_flags = FOLDER_TREE_CHANGED | FOLDER_ADD_FOLDERITEM;
hookdata.item = new_item;
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
}
return new_item;
}
2004-05-10 12:22:28 +02:00
gint folder_item_rename(FolderItem *item, gchar *newname)
{
gint retval;
g_return_val_if_fail(item != NULL, -1);
g_return_val_if_fail(newname != NULL, -1);
retval = item->folder->klass->rename_folder(item->folder, item, newname);
if (retval >= 0) {
FolderItemUpdateData hookdata;
FolderUpdateData hookdata2;
2004-05-10 12:22:28 +02:00
hookdata.item = item;
2004-06-25 10:05:09 +02:00
hookdata.update_flags = F_ITEM_UPDATE_NAME;
hookdata.msg = NULL;
2004-05-10 12:22:28 +02:00
hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &hookdata);
hookdata2.folder = item->folder;
hookdata2.item = item;
hookdata2.update_flags = FOLDER_RENAME_FOLDERITEM;
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata2);
2004-05-10 12:22:28 +02:00
}
return retval;
}
struct TotalMsgCount
2001-11-26 08:53:20 +01:00
{
guint new_msgs;
guint unread_msgs;
guint unreadmarked_msgs;
guint marked_msgs;
guint total_msgs;
};
2001-11-26 08:53:20 +01:00
2002-06-30 01:33:42 +02:00
struct FuncToAllFoldersData
{
FolderItemFunc function;
gpointer data;
};
static gboolean folder_func_to_all_folders_func(GNode *node, gpointer data)
{
FolderItem *item;
2002-06-30 01:33:42 +02:00
struct FuncToAllFoldersData *function_data = (struct FuncToAllFoldersData *) data;
g_return_val_if_fail(node->data != NULL, FALSE);
2001-11-26 08:53:20 +01:00
item = FOLDER_ITEM(node->data);
2002-06-30 01:33:42 +02:00
g_return_val_if_fail(item != NULL, FALSE);
function_data->function(item, function_data->data);
2001-12-04 10:10:36 +01:00
return FALSE;
2001-11-26 08:53:20 +01:00
}
2002-06-30 01:33:42 +02:00
void folder_func_to_all_folders(FolderItemFunc function, gpointer data)
2001-11-26 08:53:20 +01:00
{
GList *list;
Folder *folder;
2002-06-30 01:33:42 +02:00
struct FuncToAllFoldersData function_data;
function_data.function = function;
function_data.data = data;
2001-11-26 08:53:20 +01:00
for (list = folder_list; list != NULL; list = list->next) {
folder = FOLDER(list->data);
2001-12-04 10:10:36 +01:00
if (folder->node)
g_node_traverse(folder->node, G_PRE_ORDER,
2001-12-04 10:10:36 +01:00
G_TRAVERSE_ALL, -1,
2002-06-30 01:33:42 +02:00
folder_func_to_all_folders_func,
&function_data);
2001-11-26 08:53:20 +01:00
}
2002-06-30 01:33:42 +02:00
}
static void folder_count_total_msgs_func(FolderItem *item, gpointer data)
{
struct TotalMsgCount *count = (struct TotalMsgCount *)data;
count->new_msgs += item->new_msgs;
count->unread_msgs += item->unread_msgs;
count->unreadmarked_msgs += item->unreadmarked_msgs;
count->marked_msgs += item->marked_msgs;
count->total_msgs += item->total_msgs;
2002-06-30 01:33:42 +02:00
}
struct TotalMsgStatus
{
guint new;
guint unread;
guint total;
GString *str;
};
static gboolean folder_get_status_full_all_func(GNode *node, gpointer data)
{
FolderItem *item;
struct TotalMsgStatus *status = (struct TotalMsgStatus *)data;
gchar *id;
g_return_val_if_fail(node->data != NULL, FALSE);
item = FOLDER_ITEM(node->data);
if (!item->path) return FALSE;
status->new += item->new_msgs;
status->unread += item->unread_msgs;
status->total += item->total_msgs;
if (status->str) {
id = folder_item_get_identifier(item);
g_string_append_printf(status->str, "%5d %5d %5d %s\n",
item->new_msgs, item->unread_msgs,
item->total_msgs, id);
g_free(id);
}
return FALSE;
}
static void folder_get_status_full_all(GString *str, guint *new, guint *unread,
guint *total)
{
GList *list;
Folder *folder;
struct TotalMsgStatus status;
status.new = status.unread = status.total = 0;
status.str = str;
debug_print("Counting total number of messages...\n");
for (list = folder_list; list != NULL; list = list->next) {
folder = FOLDER(list->data);
if (folder->node)
g_node_traverse(folder->node, G_PRE_ORDER,
G_TRAVERSE_ALL, -1,
folder_get_status_full_all_func,
&status);
}
*new = status.new;
*unread = status.unread;
*total = status.total;
}
gchar *folder_get_status(GPtrArray *folders, gboolean full)
{
guint new, unread, total;
GString *str;
gint i;
gchar *ret;
new = unread = total = 0;
str = g_string_new(NULL);
if (folders) {
for (i = 0; i < folders->len; i++) {
FolderItem *item;
item = g_ptr_array_index(folders, i);
new += item->new_msgs;
unread += item->unread_msgs;
total += item->total_msgs;
if (full) {
gchar *id;
id = folder_item_get_identifier(item);
g_string_append_printf(str, "%5d %5d %5d %s\n",
item->new_msgs, item->unread_msgs,
item->total_msgs, id);
g_free(id);
}
}
} else {
folder_get_status_full_all(full ? str : NULL,
&new, &unread, &total);
}
if (full)
g_string_append_printf(str, "%5d %5d %5d\n", new, unread, total);
else
g_string_append_printf(str, "%d %d %d\n", new, unread, total);
ret = str->str;
g_string_free(str, FALSE);
return ret;
}
void folder_count_total_msgs(guint *new_msgs, guint *unread_msgs,
guint *unreadmarked_msgs, guint *marked_msgs,
guint *total_msgs)
2002-06-30 01:33:42 +02:00
{
struct TotalMsgCount count;
count.new_msgs = count.unread_msgs = count.unreadmarked_msgs = count.total_msgs = 0;
2002-06-30 01:33:42 +02:00
2002-08-15 09:38:17 +02:00
debug_print("Counting total number of messages...\n");
2002-06-30 01:33:42 +02:00
folder_func_to_all_folders(folder_count_total_msgs_func, &count);
2001-11-26 08:53:20 +01:00
*new_msgs = count.new_msgs;
*unread_msgs = count.unread_msgs;
*unreadmarked_msgs = count.unreadmarked_msgs;
*marked_msgs = count.marked_msgs;
*total_msgs = count.total_msgs;
2001-11-26 08:53:20 +01:00
}
2001-04-19 14:21:46 +02:00
Folder *folder_find_from_path(const gchar *path)
{
GList *list;
Folder *folder;
for (list = folder_list; list != NULL; list = list->next) {
folder = list->data;
2004-01-12 22:28:31 +01:00
if ((FOLDER_TYPE(folder) == F_MH ||
FOLDER_TYPE(folder) == F_MBOX) &&
2001-04-19 14:21:46 +02:00
!path_cmp(LOCAL_FOLDER(folder)->rootpath, path))
return folder;
}
return NULL;
}
Folder *folder_find_from_name(const gchar *name, FolderClass *klass)
2002-04-05 10:20:10 +02:00
{
GList *list;
Folder *folder;
for (list = folder_list; list != NULL; list = list->next) {
folder = list->data;
2004-01-12 22:28:31 +01:00
if (folder->klass == klass &&
strcmp2(name, folder->name) == 0)
2002-04-05 10:20:10 +02:00
return folder;
}
return NULL;
}
2001-04-19 14:21:46 +02:00
static gboolean folder_item_find_func(GNode *node, gpointer data)
{
FolderItem *item = node->data;
gpointer *d = data;
const gchar *path = d[0];
if (path_cmp(path, item->path) != 0)
return FALSE;
d[1] = item;
return TRUE;
}
FolderItem *folder_find_item_from_path(const gchar *path)
{
Folder *folder;
gpointer d[2];
folder = folder_get_default_folder();
g_return_val_if_fail(folder != NULL, NULL);
d[0] = (gpointer)path;
d[1] = NULL;
g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
folder_item_find_func, d);
return d[1];
}
2004-05-10 12:22:28 +02:00
FolderItem *folder_find_child_item_by_name(FolderItem *item, const gchar *name)
{
GNode *node;
FolderItem *child;
for (node = item->node->children; node != NULL; node = node->next) {
gchar *base;
2004-05-10 12:22:28 +02:00
child = FOLDER_ITEM(node->data);
base = g_path_get_basename(child->path);
if (strcmp2(base, name) == 0) {
g_free(base);
2004-05-10 12:22:28 +02:00
return child;
}
g_free(base);
2004-05-10 12:22:28 +02:00
}
return NULL;
}
FolderClass *folder_get_class_from_string(const gchar *str)
2002-04-05 10:20:10 +02:00
{
GSList *classlist;
2002-04-05 10:20:10 +02:00
classlist = folder_get_class_list();
for (; classlist != NULL; classlist = g_slist_next(classlist)) {
FolderClass *class = (FolderClass *) classlist->data;
if (g_ascii_strcasecmp(class->idstr, str) == 0)
return class;
2002-04-05 10:20:10 +02:00
}
return NULL;
}
gchar *folder_get_identifier(Folder *folder)
{
gchar *type_str;
g_return_val_if_fail(folder != NULL, NULL);
type_str = folder->klass->idstr;
return g_strconcat("#", type_str, "/", folder->name, NULL);
2002-04-05 10:20:10 +02:00
}
gchar *folder_item_get_identifier(FolderItem *item)
{
2004-08-07 17:40:13 +02:00
gchar *id = NULL;
gchar *folder_id = NULL;
2002-04-05 10:20:10 +02:00
g_return_val_if_fail(item != NULL, NULL);
g_return_val_if_fail(item->path != NULL, NULL);
folder_id = folder_get_identifier(item->folder);
id = g_strconcat(folder_id, "/", item->path, NULL);
g_free(folder_id);
return id;
}
FolderItem *folder_find_item_from_identifier(const gchar *identifier)
{
Folder *folder;
gpointer d[2];
gchar *str;
gchar *p;
gchar *name;
gchar *path;
FolderClass *class;
2002-04-05 10:20:10 +02:00
g_return_val_if_fail(identifier != NULL, NULL);
if (*identifier != '#')
return folder_find_item_from_path(identifier);
Xstrdup_a(str, identifier, return NULL);
p = strchr(str, '/');
if (!p)
return folder_find_item_from_path(identifier);
*p = '\0';
p++;
class = folder_get_class_from_string(&str[1]);
if (class == NULL)
2002-04-05 10:20:10 +02:00
return folder_find_item_from_path(identifier);
name = p;
p = strchr(p, '/');
if (!p)
return folder_find_item_from_path(identifier);
*p = '\0';
p++;
folder = folder_find_from_name(name, class);
2002-04-05 10:20:10 +02:00
if (!folder)
return folder_find_item_from_path(identifier);
path = p;
d[0] = (gpointer)path;
d[1] = NULL;
g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
folder_item_find_func, d);
return d[1];
}
/**
* Get a displayable name for a FolderItem
*
* \param item FolderItem for that a name should be created
* \return Displayable name for item, returned string has to
* be freed
*/
gchar *folder_item_get_name(FolderItem *item)
{
gchar *name = NULL;
g_return_val_if_fail(item != NULL, g_strdup(""));
switch (item->stype) {
case F_INBOX:
name = g_strdup(!strcmp2(item->name, INBOX_DIR) ? _("Inbox") :
item->name);
break;
case F_OUTBOX:
name = g_strdup(!strcmp2(item->name, OUTBOX_DIR) ? _("Sent") :
item->name);
break;
case F_QUEUE:
name = g_strdup(!strcmp2(item->name, QUEUE_DIR) ? _("Queue") :
item->name);
break;
case F_TRASH:
name = g_strdup(!strcmp2(item->name, TRASH_DIR) ? _("Trash") :
item->name);
break;
case F_DRAFT:
name = g_strdup(!strcmp2(item->name, DRAFT_DIR) ? _("Drafts") :
item->name);
break;
default:
break;
}
if (name == NULL) {
/*
* should probably be done by a virtual function,
* the folder knows the ui string and how to abbrev
*/
2004-02-21 12:01:01 +01:00
if (folder_item_parent(item) == NULL) {
name = g_strconcat(item->name, " (", item->folder->klass->uistr, ")", NULL);
} else {
if (FOLDER_CLASS(item->folder) == news_get_class() &&
item->path && !strcmp2(item->name, item->path))
name = get_abbrev_newsgroup_name
(item->path,
prefs_common.ng_abbrev_len);
else
name = g_strdup(item->name);
}
}
if (name == NULL)
name = g_strdup("");
return name;
}
2001-04-19 14:21:46 +02:00
Folder *folder_get_default_folder(void)
{
2001-07-16 20:18:53 +02:00
return folder_list ? FOLDER(folder_list->data) : NULL;
2001-04-19 14:21:46 +02:00
}
gboolean folder_have_mailbox (void)
{
GList *cur;
for (cur = folder_list; cur != NULL; cur = g_list_next(cur)) {
Folder *folder = FOLDER(cur->data);
if (folder->inbox && folder->outbox)
return TRUE;
}
return FALSE;
}
2001-04-19 14:21:46 +02:00
FolderItem *folder_get_default_inbox(void)
{
2004-05-22 09:27:30 +02:00
GList *flist;
2001-04-19 14:21:46 +02:00
2004-05-22 09:27:30 +02:00
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
Folder * folder = FOLDER(flist->data);
if (folder == NULL)
continue;
if (folder->inbox == NULL)
continue;
if (folder->klass->type == F_UNKNOWN)
continue;
2004-05-22 09:27:30 +02:00
return folder->inbox;
}
return NULL;
2001-04-19 14:21:46 +02:00
}
FolderItem *folder_get_default_outbox(void)
{
2004-05-22 09:27:30 +02:00
GList *flist;
2001-04-19 14:21:46 +02:00
2004-05-22 09:27:30 +02:00
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
Folder * folder = FOLDER(flist->data);
if (folder == NULL)
continue;
if (folder->outbox == NULL)
continue;
return folder->outbox;
}
return NULL;
2001-04-19 14:21:46 +02:00
}
FolderItem *folder_get_default_draft(void)
{
2004-05-22 09:27:30 +02:00
GList *flist;
2001-04-19 14:21:46 +02:00
2004-05-22 09:27:30 +02:00
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
Folder * folder = FOLDER(flist->data);
if (folder == NULL)
continue;
if (folder->draft == NULL)
continue;
return folder->draft;
}
return NULL;
2001-04-19 14:21:46 +02:00
}
FolderItem *folder_get_default_queue(void)
{
2004-05-22 09:27:30 +02:00
GList *flist;
2001-04-19 14:21:46 +02:00
2004-05-22 09:27:30 +02:00
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
Folder * folder = FOLDER(flist->data);
if (folder == NULL)
continue;
if (folder->queue == NULL)
continue;
return folder->queue;
}
return NULL;
2001-04-19 14:21:46 +02:00
}
FolderItem *folder_get_default_trash(void)
{
2004-05-22 09:27:30 +02:00
GList *flist;
2001-04-19 14:21:46 +02:00
2004-05-22 09:27:30 +02:00
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
Folder * folder = FOLDER(flist->data);
if (folder == NULL)
continue;
if (folder->trash == NULL)
continue;
return folder->trash;
}
return NULL;
2001-04-19 14:21:46 +02:00
}
#define CREATE_FOLDER_IF_NOT_EXIST(member, dir, type) \
{ \
if (!folder->member) { \
item = folder_item_new(folder, dir, dir); \
item->stype = type; \
folder_item_append(rootitem, item); \
folder->member = item; \
} \
2002-03-19 09:37:53 +01:00
}
void folder_set_missing_folders(void)
{
Folder *folder;
FolderItem *rootitem;
FolderItem *item;
GList *list;
for (list = folder_list; list != NULL; list = list->next) {
folder = list->data;
if (FOLDER_TYPE(folder) != F_MH) continue;
2002-03-19 09:37:53 +01:00
rootitem = FOLDER_ITEM(folder->node->data);
g_return_if_fail(rootitem != NULL);
if (folder->inbox && folder->outbox && folder->draft &&
folder->queue && folder->trash)
continue;
if (folder->klass->create_tree(folder) < 0) {
2002-03-19 09:37:53 +01:00
g_warning("%s: can't create the folder tree.\n",
LOCAL_FOLDER(folder)->rootpath);
continue;
}
CREATE_FOLDER_IF_NOT_EXIST(inbox, INBOX_DIR, F_INBOX);
2002-06-08 17:52:42 +02:00
CREATE_FOLDER_IF_NOT_EXIST(outbox, OUTBOX_DIR, F_OUTBOX);
CREATE_FOLDER_IF_NOT_EXIST(draft, DRAFT_DIR, F_DRAFT);
CREATE_FOLDER_IF_NOT_EXIST(queue, QUEUE_DIR, F_QUEUE);
CREATE_FOLDER_IF_NOT_EXIST(trash, TRASH_DIR, F_TRASH);
2002-03-19 09:37:53 +01:00
}
}
2002-10-13 17:43:22 +02:00
static gboolean folder_unref_account_func(GNode *node, gpointer data)
{
FolderItem *item = node->data;
PrefsAccount *account = data;
if (item->account == account)
item->account = NULL;
return FALSE;
}
void folder_unref_account_all(PrefsAccount *account)
{
Folder *folder;
GList *list;
if (!account) return;
for (list = folder_list; list != NULL; list = list->next) {
folder = list->data;
if (folder->account == account)
folder->account = NULL;
g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
folder_unref_account_func, account);
}
}
2002-03-19 09:37:53 +01:00
#undef CREATE_FOLDER_IF_NOT_EXIST
2002-08-28 13:54:45 +02:00
gchar *folder_item_get_path(FolderItem *item)
{
Folder *folder;
2002-08-28 13:54:45 +02:00
g_return_val_if_fail(item != NULL, NULL);
folder = item->folder;
g_return_val_if_fail(folder != NULL, NULL);
2001-04-19 14:21:46 +02:00
return folder->klass->item_get_path(folder, item);
2001-04-19 14:21:46 +02:00
}
2002-06-30 01:33:42 +02:00
void folder_item_set_default_flags(FolderItem *dest, MsgFlags *flags)
{
if (!(folder_has_parent_of_type(dest, F_OUTBOX) ||
folder_has_parent_of_type(dest, F_QUEUE) ||
folder_has_parent_of_type(dest, F_DRAFT) ||
folder_has_parent_of_type(dest, F_TRASH))) {
2002-06-30 01:33:42 +02:00
flags->perm_flags = MSG_NEW|MSG_UNREAD;
} else {
flags->perm_flags = 0;
}
if (FOLDER_TYPE(dest->folder) == F_MH) {
if (folder_has_parent_of_type(dest, F_QUEUE)) {
2002-06-30 01:33:42 +02:00
MSG_SET_TMP_FLAGS(*flags, MSG_QUEUED);
} else if (folder_has_parent_of_type(dest, F_DRAFT)) {
2002-06-30 01:33:42 +02:00
MSG_SET_TMP_FLAGS(*flags, MSG_DRAFT);
}
}
}
static gint folder_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 gint folder_sort_folder_list(gconstpointer a, gconstpointer b)
{
guint gint_a = GPOINTER_TO_INT(a);
2002-09-11 00:23:56 +02:00
guint gint_b = GPOINTER_TO_INT(b);
return (gint_a - gint_b);
}
2002-06-30 01:33:42 +02:00
void folder_item_process_open (FolderItem *item,
void (*before_proc_func)(gpointer data),
void (*after_proc_func)(gpointer data),
gpointer data)
{
2004-05-10 12:22:28 +02:00
gchar *buf;
if (item == NULL)
return;
if((item->folder->klass->scan_required != NULL) &&
(item->folder->klass->scan_required(item->folder, item))) {
folder_item_scan_full(item, TRUE);
} else {
folder_item_syncronize_flags(item);
}
2004-05-10 12:22:28 +02:00
/* Processing */
2004-05-10 12:22:28 +02:00
buf = g_strdup_printf(_("Processing (%s)...\n"),
item->path ? item->path : item->name);
debug_print("%s\n", buf);
g_free(buf);
if (before_proc_func)
before_proc_func(data);
2004-05-10 12:22:28 +02:00
folder_item_apply_processing(item);
if (after_proc_func)
after_proc_func(data);
2004-05-10 12:22:28 +02:00
debug_print("done.\n");
item->processing_pending = FALSE;
return;
}
gint folder_item_open(FolderItem *item)
{
START_TIMING("folder_item_open");
if (item->no_select)
return -1;
if (item->scanning) {
debug_print("%s is scanning... \n", item->path ? item->path : item->name);
return -2;
}
item->processing_pending = TRUE;
folder_item_process_open (item, NULL, NULL, NULL);
item->opened = TRUE;
END_TIMING();
return 0;
}
gint folder_item_close(FolderItem *item)
{
GSList *mlist, *cur;
Folder *folder;
g_return_val_if_fail(item != NULL, -1);
if (item->no_select)
return -1;
if (item->new_msgs) {
folder_item_update_freeze();
mlist = folder_item_get_msg_list(item);
for (cur = mlist ; cur != NULL ; cur = cur->next) {
MsgInfo * msginfo;
msginfo = (MsgInfo *) cur->data;
if (MSG_IS_NEW(msginfo->flags))
procmsg_msginfo_unset_flags(msginfo, MSG_NEW, 0);
procmsg_msginfo_free(msginfo);
}
g_slist_free(mlist);
folder_item_update_thaw();
}
2002-11-13 14:30:55 +01:00
folder_item_write_cache(item);
folder_item_update(item, F_ITEM_UPDATE_MSGCNT);
item->opened = FALSE;
folder = item->folder;
if (folder->klass->close == NULL)
return 0;
return folder->klass->close(folder, item);
}
2004-06-25 10:05:09 +02:00
static MsgInfoList *get_msginfos(FolderItem *item, MsgNumberList *numlist)
{
MsgInfoList *msglist = NULL;
Folder *folder = item->folder;
if (item->no_select)
return NULL;
2004-06-25 10:05:09 +02:00
if (folder->klass->get_msginfos != NULL)
msglist = folder->klass->get_msginfos(folder, item, numlist);
else {
MsgNumberList *elem;
for (elem = numlist; elem != NULL; elem = g_slist_next(elem)) {
MsgInfo *msginfo;
guint num;
num = GPOINTER_TO_INT(elem->data);
msginfo = folder->klass->get_msginfo(folder, item, num);
if (msginfo != NULL)
msglist = g_slist_prepend(msglist, msginfo);
}
}
return msglist;
}
static MsgInfo *get_msginfo(FolderItem *item, guint num)
{
MsgNumberList numlist;
MsgInfoList *msglist;
MsgInfo *msginfo = NULL;
numlist.data = GINT_TO_POINTER(num);
numlist.next = NULL;
msglist = get_msginfos(item, &numlist);
if (msglist != NULL)
msginfo = procmsg_msginfo_new_ref(msglist->data);
procmsg_msg_list_free(msglist);
return msginfo;
}
static gint syncronize_flags(FolderItem *item, MsgInfoList *msglist)
{
GRelation *relation;
gint ret = 0;
GSList *cur;
if(msglist == NULL)
return 0;
if(item->folder->klass->get_flags == NULL)
return 0;
if (item->no_select)
return 0;
relation = g_relation_new(2);
g_relation_index(relation, 0, g_direct_hash, g_direct_equal);
folder_item_set_batch(item, TRUE);
if ((ret = item->folder->klass->get_flags(
item->folder, item, msglist, relation)) == 0) {
GTuples *tuples;
MsgInfo *msginfo;
MsgPermFlags permflags = 0;
gboolean skip;
for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
msginfo = (MsgInfo *) cur->data;
tuples = g_relation_select(relation, msginfo, 0);
skip = tuples->len < 1;
if (!skip)
permflags = GPOINTER_TO_INT(g_tuples_index(tuples, 0, 1));
g_tuples_destroy(tuples);
if (skip)
continue;
if (msginfo->flags.perm_flags != permflags) {
procmsg_msginfo_change_flags(msginfo,
permflags & ~msginfo->flags.perm_flags, 0,
~permflags & msginfo->flags.perm_flags, 0);
}
}
}
folder_item_set_batch(item, FALSE);
g_relation_destroy(relation);
return ret;
}
gint folder_item_scan_full(FolderItem *item, gboolean filtering)
2001-04-19 14:21:46 +02:00
{
Folder *folder;
GSList *folder_list = NULL, *cache_list = NULL;
GSList *folder_list_cur, *cache_list_cur, *new_list = NULL;
GSList *exists_list = NULL, *elem;
GSList *newmsg_list = NULL;
guint newcnt = 0, unreadcnt = 0, totalcnt = 0;
guint markedcnt = 0, unreadmarkedcnt = 0;
guint cache_max_num, folder_max_num, cache_cur_num, folder_cur_num;
gboolean update_flags = 0, old_uids_valid = FALSE;
GHashTable *subject_table = NULL;
g_return_val_if_fail(item != NULL, -1);
if (item->path == NULL) return -1;
2001-04-19 14:21:46 +02:00
folder = item->folder;
2002-06-30 01:33:42 +02:00
g_return_val_if_fail(folder != NULL, -1);
g_return_val_if_fail(folder->klass->get_num_list != NULL, -1);
2002-06-30 01:33:42 +02:00
item->scanning = TRUE;
debug_print("Scanning folder %s for cache changes.\n", item->path ? item->path : "(null)");
2002-06-30 01:33:42 +02:00
/* Get list of messages for folder and cache */
if (folder->klass->get_num_list(item->folder, item, &folder_list, &old_uids_valid) < 0) {
debug_print("Error fetching list of message numbers\n");
item->scanning = FALSE;
return(-1);
}
if(prefs_common.thread_by_subject) {
subject_table = g_hash_table_new(g_str_hash, g_str_equal);
}
if (old_uids_valid) {
if (!item->cache)
2002-06-30 01:33:42 +02:00
folder_item_read_cache(item);
cache_list = msgcache_get_msg_list(item->cache);
} else {
if (item->cache)
2002-06-30 01:33:42 +02:00
msgcache_destroy(item->cache);
item->cache = msgcache_new();
cache_list = NULL;
}
/* Sort both lists */
cache_list = g_slist_sort(cache_list, folder_sort_cache_list_by_msgnum);
folder_list = g_slist_sort(folder_list, folder_sort_folder_list);
2002-06-30 01:33:42 +02:00
cache_list_cur = cache_list;
folder_list_cur = folder_list;
2002-06-30 01:33:42 +02:00
if (cache_list_cur != NULL) {
GSList *cache_list_last;
cache_cur_num = ((MsgInfo *)cache_list_cur->data)->msgnum;
cache_list_last = g_slist_last(cache_list);
cache_max_num = ((MsgInfo *)cache_list_last->data)->msgnum;
} else {
cache_cur_num = G_MAXINT;
cache_max_num = 0;
}
2002-06-30 01:33:42 +02:00
if (folder_list_cur != NULL) {
GSList *folder_list_last;
folder_cur_num = GPOINTER_TO_INT(folder_list_cur->data);
folder_list_last = g_slist_last(folder_list);
folder_max_num = GPOINTER_TO_INT(folder_list_last->data);
} else {
folder_cur_num = G_MAXINT;
folder_max_num = 0;
}
while ((cache_cur_num != G_MAXINT) || (folder_cur_num != G_MAXINT)) {
/*
* Message only exists in the folder
* Remember message for fetching
*/
if (folder_cur_num < cache_cur_num) {
gboolean add = FALSE;
switch(FOLDER_TYPE(folder)) {
case F_NEWS:
if (folder_cur_num < cache_max_num)
break;
if (folder->account->max_articles == 0) {
add = TRUE;
}
if (folder_max_num <= folder->account->max_articles) {
add = TRUE;
} else if (folder_cur_num > (folder_max_num - folder->account->max_articles)) {
add = TRUE;
}
break;
default:
add = TRUE;
break;
}
if (add) {
new_list = g_slist_prepend(new_list, GINT_TO_POINTER(folder_cur_num));
debug_print("Remembered message %d for fetching\n", folder_cur_num);
}
/* Move to next folder number */
folder_list_cur = folder_list_cur->next;
if (folder_list_cur != NULL)
folder_cur_num = GPOINTER_TO_INT(folder_list_cur->data);
else
folder_cur_num = G_MAXINT;
continue;
2002-06-30 01:33:42 +02:00
}
/*
* Message only exists in the cache
* Remove the message from the cache
*/
if (cache_cur_num < folder_cur_num) {
msgcache_remove_msg(item->cache, cache_cur_num);
debug_print("Removed message %d from cache.\n", cache_cur_num);
/* Move to next cache number */
cache_list_cur = cache_list_cur->next;
if (cache_list_cur != NULL)
cache_cur_num = ((MsgInfo *)cache_list_cur->data)->msgnum;
else
cache_cur_num = G_MAXINT;
update_flags |= F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT;
continue;
2002-06-30 01:33:42 +02:00
}
/*
* Message number exists in folder and cache!
* Check if the message has been modified
*/
if (cache_cur_num == folder_cur_num) {
2002-06-30 01:33:42 +02:00
MsgInfo *msginfo;
msginfo = msgcache_get_msg(item->cache, folder_cur_num);
if (folder->klass->is_msg_changed && folder->klass->is_msg_changed(folder, item, msginfo)) {
2002-06-30 01:33:42 +02:00
msgcache_remove_msg(item->cache, msginfo->msgnum);
new_list = g_slist_prepend(new_list, GINT_TO_POINTER(msginfo->msgnum));
procmsg_msginfo_free(msginfo);
2002-06-30 01:33:42 +02:00
debug_print("Remembering message %d to update...\n", folder_cur_num);
} else {
exists_list = g_slist_prepend(exists_list, msginfo);
if(prefs_common.thread_by_subject &&
MSG_IS_IGNORE_THREAD(msginfo->flags) &&
!subject_table_lookup(subject_table, msginfo->subject)) {
subject_table_insert(subject_table, msginfo->subject, msginfo);
}
}
/* Move to next folder and cache number */
cache_list_cur = cache_list_cur->next;
folder_list_cur = folder_list_cur->next;
if (cache_list_cur != NULL)
cache_cur_num = ((MsgInfo *)cache_list_cur->data)->msgnum;
else
cache_cur_num = G_MAXINT;
if (folder_list_cur != NULL)
folder_cur_num = GPOINTER_TO_INT(folder_list_cur->data);
else
folder_cur_num = G_MAXINT;
continue;
2002-06-30 01:33:42 +02:00
}
}
for(cache_list_cur = cache_list; cache_list_cur != NULL; cache_list_cur = g_slist_next(cache_list_cur))
procmsg_msginfo_free((MsgInfo *) cache_list_cur->data);
g_slist_free(cache_list);
g_slist_free(folder_list);
if (new_list != NULL) {
GSList *tmp_list = NULL;
2004-06-25 10:05:09 +02:00
newmsg_list = get_msginfos(item, new_list);
g_slist_free(new_list);
tmp_list = g_slist_concat(g_slist_copy(exists_list), g_slist_copy(newmsg_list));
syncronize_flags(item, tmp_list);
g_slist_free(tmp_list);
} else {
syncronize_flags(item, exists_list);
}
folder_item_update_freeze();
if (newmsg_list != NULL) {
GSList *elem, *to_filter = NULL;
int total = g_slist_length(newmsg_list), cur = 0;
if ((filtering == TRUE) &&
(item->stype == F_INBOX) &&
(item->folder->account != NULL) &&
(item->folder->account->filter_on_recv))
statusbar_print_all(_("Filtering messages...\n"));
for (elem = newmsg_list; elem != NULL; elem = g_slist_next(elem)) {
MsgInfo *msginfo = (MsgInfo *) elem->data;
statusbar_progress_all(cur++,total, 10);
msgcache_add_msg(item->cache, msginfo);
if ((filtering == TRUE) &&
(item->stype == F_INBOX) &&
(item->folder->account != NULL) &&
(item->folder->account->filter_on_recv) &&
procmsg_msginfo_filter(msginfo, item->folder->account))
to_filter = g_slist_prepend(to_filter, msginfo);
else {
exists_list = g_slist_prepend(exists_list, msginfo);
if(prefs_common.thread_by_subject &&
MSG_IS_IGNORE_THREAD(msginfo->flags) &&
!subject_table_lookup(subject_table, msginfo->subject)) {
subject_table_insert(subject_table, msginfo->subject, msginfo);
}
}
}
filtering_move_and_copy_msgs(to_filter);
for (elem = to_filter; elem; elem = g_slist_next(elem)) {
MsgInfo *msginfo = (MsgInfo *)elem->data;
procmsg_msginfo_free(msginfo);
}
g_slist_free(to_filter);
g_slist_free(newmsg_list);
statusbar_progress_all(0,0,0);
statusbar_pop_all();
update_flags |= F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT;
2002-06-30 01:33:42 +02:00
}
folder_item_set_batch(item, TRUE);
for (elem = exists_list; elem != NULL; elem = g_slist_next(elem)) {
MsgInfo *msginfo, *parent_msginfo;
msginfo = elem->data;
if (MSG_IS_IGNORE_THREAD(msginfo->flags) && (MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)))
procmsg_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
if (!MSG_IS_IGNORE_THREAD(msginfo->flags) && procmsg_msg_has_flagged_parent(msginfo, MSG_IGNORE_THREAD)) {
procmsg_msginfo_change_flags(msginfo, MSG_IGNORE_THREAD, 0, MSG_NEW | MSG_UNREAD, 0);
}
if(prefs_common.thread_by_subject && !msginfo->inreplyto &&
!msginfo->references && !MSG_IS_IGNORE_THREAD(msginfo->flags) &&
(parent_msginfo = subject_table_lookup(subject_table, msginfo->subject)))
{
if(MSG_IS_IGNORE_THREAD(parent_msginfo->flags)) {
procmsg_msginfo_change_flags(msginfo, MSG_IGNORE_THREAD, 0,
MSG_NEW | MSG_UNREAD, 0);
}
}
if ((folder_has_parent_of_type(item, F_OUTBOX) ||
folder_has_parent_of_type(item, F_QUEUE) ||
folder_has_parent_of_type(item, F_DRAFT) ||
folder_has_parent_of_type(item, F_TRASH)) &&
(MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)))
procmsg_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
if (MSG_IS_NEW(msginfo->flags))
newcnt++;
if (MSG_IS_UNREAD(msginfo->flags))
unreadcnt++;
if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
unreadmarkedcnt++;
if (MSG_IS_MARKED(msginfo->flags))
markedcnt++;
totalcnt++;
procmsg_msginfo_free(msginfo);
}
folder_item_set_batch(item, FALSE);
g_slist_free(exists_list);
if(prefs_common.thread_by_subject) {
g_hash_table_destroy(subject_table);
}
if (item->new_msgs != newcnt || item->unread_msgs != unreadcnt
|| item->total_msgs != totalcnt || item->marked_msgs != markedcnt
|| item->unreadmarked_msgs != unreadmarkedcnt) {
update_flags |= F_ITEM_UPDATE_CONTENT;
}
item->new_msgs = newcnt;
item->unread_msgs = unreadcnt;
item->total_msgs = totalcnt;
item->unreadmarked_msgs = unreadmarkedcnt;
item->marked_msgs = markedcnt;
update_flags |= F_ITEM_UPDATE_MSGCNT;
2002-06-30 01:33:42 +02:00
folder_item_update(item, update_flags);
folder_item_update_thaw();
item->scanning = FALSE;
return 0;
2001-04-19 14:21:46 +02:00
}
gint folder_item_scan(FolderItem *item)
{
return folder_item_scan_full(item, TRUE);
}
static gboolean folder_scan_all_items_func(GNode *node, gpointer data)
{
FolderItem *item = node->data;
folder_item_scan(item);
return FALSE;
}
void folder_scan_all_items(Folder * folder)
{
g_node_traverse(folder->node, G_PRE_ORDER,
G_TRAVERSE_ALL, -1, folder_scan_all_items_func, NULL);
}
2001-04-19 14:21:46 +02:00
static void folder_item_scan_foreach_func(gpointer key, gpointer val,
gpointer data)
{
folder_item_scan(FOLDER_ITEM(key));
}
void folder_item_scan_foreach(GHashTable *table)
{
g_hash_table_foreach(table, folder_item_scan_foreach_func, NULL);
}
2002-06-30 01:33:42 +02:00
void folder_count_total_cache_memusage(FolderItem *item, gpointer data)
{
gint *memusage = (gint *)data;
if (item->cache == NULL)
2002-06-30 01:33:42 +02:00
return;
*memusage += msgcache_get_memory_usage(item->cache);
}
gint folder_item_syncronize_flags(FolderItem *item)
{
MsgInfoList *msglist = NULL;
GSList *cur;
gint ret = 0;
g_return_val_if_fail(item != NULL, -1);
g_return_val_if_fail(item->folder != NULL, -1);
g_return_val_if_fail(item->folder->klass != NULL, -1);
if (item->no_select)
return -1;
item->scanning = TRUE;
if (item->cache == NULL)
folder_item_read_cache(item);
msglist = msgcache_get_msg_list(item->cache);
ret = syncronize_flags(item, msglist);
for (cur = msglist; cur != NULL; cur = g_slist_next(cur))
procmsg_msginfo_free((MsgInfo *) cur->data);
g_slist_free(msglist);
item->scanning = FALSE;
return ret;
}
2002-06-30 01:33:42 +02:00
gint folder_cache_time_compare_func(gconstpointer a, gconstpointer b)
{
FolderItem *fa = (FolderItem *)a;
FolderItem *fb = (FolderItem *)b;
return (gint) (msgcache_get_last_access_time(fa->cache) - msgcache_get_last_access_time(fb->cache));
}
void folder_find_expired_caches(FolderItem *item, gpointer data)
{
GSList **folder_item_list = (GSList **)data;
gint difftime, expiretime;
if (item->cache == NULL)
2002-06-30 01:33:42 +02:00
return;
if (item->opened > 0)
return;
2002-06-30 01:33:42 +02:00
difftime = (gint) (time(NULL) - msgcache_get_last_access_time(item->cache));
expiretime = prefs_common.cache_min_keep_time * 60;
2002-08-15 09:38:17 +02:00
debug_print("Cache unused time: %d (Expire time: %d)\n", difftime, expiretime);
if (difftime > expiretime && !item->opened && !item->processing_pending) {
2002-06-30 01:33:42 +02:00
*folder_item_list = g_slist_insert_sorted(*folder_item_list, item, folder_cache_time_compare_func);
}
}
gboolean folder_item_free_cache(FolderItem *item, gboolean force)
2002-06-30 01:33:42 +02:00
{
g_return_val_if_fail(item != NULL, TRUE);
if (item->cache == NULL)
return TRUE;
2002-06-30 01:33:42 +02:00
if (item->opened > 0 && !force)
return FALSE;
2002-06-30 01:33:42 +02:00
folder_item_write_cache(item);
msgcache_destroy(item->cache);
item->cache = NULL;
return TRUE;
2002-06-30 01:33:42 +02:00
}
void folder_clean_cache_memory_force(void)
{
int old_cache_max_mem_usage = prefs_common.cache_max_mem_usage;
int old_cache_min_keep_time = prefs_common.cache_min_keep_time;
prefs_common.cache_max_mem_usage = 0;
prefs_common.cache_min_keep_time = 0;
folder_clean_cache_memory(NULL);
prefs_common.cache_max_mem_usage = old_cache_max_mem_usage;
prefs_common.cache_min_keep_time = old_cache_min_keep_time;
}
void folder_clean_cache_memory(FolderItem *protected_item)
2002-06-30 01:33:42 +02:00
{
gint memusage = 0;
folder_func_to_all_folders(folder_count_total_cache_memusage, &memusage);
2002-08-15 09:38:17 +02:00
debug_print("Total cache memory usage: %d\n", memusage);
2002-06-30 01:33:42 +02:00
if (memusage > (prefs_common.cache_max_mem_usage * 1024)) {
2002-06-30 01:33:42 +02:00
GSList *folder_item_list = NULL, *listitem;
2002-08-15 09:38:17 +02:00
debug_print("Trying to free cache memory\n");
2002-06-30 01:33:42 +02:00
folder_func_to_all_folders(folder_find_expired_caches, &folder_item_list);
listitem = folder_item_list;
while((listitem != NULL) && (memusage > (prefs_common.cache_max_mem_usage * 1024))) {
FolderItem *item = (FolderItem *)(listitem->data);
gint cache_size = 0;
if (item == protected_item) {
listitem = listitem->next;
continue;
}
debug_print("Freeing cache memory for %s\n", item->path ? item->path : item->name);
cache_size = msgcache_get_memory_usage(item->cache);
if (folder_item_free_cache(item, FALSE))
memusage -= cache_size;
2002-06-30 01:33:42 +02:00
listitem = listitem->next;
}
g_slist_free(folder_item_list);
}
}
void folder_item_read_cache(FolderItem *item)
{
gchar *cache_file, *mark_file;
START_TIMING("folder_item_read_cache");
2002-06-30 01:33:42 +02:00
g_return_if_fail(item != NULL);
2004-05-10 12:22:28 +02:00
if (item->path != NULL) {
cache_file = folder_item_get_cache_file(item);
mark_file = folder_item_get_mark_file(item);
item->cache = msgcache_read_cache(item, cache_file);
if (!item->cache) {
MsgInfoList *list, *cur;
guint newcnt = 0, unreadcnt = 0;
guint markedcnt = 0, unreadmarkedcnt = 0;
MsgInfo *msginfo;
2004-05-10 12:22:28 +02:00
item->cache = msgcache_new();
folder_item_scan_full(item, TRUE);
msgcache_read_mark(item->cache, mark_file);
list = msgcache_get_msg_list(item->cache);
for (cur = list; cur != NULL; cur = g_slist_next(cur)) {
msginfo = cur->data;
if (MSG_IS_NEW(msginfo->flags))
newcnt++;
if (MSG_IS_UNREAD(msginfo->flags))
unreadcnt++;
if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
unreadmarkedcnt++;
if (MSG_IS_MARKED(msginfo->flags))
markedcnt++;
}
item->new_msgs = newcnt;
item->unread_msgs = unreadcnt;
item->unreadmarked_msgs = unreadmarkedcnt;
item->marked_msgs = markedcnt;
procmsg_msg_list_free(list);
} else
msgcache_read_mark(item->cache, mark_file);
2004-05-10 12:22:28 +02:00
g_free(cache_file);
g_free(mark_file);
} else {
2002-06-30 01:33:42 +02:00
item->cache = msgcache_new();
}
END_TIMING();
folder_clean_cache_memory(item);
2002-06-30 01:33:42 +02:00
}
void folder_item_write_cache(FolderItem *item)
{
gchar *cache_file, *mark_file;
FolderItemPrefs *prefs;
2002-06-30 01:33:42 +02:00
gint filemode = 0;
gchar *id;
if (!item || !item->path || !item->cache)
return;
id = folder_item_get_identifier(item);
2002-08-15 09:38:17 +02:00
debug_print("Save cache for folder %s\n", id);
2002-06-30 01:33:42 +02:00
g_free(id);
cache_file = folder_item_get_cache_file(item);
mark_file = folder_item_get_mark_file(item);
if (msgcache_write(cache_file, mark_file, item->cache) < 0) {
2002-06-30 01:33:42 +02:00
prefs = item->prefs;
if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
/* for cache file */
filemode = prefs->folder_chmod;
if (filemode & S_IRGRP) filemode |= S_IWGRP;
if (filemode & S_IROTH) filemode |= S_IWOTH;
chmod(cache_file, filemode);
}
}
g_free(cache_file);
g_free(mark_file);
}
MsgInfo *folder_item_get_msginfo(FolderItem *item, gint num)
2002-06-30 01:33:42 +02:00
{
Folder *folder;
2004-06-25 10:05:09 +02:00
MsgInfo *msginfo = NULL;
2002-06-30 01:33:42 +02:00
g_return_val_if_fail(item != NULL, NULL);
if (item->no_select)
return NULL;
2002-06-30 01:33:42 +02:00
folder = item->folder;
if (!item->cache)
2002-06-30 01:33:42 +02:00
folder_item_read_cache(item);
if ((msginfo = msgcache_get_msg(item->cache, num)) != NULL)
2002-06-30 01:33:42 +02:00
return msginfo;
2004-06-25 10:05:09 +02:00
msginfo = get_msginfo(item, num);
if (msginfo != NULL) {
msgcache_add_msg(item->cache, msginfo);
return msginfo;
}
return NULL;
}
MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem *item, const gchar *msgid)
{
Folder *folder;
MsgInfo *msginfo;
g_return_val_if_fail(item != NULL, NULL);
2004-01-12 22:28:31 +01:00
g_return_val_if_fail(msgid != NULL, NULL);
if (item->no_select)
return FALSE;
folder = item->folder;
if (!item->cache)
folder_item_read_cache(item);
if ((msginfo = msgcache_get_msg_by_id(item->cache, msgid)) != NULL)
return msginfo;
return NULL;
2002-06-30 01:33:42 +02:00
}
GSList *folder_item_get_msg_list(FolderItem *item)
{
g_return_val_if_fail(item != NULL, NULL);
if (item->no_select)
return FALSE;
2002-06-30 01:33:42 +02:00
if (item->cache == 0)
2002-06-30 01:33:42 +02:00
folder_item_read_cache(item);
g_return_val_if_fail(item->cache != NULL, NULL);
return msgcache_get_msg_list(item->cache);
}
void msginfo_set_mime_flags(GNode *node, gpointer data)
{
MsgInfo *msginfo = data;
MimeInfo *mimeinfo = node->data;
if (mimeinfo->disposition == DISPOSITIONTYPE_ATTACHMENT
&& (!mimeinfo->subtype || strcmp(mimeinfo->subtype, "pgp-signature"))) {
procmsg_msginfo_set_flags(msginfo, 0, MSG_HAS_ATTACHMENT);
} else if (mimeinfo->disposition == DISPOSITIONTYPE_UNKNOWN &&
mimeinfo->type != MIMETYPE_TEXT &&
mimeinfo->type != MIMETYPE_MULTIPART) {
if (!mimeinfo->subtype
|| strcmp(mimeinfo->subtype, "pgp-signature"))
procmsg_msginfo_set_flags(msginfo, 0, MSG_HAS_ATTACHMENT);
} else if (mimeinfo->disposition == DISPOSITIONTYPE_INLINE &&
strcmp(mimeinfo->subtype, "pgp-signature") &&
(procmime_mimeinfo_get_parameter(mimeinfo, "name") != NULL ||
procmime_mimeinfo_get_parameter(mimeinfo, "filename") != NULL)) {
procmsg_msginfo_set_flags(msginfo, 0, MSG_HAS_ATTACHMENT);
}
/* don't descend below top level message for signed and encrypted info */
if (mimeinfo->type == MIMETYPE_MESSAGE)
return;
if (privacy_mimeinfo_is_signed(mimeinfo)) {
procmsg_msginfo_set_flags(msginfo, 0, MSG_SIGNED);
}
if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
procmsg_msginfo_set_flags(msginfo, 0, MSG_ENCRYPTED);
} else {
/* searching inside encrypted parts doesn't really make sense */
g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_mime_flags, msginfo);
}
}
2001-04-19 14:21:46 +02:00
gchar *folder_item_fetch_msg(FolderItem *item, gint num)
{
Folder *folder;
gchar *msgfile;
MsgInfo *msginfo;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(item != NULL, NULL);
folder = item->folder;
2001-05-23 14:08:40 +02:00
g_return_val_if_fail(folder->klass->fetch_msg != NULL, NULL);
if (item->no_select)
return NULL;
2001-05-23 14:08:40 +02:00
msgfile = folder->klass->fetch_msg(folder, item, num);
if (msgfile != NULL) {
msginfo = folder_item_get_msginfo(item, num);
if ((msginfo != NULL) && !MSG_IS_SCANNED(msginfo->flags)) {
MimeInfo *mimeinfo;
if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
!folder_has_parent_of_type(msginfo->folder, F_DRAFT))
mimeinfo = procmime_scan_file(msgfile);
else
mimeinfo = procmime_scan_queue_file(msgfile);
/* check for attachments */
if (mimeinfo != NULL) {
g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_mime_flags, msginfo);
procmime_mimeinfo_free_all(mimeinfo);
procmsg_msginfo_set_flags(msginfo, 0, MSG_SCANNED);
}
}
procmsg_msginfo_free(msginfo);
}
return msgfile;
2001-04-19 14:21:46 +02:00
}
gchar *folder_item_fetch_msg_full(FolderItem *item, gint num, gboolean headers,
gboolean body)
{
Folder *folder;
gchar *msgfile;
MsgInfo *msginfo;
g_return_val_if_fail(item != NULL, NULL);
if (item->no_select)
return NULL;
folder = item->folder;
if (folder->klass->fetch_msg_full == NULL)
return folder_item_fetch_msg(item, num);
msgfile = folder->klass->fetch_msg_full(folder, item, num,
headers, body);
if (msgfile != NULL) {
msginfo = folder_item_get_msginfo(item, num);
if ((msginfo != NULL) && !MSG_IS_SCANNED(msginfo->flags)) {
MimeInfo *mimeinfo;
if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
!folder_has_parent_of_type(msginfo->folder, F_DRAFT))
mimeinfo = procmime_scan_file(msgfile);
else
mimeinfo = procmime_scan_queue_file(msgfile);
/* check for attachments */
if (mimeinfo != NULL) {
g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_mime_flags, msginfo);
procmime_mimeinfo_free_all(mimeinfo);
procmsg_msginfo_set_flags(msginfo, 0, MSG_SCANNED);
}
}
procmsg_msginfo_free(msginfo);
}
return msgfile;
}
2004-02-21 12:01:01 +01:00
gint folder_item_fetch_all_msg(FolderItem *item)
{
Folder *folder;
GSList *mlist;
GSList *cur;
gint num = 0;
gint ret = 0;
gint total = 0;
2004-02-21 12:01:01 +01:00
g_return_val_if_fail(item != NULL, -1);
if (item->no_select)
return -1;
2004-02-21 12:01:01 +01:00
debug_print("fetching all messages in %s ...\n", item->path ? item->path : "(null)");
statusbar_print_all(_("Fetching all messages in %s ...\n"), item->path ? item->path : "(null)");
2004-02-21 12:01:01 +01:00
folder = item->folder;
if (folder->ui_func)
folder->ui_func(folder, item, folder->ui_func_data ?
folder->ui_func_data : GINT_TO_POINTER(num));
mlist = folder_item_get_msg_list(item);
total = g_slist_length(mlist);
2004-02-21 12:01:01 +01:00
for (cur = mlist; cur != NULL; cur = cur->next) {
MsgInfo *msginfo = (MsgInfo *)cur->data;
gchar *msg;
statusbar_progress_all(num++,total, 10);
2004-02-21 12:01:01 +01:00
if (folder->ui_func)
folder->ui_func(folder, item,
folder->ui_func_data ?
folder->ui_func_data :
GINT_TO_POINTER(num));
msg = folder_item_fetch_msg(item, msginfo->msgnum);
if (!msg) {
g_warning("Can't fetch message %d. Aborting.\n",
msginfo->msgnum);
ret = -1;
break;
}
g_free(msg);
}
statusbar_progress_all(0,0,0);
statusbar_pop_all();
2004-02-21 12:01:01 +01:00
procmsg_msg_list_free(mlist);
return ret;
}
static gint folder_item_get_msg_num_by_file(FolderItem *dest, const gchar *file)
{
static HeaderEntry hentry[] = {{"Message-ID:", NULL, TRUE},
{NULL, NULL, FALSE}};
FILE *fp;
MsgInfo *msginfo;
gint msgnum = 0;
gchar buf[BUFFSIZE];
if ((fp = g_fopen(file, "rb")) == NULL)
return 0;
if ((folder_has_parent_of_type(dest, F_QUEUE)) ||
(folder_has_parent_of_type(dest, F_DRAFT)))
while (fgets(buf, sizeof(buf), fp) != NULL)
if (buf[0] == '\r' || buf[0] == '\n') break;
procheader_get_header_fields(fp, hentry);
if (hentry[0].body) {
extract_parenthesis(hentry[0].body, '<', '>');
remove_space(hentry[0].body);
if ((msginfo = msgcache_get_msg_by_id(dest->cache, hentry[0].body)) != NULL) {
msgnum = msginfo->msgnum;
procmsg_msginfo_free(msginfo);
debug_print("found message as uid %d\n", msgnum);
}
}
g_free(hentry[0].body);
hentry[0].body = NULL;
fclose(fp);
return msgnum;
}
static void copy_msginfo_flags(MsgInfo *source, MsgInfo *dest)
{
MsgPermFlags perm_flags = 0;
MsgTmpFlags tmp_flags = 0;
/* create new flags */
if (source != NULL) {
/* copy original flags */
perm_flags = source->flags.perm_flags;
tmp_flags = source->flags.tmp_flags;
} else {
perm_flags = dest->flags.perm_flags;
tmp_flags = dest->flags.tmp_flags;
}
/* remove new, unread and deleted in special folders */
if (folder_has_parent_of_type(dest->folder, F_OUTBOX) ||
folder_has_parent_of_type(dest->folder, F_QUEUE) ||
folder_has_parent_of_type(dest->folder, F_DRAFT) ||
folder_has_parent_of_type(dest->folder, F_TRASH))
perm_flags &= ~(MSG_NEW | MSG_UNREAD | MSG_DELETED);
/* set ignore flag of ignored parent exists */
if (procmsg_msg_has_flagged_parent(dest, MSG_IGNORE_THREAD))
perm_flags |= MSG_IGNORE_THREAD;
/* Unset tmp flags that should not be copied */
tmp_flags &= ~(MSG_MOVE | MSG_COPY);
/* unset flags that are set but should not */
/* and set new flags */
procmsg_msginfo_change_flags(dest,
~dest->flags.perm_flags & perm_flags,
~dest->flags.tmp_flags & tmp_flags,
dest->flags.perm_flags & ~perm_flags,
dest->flags.tmp_flags & ~tmp_flags);
}
static void add_msginfo_to_cache(FolderItem *item, MsgInfo *newmsginfo, MsgInfo *flagsource)
{
/* update folder stats */
if (MSG_IS_NEW(newmsginfo->flags))
item->new_msgs++;
if (MSG_IS_UNREAD(newmsginfo->flags))
item->unread_msgs++;
if (MSG_IS_UNREAD(newmsginfo->flags) && procmsg_msg_has_marked_parent(newmsginfo))
item->unreadmarked_msgs++;
if (MSG_IS_MARKED(newmsginfo->flags))
item->marked_msgs++;
item->total_msgs++;
2004-01-12 22:28:31 +01:00
folder_item_update_freeze();
if (!item->cache)
folder_item_read_cache(item);
msgcache_add_msg(item->cache, newmsginfo);
2004-01-12 22:28:31 +01:00
copy_msginfo_flags(flagsource, newmsginfo);
2004-06-25 10:05:09 +02:00
folder_item_update_with_msg(item, F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT | F_ITEM_UPDATE_ADDMSG, newmsginfo);
2004-01-12 22:28:31 +01:00
folder_item_update_thaw();
}
static void remove_msginfo_from_cache(FolderItem *item, MsgInfo *msginfo)
{
MsgInfoUpdate msginfo_update;
if (!item->cache)
folder_item_read_cache(item);
if (MSG_IS_NEW(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
msginfo->folder->new_msgs--;
if (MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
msginfo->folder->unread_msgs--;
if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
msginfo->folder->unreadmarked_msgs--;
if (MSG_IS_MARKED(msginfo->flags))
item->marked_msgs--;
msginfo->folder->total_msgs--;
msginfo_update.msginfo = msginfo;
msginfo_update.flags = MSGINFO_UPDATE_DELETED;
hooks_invoke(MSGINFO_UPDATE_HOOKLIST, &msginfo_update);
msgcache_remove_msg(item->cache, msginfo->msgnum);
2004-06-25 10:05:09 +02:00
folder_item_update_with_msg(msginfo->folder, F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT | F_ITEM_UPDATE_REMOVEMSG, msginfo);
}
2001-05-17 15:25:31 +02:00
gint folder_item_add_msg(FolderItem *dest, const gchar *file,
MsgFlags *flags, gboolean remove_source)
2001-04-19 14:21:46 +02:00
{
GSList file_list;
MsgFileInfo fileinfo;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(dest != NULL, -1);
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;
2001-05-23 14:08:40 +02:00
return folder_item_add_msgs(dest, &file_list, remove_source);
}
2001-05-23 14:08:40 +02:00
gint folder_item_add_msgs(FolderItem *dest, GSList *file_list,
gboolean remove_source)
{
Folder *folder;
gint ret, num, lastnum = -1;
GSList *file_cur;
GRelation *relation;
MsgFileInfo *fileinfo = NULL;
gboolean folderscan = FALSE;
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);
g_return_val_if_fail(dest->folder != NULL, -1);
if (dest->no_select)
return -1;
2002-06-30 01:33:42 +02:00
folder = dest->folder;
2002-06-30 01:33:42 +02:00
relation = g_relation_new(2);
g_relation_index(relation, 0, g_direct_hash, g_direct_equal);
if (folder->klass->add_msgs != NULL) {
ret = folder->klass->add_msgs(folder, dest, file_list, relation);
if (ret < 0) {
g_relation_destroy(relation);
return ret;
}
} else {
for (file_cur = file_list; file_cur != NULL; file_cur = g_slist_next(file_cur)) {
fileinfo = (MsgFileInfo *) file_cur->data;
2002-06-30 01:33:42 +02:00
ret = folder->klass->add_msg(folder, dest, fileinfo->file, fileinfo->flags);
if (ret < 0) {
g_relation_destroy(relation);
return ret;
}
g_relation_insert(relation, fileinfo, GINT_TO_POINTER(ret));
}
}
for (file_cur = file_list; file_cur != NULL; file_cur = g_slist_next(file_cur)) {
GTuples *tuples;
2001-04-19 14:21:46 +02:00
fileinfo = (MsgFileInfo *) file_cur->data;
tuples = g_relation_select(relation, fileinfo, 0);
num = GPOINTER_TO_INT(g_tuples_index(tuples, 0, 1));
g_tuples_destroy(tuples);
2001-04-19 14:21:46 +02:00
if (num >= 0) {
MsgInfo *newmsginfo;
if (num == 0) {
if (!folderscan) {
folder_item_scan_full(dest, FALSE);
folderscan = TRUE;
}
num = folder_item_get_msg_num_by_file(dest, fileinfo->file);
}
if (num > lastnum)
lastnum = num;
if (num >= 0 && remove_source) {
if (g_unlink(fileinfo->file) < 0)
FILE_OP_ERROR(fileinfo->file, "unlink");
}
if (num == 0)
continue;
if (!folderscan &&
2004-06-25 10:05:09 +02:00
((newmsginfo = get_msginfo(dest, num)) != NULL)) {
add_msginfo_to_cache(dest, newmsginfo, NULL);
procmsg_msginfo_free(newmsginfo);
} else if ((newmsginfo = msgcache_get_msg(dest->cache, num)) != NULL) {
/* TODO: set default flags */
procmsg_msginfo_free(newmsginfo);
}
}
}
g_relation_destroy(relation);
return lastnum;
}
2002-11-07 00:56:26 +01:00
FolderItem *folder_item_move_recursive(FolderItem *src, FolderItem *dest)
2002-11-07 00:56:26 +01:00
{
GSList *mlist;
FolderItem *new_item;
FolderItem *next_item;
GNode *srcnode;
gchar *old_id, *new_id;
2002-11-07 00:56:26 +01:00
/* move messages */
debug_print("Moving %s to %s\n", src->path, dest->path);
2004-06-25 10:05:09 +02:00
new_item = folder_create_folder(dest, src->name);
2002-11-07 00:56:26 +01:00
if (new_item == NULL) {
printf("Can't create folder\n");
return NULL;
2002-11-07 00:56:26 +01:00
}
2002-11-08 16:42:57 +01:00
if (new_item->folder == NULL)
new_item->folder = dest->folder;
/* move messages */
2003-03-21 18:28:52 +01:00
log_message(_("Moving %s to %s...\n"),
src->name, new_item->path);
mlist = folder_item_get_msg_list(src);
if (mlist != NULL) {
2004-06-25 10:05:09 +02:00
folder_item_move_msgs(new_item, mlist);
procmsg_msg_list_free(mlist);
}
2002-11-08 16:42:57 +01:00
/*copy prefs*/
folder_item_prefs_copy_prefs(src, new_item);
new_item->collapsed = src->collapsed;
new_item->thread_collapsed = src->thread_collapsed;
new_item->threaded = src->threaded;
new_item->ret_rcpt = src->ret_rcpt;
new_item->hide_read_msgs = src->hide_read_msgs;
new_item->sort_key = src->sort_key;
new_item->sort_type = src->sort_type;
2002-11-08 16:42:57 +01:00
prefs_matcher_write_config();
2002-11-08 16:42:57 +01:00
/* recurse */
2002-11-07 00:56:26 +01:00
srcnode = src->folder->node;
srcnode = g_node_find(srcnode, G_PRE_ORDER, G_TRAVERSE_ALL, src);
srcnode = srcnode->children;
while (srcnode != NULL) {
if (srcnode && srcnode->data) {
next_item = (FolderItem*) srcnode->data;
2002-11-27 14:21:07 +01:00
srcnode = srcnode->next;
if (folder_item_move_recursive(next_item, new_item) == NULL) {
return NULL;
}
2002-11-07 00:56:26 +01:00
}
}
old_id = folder_item_get_identifier(src);
new_id = folder_item_get_identifier(new_item);
debug_print("updating rules : %s => %s\n", old_id, new_id);
2004-06-25 10:05:09 +02:00
/* if src supports removing, otherwise only copy folder */
if (src->folder->klass->remove_folder != NULL)
src->folder->klass->remove_folder(src->folder, src);
folder_write_list();
if (old_id != NULL && new_id != NULL) {
prefs_filtering_rename_path(old_id, new_id);
account_rename_path(old_id, new_id);
}
g_free(old_id);
g_free(new_id);
return new_item;
2002-11-07 00:56:26 +01:00
}
gint folder_item_move_to(FolderItem *src, FolderItem *dest, FolderItem **new_item)
2002-11-07 00:56:26 +01:00
{
2004-02-21 12:01:01 +01:00
FolderItem *tmp = folder_item_parent(dest);
gchar * src_identifier, * dst_identifier;
gchar * phys_srcpath, * phys_dstpath, *tmppath;
2002-11-08 18:36:53 +01:00
2002-11-07 00:56:26 +01:00
while (tmp) {
if (tmp == src) {
return F_MOVE_FAILED_DEST_IS_CHILD;
2002-11-07 00:56:26 +01:00
}
tmp = folder_item_parent(tmp);
2002-11-07 00:56:26 +01:00
}
2004-02-21 12:01:01 +01:00
tmp = folder_item_parent(src);
2002-11-07 00:56:26 +01:00
2002-11-09 14:02:30 +01:00
src_identifier = folder_item_get_identifier(src);
dst_identifier = folder_item_get_identifier(dest);
2002-11-07 00:56:26 +01:00
2004-02-21 12:01:01 +01:00
if(dst_identifier == NULL && dest->folder && folder_item_parent(dest) == NULL) {
/* dest can be a root folder */
2002-11-09 14:02:30 +01:00
dst_identifier = folder_get_identifier(dest->folder);
}
2002-11-09 14:02:30 +01:00
if (src_identifier == NULL || dst_identifier == NULL) {
debug_print("Can't get identifiers\n");
return F_MOVE_FAILED;
2002-11-07 00:56:26 +01:00
}
if (src->folder != dest->folder) {
return F_MOVE_FAILED_DEST_OUTSIDE_MAILBOX;
}
2002-11-07 00:56:26 +01:00
phys_srcpath = folder_item_get_path(src);
tmppath = folder_item_get_path(dest);
phys_dstpath = g_strconcat(tmppath,
G_DIR_SEPARATOR_S,
g_path_get_basename(phys_srcpath),
NULL);
g_free(tmppath);
2004-02-21 12:01:01 +01:00
if (folder_item_parent(src) == dest || src == dest) {
2002-11-09 14:02:30 +01:00
g_free(src_identifier);
g_free(dst_identifier);
2002-11-07 00:56:26 +01:00
g_free(phys_srcpath);
g_free(phys_dstpath);
return F_MOVE_FAILED_DEST_IS_PARENT;
2002-11-07 00:56:26 +01:00
}
debug_print("moving \"%s\" to \"%s\"\n", phys_srcpath, phys_dstpath);
2002-11-08 16:42:57 +01:00
if ((tmp = folder_item_move_recursive(src, dest)) == NULL) {
return F_MOVE_FAILED;
2002-11-07 00:56:26 +01:00
}
2002-11-09 14:02:30 +01:00
g_free(src_identifier);
g_free(dst_identifier);
2002-11-07 00:56:26 +01:00
g_free(phys_srcpath);
g_free(phys_dstpath);
2002-11-08 16:42:57 +01:00
*new_item = tmp;
return F_MOVE_OK;
2002-11-07 00:56:26 +01:00
}
2001-05-28 00:40:29 +02:00
/**
2004-01-12 22:28:31 +01:00
* Copy a list of message to a new folder and remove
* source messages if wanted
*/
2004-01-12 22:28:31 +01:00
static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_source)
2001-05-28 00:40:29 +02:00
{
Folder *folder;
GSList *l;
gint num, lastnum = -1;
gboolean folderscan = FALSE;
GRelation *relation;
GSList *not_moved = NULL;
gint total = 0, curmsg = 0;
MsgInfo *msginfo = NULL;
2001-05-28 00:40:29 +02:00
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(msglist != NULL, -1);
folder = dest->folder;
g_return_val_if_fail(folder->klass->copy_msg != NULL, -1);
if (dest->no_select)
return -1;
2001-05-28 00:40:29 +02:00
msginfo = (MsgInfo *)msglist->data;
if (!msginfo)
return -1;
if (!MSG_IS_QUEUED(msginfo->flags) &&
MSG_IS_DRAFT(msginfo->flags) &&
folder_has_parent_of_type(dest, F_QUEUE)) {
GSList *cur = msglist;
gboolean queue_err = FALSE;
for (; cur; cur = cur->next) {
Compose *compose = NULL;
FolderItem *queue = dest;
int val = 0;
msginfo = (MsgInfo *)cur->data;
compose = compose_reedit(msginfo, TRUE);
if (compose == NULL) {
queue_err = TRUE;
continue;
}
val = compose_queue(compose, NULL, &queue, NULL,
FALSE);
if (val < 0) {
queue_err = TRUE;
} else if (remove_source) {
folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
}
if (val == 0)
compose_close(compose);
}
return queue_err ? -1:0;
}
relation = g_relation_new(2);
g_relation_index(relation, 0, g_direct_hash, g_direct_equal);
2004-01-12 22:28:31 +01:00
g_relation_index(relation, 1, g_direct_hash, g_direct_equal);
for (l = msglist ; l != NULL ; l = g_slist_next(l)) {
MsgInfo * msginfo = (MsgInfo *) l->data;
if (msginfo->planned_download != 0) {
int old_planned = msginfo->planned_download;
partial_unmark(msginfo);
/* little hack to reenable after */
msginfo->planned_download = old_planned;
}
}
/*
* Copy messages to destination folder and
* store new message numbers in newmsgnums
*/
if (folder->klass->copy_msgs != NULL) {
if (folder->klass->copy_msgs(folder, dest, msglist, relation) < 0) {
g_relation_destroy(relation);
return -1;
}
} else {
MsgInfo * msginfo;
l = msglist;
/* immediately stop if src and dest folders are identical */
if (l != NULL) {
msginfo = (MsgInfo *) l->data;
if (msginfo != NULL && msginfo->folder == dest) {
g_relation_destroy(relation);
return -1;
}
}
for (; l != NULL ; l = g_slist_next(l)) {
msginfo = (MsgInfo *) l->data;
2001-05-28 00:40:29 +02:00
num = folder->klass->copy_msg(folder, dest, msginfo);
if (num > 0)
g_relation_insert(relation, msginfo, GINT_TO_POINTER(num));
else
not_moved = g_slist_prepend(not_moved, msginfo);
}
}
if (remove_source) {
MsgInfo *msginfo = (MsgInfo *) msglist->data;
FolderItem *item = msginfo->folder;
/*
* Remove source messages from their folders if
* copying was successfull and update folder
* message counts
*/
if (item->folder->klass->remove_msgs) {
item->folder->klass->remove_msgs(item->folder,
msginfo->folder,
msglist,
relation);
}
for (l = msglist; l != NULL; l = g_slist_next(l)) {
GTuples *tuples;
msginfo = (MsgInfo *) l->data;
item = msginfo->folder;
tuples = g_relation_select(relation, msginfo, 0);
num = GPOINTER_TO_INT(g_tuples_index(tuples, 0, 1));
g_tuples_destroy(tuples);
if (g_slist_find(not_moved, msginfo))
continue;
if ((num >= 0) && (item->folder->klass->remove_msg != NULL)) {
if (!item->folder->klass->remove_msgs)
item->folder->klass->remove_msg(item->folder,
msginfo->folder,
msginfo->msgnum);
remove_msginfo_from_cache(item, msginfo);
}
}
}
/* Read cache for dest folder */
if (!dest->cache) folder_item_read_cache(dest);
/*
* Fetch new MsgInfos for new messages in dest folder,
* add them to the msgcache and update folder message counts
*/
2004-01-12 22:28:31 +01:00
if (g_relation_count(relation, GINT_TO_POINTER(0), 1) > 0) {
folder_item_scan_full(dest, FALSE);
folderscan = TRUE;
}
statusbar_print_all(_("Updating cache for %s..."), dest->path ? dest->path : "(null)");
total = g_slist_length(msglist);
for (l = msglist; l != NULL; l = g_slist_next(l)) {
MsgInfo *msginfo = (MsgInfo *) l->data;
GTuples *tuples;
tuples = g_relation_select(relation, msginfo, 0);
num = GPOINTER_TO_INT(g_tuples_index(tuples, 0, 1));
g_tuples_destroy(tuples);
statusbar_progress_all(curmsg++,total, 100);
if (curmsg % 100 == 0)
GTK_EVENTS_FLUSH();
if (num >= 0) {
MsgInfo *newmsginfo = NULL;
2002-06-30 01:33:42 +02:00
2004-01-12 22:28:31 +01:00
if (folderscan) {
if (msginfo->msgid != NULL) {
newmsginfo = folder_item_get_msginfo_by_msgid(dest, msginfo->msgid);
if (newmsginfo != NULL) {
copy_msginfo_flags(msginfo, newmsginfo);
num = newmsginfo->msgnum;
}
}
} else {
2004-06-25 10:05:09 +02:00
newmsginfo = get_msginfo(dest, num);
2004-01-12 22:28:31 +01:00
if (newmsginfo != NULL) {
add_msginfo_to_cache(dest, newmsginfo, msginfo);
}
}
if (msginfo->planned_download
== POP3_PARTIAL_DLOAD_DELE) {
partial_mark_for_delete(newmsginfo);
}
if (msginfo->planned_download
== POP3_PARTIAL_DLOAD_DLOAD) {
partial_mark_for_download(newmsginfo);
}
if (!MSG_IS_POSTFILTERED (msginfo->flags)) {
procmsg_msginfo_set_flags ( msginfo, MSG_POSTFILTERED, 0);
procmsg_msginfo_set_flags (newmsginfo, MSG_POSTFILTERED, 0);
hooks_invoke (MAIL_POSTFILTERING_HOOKLIST, newmsginfo);
}
procmsg_msginfo_free(newmsginfo);
if (num > lastnum)
lastnum = num;
}
}
statusbar_progress_all(0,0,0);
statusbar_pop_all();
g_relation_destroy(relation);
if (not_moved != NULL) {
g_slist_free(not_moved);
return -1;
} else
return lastnum;
2001-05-28 00:40:29 +02:00
}
2001-04-19 14:21:46 +02:00
2004-01-12 22:28:31 +01:00
/**
* Move a message to a new folder.
*
* \param dest Destination folder
* \param msginfo The message
*/
gint folder_item_move_msg(FolderItem *dest, MsgInfo *msginfo)
2001-04-19 14:21:46 +02:00
{
2004-01-12 22:28:31 +01:00
GSList list;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(msginfo != NULL, -1);
2004-01-12 22:28:31 +01:00
list.data = msginfo;
list.next = NULL;
2001-04-19 14:21:46 +02:00
2004-01-12 22:28:31 +01:00
return do_copy_msgs(dest, &list, TRUE);
}
2001-04-19 14:21:46 +02:00
2004-01-12 22:28:31 +01:00
/**
* Move a list of messages to a new folder.
*
* \param dest Destination folder
* \param msglist List of messages
*/
gint folder_item_move_msgs(FolderItem *dest, GSList *msglist)
{
gint result = -1;
2004-01-12 22:28:31 +01:00
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(msglist != NULL, -1);
inc_lock();
result = do_copy_msgs(dest, msglist, TRUE);
inc_unlock();
return result;
2001-04-19 14:21:46 +02:00
}
2004-01-12 22:28:31 +01:00
/**
* Copy a message to a new folder.
*
* \param dest Destination folder
* \param msginfo The message
*/
2001-05-28 00:40:29 +02:00
gint folder_item_copy_msg(FolderItem *dest, MsgInfo *msginfo)
{
2004-01-12 22:28:31 +01:00
GSList list;
2001-05-28 00:40:29 +02:00
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(msginfo != NULL, -1);
2004-01-12 22:28:31 +01:00
list.data = msginfo;
list.next = NULL;
2004-01-12 22:28:31 +01:00
return do_copy_msgs(dest, &list, FALSE);
2001-05-28 00:40:29 +02:00
}
2004-01-12 22:28:31 +01:00
/**
* Copy a list of messages to a new folder.
*
* \param dest Destination folder
* \param msglist List of messages
*/
2003-08-05 11:01:01 +02:00
gint folder_item_copy_msgs(FolderItem *dest, GSList *msglist)
2001-05-28 00:40:29 +02:00
{
gint result;
2001-05-28 00:40:29 +02:00
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(msglist != NULL, -1);
inc_lock();
result = do_copy_msgs(dest, msglist, FALSE);
inc_unlock();
return result;
2001-05-28 00:40:29 +02:00
}
2001-04-19 14:21:46 +02:00
gint folder_item_remove_msg(FolderItem *item, gint num)
{
Folder *folder;
2001-08-30 14:59:38 +02:00
gint ret;
2002-06-30 01:33:42 +02:00
MsgInfo *msginfo;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(item != NULL, -1);
folder = item->folder;
g_return_val_if_fail(folder->klass->remove_msg != NULL, -1);
if (item->no_select)
return -1;
2001-04-19 14:21:46 +02:00
2002-06-30 01:33:42 +02:00
if (!item->cache) folder_item_read_cache(item);
2001-04-19 14:21:46 +02:00
ret = folder->klass->remove_msg(folder, item, num);
2002-06-30 01:33:42 +02:00
msginfo = msgcache_get_msg(item->cache, num);
if (msginfo != NULL) {
remove_msginfo_from_cache(item, msginfo);
procmsg_msginfo_free(msginfo);
}
2001-08-30 14:59:38 +02:00
return ret;
2001-04-19 14:21:46 +02:00
}
2001-10-07 11:15:06 +02:00
gint folder_item_remove_msgs(FolderItem *item, GSList *msglist)
{
Folder *folder;
2001-10-07 11:15:06 +02:00
gint ret = 0;
g_return_val_if_fail(item != NULL, -1);
folder = item->folder;
g_return_val_if_fail(folder != NULL, -1);
if (item->no_select)
return -1;
inc_lock();
if (!item->cache) folder_item_read_cache(item);
2004-02-21 12:01:01 +01:00
folder_item_update_freeze();
if (item->folder->klass->remove_msgs) {
ret = item->folder->klass->remove_msgs(item->folder,
item,
msglist,
NULL);
}
while (ret == 0 && msglist != NULL) {
2001-10-07 11:15:06 +02:00
MsgInfo *msginfo = (MsgInfo *)msglist->data;
if (MSG_IS_LOCKED(msginfo->flags)) {
msglist = msglist->next;
continue;
}
if (!item->folder->klass->remove_msgs)
ret = folder_item_remove_msg(item, msginfo->msgnum);
2001-10-07 11:15:06 +02:00
if (ret != 0) break;
2002-06-30 01:33:42 +02:00
msgcache_remove_msg(item->cache, msginfo->msgnum);
2001-10-07 11:15:06 +02:00
msglist = msglist->next;
}
folder_item_scan_full(item, FALSE);
2004-02-21 12:01:01 +01:00
folder_item_update_thaw();
inc_unlock();
2001-10-07 11:15:06 +02:00
return ret;
}
2001-04-19 14:21:46 +02:00
gint folder_item_remove_all_msg(FolderItem *item)
{
Folder *folder;
gint result;
2001-04-19 14:21:46 +02:00
g_return_val_if_fail(item != NULL, -1);
if (item->no_select)
return -1;
2001-05-28 00:40:29 +02:00
folder = item->folder;
inc_lock();
if (folder->klass->remove_all_msg != NULL) {
result = folder->klass->remove_all_msg(folder, item);
2001-04-19 14:21:46 +02:00
if (result == 0) {
folder_item_free_cache(item, TRUE);
item->cache = msgcache_new();
}
} else {
MsgInfoList *msglist;
msglist = folder_item_get_msg_list(item);
result = folder_item_remove_msgs(item, msglist);
procmsg_msg_list_free(msglist);
}
if (result == 0) {
item->new_msgs = 0;
item->unread_msgs = 0;
item->unreadmarked_msgs = 0;
item->marked_msgs = 0;
item->total_msgs = 0;
folder_item_update(item, F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT);
}
inc_unlock();
return result;
2001-04-19 14:21:46 +02:00
}
void folder_item_change_msg_flags(FolderItem *item, MsgInfo *msginfo, MsgPermFlags newflags)
{
g_return_if_fail(item != NULL);
g_return_if_fail(msginfo != NULL);
if (item->no_select)
return;
if (item->folder->klass->change_flags != NULL) {
item->folder->klass->change_flags(item->folder, item, msginfo, newflags);
} else {
msginfo->flags.perm_flags = newflags;
}
}
2001-04-19 14:21:46 +02:00
gboolean folder_item_is_msg_changed(FolderItem *item, MsgInfo *msginfo)
{
Folder *folder;
g_return_val_if_fail(item != NULL, FALSE);
if (item->no_select)
return FALSE;
2001-04-19 14:21:46 +02:00
folder = item->folder;
2001-05-23 14:08:40 +02:00
g_return_val_if_fail(folder->klass->is_msg_changed != NULL, -1);
2001-05-23 14:08:40 +02:00
return folder->klass->is_msg_changed(folder, item, msginfo);
2001-04-19 14:21:46 +02:00
}
gchar *folder_item_get_cache_file(FolderItem *item)
{
gchar *path;
gchar *file;
g_return_val_if_fail(item != NULL, NULL);
g_return_val_if_fail(item->path != NULL, NULL);
path = folder_item_get_path(item);
g_return_val_if_fail(path != NULL, NULL);
if (!is_dir_exist(path))
make_dir_hier(path);
file = g_strconcat(path, G_DIR_SEPARATOR_S, CACHE_FILE, NULL);
g_free(path);
return file;
}
gchar *folder_item_get_mark_file(FolderItem *item)
{
gchar *path;
gchar *file;
g_return_val_if_fail(item != NULL, NULL);
g_return_val_if_fail(item->path != NULL, NULL);
path = folder_item_get_path(item);
g_return_val_if_fail(path != NULL, NULL);
if (!is_dir_exist(path))
make_dir_hier(path);
file = g_strconcat(path, G_DIR_SEPARATOR_S, MARK_FILE, NULL);
g_free(path);
return file;
}
2004-02-21 12:01:01 +01:00
static gpointer xml_to_folder_item(gpointer nodedata, gpointer data)
2001-04-19 14:21:46 +02:00
{
2004-02-21 12:01:01 +01:00
XMLNode *xmlnode = (XMLNode *) nodedata;
Folder *folder = (Folder *) data;
2001-04-19 14:21:46 +02:00
FolderItem *item;
2004-02-21 12:01:01 +01:00
g_return_val_if_fail(xmlnode != NULL, NULL);
g_return_val_if_fail(folder != NULL, NULL);
2001-04-19 14:21:46 +02:00
if (strcmp2(xmlnode->tag->tag, "folderitem") != 0) {
g_warning("tag name != \"folderitem\"\n");
2004-02-21 12:01:01 +01:00
return NULL;
2001-04-19 14:21:46 +02:00
}
2004-01-12 22:28:31 +01:00
item = folder_item_new(folder, "", "");
if (folder->klass->item_set_xml != NULL)
folder->klass->item_set_xml(folder, item, xmlnode->tag);
else
folder_item_set_xml(folder, item, xmlnode->tag);
2004-02-21 12:01:01 +01:00
2001-04-19 14:21:46 +02:00
item->folder = folder;
2004-02-21 12:01:01 +01:00
2004-01-12 22:28:31 +01:00
switch (item->stype) {
2001-04-19 14:21:46 +02:00
case F_INBOX: folder->inbox = item; break;
case F_OUTBOX: folder->outbox = item; break;
case F_DRAFT: folder->draft = item; break;
case F_QUEUE: folder->queue = item; break;
case F_TRASH: folder->trash = item; break;
2002-03-07 14:22:39 +01:00
default: break;
2001-04-19 14:21:46 +02:00
}
folder_item_prefs_read_config(item);
2001-05-06 06:27:28 +02:00
2004-02-21 12:01:01 +01:00
return item;
}
static gboolean folder_item_set_node(GNode *node, gpointer data)
{
FolderItem *item = (FolderItem *) node->data;
item->node = node;
2001-04-19 14:21:46 +02:00
return FALSE;
}
2004-02-21 12:01:01 +01:00
static Folder *folder_get_from_xml(GNode *node)
2001-04-19 14:21:46 +02:00
{
Folder *folder;
XMLNode *xmlnode;
GList *list;
2004-01-12 22:28:31 +01:00
FolderClass *klass = NULL;
2004-02-21 12:01:01 +01:00
GNode *cur;
2001-04-19 14:21:46 +02:00
2004-02-21 12:01:01 +01:00
g_return_val_if_fail(node->data != NULL, NULL);
2001-04-19 14:21:46 +02:00
xmlnode = node->data;
if (strcmp2(xmlnode->tag->tag, "folder") != 0) {
g_warning("tag name != \"folder\"\n");
2004-02-21 12:01:01 +01:00
return NULL;
2001-04-19 14:21:46 +02:00
}
list = xmlnode->tag->attr;
for (; list != NULL; list = list->next) {
XMLAttr *attr = list->data;
if (!attr || !attr->name || !attr->value) continue;
if (!strcmp(attr->name, "type"))
2004-01-12 22:28:31 +01:00
klass = folder_get_class_from_string(attr->value);
2001-04-19 14:21:46 +02:00
}
2004-02-21 12:01:01 +01:00
if (klass == NULL)
return NULL;
2001-04-19 14:21:46 +02:00
2004-01-12 22:28:31 +01:00
folder = folder_new(klass, "", "");
2004-02-21 12:01:01 +01:00
g_return_val_if_fail(folder != NULL, NULL);
2004-01-12 22:28:31 +01:00
if (klass->set_xml)
klass->set_xml(folder, xmlnode->tag);
else
folder_set_xml(folder, xmlnode->tag);
2001-04-19 14:21:46 +02:00
2004-02-21 12:01:01 +01:00
cur = node->children;
while (cur != NULL) {
GNode *itemnode;
2001-04-19 14:21:46 +02:00
2004-02-21 12:01:01 +01:00
itemnode = g_node_map(cur, xml_to_folder_item, (gpointer) folder);
g_node_append(folder->node, itemnode);
cur = cur->next;
}
g_node_traverse(folder->node, G_IN_ORDER, G_TRAVERSE_ALL, -1, folder_item_set_node, NULL);
return folder;
2001-04-19 14:21:46 +02:00
}
static gchar *folder_get_list_path(void)
{
static gchar *filename = NULL;
if (!filename)
filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
FOLDER_LIST, NULL);
return filename;
}
2002-11-12 10:09:22 +01:00
#define PUT_ESCAPE_STR(fp, attr, str) \
{ \
fputs(" " attr "=\"", fp); \
xml_file_put_escape_str(fp, str); \
fputs("\"", fp); \
}
2004-02-21 12:01:01 +01:00
static gpointer folder_item_to_xml(gpointer nodedata, gpointer data)
2004-01-12 22:28:31 +01:00
{
2004-02-21 12:01:01 +01:00
FolderItem *item = (FolderItem *) nodedata;
2004-01-12 22:28:31 +01:00
XMLTag *tag;
2004-02-21 12:01:01 +01:00
g_return_val_if_fail(item != NULL, NULL);
2004-01-12 22:28:31 +01:00
2004-02-21 12:01:01 +01:00
if (item->folder->klass->item_get_xml != NULL)
tag = item->folder->klass->item_get_xml(item->folder, item);
else
tag = folder_item_get_xml(item->folder, item);
2004-01-12 22:28:31 +01:00
return xml_node_new(tag, NULL);
2004-02-21 12:01:01 +01:00
}
2002-06-03 08:03:31 +02:00
2004-02-21 12:01:01 +01:00
static GNode *folder_get_xml_node(Folder *folder)
{
GNode *node;
XMLNode *xmlnode;
XMLTag *tag;
2004-01-12 22:28:31 +01:00
2004-02-21 12:01:01 +01:00
g_return_val_if_fail(folder != NULL, NULL);
2002-11-12 10:09:22 +01:00
2004-02-21 12:01:01 +01:00
if (folder->klass->get_xml != NULL)
tag = folder->klass->get_xml(folder);
else
tag = folder_get_xml(folder);
2004-01-12 22:28:31 +01:00
xml_tag_add_attr(tag, xml_attr_new("type", folder->klass->idstr));
2004-01-12 22:28:31 +01:00
xmlnode = xml_node_new(tag, NULL);
2001-04-19 14:21:46 +02:00
2004-02-21 12:01:01 +01:00
node = g_node_new(xmlnode);
g_return_val_if_fail (folder->node != NULL, NULL);
2004-02-21 12:01:01 +01:00
if (folder->node->children) {
GNode *cur;
2001-04-19 14:21:46 +02:00
2004-02-21 12:01:01 +01:00
cur = folder->node->children;
while (cur) {
GNode *xmlnode;
2001-04-19 14:21:46 +02:00
2004-02-21 12:01:01 +01:00
xmlnode = g_node_map(cur, folder_item_to_xml, (gpointer) folder);
g_node_append(node, xmlnode);
cur = cur->next;
2001-04-19 14:21:46 +02:00
}
2004-02-21 12:01:01 +01:00
}
2001-04-19 14:21:46 +02:00
2004-02-21 12:01:01 +01:00
return node;
2001-04-19 14:21:46 +02:00
}
static void folder_update_op_count_rec(GNode *node)
{
2001-07-31 08:17:48 +02:00
FolderItem *fitem = FOLDER_ITEM(node->data);
if (g_node_depth(node) > 0) {
if (fitem->op_count > 0) {
fitem->op_count = 0;
folder_item_update(fitem, F_ITEM_UPDATE_MSGCNT);
2001-07-31 08:17:48 +02:00
}
if (node->children) {
GNode *child;
child = node->children;
while (child) {
GNode *cur;
cur = child;
child = cur->next;
folder_update_op_count_rec(cur);
}
}
}
}
void folder_update_op_count(void)
{
2001-07-31 08:17:48 +02:00
GList *cur;
Folder *folder;
for (cur = folder_list; cur != NULL; cur = cur->next) {
folder = cur->data;
folder_update_op_count_rec(folder->node);
}
}
typedef struct _type_str {
gchar * str;
gint type;
} type_str;
/*
static gchar * folder_item_get_tree_identifier(FolderItem * item)
{
if (item->parent != NULL) {
gchar * path;
gchar * id;
path = folder_item_get_tree_identifier(item->parent);
if (path == NULL)
return NULL;
id = g_strconcat(path, "/", item->name, NULL);
g_free(path);
return id;
}
else {
return g_strconcat("/", item->name, NULL);
}
}
*/
2001-12-05 23:09:25 +01:00
/* CLAWS: temporary local folder for filtering */
#define TEMP_FOLDER "TEMP_FOLDER"
#define PROCESSING_FOLDER_ITEM "processing"
2001-12-05 23:09:25 +01:00
static FolderItem *processing_folder_item;
static void folder_create_processing_folder(void)
{
Folder *processing_folder;
2001-12-05 23:09:25 +01:00
gchar *tmpname;
if ((processing_folder = folder_find_from_name(TEMP_FOLDER, mh_get_class())) == NULL) {
gchar *tmppath;
tmppath =
g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
"tempfolder", NULL);
processing_folder =
folder_new(mh_get_class(), TEMP_FOLDER, tmppath);
g_free(tmppath);
}
g_assert(processing_folder != NULL);
debug_print("tmpparentroot %s\n", LOCAL_FOLDER(processing_folder)->rootpath);
/* FIXME: [W32] The code below does not correctly merge
relative filenames; there should be a function to handle
this. */
if (!is_relative_filename(LOCAL_FOLDER(processing_folder)->rootpath))
tmpname = g_strconcat(LOCAL_FOLDER(processing_folder)->rootpath,
G_DIR_SEPARATOR_S, PROCESSING_FOLDER_ITEM,
2001-12-08 18:41:56 +01:00
NULL);
else
tmpname = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
LOCAL_FOLDER(processing_folder)->rootpath,
G_DIR_SEPARATOR_S, PROCESSING_FOLDER_ITEM,
2001-12-08 18:41:56 +01:00
NULL);
2001-12-05 23:09:25 +01:00
if (!is_dir_exist(tmpname)) {
debug_print("*TMP* creating %s\n", tmpname);
processing_folder_item = processing_folder->klass->create_folder(processing_folder,
processing_folder->node->data,
PROCESSING_FOLDER_ITEM);
} else {
2001-12-05 23:09:25 +01:00
debug_print("*TMP* already created\n");
processing_folder_item = folder_item_new(processing_folder, PROCESSING_FOLDER_ITEM, PROCESSING_FOLDER_ITEM);
2001-12-05 23:09:25 +01:00
g_assert(processing_folder_item);
folder_item_append(processing_folder->node->data, processing_folder_item);
}
g_assert(processing_folder_item != NULL);
2001-12-05 23:09:25 +01:00
g_free(tmpname);
}
FolderItem *folder_get_default_processing(void)
{
if (!processing_folder_item) {
folder_create_processing_folder();
}
return processing_folder_item;
}
/* folder_persist_prefs_new() - return hash table with persistent
* settings (and folder name as key).
* (note that in claws other options are in the folder_item_prefs_RC
* file, so those don't need to be included in PersistPref yet)
*/
GHashTable *folder_persist_prefs_new(Folder *folder)
{
GHashTable *pptable;
g_return_val_if_fail(folder, NULL);
pptable = g_hash_table_new(g_str_hash, g_str_equal);
folder_get_persist_prefs_recursive(folder->node, pptable);
return pptable;
}
void folder_persist_prefs_free(GHashTable *pptable)
{
g_return_if_fail(pptable);
g_hash_table_foreach_remove(pptable, persist_prefs_free, NULL);
g_hash_table_destroy(pptable);
}
const PersistPrefs *folder_get_persist_prefs(GHashTable *pptable, const char *name)
{
if (pptable == NULL || name == NULL) return NULL;
return g_hash_table_lookup(pptable, name);
}
void folder_item_restore_persist_prefs(FolderItem *item, GHashTable *pptable)
{
const PersistPrefs *pp;
gchar *id = folder_item_get_identifier(item);
pp = folder_get_persist_prefs(pptable, id);
g_free(id);
if (!pp) return;
/* CLAWS: since not all folder properties have been migrated to
* folderlist.xml, we need to call the old stuff first before
* setting things that apply both to Main and Claws. */
folder_item_prefs_read_config(item);
2004-02-21 12:01:01 +01:00
item->collapsed = pp->collapsed;
item->thread_collapsed = pp->thread_collapsed;
item->threaded = pp->threaded;
item->ret_rcpt = pp->ret_rcpt;
item->hide_read_msgs = pp->hide_read_msgs;
item->sort_key = pp->sort_key;
item->sort_type = pp->sort_type;
}
static void folder_get_persist_prefs_recursive(GNode *node, GHashTable *pptable)
{
FolderItem *item = FOLDER_ITEM(node->data);
PersistPrefs *pp;
GNode *child, *cur;
gchar *id;
g_return_if_fail(node != NULL);
g_return_if_fail(item != NULL);
/* NOTE: item->path == NULL means top level folder; not interesting
* to store preferences of that one. */
if (item->path) {
id = folder_item_get_identifier(item);
pp = g_new0(PersistPrefs, 1);
g_return_if_fail(pp != NULL);
pp->collapsed = item->collapsed;
pp->thread_collapsed = item->thread_collapsed;
pp->threaded = item->threaded;
pp->ret_rcpt = item->ret_rcpt;
pp->hide_read_msgs = item->hide_read_msgs;
pp->sort_key = item->sort_key;
pp->sort_type = item->sort_type;
g_hash_table_insert(pptable, id, pp);
}
if (node->children) {
child = node->children;
while (child) {
cur = child;
child = cur->next;
folder_get_persist_prefs_recursive(cur, pptable);
}
}
}
static gboolean persist_prefs_free(gpointer key, gpointer val, gpointer data)
{
g_free(key);
g_free(val);
return TRUE;
}
void folder_item_apply_processing(FolderItem *item)
{
GSList *processing_list;
GSList *mlist, *cur;
guint total = 0, curmsg = 0;
g_return_if_fail(item != NULL);
if (item->no_select)
return;
processing_list = item->prefs->processing;
if (!pre_global_processing && !processing_list
&& !post_global_processing)
return;
folder_item_update_freeze();
mlist = folder_item_get_msg_list(item);
total = g_slist_length(mlist);
statusbar_print_all(_("Processing messages..."));
for (cur = mlist ; cur != NULL ; cur = cur->next) {
MsgInfo * msginfo;
msginfo = (MsgInfo *) cur->data;
2004-01-12 22:28:31 +01:00
/* reset parameters that can be modified by processing */
msginfo->hidden = 0;
msginfo->score = 0;
statusbar_progress_all(curmsg++,total, 10);
2004-01-12 22:28:31 +01:00
/* apply pre global rules */
filter_message_by_msginfo(pre_global_processing, msginfo, NULL);
2004-01-12 22:28:31 +01:00
/* apply rules of the folder */
filter_message_by_msginfo(processing_list, msginfo, NULL);
2004-01-12 22:28:31 +01:00
/* apply post global rules */
filter_message_by_msginfo(post_global_processing, msginfo, NULL);
2004-01-12 22:28:31 +01:00
}
if (pre_global_processing || processing_list
|| post_global_processing)
filtering_move_and_copy_msgs(mlist);
for (cur = mlist ; cur != NULL ; cur = cur->next) {
MsgInfo * msginfo = (MsgInfo *)cur->data;
procmsg_msginfo_free(msginfo);
}
g_slist_free(mlist);
statusbar_progress_all(0,0,0);
statusbar_pop_all();
folder_item_update_thaw();
}
/*
* functions for handling FolderItem content changes
*/
static gint folder_item_update_freeze_cnt = 0;
2004-06-25 10:05:09 +02:00
static void folder_item_update_with_msg(FolderItem *item, FolderItemUpdateFlags update_flags, MsgInfo *msg)
{
2004-08-08 11:52:16 +02:00
if (folder_item_update_freeze_cnt == 0 /* || (msg != NULL && item->opened) */) {
2004-06-25 10:05:09 +02:00
FolderItemUpdateData source;
source.item = item;
source.update_flags = update_flags;
source.msg = msg;
hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
} else {
item->update_flags |= update_flags & ~(F_ITEM_UPDATE_ADDMSG | F_ITEM_UPDATE_REMOVEMSG);
}
}
/**
* Notify the folder system about changes to a folder. If the
* update system is not frozen the FOLDER_ITEM_UPDATE_HOOKLIST will
* be invoked, otherwise the changes will be remebered until
* the folder system is thawed.
*
* \param item The FolderItem that was changed
* \param update_flags Type of changed that was made
*/
void folder_item_update(FolderItem *item, FolderItemUpdateFlags update_flags)
{
2004-06-25 10:05:09 +02:00
folder_item_update_with_msg(item, update_flags, NULL);
}
void folder_item_update_recursive(FolderItem *item, FolderItemUpdateFlags update_flags)
{
GNode *node = item->folder->node;
node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
node = node->children;
folder_item_update(item, update_flags);
while (node != NULL) {
if (node && node->data) {
FolderItem *next_item = (FolderItem*) node->data;
folder_item_update(next_item, update_flags);
}
node = node->next;
}
}
2002-11-12 10:09:22 +01:00
void folder_item_update_freeze(void)
{
folder_item_update_freeze_cnt++;
}
static void folder_item_update_func(FolderItem *item, gpointer data)
{
FolderItemUpdateData source;
if (item->update_flags) {
source.item = item;
source.update_flags = item->update_flags;
source.msg = NULL;
hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
item->update_flags = 0;
}
}
void folder_item_update_thaw(void)
{
if (folder_item_update_freeze_cnt > 0)
folder_item_update_freeze_cnt--;
if (folder_item_update_freeze_cnt == 0) {
/* Update all folders */
folder_func_to_all_folders(folder_item_update_func, NULL);
}
}
static void folder_item_synchronise_func(FolderItem *item, gpointer data)
{
Folder *folder = (Folder *)data;
if (folder == NULL || item->folder == folder) {
if(item->prefs->offlinesync && item->folder->klass->synchronise)
item->folder->klass->synchronise(item);
}
}
void folder_synchronise(Folder *folder)
{
folder_func_to_all_folders(folder_item_synchronise_func, folder);
}
typedef struct _WantSyncData {
Folder *folder;
gboolean want_sync;
} WantSyncData;
static void folder_item_want_synchronise_func(FolderItem *item, gpointer data)
{
WantSyncData *want_sync_data = (WantSyncData *)data;
if (want_sync_data->folder == NULL || item->folder == want_sync_data->folder) {
if (item->prefs->offlinesync && item->folder->klass->synchronise)
want_sync_data->want_sync |= TRUE;
}
}
gboolean folder_want_synchronise(Folder *folder)
{
WantSyncData *want_sync_data = g_new0(WantSyncData, 1);
gboolean result;
want_sync_data->folder = folder;
want_sync_data->want_sync = FALSE;
folder_func_to_all_folders(folder_item_want_synchronise_func, want_sync_data);
result = want_sync_data->want_sync;
g_free(want_sync_data);
debug_print("Folder %s wants sync: %d\n", folder->name, result);
return result;
}
void folder_item_set_batch (FolderItem *item, gboolean batch)
{
if (item->folder->klass->set_batch) {
item->folder->klass->set_batch(item->folder, item, batch);
}
}
gboolean folder_has_parent_of_type(FolderItem *item,
SpecialFolderItemType type)
{
FolderItem *cur = item;
/* if we already know it, make it short */
if (item->parent_stype != -1) {
return (item->parent_stype == type);
}
/* if we don't, find the type from the first possible parent,
* and set our parent type to be faster next time */
while (cur) {
if (cur->stype == type || cur->parent_stype == type) {
item->parent_stype = type;
return TRUE;
}
cur = folder_item_parent(cur);
}
/* if we didn't match what was asked, we didn't return. If our
* parent type is unknown, we may as well find it now to be faster
* later. */
if (item->parent_stype == -1) {
cur = item;
while (cur) {
/* here's an exception: Inbox subfolders are normal. */
if (item->parent_stype == -1 && cur->stype == F_INBOX
&& item != cur) {
debug_print("set item %s parent type to %d "
"even if %s is F_INBOX\n",
item->path ? item->path : "(null)",
0, cur->path);
item->parent_stype = F_NORMAL;
break;
}
/* ah, we know this parent's parent's type, we may as
* well copy it instead of going up the full way */
if (cur->parent_stype != -1) {
item->parent_stype = cur->parent_stype;
debug_print("set item %s parent type to %d "
"from %s's parent type\n",
item->path ? item->path : "(null)",
cur->parent_stype ? cur->parent_stype : 0,
cur->path ? cur->path : "(null)");
break;
}
/* we found a parent that has a special type. That's
* our parent type. */
if (cur->stype != F_NORMAL) {
debug_print("set item %s parent type to %d "
"from %s's type\n",
item->path ? item->path : "(null)",
cur->stype ? cur->stype : 0,
cur->path ? cur->path : "(null)");
cur->parent_stype = cur->stype;
item->parent_stype = cur->stype;
break;
}
/* if we didn't find anything, go up once more */
cur = folder_item_parent(cur);
}
/* as we still didn't find anything, our parents must all be
* normal. */
if (item->parent_stype == -1) {
debug_print("set item %s to 0 from default\n",
item->path ? item->path : "(null)");
item->parent_stype = F_NORMAL;
}
}
return FALSE;
}
gboolean folder_subscribe (const gchar *uri)
{
GList *cur;
for (cur = folder_get_list(); cur != NULL; cur = g_list_next(cur)) {
Folder *folder = (Folder *) cur->data;
if (folder->klass->subscribe
&& folder->klass->subscribe(folder, uri)) {
return TRUE;
}
}
return FALSE;
}
2002-11-12 10:09:22 +01:00
#undef PUT_ESCAPE_STR