On Fri, Oct 26 2012, Taesoo Kim <[email protected]> wrote: > @@ -240,6 +242,32 @@ _entry_in_ignore_list (const char *entry, > add_files_state_t *state) > return FALSE; > } > > +static void > +_add_maildir_as_tag(notmuch_database_t *notmuch, > + notmuch_message_t *msg, const char *path) > +{ > + char *tok = talloc_strdup (notmuch, path); > + int len = strlen(tok); > + > + /* asserts path ends with /cur|/tmp|/new */
It actually does not assert that. It just checks “/”.
> + if (len > 4 && tok[len - 4] == '/') {
> + char *iter = tok + len - 4;
> + *iter = '\0';
> + while (-- iter && iter >= tok) {
> + char c = *iter;
> + if (c == '/' || c == '.') {
> + *iter = '\0';
> + notmuch_message_add_tag (msg, iter + 1);
> + if (c == '/') {
> + break;
> + }
> + }
> + *iter = tolower(*iter);
> + }
strtok() would make it easier.
> + }
> + talloc_free (tok);
> +}
How about (not tested):
static void
_add_maildir_as_tag(notmuch_database_t *notmuch,
notmuch_message_t *msg, const char *path)
{
const char *a = NULL, *b = NULL;
char *dir, *tag, *saveptr;
while ((path = strchr(path, '/'))) {
a = b;
b = path;
}
if (!a || ++a >= b ||
(strcmp(b, "/cur") && strcmp(b, "/new") && strcmp(b, "/tmp")))
return;
dir = talloc_strndup(notmuch, a, b - a);
while ((tag = strtok_r(dir, ".", &saveptr)))
notmuch_message_add_tag(msg, tag);
talloc_free(dir);
}
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--
pgpsfeYoc9qcB.pgp
Description: PGP signature
_______________________________________________ notmuch mailing list [email protected] http://notmuchmail.org/mailman/listinfo/notmuch
