Re: [PATCH] Mailbox Aliases
Rocco Rutte wrote :
> Mutt has quite a few library functions, so please use them. Especially
> safe_malloc() and the strfcpy() macro. Also see mutt_substrdup().
[...]
> I also think you should check that *buf != '=' in case of typos like:
>
> mailboxes ==foo
[...]
Thank you for looking at it, here is an updated version, using library
functions and following your recommendations.
Bertrand
diff -r d213f3acdb68 buffy.c
--- a/buffy.c Mon Jun 15 14:24:27 2009 -0700
+++ b/buffy.c Wed Jun 17 13:34:13 2009 -0400
@@ -194,7 +194,9 @@
int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER
*err)
{
BUFFY **tmp,*tmp1;
+ char *alias;
char buf[_POSIX_PATH_MAX];
+ char tbuf[_POSIX_PATH_MAX];
struct stat sb;
char f1[PATH_MAX], f2[PATH_MAX];
char *p, *q;
@@ -203,6 +205,7 @@
{
mutt_extract_token (path, s, 0);
strfcpy (buf, path->data, sizeof (buf));
+ alias = NULL;
if(data == M_UNMAILBOXES && mutt_strcmp(buf,"*") == 0)
{
@@ -220,6 +223,14 @@
/* Skip empty tokens. */
if(!*buf) continue;
+ /* Extract mailbox alias if any. */
+ if (*buf != '=' && (p = strchr(buf, '=')) != NULL)
+ {
+ alias = mutt_substrdup(buf, p);
+ strcpy(tbuf, p + 1);
+ strcpy(buf, tbuf);
+ }
+
/* avoid duplicates */
p = realpath (buf, f1);
for (tmp = &Incoming; *tmp; tmp = &((*tmp)->next))
@@ -249,15 +260,21 @@
*tmp = (BUFFY *) safe_calloc (1, sizeof (BUFFY));
strfcpy ((*tmp)->path, buf, sizeof ((*tmp)->path));
(*tmp)->next = NULL;
+ (*tmp)->alias = NULL;
/* it is tempting to set magic right here */
(*tmp)->magic = 0;
-
}
(*tmp)->new = 0;
(*tmp)->notified = 1;
(*tmp)->newly_created = 0;
+ if (alias != NULL)
+ {
+ mutt_str_replace(&(*tmp)->alias, alias);
+ free(alias);
+ }
+
/* for check_mbox_size, it is important that if the folder is new (tested
by
* reading it), the size is set to 0 so that later when we check we see
* that it increased . without check_mbox_size we probably don't care.
@@ -271,6 +288,7 @@
else
(*tmp)->size = 0;
}
+
return 0;
}
diff -r d213f3acdb68 buffy.h
--- a/buffy.h Mon Jun 15 14:24:27 2009 -0700
+++ b/buffy.h Wed Jun 17 13:34:13 2009 -0400
@@ -23,6 +23,7 @@
typedef struct buffy_t
{
char path[_POSIX_PATH_MAX];
+ char *alias;
off_t size;
struct buffy_t *next;
short new; /* mailbox has new mail */
diff -r d213f3acdb68 muttlib.c
--- a/muttlib.c Mon Jun 15 14:24:27 2009 -0700
+++ b/muttlib.c Wed Jun 17 13:34:13 2009 -0400
@@ -27,6 +27,7 @@
#include "mailbox.h"
#include "mx.h"
#include "url.h"
+#include "buffy.h"
#ifdef USE_IMAP
#include "imap.h"
@@ -354,6 +355,7 @@
char q[_POSIX_PATH_MAX] = "";
char tmp[_POSIX_PATH_MAX];
char *t;
+ BUFFY *btmp;
char *tail = "";
@@ -444,6 +446,20 @@
}
}
break;
+
+ case '*':
+ {
+ tail = s + 1;
+ for (btmp = Incoming; btmp; btmp = btmp->next) {
+ if (btmp->alias != NULL && mutt_strcmp(s + 1, btmp->alias) == 0)
+ {
+ strfcpy (p, btmp->path, sizeof (p));
+ tail = "";
+ break;
+ }
+ }
+ }
+ break;
case '>':
{