Commit f495b84d authored by GT's avatar GT Committed by Kevin J. McCarthy

add feature file monitoring with Linux inotify

parent 479241fe
Pipeline #23110857 passed with stages
in 14 minutes and 51 seconds
......@@ -56,7 +56,7 @@ AM_CPPFLAGS=-I. -I$(top_srcdir) $(IMAP_INCLUDES) $(GPGME_CFLAGS) -Iintl
EXTRA_mutt_SOURCES = account.c bcache.c compress.c crypt-gpgme.c crypt-mod-pgp-classic.c \
crypt-mod-pgp-gpgme.c crypt-mod-smime-classic.c \
crypt-mod-smime-gpgme.c dotlock.c gnupgparse.c hcache.c md5.c \
crypt-mod-smime-gpgme.c dotlock.c gnupgparse.c hcache.c md5.c monitor.c \
mutt_idna.c mutt_sasl.c mutt_socket.c mutt_ssl.c mutt_ssl_gnutls.c \
mutt_tunnel.c pgp.c pgpinvoke.c pgpkey.c pgplib.c pgpmicalg.c \
pgppacket.c pop.c pop_auth.c pop_lib.c remailer.c resize.c sha1.c \
......
......@@ -37,6 +37,10 @@
#include "imap.h"
#endif
#ifdef USE_INOTIFY
#include "monitor.h"
#endif
#include <string.h>
#include <sys/stat.h>
#include <dirent.h>
......@@ -241,6 +245,9 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e
tmp1=(*tmp)->next;
#ifdef USE_SIDEBAR
mutt_sb_notify_mailbox (*tmp, 0);
#endif
#ifdef USE_INOTIFY
mutt_monitor_remove (*tmp);
#endif
buffy_free (tmp);
*tmp=tmp1;
......@@ -271,6 +278,9 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e
tmp1=(*tmp)->next;
#ifdef USE_SIDEBAR
mutt_sb_notify_mailbox (*tmp, 0);
#endif
#ifdef USE_INOTIFY
mutt_monitor_remove (*tmp);
#endif
buffy_free (tmp);
*tmp=tmp1;
......@@ -282,6 +292,10 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e
*tmp = buffy_new (buf);
#ifdef USE_SIDEBAR
mutt_sb_notify_mailbox (*tmp, 1);
#endif
#ifdef USE_INOTIFY
(*tmp)->magic = mx_get_magic ((*tmp)->path);
mutt_monitor_add (*tmp);
#endif
}
......
......@@ -832,6 +832,26 @@ if test $mutt_cv_fcntl = yes; then
AC_DEFINE(USE_FCNTL,1, [ Define to use fcntl() to lock folders. ])
fi
AC_ARG_ENABLE(filemonitor, AS_HELP_STRING([--disable-filemonitor],[Disable file monitoring support (Linux only)]),
[ if test x$enableval = xno ; then
have_filemonitor=no
fi
])
if test x$have_filemonitor != xno ; then
AC_CHECK_FUNCS(inotify_init1 inotify_add_watch inotify_rm_watch,
[
AC_DEFINE(USE_INOTIFY,1,[ Define if want to use inotify for filesystem monitoring (available in Linux only). ])
],
[
have_filemonitor=no
])
if test x$have_filemonitor != xno ; then
AC_CHECK_HEADERS(sys/inotify.h)
MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS monitor.o"
fi
fi
AC_MSG_CHECKING(whether struct dirent defines d_ino)
ac_cv_dirent_d_ino=no
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <dirent.h>]], [[struct dirent dp; (void)dp.d_ino]])],[ac_cv_dirent_d_ino=yes],[])
......
......@@ -26,6 +26,9 @@
#include "mutt_curses.h"
#include "pager.h"
#include "mbyte.h"
#ifdef USE_INOTIFY
#include "monitor.h"
#endif
#include <termios.h>
#include <sys/types.h>
......@@ -131,7 +134,12 @@ event_t mutt_getch (void)
ch = KEY_RESIZE;
while (ch == KEY_RESIZE)
#endif /* KEY_RESIZE */
ch = getch ();
#ifdef USE_INOTIFY
if (mutt_monitor_poll () != 0)
ch = ERR;
else
#endif
ch = getch ();
mutt_allow_interrupt (0);
if (SigInt)
......
......@@ -41,6 +41,10 @@
#include "imap_private.h"
#endif
#ifdef USE_INOTIFY
#include "monitor.h"
#endif
#include "mutt_crypt.h"
......@@ -577,6 +581,9 @@ int mutt_index_menu (void)
if (!attach_msg)
mutt_buffy_check(1); /* force the buffy check after we enter the folder */
#ifdef USE_INOTIFY
mutt_monitor_add (NULL);
#endif
FOREVER
{
......@@ -1270,7 +1277,11 @@ int mutt_index_menu (void)
{
int check;
char *new_last_folder;
#ifdef USE_INOTIFY
int monitor_remove_rc;
monitor_remove_rc = mutt_monitor_remove (NULL);
#endif
#ifdef USE_COMPRESSED
if (Context->compress_info && Context->realpath)
new_last_folder = safe_strdup (Context->realpath);
......@@ -1281,6 +1292,10 @@ int mutt_index_menu (void)
if ((check = mx_close_mailbox (Context, &index_hint)) != 0)
{
#ifdef USE_INOTIFY
if (!monitor_remove_rc)
mutt_monitor_add (NULL);
#endif
if (check == MUTT_NEW_MAIL || check == MUTT_REOPENED)
update_index (menu, Context, check, oldcount, index_hint);
......@@ -1312,6 +1327,9 @@ int mutt_index_menu (void)
MUTT_READONLY : 0, NULL)) != NULL)
{
menu->current = ci_first_message ();
#ifdef USE_INOTIFY
mutt_monitor_add (NULL);
#endif
}
else
menu->current = 0;
......
......@@ -6385,6 +6385,40 @@ to immediately open the next folder with unread mail (if any).
</sect2>
<sect2 id="new-mail-monitoring">
<title>Monitoring New Mail</title>
<para>
When the <emphasis>Inotify</emphasis> mechanism for monitoring of
files is supported (Linux only) and not disabled at compilation time,
Mutt immediately notifies about new mail for all folders configured via
the <link linkend="mailboxes"><command>mailboxes</command></link>
command. Dependent on
<link linkend="mailbox-formats">mailbox format</link> also added
<emphasis>old</emphasis> mails are tracked (not for Maildir).
</para>
<para>
No configuration variables are available. Trace output is given when
debugging is enabled via <link linkend="tab-commandline-options">command
line option</link> <literal>-d3</literal>. The lower level 2 only shows
errors, the higher level 5 all including raw Inotify events.
</para>
<note>
<para>
Getting events about new mail is limited to the capabilities of the
underlying mechanism. <emphasis>Inotify</emphasis> only reports local
changes, i. e. new mail notification works for mails delivered by an
agent on the same machine as Mutt, but not when delivered remotely on
a network file system as NFS. Also the monitoring handles might fail
in rare conditions, so you better don't completely rely on this
feature.
</para>
</note>
</sect2>
<sect2 id="calc-mailbox-counts">
<title>Calculating Mailbox Message Counts</title>
......
......@@ -29,6 +29,9 @@
#ifdef USE_IMAP
#include "imap/imap.h"
#endif
#ifdef USE_INOTIFY
#include "monitor.h"
#endif
#include <stdlib.h>
#include <string.h>
......@@ -450,7 +453,11 @@ int km_dokey (int menu)
* loop now. Otherwise, continue to loop until reaching a total of
* $timeout seconds.
*/
#ifdef USE_INOTIFY
if (tmp.ch != -2 || SigWinch || MonitorFilesChanged)
#else
if (tmp.ch != -2 || SigWinch)
#endif
goto gotkey;
i -= ImapKeepalive;
imap_keepalive ();
......
......@@ -47,6 +47,10 @@
#include "hcache.h"
#endif
#ifdef USE_INOTIFY
#include "monitor.h"
#endif
#include <string.h>
#include <stdlib.h>
#include <locale.h>
......@@ -509,6 +513,8 @@ static void show_version (void)
"-USE_HCACHE "
#endif
"\n"
#ifdef USE_SIDEBAR
"+USE_SIDEBAR "
#else
......@@ -521,6 +527,12 @@ static void show_version (void)
"-USE_COMPRESSED "
#endif
#ifdef USE_INOTIFY
"+USE_INOTIFY "
#else
"-USE_INOTIFY "
#endif
);
#ifdef ISPELL
......
This diff is collapsed.
/*
* Copyright (C) 2018 Gero Treuer <gero@70t.de>
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MONITOR_H
#define MONITOR_H
WHERE int MonitorFilesChanged INITVAL (0);
#ifdef _BUFFY_H
int mutt_monitor_add (BUFFY *b);
int mutt_monitor_remove (BUFFY *b);
#endif
int mutt_monitor_poll ();
#endif /* MONITOR_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment