unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: meskio@sindominio.net
To: notmuch@notmuchmail.org
Subject: [PATCH] Including 'unread' tag to mails without maildir flags
Date: Fri, 19 Nov 2010 16:41:04 +0100	[thread overview]
Message-ID: <1290181264-5900-1-git-send-email-meskio@sindominio.net> (raw)
In-Reply-To: <20101118153744.GE3049@blackspot>

From: Ruben Pollan <meskio@sindominio.net>

Some mail fetchers, like fetchmail, leaves the email without ':2,' at the end of
the filename. Notmuch didn't detect this emails as maildir, it didn't add the
maildir flags to them.

Now it detects if a mail is in a maildir by the directory structure, and add its
maildir flags correctly.
---
 lib/message.cc |   87 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 45 insertions(+), 42 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 225b7e9..996c1df 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -854,6 +854,47 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag)
     return NOTMUCH_STATUS_SUCCESS;
 }
 
+/* Is the given filename within a maildir directory?
+ *
+ * Specifically, is the final directory component of 'filename' either
+ * "cur" or "new". If so, return a pointer to that final directory
+ * component within 'filename'. If not, return NULL.
+ *
+ * A non-NULL return value is guaranteed to be a valid string pointer
+ * pointing to the characters "new/" or "cur/", (but not
+ * NUL-terminated).
+ */
+static const char *
+_filename_is_in_maildir (const char *filename)
+{
+    const char *slash, *dir = NULL;
+
+    /* Find the last '/' separating directory from filename. */
+    slash = strrchr (filename, '/');
+    if (slash == NULL)
+	return NULL;
+
+    /* Jump back 4 characters to where the previous '/' will be if the
+     * directory is named "cur" or "new". */
+    if (slash - filename < 4)
+	return NULL;
+
+    slash -= 4;
+
+    if (*slash != '/')
+	return NULL;
+
+    dir = slash + 1;
+
+    if (STRNCMP_LITERAL (dir, "cur/") == 0 ||
+	STRNCMP_LITERAL (dir, "new/") == 0)
+    {
+	return dir;
+    }
+
+    return NULL;
+}
+
 notmuch_status_t
 notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
 {
@@ -871,11 +912,14 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
     {
 	filename = notmuch_filenames_get (filenames);
 
+	if (! _filename_is_in_maildir(filename))
+	    continue;
+	seen_maildir_info = 1;
+
 	flags = strstr (filename, ":2,");
 	if (! flags)
 	    continue;
 
-	seen_maildir_info = 1;
 	flags += 3;
 
 	combined_flags = talloc_strdup_append (combined_flags, flags);
@@ -910,47 +954,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
     return status;
 }
 
-/* Is the given filename within a maildir directory?
- *
- * Specifically, is the final directory component of 'filename' either
- * "cur" or "new". If so, return a pointer to that final directory
- * component within 'filename'. If not, return NULL.
- *
- * A non-NULL return value is guaranteed to be a valid string pointer
- * pointing to the characters "new/" or "cur/", (but not
- * NUL-terminated).
- */
-static const char *
-_filename_is_in_maildir (const char *filename)
-{
-    const char *slash, *dir = NULL;
-
-    /* Find the last '/' separating directory from filename. */
-    slash = strrchr (filename, '/');
-    if (slash == NULL)
-	return NULL;
-
-    /* Jump back 4 characters to where the previous '/' will be if the
-     * directory is named "cur" or "new". */
-    if (slash - filename < 4)
-	return NULL;
-
-    slash -= 4;
-
-    if (*slash != '/')
-	return NULL;
-
-    dir = slash + 1;
-
-    if (STRNCMP_LITERAL (dir, "cur/") == 0 ||
-	STRNCMP_LITERAL (dir, "new/") == 0)
-    {
-	return dir;
-    }
-
-    return NULL;
-}
-
 /* From the set of tags on 'message' and the flag2tag table, compute a
  * set of maildir-flag actions to be taken, (flags that should be
  * either set or cleared).
-- 
1.7.1

  reply	other threads:[~2010-11-19 15:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-11 13:04 Maildir-flags synchronization now on master branch Carl Worth
2010-11-11 14:11 ` Kristoffer Ström
2010-11-11 22:38   ` Carl Worth
2010-11-12  0:43 ` Carl Worth
2010-11-12  1:43   ` Dirk Hohndel
2010-11-18 15:37 ` Ruben Pollan
2010-11-19 15:41   ` meskio [this message]
2010-11-20 23:26     ` [PATCH] Including 'unread' tag to mails without maildir flags Michal Sojka
2010-11-20 23:27       ` [PATCH 1/2] test: Add test for messages without maildir info in new Michal Sojka
2010-11-20 23:27       ` [PATCH 2/2] Include 'unread' tag only to mails " Michal Sojka
2010-11-22 10:43         ` Ruben Pollan
2010-11-20 23:54       ` [PATCH] Additional maildir-sync test Michal Sojka
2010-11-22 10:41         ` Ruben

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=1290181264-5900-1-git-send-email-meskio@sindominio.net \
    --to=meskio@sindominio.net \
    --cc=notmuch@notmuchmail.org \
    /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).