From: Michal Nazarewicz <mina86@mina86.com>
To: Taesoo Kim <taesoo@mit.edu>, notmuch@notmuchmail.org
Cc: Taesoo Kim <taesoo@mit.edu>
Subject: Re: [PATCH 1/2] Automatic tagging based on maildir
Date: Fri, 26 Oct 2012 15:19:54 +0200 [thread overview]
Message-ID: <xa1tr4olpdz9.fsf@mina86.com> (raw)
In-Reply-To: <1351208039-32293-2-git-send-email-taesoo@mit.edu>
[-- Attachment #1: Type: text/plain, Size: 1780 bytes --]
On Fri, Oct 26 2012, Taesoo Kim <taesoo@mit.edu> 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: mpn@google.com>--------------ooO--(_)--Ooo--
[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]
[-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --]
next prev parent reply other threads:[~2012-10-26 13:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-25 23:33 [PATCH 0/2] automatic tagging based on imap maildir Taesoo Kim
2012-10-25 23:33 ` [PATCH 1/2] Automatic tagging based on maildir Taesoo Kim
2012-10-26 11:31 ` David Bremner
2012-10-26 13:19 ` Michal Nazarewicz [this message]
2012-10-26 17:14 ` Jani Nikula
2012-10-25 23:33 ` [PATCH 2/2] fix: initialize error var before using it Taesoo Kim
2012-10-26 17:10 ` [PATCH 0/2] automatic tagging based on imap maildir Amadeusz Żołnowski
2012-10-26 23:02 ` David Bremner
2012-10-27 4:41 ` Taesoo Kim
2012-10-27 13:00 ` David Bremner
2012-10-28 10:03 ` Andrei POPESCU
2012-10-28 15:31 ` Austin Clements
2012-10-28 21:44 ` Andrei POPESCU
2012-10-28 22:12 ` Austin Clements
2012-10-29 0:07 ` Andrei POPESCU
2012-10-30 18:18 ` Amadeusz Żołnowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xa1tr4olpdz9.fsf@mina86.com \
--to=mina86@mina86.com \
--cc=notmuch@notmuchmail.org \
--cc=taesoo@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).