<<< Date Index >>>     <<< Thread Index >>>

Re: wish: file/directory funtions for maildir etc (was: Re: New IMAP function: rename-mailbox)



On Tue, 22 Feb 2005, Tamotsu Takahashi wrote:
> On Tue, Feb 22, 2005 at 12:52:38PM +0100, Gregor Zattler wrote:
> > me too.  Deleting, moving, copying, renaming, linking of mailboxes
> > would be very useful.  
> > 
> > Dito a funktion which simply shows the file name of a message
> > (like <display-name>) and the possibility to (hard) link a
> > message to another maildir.
> 
> A feature which allows a user to type '!mv %s anotherfile'
> (on a message [in index] or a mailbox [in browser]) would be
> useful;
> 
> delete a maildir: !rm -fr %s
> safely delete?:   !ls %s/cur/* %s/new/* || rm -r %s
> move a maildir:   !mv %s another
> link a message:   !ln %s `dirname %s`/../anotherdir/cur/
> 
> But this will introduce incompatibility if implemented.
> (i.e. '%%s' for literal '%s')

I tried to make a patch, but failed to complete it.
The attached patch works only for a single object
(a message in index, a file/directory in browser).
If someone implements a support for tagged object,
it will be a very useful feature.

-- 
tamo

Index: OPS
===================================================================
RCS file: /home/roessler/cvs/mutt/OPS,v
retrieving revision 3.6
diff -u -r3.6 OPS
--- OPS 17 Feb 2005 03:33:00 -0000      3.6
+++ OPS 25 Feb 2005 08:34:29 -0000
@@ -133,6 +133,7 @@
 OP_PAGER_HIDE_QUOTED "toggle display of quoted text"
 OP_PAGER_SKIP_QUOTED "skip beyond quoted text"
 OP_PAGER_TOP "jump to the top of the message"
+OP_PASS_TO_COMMAND "pass filename to a shell command"
 OP_PIPE "pipe message/attachment to a shell command"
 OP_PREV_ENTRY "move to the previous entry"
 OP_PREV_LINE "scroll up one line"
Index: browser.c
===================================================================
RCS file: /home/roessler/cvs/mutt/browser.c,v
retrieving revision 3.14
diff -u -r3.14 browser.c
--- browser.c   17 Feb 2005 03:33:00 -0000      3.14
+++ browser.c   25 Feb 2005 08:34:29 -0000
@@ -829,6 +829,25 @@
        mutt_menuDestroy (&menu);
        goto bail;
 
+      case OP_PASS_TO_COMMAND:
+       if (state.entrylen)
+       {
+         char full[_POSIX_PATH_MAX];
+         char tfiles[LONG_STRING];
+
+         full[0] = 0;
+         tfiles[0] = 0;
+
+         /* tagged messages are not yet supported */
+         mutt_concat_path (full, LastDir, state.entry[menu->current].name, 
sizeof (full));
+         mutt_expand_path (full, sizeof (full));
+         safe_strcat (tfiles, sizeof (tfiles), full);
+
+         mutt_pass_to_command (tfiles);
+         MAYBE_REDRAW (menu->redraw);
+       }
+       break;
+
       case OP_BROWSER_TELL:
         if(state.entrylen)
          mutt_message("%s", state.entry[menu->current].name);
Index: commands.c
===================================================================
RCS file: /home/roessler/cvs/mutt/commands.c,v
retrieving revision 3.30
diff -u -r3.30 commands.c
--- commands.c  12 Feb 2005 19:19:24 -0000      3.30
+++ commands.c  25 Feb 2005 08:34:30 -0000
@@ -988,4 +988,32 @@
   return rv;
 }
 
