# HG changeset patch
# User David Champion <d...@uchicago.edu>
# Date 1355527745 21600
# Branch HEAD
# Node ID 8f4ff2c8f2e7314e3d62e879aaf91bb035d92da0
# Parent  ecae1a363182797c2c157e88ff51d07c82f0a20c
Adds mailboxrx (and unmailboxrx) command.

Mailboxrx allows you to define a regular expression and replacement
template for mailbox names.  Wherever status_format's %f is expanded,
the folder name will be matched in turn against each mailboxrx
expression.  If any expression matches, a replacement of the mailbox
name will be performed, with backreference expansion.

Example:
mailboxrx imaps://(.*)@imap.gmail.com/ %1@gmail:%R

This makes any Google Mail IMAP mailbox look like username@gmail:folder.
%1 expands to the first parenthesized subexpression in the regex.  %L is
all text to the left of the matching expression, and %R is all text to
the right of the matching expression.


mailboxrx (pop|imap)s?://.*\.([^.]+).[^.]+/ %2:%R
This more generally simplifies POP or IMAP mailbox display, reducing it
to "domain:folder" where "domain" is the DNS domain of the server minus
the top-level domain (.com, .net, etc).


Mailboxrx commands are stackable.  On top of the above, you could add:
mailboxrx earthlink %Leln%R

This would replace "earthlink" with "eln" regardless of where it appears
in the mailbox name.

diff -r ecae1a363182 -r 8f4ff2c8f2e7 doc/manual.xml.head
--- a/doc/manual.xml.head       Fri Dec 14 17:29:03 2012 -0600
+++ b/doc/manual.xml.head       Fri Dec 14 17:29:05 2012 -0600
@@ -5900,6 +5900,41 @@
 </screen>
 </example>
 
+<para>
+Similarly, <literal>mailboxrx</literal> lets you replace mailbox names in the
+display, which can be useful if they are very long -- for example, mailboxes
+deep in your filesystem, or IMAP URLs with a lot of prefatory junk.
+</para>
+
+<cmdsynopsis>
+<command>mailboxrx</command>
+<arg choice="plain">
+<replaceable class="parameter">pattern</replaceable>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">replacement</replaceable>
+</arg>
+
+<command>unmailboxrx</command>
+<arg choice="plain">
+<replaceable class="parameter">pattern</replaceable>
+</arg>
+</cmdsynopsis>
+
+<example id="ex-mailboxrx">
+<title>Mailbox Munging</title>
+<screen>
+# Shorten my home directory path
+mailboxrx '/home/dgc' '~/%R'
+
+# Shorten my Mail folder
+mailboxrx '/home/dgc/[mM]ail/' '=%R'
+
+# Shorten IMAP
+mailboxrx 'imaps?://[^/]*/' 'imap:%R'
+</screen>
+</example>
+
 </sect1>
 
 <sect1 id="new-mail">
diff -r ecae1a363182 -r 8f4ff2c8f2e7 globals.h
--- a/globals.h Fri Dec 14 17:29:03 2012 -0600
+++ b/globals.h Fri Dec 14 17:29:05 2012 -0600
@@ -171,6 +171,7 @@
 WHERE REPLACE_LIST *SpamList INITVAL(0);
 WHERE RX_LIST *NoSpamList INITVAL(0);
 WHERE REPLACE_LIST *SubjectRxList INITVAL(0);
+WHERE REPLACE_LIST *MailboxRxList INITVAL(0);
 
 
 /* bit vector for boolean variables */
diff -r ecae1a363182 -r 8f4ff2c8f2e7 init.h
--- a/init.h    Fri Dec 14 17:29:03 2012 -0600
+++ b/init.h    Fri Dec 14 17:29:05 2012 -0600
@@ -3534,6 +3534,8 @@
   { "macro",           mutt_parse_macro,       0 },
   { "mailboxes",       mutt_parse_mailboxes,   M_MAILBOXES },
   { "unmailboxes",     mutt_parse_mailboxes,   M_UNMAILBOXES },
+  { "mailboxrx",    parse_replace_list, UL &MailboxRxList },
+  { "unmailboxrx",  parse_unreplace_list, UL &MailboxRxList },
   { "message-hook",    mutt_parse_hook,        M_MESSAGEHOOK },
   { "mbox-hook",       mutt_parse_hook,        M_MBOXHOOK },
   { "mime_lookup",     parse_list,     UL &MimeLookupList },
diff -r ecae1a363182 -r 8f4ff2c8f2e7 muttlib.c
--- a/muttlib.c Fri Dec 14 17:29:03 2012 -0600
+++ b/muttlib.c Fri Dec 14 17:29:05 2012 -0600
@@ -809,10 +809,24 @@
   }
 }
 
+static void apply_mailboxrx (char *s, size_t buflen)
+{
+  char *repl;
+
+  repl = mutt_apply_replace (NULL, 0, s, MailboxRxList);
+  if (repl)
+  {
+    strncpy(s, repl, buflen-1);
+    s[buflen-1] = '\0';
+    FREE(&repl);
+  }
+}
+
 /* collapse the pathname using ~ or = when possible */
-void mutt_pretty_mailbox (char *s, size_t buflen)
+void mutt_pretty_mailbox (char *buf, size_t buflen)
 {
-  char *p = s, *q = s;
+  char *s = buf;
+  char *p = buf, *q = buf;
   size_t len;
   url_scheme_t scheme;
   char tmp[PATH_MAX];
@@ -823,6 +837,7 @@
   if (scheme == U_IMAP || scheme == U_IMAPS)
   {
     imap_pretty_mailbox (s);
+    apply_mailboxrx (buf, buflen);
     return;
   }
 #endif
@@ -878,6 +893,8 @@
     *s++ = '~';
     memmove (s, s + len - 1, mutt_strlen (s + len - 1) + 1);
   }
+
+  apply_mailboxrx (buf, buflen);
 }
 
 void mutt_pretty_size (char *s, size_t len, LOFF_T n)

Reply via email to