Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id BEEB8431FBD for ; Mon, 15 Feb 2010 18:21:33 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.007 X-Spam-Level: X-Spam-Status: No, score=-2.007 tagged_above=-999 required=5 tests=[AWL=0.592, BAYES_00=-2.599] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E5OeefNZkxtk for ; Mon, 15 Feb 2010 18:21:32 -0800 (PST) Received: from kaylee.flamingspork.com (kaylee.flamingspork.com [74.207.245.61]) by olra.theworths.org (Postfix) with ESMTP id 8F6AE431FBC for ; Mon, 15 Feb 2010 18:21:32 -0800 (PST) Received: from willster (localhost [127.0.0.1]) by kaylee.flamingspork.com (Postfix) with ESMTPS id 6772E6393; Tue, 16 Feb 2010 02:18:31 +0000 (UTC) Received: from flamingspork.com (localhost.localdomain [127.0.0.1]) by willster (Postfix) with ESMTPS id 3AD461026130; Tue, 16 Feb 2010 13:21:30 +1100 (EST) Date: Tue, 16 Feb 2010 13:21:28 +1100 From: Stewart Smith To: Tim Stoakes , notmuch@notmuchmail.org Message-ID: <20100216022128.GH22402@flamingspork.com> References: <87d43b2oif.fsf@yoom.home.cworth.org> <9bfdedddeab9c58cd45d8d448323d0fc@localhost> <87skc23327.fsf@yoom.home.cworth.org> <4b0eef22.JwxdgTGElffx149F%michiel@michielbuddingh.net> <87ws1bjpmm.fsf@yoom.home.cworth.org> <878wdfkhcl.fsf@aegir.org.uk> <20100210031339.GH16686@mail.rocksoft.com> <20100215081331.GD22402@flamingspork.com> <20100216015856.GG22402@flamingspork.com> <20100216021250.GB21780@lapse.rw.madduck.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="PEIAKu/WMn1b1Hv9" Content-Disposition: inline In-Reply-To: <20100216021250.GB21780@lapse.rw.madduck.net> User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: [notmuch] [PATCH] notmuch: Respect maildir message flags X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Feb 2010 02:21:33 -0000 --PEIAKu/WMn1b1Hv9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Feb 16, 2010 at 03:12:50PM +1300, martin f krafft wrote: > also sprach Stewart Smith [2010.02.16.1458 +13= 00]: > > + case 'R': /* replied */ > > + notmuch_message_add_tag (message, "answered"); > > + break; >=20 > 'r' means replied, not 'answered'. fixed. (i have to admit... i didn't look too closely at this... it just worked enough for me) >=20 > > + case 'T': /* trashed */ > > + notmuch_message_add_tag (message, "deleted"); > > + break; >=20 > Same. trashed and deleted are not the same thing. changed to 'trashed'. > I don't want to get into an argument over this, because I think this > already exposes a problem: you are putting into global namespace > something not everyone might want, or agree with. >=20 > Why not use 'maildirflags::replied' instead? People can always map > that to something in the global namespace. What about putting them all in there except for the seen tag, with the seen tag dictating if it gets marked 'unread' or not? I cannot imagine where somebody would want this not to be the case... it was bad enough discovering 100,000 unread messages :) What about this patch (just with those few things fixed)? diff --git a/notmuch-new.c b/notmuch-new.c index f25c71f..8303047 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -39,6 +39,7 @@ typedef struct { int total_files; int processed_files; int added_messages; + int tag_maildir; struct timeval tv_start; =20 _filename_list_t *removed_files; @@ -169,6 +170,60 @@ _entries_resemble_maildir (struct dirent **entries, in= t count) return 0; } =20 +/* Tag new mail according to its Maildir attribute flags. + * + * Test if the mail file's filename contains any of the + * standard Maildir attributes, and translate these to + * the corresponding standard notmuch tags. + * + * If the message is not marked as 'seen', or if no + * flags are present, tag as 'inbox, unread'. + */ +static void +derive_tags_from_maildir_flags (notmuch_message_t *message, + const char * path) +{ + int seen =3D FALSE; + int end_of_flags =3D FALSE; + size_t l =3D strlen(path); + + /* Non-experimental message flags start with this */ + char * i =3D strstr(path, ":2,"); + i =3D (i) ? i : strstr(path, "!2,"); /* This format is used on VFAT */ + if (i !=3D NULL) { + i +=3D 3; + for (; i < (path + l) && !end_of_flags; i++) { + switch (*i) { + case 'F' : + notmuch_message_add_tag (message, "maildir::flagged"); + break; + case 'R': /* replied */ + notmuch_message_add_tag (message, "maildir::replied"); + break; + case 'D': + notmuch_message_add_tag (message, "maildir::draft"); + break; + case 'S': /* seen */ + seen =3D TRUE; + break; + case 'T': /* trashed */ + notmuch_message_add_tag (message, "maildir::trashed"); + break; + case 'P': /* passed */ + notmuch_message_add_tag (message, "maildir::forwarded"); + break; + default: + end_of_flags =3D TRUE; + break; + } + } + } + + if (i =3D=3D NULL || !seen) { + tag_inbox_and_unread (message); + } +} + /* Examine 'path' recursively as follows: * * o Ask the filesystem for the mtime of 'path' (fs_mtime) @@ -222,6 +277,7 @@ add_files_recursive (notmuch_database_t *notmuch, notmuch_filenames_t *db_subdirs =3D NULL; struct stat st; notmuch_bool_t is_maildir, new_directory; + int maildir_detected =3D -1; =20 if (stat (path, &st)) { fprintf (stderr, "Error reading directory %s: %s\n", @@ -301,6 +357,28 @@ add_files_recursive (notmuch_database_t *notmuch, continue; } =20 + /* If this directory is a Maildir folder, we need to + * ignore any subdirectories marked tmp/, and scan for + * Maildir attributes on messages contained in the sub- + * directories 'new' and 'cur'. */ + if (maildir_detected !=3D 0 && + (entry->d_type =3D=3D DT_DIR || entry->d_type =3D=3D DT_UNKNOWN) && + ((strcmp (entry->d_name, "tmp") =3D=3D 0) || + (strcmp (entry->d_name, "new") =3D=3D 0) || + (strcmp (entry->d_name, "cur") =3D=3D 0))) { + + if (maildir_detected =3D=3D -1) { + maildir_detected =3D _entries_resemble_maildir(fs_entries, num_fs_en= tries); + } + if (maildir_detected =3D=3D 1) { + if (strcmp (entry->d_name, "tmp") =3D=3D 0) { + continue; + } else { + state->tag_maildir =3D TRUE; + } + } + } + next =3D talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); status =3D add_files_recursive (notmuch, next, state); if (status && ret =3D=3D NOTMUCH_STATUS_SUCCESS) @@ -412,7 +490,12 @@ add_files_recursive (notmuch_database_t *notmuch, /* success */ case NOTMUCH_STATUS_SUCCESS: state->added_messages++; - tag_inbox_and_unread (message); + if (state->tag_maildir) { + derive_tags_from_maildir_flags (message, + entry->d_name); + } else { + tag_inbox_and_unread (message); + } break; /* Non-fatal issues (go on to next file) */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: --=20 Stewart Smith --PEIAKu/WMn1b1Hv9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkt6AScACgkQFtJC9tN9Son7nQCglX2I9IQTe2cdzUb/3qNGWyE2 Y+kAoKttgVm/E3wdbjFNMgrjwYLBCVM0 =yKRH -----END PGP SIGNATURE----- --PEIAKu/WMn1b1Hv9--