]> granicus.if.org Git - neomutt/commitdiff
Send imap keepalives for interactive filters.
authorKevin McCarthy <kevin@8t8.us>
Tue, 18 Sep 2018 02:40:22 +0000 (19:40 -0700)
committerRichard Russon <rich@flatcap.org>
Tue, 25 Sep 2018 12:27:55 +0000 (13:27 +0100)
When viewing attachments externally with a (non-copiousoutput) mailcap
entry missing %s, the command is invoked as a filter, with the
attachment piped into stdin.  However, unlike a filter, the user
interacts with the command, instead of just displaying the output in
the pager.

Just as with the mutt_system() command, Mutt needs to send imap
keepalives to keep those connections from closing during the
potentially extended invocation.

Thanks to John Hawkinson for the bug report, and his suggested patch,
which this commit is based upon.

filter.c
filter.h

index 5c74f46cfa70448e8bb9d9f5efca5599c242ed95..267d7dccf6c5ae7496e85827b8da2f1bdd8af980 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -34,6 +34,9 @@
 #include "mutt.h"
 #include "filter.h"
 #include "mutt_window.h"
+#ifdef USE_IMAP
+#include "imap/imap.h"
+#endif
 
 /**
  * mutt_create_filter_fd - Run a command on a pipe (optionally connect stdin/stdout)
@@ -231,3 +234,31 @@ int mutt_wait_filter(pid_t pid)
 
   return rc;
 }
+
+/**
+ * mutt_wait_interactive_filter - Wait after an interactive filter
+ * @param pid Process id of the process to wait for
+ * @retval num Exit status of the process identified by pid
+ * @retval -1  Error
+ *
+ * This is used for filters that are actually interactive commands
+ * with input piped in: e.g. in mutt_view_attachment(), a mailcap
+ * entry without copiousoutput _and_ without a %s.
+ *
+ * For those cases, we treat it like a blocking system command, and
+ * poll IMAP to keep connections open.
+ */
+int mutt_wait_interactive_filter(pid_t pid)
+{
+  int rc;
+
+#ifdef USE_IMAP
+  rc = imap_wait_keepalive(pid);
+#else
+  waitpid(pid, &rc, 0);
+#endif
+  mutt_sig_unblock_system(true);
+  rc = WIFEXITED(rc) ? WEXITSTATUS(rc) : -1;
+
+  return rc;
+}
index 61cd7e708a9e8fe8c9f8c49f2ce6b1beb755b668..983a721f74acc4269df344f5c44b15c96bd37277 100644 (file)
--- a/filter.h
+++ b/filter.h
@@ -28,5 +28,6 @@ pid_t mutt_create_filter_fd(const char *cmd, FILE **in, FILE **out, FILE **err,
                             int fdin, int fdout, int fderr);
 pid_t mutt_create_filter(const char *s, FILE **in, FILE **out, FILE **err);
 int mutt_wait_filter(pid_t pid);
+int mutt_wait_interactive_filter (pid_t pid);
 
 #endif /* MUTT_FILTER_H */