]> granicus.if.org Git - neomutt/commitdiff
change-vfolder, print folder info, etc.
authorKarel Zak <kzak@redhat.com>
Wed, 14 Dec 2011 15:48:40 +0000 (16:48 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 15:30:04 +0000 (16:30 +0100)
 - allow to open email in virtual folder
 - allow to open virtual folder
 - print vfolder specific stuff in index and pager

Signed-off-by: Karel Zak <kzak@redhat.com>
compose.c
copy.c
curs_lib.c
curs_main.c
hdrline.c
protos.h

index 3eb4cc70220a5bdffb5544577b63829bee1d5dfc..37dc9a54f8aa658b797e41c73afa1db0fd147e4c 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -692,7 +692,8 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
          numfiles = 0;
          files = NULL;
 
-         if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 ||
+         if (_mutt_enter_fname (prompt, fname, sizeof (fname),
+                       &menu->redraw, 0, 1, &files, &numfiles, 0) == -1 ||
              *fname == '\0')
            break;
 
diff --git a/copy.c b/copy.c
index 7a250e604039afd5f148c5442f33d65a0c818f6b..a8b75da381fed5b30f7d8c0874ae1cddc3c338bb 100644 (file)
--- a/copy.c
+++ b/copy.c
 #include <ctype.h>
 #include <unistd.h> /* needed for SEEK_SET under SunOS 4.1.4 */
 
+#if USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
+
 static int address_header_decode (char **str);
 static int copy_delete_attach (BODY *b, FILE *fpin, FILE *fpout, char *date);
 
@@ -682,7 +686,7 @@ mutt_copy_message (FILE *fpout, CONTEXT *src, HEADER *hdr, int flags,
 {
   MESSAGE *msg;
   int r;
-  
+
   if ((msg = mx_open_message (src, hdr->msgno)) == NULL)
     return -1;
   if ((r = _mutt_copy_message (fpout, msg->fp, hdr, hdr->content, flags, chflags)) == 0 
@@ -727,6 +731,15 @@ _mutt_append_message (CONTEXT *dest, FILE *fpin, CONTEXT *src, HEADER *hdr,
   if (mx_commit_message (msg, dest) != 0)
     r = -1;
 
+#ifdef USE_NOTMUCH
+  if (r != -1 && src->magic == M_NOTMUCH) {
+       char old[_POSIX_PATH_MAX];
+
+       if (nm_header_get_fullpath(hdr, old, sizeof(old)))
+               nm_update_filename(src, old, msg->commited_path);
+  }
+#endif
+
   mx_close_message (&msg);
   return r;
 }
index eb06c365e7e5c4cdc3c138cedf4179ba3b99374a..a3c82514bdf951711b69c0c0801c5177cf5ea91b 100644 (file)
@@ -624,7 +624,9 @@ int mutt_do_pager (const char *banner,
   return rc;
 }
 
-int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, int buffy, int multiple, char ***files, int *numfiles)
+int _mutt_enter_fname (const char *prompt, char *buf, size_t blen,
+               int *redraw, int buffy, int multiple,
+               char ***files, int *numfiles, int flags)
 {
   event_t ch;
 
@@ -647,8 +649,14 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw,
   {
     mutt_refresh ();
     buf[0] = 0;
-    _mutt_select_file (buf, blen, M_SEL_FOLDER | (multiple ? M_SEL_MULTI : 0), 
-                      files, numfiles);
+    if (!flags)
+      flags = M_SEL_FOLDER | (multiple ? M_SEL_MULTI : 0);
+
+    _mutt_select_file (buf, blen, flags, files, numfiles);
+    *redraw = REDRAW_FULL;
+  }
+  else if (flags & M_SEL_VFOLDER) {
+    _mutt_select_file (buf, blen, flags, files, numfiles);
     *redraw = REDRAW_FULL;
   }
   else
index efbac728a719619901d76c1e5466dad448210f40..7b8f98b0201b419292d2535740d1961d1792cd0a 100644 (file)
 #include "imap_private.h"
 #endif
 
+#ifdef USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
+
 #include "mutt_crypt.h"
 
 
@@ -590,6 +594,71 @@ mutt_draw_statusline (int cols, char *inbuf)
        safe_free (&lineInfo.syntax);
 }
 
+static int main_change_folder(MUTTMENU *menu, int op, char *buf, size_t bufsz,
+                         int *oldcount, int *index_hint)
+{
+  mutt_expand_path (buf, bufsz);
+#ifdef USE_SIDEBAR
+  if (sb_set_open_buffy (buf) == NULL)
+    break;
+#endif
+  if (mx_get_magic (buf) <= 0)
+  {
+    mutt_error (_("%s is not a mailbox."), buf);
+    return -1;
+  }
+  mutt_str_replace (&CurrentFolder, buf);
+
+  /* keepalive failure in mutt_enter_fname may kill connection. #3028 */
+  if (Context && !Context->path)
+    FREE (&Context);
+
+  if (Context)
+  {
+    int check;
+
+    mutt_str_replace (&LastFolder, Context->path);
+    *oldcount = Context ? Context->msgcount : 0;
+
+    if ((check = mx_close_mailbox (Context, index_hint)) != 0)
+    {
+      if (check == M_NEW_MAIL || check == M_REOPENED)
+        update_index (menu, Context, check, *oldcount, *index_hint);
+
+      set_option (OPTSEARCHINVALID);
+      menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
+      return 0;
+    }
+    FREE (&Context);
+  }
+
+  mutt_sleep (0);
+
+  /* Set CurrentMenu to MENU_MAIN before executing any folder
+   * hooks so that all the index menu functions are available to
+   * the exec command.
+   */
+
+  CurrentMenu = MENU_MAIN;
+  mutt_folder_hook (buf);
+
+  if ((Context = mx_open_mailbox (buf,
+               (option (OPTREADONLY) || op == OP_MAIN_CHANGE_FOLDER_READONLY) ?
+               M_READONLY : 0, NULL)) != NULL)
+  {
+    menu->current = ci_first_message ();
+  }
+  else
+    menu->current = 0;
+
+  mutt_clear_error ();
+  mutt_buffy_check(1); /* force the buffy check after we have changed the folder */
+  menu->redraw = REDRAW_FULL;
+  set_option (OPTSEARCHINVALID);
+
+  return 0;
+}
+
 static const struct mapping_t IndexHelp[] = {
   { N_("Quit"),  OP_QUIT },
   { N_("Del"),   OP_DELETE },
@@ -1309,6 +1378,23 @@ int mutt_index_menu (void)
        }
        break;
 
+#ifdef USE_NOTMUCH
+      case OP_MAIN_VFOLDER_FROM_QUERY:
+
+       buf[0] = '\0';
+        if (mutt_get_field ("Query: ", buf, sizeof (buf), 0) != 0 || !buf[0])
+        {
+          mutt_message _("No query, aborting.");
+          break;
+        }
+       if (!nm_uri_from_query(Context, buf, sizeof (buf)))
+         mutt_message _("Failed to create query, aborting.");
+       else
+         main_change_folder(menu, op, buf, sizeof (buf), &oldcount, &index_hint);
+       break;
+
+      case OP_MAIN_CHANGE_VFOLDER:
+#endif
 #ifdef USE_SIDEBAR
       case OP_SIDEBAR_OPEN:
 #endif
@@ -1324,7 +1410,11 @@ int mutt_index_menu (void)
 
         if ((op == OP_MAIN_CHANGE_FOLDER_READONLY) || option (OPTREADONLY))
           cp = _("Open mailbox in read-only mode");
-        else
+#ifdef USE_NOTMUCH
+        else if (op == OP_MAIN_CHANGE_VFOLDER)
+         cp = _("Open virtual folder");
+#endif
+       else
           cp = _("Open mailbox");
 
        buf[0] = '\0';
@@ -1350,6 +1440,11 @@ int mutt_index_menu (void)
              break;
            strncpy (buf, path, sizeof (buf));
          } else
+#endif
+#ifdef USE_NOTMUCH
+         if (op == OP_MAIN_CHANGE_VFOLDER)
+           mutt_enter_vfolder (cp, buf, sizeof (buf), &menu->redraw, 1);
+         else
 #endif
          if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
          {
@@ -1368,65 +1463,7 @@ int mutt_index_menu (void)
          }
        }
 
-       mutt_expand_path (buf, sizeof (buf));
-#ifdef USE_SIDEBAR
-       if (sb_set_open_buffy (buf) == NULL)
-               break;
-#endif
-       if (mx_get_magic (buf) <= 0)
-       {
-         mutt_error (_("%s is not a mailbox."), buf);
-         break;
-       }
-       mutt_str_replace (&CurrentFolder, buf);
-
-       /* keepalive failure in mutt_enter_fname may kill connection. #3028 */
-       if (Context && !Context->path)
-         FREE (&Context);
-
-        if (Context)
-        {
-         int check;
-
-         mutt_str_replace (&LastFolder, Context->path);
-         oldcount = Context ? Context->msgcount : 0;
-
-         if ((check = mx_close_mailbox (Context, &index_hint)) != 0)
-         {
-           if (check == M_NEW_MAIL || check == M_REOPENED)
-             update_index (menu, Context, check, oldcount, index_hint);
-
-           set_option (OPTSEARCHINVALID);
-           menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
-           break;
-         }
-         FREE (&Context);
-       }
-
-        mutt_sleep (0);
-
-       /* Set CurrentMenu to MENU_MAIN before executing any folder
-        * hooks so that all the index menu functions are available to
-        * the exec command.
-        */
-
-       CurrentMenu = MENU_MAIN;
-       mutt_folder_hook (buf);
-
-       if ((Context = mx_open_mailbox (buf,
-                                       (option (OPTREADONLY) || op == OP_MAIN_CHANGE_FOLDER_READONLY) ?
-                                       M_READONLY : 0, NULL)) != NULL)
-       {
-         menu->current = ci_first_message ();
-       }
-       else
-         menu->current = 0;
-
-       mutt_clear_error ();
-       mutt_buffy_check(1); /* force the buffy check after we have changed
-                             the folder */
-       menu->redraw = REDRAW_FULL;
-       set_option (OPTSEARCHINVALID);
+       main_change_folder(menu, op, buf, sizeof (buf), &oldcount, &index_hint);
        break;
 
       case OP_DISPLAY_MESSAGE:
index 8b1a48af28092925530aa27362f1f88d5a6e4979..1b27d4637c6bb62e5259c63db1562ccba7f8e5ae 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
 #include <alloca.h>
 #endif
 
+#ifdef USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
+
 int mutt_is_mail_list (ADDRESS *addr)
 {
   if (!mutt_match_rx_list (addr->mailbox, UnMailLists))
@@ -243,6 +247,7 @@ int mutt_user_is_recipient (HEADER *h)
  * %E = number of messages in current thread
  * %f = entire from line
  * %F = like %n, unless from self
+ * %g = message labes (e.g. notmuch tags)
  * %i = message-id
  * %l = number of lines in the message
  * %L = like %F, except `lists' are displayed first
@@ -584,7 +589,11 @@ hdr_format_str (char *dest,
       else if (mutt_addr_is_user (hdr->env->from))
         optional = 0;
       break;
-
+#ifdef USE_NOTMUCH
+    case 'g':
+      mutt_format_s (dest, destlen, prefix, nm_header_get_tags(hdr));
+      break;
+#endif
     case 'H':
       /* (Hormel) spam score */
       if (optional)
index 7c001c86fd5db43b0986a3968ae6b43a6a39dd4e..f69d736eda3cfff2303c8a023876665b6674a1e2 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -304,8 +304,10 @@ int mutt_chscmp (const char *s, const char *chs);
 int mutt_parent_message (CONTEXT *, HEADER *);
 int mutt_prepare_template(FILE*, CONTEXT *, HEADER *, HEADER *, short);
 int mutt_resend_message (FILE *, CONTEXT *, HEADER *);
-#define mutt_enter_fname(A,B,C,D,E) _mutt_enter_fname(A,B,C,D,E,0,NULL,NULL)
-int _mutt_enter_fname (const char *, char *, size_t, int *, int, int, char ***, int *);
+#define mutt_enter_fname(A,B,C,D,E) _mutt_enter_fname(A,B,C,D,E,0,NULL,NULL,0)
+#define mutt_enter_vfolder(A,B,C,D,E) _mutt_enter_fname(A,B,C,D,E,0,NULL,NULL,M_SEL_VFOLDER)
+
+int _mutt_enter_fname (const char *, char *, size_t, int *, int, int, char ***, int *, int);
 int  mutt_enter_string (char *buf, size_t buflen, int y, int x, int flags);
 int _mutt_enter_string (char *, size_t, int, int, int, int, char ***, int *, ENTER_STATE *);
 #define mutt_get_field(A,B,C,D) _mutt_get_field(A,B,C,D,0,NULL,NULL)