]> granicus.if.org Git - mutt/commitdiff
Send imap keepalives for interactive filters.
authorKevin McCarthy <kevin@8t8.us>
Tue, 18 Sep 2018 02:40:22 +0000 (19:40 -0700)
committerKevin McCarthy <kevin@8t8.us>
Tue, 18 Sep 2018 02:56:01 +0000 (19:56 -0700)
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.

attach.c
filter.c
protos.h

index f09e5acca14dd28d913984d74a8ed3455f2c9b41..2a2661f4c32fed2b50e47ebda7c47b45d652713b 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -479,11 +479,15 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr,
        else
          snprintf (descrip, sizeof (descrip),
                    _("---Command: %-30.30s Attachment: %s"), command, type);
-      }
 
-      if ((mutt_wait_filter (thepid) || (entry->needsterminal &&
-         option (OPTWAITKEY))) && !use_pager)
-       mutt_any_key_to_continue (NULL);
+        mutt_wait_filter (thepid);
+      }
+      else
+      {
+        if (mutt_wait_interactive_filter (thepid) ||
+            (entry->needsterminal && option (OPTWAITKEY)))
+          mutt_any_key_to_continue (NULL);
+      }
 
       if (tempfd != -1)
        close (tempfd);
index 331d5425682ef8f1f96903dbbf72b6243afc7588..59d1e09c3a55755de6125a5cbab2b9918dff4e1a 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -22,6 +22,9 @@
 
 #include "mutt.h"
 #include "mutt_curses.h"
+#ifdef USE_IMAP
+# include "imap.h"
+#endif
 
 #include <unistd.h>
 #include <stdlib.h>
@@ -189,3 +192,26 @@ int mutt_wait_filter (pid_t pid)
   
   return rc;
 }
+
+/*
+ * 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;
+
+#ifndef USE_IMAP
+  waitpid (pid, &rc, 0);
+#else
+  rc = imap_wait_keepalive (pid);
+#endif
+  mutt_unblock_signals_system (1);
+  rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1;
+
+  return rc;
+}
index 1b38563eb90aecf2e71968060da1c55064d018c7..a137dd14660a5c4c81156cd0d9bcdae42a0ccde9 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -385,6 +385,7 @@ int mutt_thread_set_flag (HEADER *, int, int, int);
 int mutt_user_is_recipient (HEADER *);
 void mutt_update_num_postponed (void);
 int mutt_wait_filter (pid_t);
+int mutt_wait_interactive_filter (pid_t);
 int mutt_which_case (const char *);
 int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, char *);
 int mutt_write_mime_body (BODY *, FILE *);