At 09:26 -0400 21 Mar 2015, Gregory Seidman <gsslist+m...@anthropohedron.net>
wrote:
folder-alias archive ~/archived-email/`date +%Y-%m`
Does anyone find this objectionable as a feature? Is anyone interested
in working on it? If no one is I can try to find time myself, but free
time has been in short supply since kids...
I've been using the attached patch to accomplish a similar goal for
awhile now (according to my git logs most of the work on this was done
in December of 2013), but hadn't gotten around to writing the docs so
that it would be suitable for submission.
Rather than using "folder-alias" I used the command "mailbox_prefix",
and it doesn't require any special character for expansion. The mailbox
prefixes that I have defined in my muttrc are:
mailbox_prefix + imaps://aaron.sch...@gmail.com@imap.gmail.com/
mailbox_prefix * imaps://asch...@mail.trilug.org/
As you might see by the first one, these prefixes take precedence over
the ones that mutt defines by default. So with the above configuration
the "=" and "+" prefixes are no longer equivalent.
This also causes it to use the prefix in most places where mailbox names
are displayed.
I haven't done extensive testing of this, but it's worked without
problems for my use for over a year now.
diff --git a/PATCHES b/PATCHES
index e69de29..f80882d 100644
--- a/PATCHES
+++ b/PATCHES
@@ -0,0 +1,1 @@
+ats.mailbox_prefix.1
diff --git a/complete.c b/complete.c
index d0ee4af..e724677 100644
--- a/complete.c
+++ b/complete.c
@@ -39,36 +39,52 @@
*/
int mutt_complete (char *s, size_t slen)
{
- char *p;
+ char *p, *q;
DIR *dirp = NULL;
struct dirent *de;
int i ,init=0;
size_t len;
char dirpart[_POSIX_PATH_MAX], exp_dirpart[_POSIX_PATH_MAX];
char filepart[_POSIX_PATH_MAX];
+ mailbox_prefix_t *prefix;
+ char exp_path[LONG_STRING];
+
+ prefix = MailboxPrefixList;
+ while (prefix) {
+ len = strlen(prefix->shortcut);
+ if (!strncmp (s, prefix->shortcut, len)) {
+ p = prefix->prefix;
+ q = exp_path;
+ while (*p) *q++ = *p++;
+ p = s + len;
+ while (*p) *q++ = *p++;
+ *q = 0;
+ strfcpy (s, exp_path, slen);
+ break;
+ }
+ prefix = prefix->next;
+ }
+
#ifdef USE_IMAP
- char imap_path[LONG_STRING];
-
dprint (2, (debugfile, "mutt_complete: completing %s\n", s));
-
/* we can use '/' as a delimiter, imap_complete rewrites it */
- if (*s == '=' || *s == '+' || *s == '!')
+ if (!prefix && (*s == '=' || *s == '+' || *s == '!'))
{
if (*s == '!')
p = NONULL (Spoolfile);
else
p = NONULL (Maildir);
- mutt_concat_path (imap_path, p, s+1, sizeof (imap_path));
+ mutt_concat_path (exp_path, p, s+1, sizeof (exp_path));
}
else
- strfcpy (imap_path, s, sizeof(imap_path));
+ strfcpy (exp_path, s, sizeof(exp_path));
- if (mx_is_imap (imap_path))
- return imap_complete (s, slen, imap_path);
+ if (mx_is_imap (exp_path))
+ return imap_complete (s, slen, exp_path);
#endif
- if (*s == '=' || *s == '+' || *s == '!')
+ if (!prefix && (*s == '=' || *s == '+' || *s == '!'))
{
dirpart[0] = *s;
dirpart[1] = 0;
diff --git a/globals.h b/globals.h
index 6c21fed..a652390 100644
--- a/globals.h
+++ b/globals.h
@@ -173,7 +173,7 @@ WHERE RX_LIST *SubscribedLists INITVAL(0);
WHERE RX_LIST *UnSubscribedLists INITVAL(0);
WHERE SPAM_LIST *SpamList INITVAL(0);
WHERE RX_LIST *NoSpamList INITVAL(0);
-
+WHERE mailbox_prefix_t *MailboxPrefixList INITVAL(0);
/* bit vector for boolean variables */
#ifdef MAIN_C
diff --git a/init.c b/init.c
index 3f72c1e..b914b70 100644
--- a/init.c
+++ b/init.c
@@ -797,6 +797,39 @@ static int parse_unlist (BUFFER *buf, BUFFER *s, unsigned
long data, BUFFER *err
return 0;
}
+static int mutt_parse_mailbox_prefix (BUFFER *b, BUFFER *s, unsigned long
data, BUFFER *err)
+{
+ mailbox_prefix_t *mb_prefix, *prev;
+
+ mb_prefix = safe_malloc(sizeof(*mb_prefix));
+ mb_prefix->next = NULL;
+
+ mutt_extract_token (b, s, 0);
+ mb_prefix->shortcut = safe_malloc(b->dsize);
+ strfcpy(mb_prefix->shortcut, b->data, b->dsize);
+
+ mutt_extract_token (b, s, 0);
+ mb_prefix->prefix = safe_malloc(b->dsize);
+ strfcpy(mb_prefix->prefix, b->data, b->dsize);
+
+ if (MailboxPrefixList) {
+ prev = MailboxPrefixList;
+ while (prev->next) {
+ prev = prev->next;
+ }
+ prev->next = mb_prefix;
+ }
+ else
+ MailboxPrefixList = mb_prefix;
+
+ return 0;
+bail:
+ FREE(&mb_prefix->shortcut);
+ FREE(&mb_prefix->prefix);
+ FREE(&mb_prefix);
+ return -1;
+}
+
static int parse_lists (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER
*err)
{
group_context_t *gc = NULL;
diff --git a/init.h b/init.h
index 8265551..5b4bcfd 100644
--- a/init.h
+++ b/init.h
@@ -3527,6 +3527,7 @@ static int parse_subscribe (BUFFER *, BUFFER *, unsigned
long, BUFFER *);
static int parse_unsubscribe (BUFFER *, BUFFER *, unsigned long, BUFFER *);
static int parse_attachments (BUFFER *, BUFFER *, unsigned long, BUFFER *);
static int parse_unattachments (BUFFER *, BUFFER *, unsigned long, BUFFER *);
+static int mutt_parse_mailbox_prefix (BUFFER *, BUFFER *, unsigned long,
BUFFER *);
static int parse_alternates (BUFFER *, BUFFER *, unsigned long, BUFFER *);
@@ -3573,6 +3574,7 @@ const struct command_t Commands[] = {
{ "ignore", parse_ignore, 0 },
{ "lists", parse_lists, 0 },
{ "macro", mutt_parse_macro, 0 },
+ { "mailbox_prefix", mutt_parse_mailbox_prefix, 0 },
{ "mailboxes", mutt_parse_mailboxes, M_MAILBOXES },
{ "unmailboxes", mutt_parse_mailboxes, M_UNMAILBOXES },
{ "message-hook", mutt_parse_hook, M_MESSAGEHOOK },
diff --git a/mutt.h b/mutt.h
index 9dc123a..15907e0 100644
--- a/mutt.h
+++ b/mutt.h
@@ -955,6 +955,13 @@ typedef struct
#define M_PARTS_TOPLEVEL (1<<0) /* is the top-level part */
+typedef struct mailbox_prefix_t
+{
+ char *shortcut;
+ char *prefix;
+ struct mailbox_prefix_t *next;
+} mailbox_prefix_t;
+
#include "ascii.h"
#include "protos.h"
#include "lib.h"
diff --git a/muttlib.c b/muttlib.c
index 75177dd..bb0cdca 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -391,6 +391,8 @@ char *_mutt_expand_path (char *s, size_t slen, int rx)
char q[_POSIX_PATH_MAX] = "";
char tmp[_POSIX_PATH_MAX];
char *t;
+ int pfx_len;
+ mailbox_prefix_t *prefix;
char *tail = "";
@@ -399,6 +401,16 @@ char *_mutt_expand_path (char *s, size_t slen, int rx)
do
{
recurse = 0;
+ prefix = MailboxPrefixList;
+ while (prefix) {
+ pfx_len = strlen(prefix->shortcut);
+ if (!strncmp(s, prefix->shortcut, pfx_len)) {
+ strfcpy (p, prefix->prefix, sizeof (p));
+ tail = s + pfx_len;
+ goto tail;
+ }
+ prefix = prefix->next;
+ }
switch (*s)
{
@@ -532,6 +544,7 @@ char *_mutt_expand_path (char *s, size_t slen, int rx)
}
}
+tail:
if (rx && *p && !recurse)
{
mutt_rx_sanitize_string (q, sizeof (q), p);
@@ -813,8 +826,24 @@ void mutt_pretty_mailbox (char *s, size_t buflen)
char *p = s, *q = s;
size_t len;
url_scheme_t scheme;
+ mailbox_prefix_t *prefix;
char tmp[PATH_MAX];
+ prefix = MailboxPrefixList;
+ while (prefix) {
+ len = strlen (prefix->prefix);
+ if (!strncmp (prefix->prefix, s, len)) {
+ p = prefix->shortcut;
+ while (*p) *q++ = *p++;
+ p = s+len;
+ while (*p) *q++ = *p++;
+ *q = 0;
+ p = q = s;
+ break;
+ }
+ prefix = prefix->next;
+ }
+
scheme = url_check_scheme (s);
#ifdef USE_IMAP