+void mutt_pass_to_command (const char *path)
+{
+  char command[HUGE_STRING];
+  char format[LONG_STRING];
+  char files[LONG_STRING];
+
+  format[0] = 0;
+  if (mutt_get_field (_("Pass to command: "), format, sizeof (format), M_CMD)
+      != 0 || !format[0])
+    return;
+  mutt_expand_path (format, sizeof (format));
+
+  files[0] = 0;
+  if (path)
+    safe_strcat (files, sizeof (files), path);
+  else
+  {
+    /* process tagged messages. browser always gives path. */
+  }
+
+  mutt_expand_fmt (command, sizeof (command), format, files);
+
+  CLEARLINE (LINES-1);
+  mutt_endwin (NULL);
+  fflush (stdout);
+  if (mutt_system (command) != 0 || option (OPTWAITKEY))
+    mutt_any_key_to_continue (NULL);
+}
 
Index: curs_main.c
===================================================================
RCS file: /home/roessler/cvs/mutt/curs_main.c,v
retrieving revision 3.20
diff -u -r3.20 curs_main.c
--- curs_main.c 12 Feb 2005 19:19:24 -0000      3.20
+++ curs_main.c 25 Feb 2005 08:34:30 -0000
@@ -1903,6 +1903,21 @@
        }
         break;
       
+      case OP_PASS_TO_COMMAND:
+
+       CHECK_MSGCOUNT;
+       CHECK_VISIBLE;
+        {
+         char path[_POSIX_PATH_MAX];
+
+         mutt_concat_path (path, NONULL (Context->path), CURHDR->path, sizeof 
(path));
+         mutt_expand_path (path, sizeof (path));
+
+         mutt_pass_to_command (tag ? NULL : path);
+         MAYBE_REDRAW (menu->redraw);
+        }
+       break;
+
       case OP_PIPE:
 
        CHECK_MSGCOUNT;
Index: functions.h
===================================================================
RCS file: /home/roessler/cvs/mutt/functions.h,v
retrieving revision 3.9
diff -u -r3.9 functions.h
--- functions.h 17 Feb 2005 03:33:00 -0000      3.9
+++ functions.h 25 Feb 2005 08:34:30 -0000
@@ -131,6 +131,7 @@
   { "buffy-list",              OP_BUFFY_LIST,                  "." },
   { "sync-mailbox",            OP_MAIN_SYNC_FOLDER,            "$" },
   { "display-address",         OP_DISPLAY_ADDRESS,             "@" },
+  { "pass-to-command",         OP_PASS_TO_COMMAND,             NULL },
   { "pipe-message",            OP_PIPE,                        "|" },
   { "next-new",                        OP_MAIN_NEXT_NEW,               NULL },
   { "next-new-then-unread",    OP_MAIN_NEXT_NEW_THEN_UNREAD,   "\t" },
@@ -347,6 +348,7 @@
   { "toggle-mailboxes", OP_TOGGLE_MAILBOXES,   "\t" },
   { "view-file",       OP_BROWSER_VIEW_FILE,   " " },
   { "buffy-list",      OP_BUFFY_LIST,          "." },
+  { "pass-to-command", OP_PASS_TO_COMMAND,     NULL },
 #ifdef USE_IMAP
   { "create-mailbox",   OP_CREATE_MAILBOX,      "C" },
   { "delete-mailbox",   OP_DELETE_MAILBOX,      "d" },
Index: protos.h
===================================================================
RCS file: /home/roessler/cvs/mutt/protos.h,v
retrieving revision 3.25
diff -u -r3.25 protos.h
--- protos.h    1 Feb 2005 03:36:39 -0000       3.25
+++ protos.h    25 Feb 2005 08:34:30 -0000
@@ -222,6 +222,7 @@
 void mutt_unprepare_envelope (ENVELOPE *);
 void mutt_pretty_mailbox (char *);
 void mutt_pretty_size (char *, size_t, long);
+void mutt_pass_to_command (const char *);
 void mutt_pipe_message (HEADER *);
 void mutt_print_message (HEADER *);
 void mutt_print_patchlist (void);