]> 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, 14 Mar 2016 23:11:40 +0000 (23:11 +0000)
 - 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 5ec9f3ff4f525552e46e7062932bc1fd90878305..0bd17b63312f8c2b0bbfc60dc44921b12a4bf503 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -687,7 +687,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 62ee5875e9c6433b946dd7db93c9435ba994f4a5..db728f150bfb12acf0e9ce65a741f73321e12ac1 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 235be0d167d17c9ccdefa486aa29b7558a39d9da..4ea7e190bf745dd5166347c996c4a6aa87d31ac3 100644 (file)
@@ -610,7 +610,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;
 
@@ -633,8 +635,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 64bd3702742ce5eb7a0acaad9f4c127e9077826e..510e360b413be02ce6d6e37399c17c376e21ce20 100644 (file)
 #include "imap_private.h"
 #endif
 
+#ifdef USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
+
 #include "mutt_crypt.h"
 
 
@@ -589,6 +593,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 },
@@ -1311,6 +1380,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
@@ -1326,7 +1412,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';
@@ -1352,6 +1442,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)
          {
@@ -1370,65 +1465,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 4a2884540500e7d05937adbd7054d1a6538c7c71..55e8156f511101fe518d3361ccc8120e10e78f72 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
@@ -582,7 +587,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 b1d20daebc4a5a20f24b0963d1b469c3a1530f09..4aa5c1a9e2bfa0f4638588ed5c6326988f031cf0 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -303,8 +303,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)