diff --git a/libmuguile/mu-guile-msg.c b/libmuguile/mu-guile-msg.c index 30cd92ea..69138aba 100644 --- a/libmuguile/mu-guile-msg.c +++ b/libmuguile/mu-guile-msg.c @@ -524,10 +524,13 @@ define_symbols (void) scm_c_define ("mu:trashed", scm_from_int(MU_FLAG_TRASHED)); scm_c_define ("mu:draft", scm_from_int(MU_FLAG_DRAFT)); scm_c_define ("mu:flagged", scm_from_int(MU_FLAG_FLAGGED)); - scm_c_define ("mu:unread", scm_from_int(MU_FLAG_UNREAD)); + scm_c_define ("mu:signed", scm_from_int(MU_FLAG_SIGNED)); scm_c_define ("mu:encrypted", scm_from_int(MU_FLAG_ENCRYPTED)); scm_c_define ("mu:has-attach", scm_from_int(MU_FLAG_HAS_ATTACH)); + + scm_c_define ("mu:unread", scm_from_int(MU_FLAG_UNREAD)); + } diff --git a/man/mu-easy.1 b/man/mu-easy.1 index 141ae434..ea44c921 100644 --- a/man/mu-easy.1 +++ b/man/mu-easy.1 @@ -1,4 +1,4 @@ -.TH MU-EASY 1 "May 2011" "User Manuals" +.TH MU-EASY 1 "August 2011" "User Manuals" .SH NAME @@ -138,20 +138,20 @@ Get all messages from Jim without an attachment: \fB$ mu find from:jim AND NOT flag:attach\fR .fi -Get all unseen messages where the subject mentions Ångström: +Get all unread messages where the subject mentions Ångström: .nf - \fB$ mu find subject:Ångström NOT flag:seen\fR + \fB$ mu find subject:Ångström flag:unread\fR .fi which is equivalent to: .nf - \fB$ mu find subject:angstrom NOT flag:seen\fR + \fB$ mu find subject:angstrom flag:unread\fR .fi because does mu is case-insensitive and accent-insensitive. -Get all unseen messages between March 2002 and August 2003 about some bird (or +Get all unread messages between March 2002 and August 2003 about some bird (or a Swedish rock band): .nf - \fB$ mu find date:20020301..20030831 nightingale NOT flag:seen\fR + \fB$ mu find date:20020301..20030831 nightingale flag:unread\fR .fi Get all messages received today: diff --git a/man/mu-find.1 b/man/mu-find.1 index abb6077c..e5ac5955 100644 --- a/man/mu-find.1 +++ b/man/mu-find.1 @@ -469,7 +469,7 @@ Find all messages in the 'Archive' folder from Fred: Find all unread messages with attachments: .nf - $ mu find flag:attach NOT flag:seen + $ mu find flag:attach flag:unread .fi @@ -520,7 +520,7 @@ VFolders { [size:1m..100m]!mu "Big" - [NOT flag:seen]!mu "Unread" + [flag:unread]!mu "Unread" } .fi diff --git a/src/mu-flags.c b/src/mu-flags.c index d4fc08fd..2ea79a17 100644 --- a/src/mu-flags.c +++ b/src/mu-flags.c @@ -42,7 +42,9 @@ static const FlagInfo FLAG_INFO[] = { { MU_FLAG_SIGNED, 's', "signed", MU_FLAG_TYPE_CONTENT }, { MU_FLAG_ENCRYPTED, 'x', "encrypted", MU_FLAG_TYPE_CONTENT }, - { MU_FLAG_HAS_ATTACH, 'a', "attach", MU_FLAG_TYPE_CONTENT } + { MU_FLAG_HAS_ATTACH, 'a', "attach", MU_FLAG_TYPE_CONTENT }, + + { MU_FLAG_UNREAD, 'u', "unread", MU_FLAG_TYPE_PSEUDO } }; /* does not use FLAG_INFO, optimized */ @@ -53,9 +55,12 @@ mu_flag_type (MuFlags flag) return MU_FLAG_TYPE_MAILFILE; if (flag == MU_FLAG_NEW) return MU_FLAG_TYPE_MAILDIR; + if (flag == MU_FLAG_UNREAD) + return MU_FLAG_TYPE_PSEUDO; if (flag >= MU_FLAG_SIGNED && flag <= MU_FLAG_HAS_ATTACH) return MU_FLAG_TYPE_CONTENT; + g_return_val_if_reached (MU_FLAG_TYPE_INVALID); return MU_FLAG_TYPE_INVALID; } @@ -78,9 +83,10 @@ mu_flag_char (MuFlags flag) case MU_FLAG_SIGNED: return 's'; case MU_FLAG_ENCRYPTED: return 'x'; case MU_FLAG_HAS_ATTACH: return 'a'; - + + case MU_FLAG_UNREAD: return 'u'; + default: - g_message ("unsupported flag %u", flag); g_return_val_if_reached (0); return 0; } @@ -105,9 +111,10 @@ mu_flag_from_char (char kar) case 's': return MU_FLAG_SIGNED; case 'x': return MU_FLAG_ENCRYPTED; case 'a': return MU_FLAG_HAS_ATTACH; - + + case 'u': return MU_FLAG_UNREAD; + default: - g_message ("unsupported char %c", kar); g_return_val_if_reached (MU_FLAG_INVALID); return MU_FLAG_INVALID; } @@ -132,6 +139,9 @@ mu_flag_name (MuFlags flag) case MU_FLAG_SIGNED: return "signed"; case MU_FLAG_ENCRYPTED: return "encrypted"; case MU_FLAG_HAS_ATTACH: return "attach"; + + case MU_FLAG_UNREAD: return "unread"; + default: g_return_val_if_reached (NULL); return NULL; diff --git a/src/mu-flags.h b/src/mu-flags.h index 7dab13fa..1f5681b7 100644 --- a/src/mu-flags.h +++ b/src/mu-flags.h @@ -27,18 +27,31 @@ G_BEGIN_DECLS enum _MuFlags { MU_FLAG_NONE = 0, - + + /* next 6 are seen in the file-info part of maildir message + * file names, ie., in a name like "1234345346:2,", + * consists of zero or more of the following + * characters (in ascii order) */ MU_FLAG_DRAFT = 1 << 0, MU_FLAG_FLAGGED = 1 << 1, MU_FLAG_PASSED = 1 << 2, MU_FLAG_REPLIED = 1 << 3, MU_FLAG_SEEN = 1 << 4, MU_FLAG_TRASHED = 1 << 5, - - MU_FLAG_NEW = 1 << 6, + + /* decides on cur/ or new/ in the maildir */ + MU_FLAG_NEW = 1 << 6, + + /* content flags -- not visible in the filename, but used for + * searching */ MU_FLAG_SIGNED = 1 << 7, MU_FLAG_ENCRYPTED = 1 << 8, - MU_FLAG_HAS_ATTACH = 1 << 9 + MU_FLAG_HAS_ATTACH = 1 << 9, + + /* pseudo-flag, only for queries, so we can search for + * flag:unread, which is equivalent to 'flag:new OR NOT + * flag:seen' */ + MU_FLAG_UNREAD = 1 << 10 }; typedef enum _MuFlags MuFlags; @@ -47,7 +60,8 @@ typedef enum _MuFlags MuFlags; enum _MuFlagType { MU_FLAG_TYPE_MAILFILE = 1 << 0, MU_FLAG_TYPE_MAILDIR = 1 << 1, - MU_FLAG_TYPE_CONTENT = 1 << 2 + MU_FLAG_TYPE_CONTENT = 1 << 2, + MU_FLAG_TYPE_PSEUDO = 1 << 3 }; typedef enum _MuFlagType MuFlagType; @@ -62,7 +76,7 @@ typedef enum _MuFlagType MuFlagType; * * @return the flag type or MU_FLAG_TYPE_INVALID in case of error */ -MuFlagType mu_flag_type (MuFlags flag); +MuFlagType mu_flag_type (MuFlags flag) G_GNUC_CONST; /** @@ -72,7 +86,7 @@ MuFlagType mu_flag_type (MuFlags flag); * * @return the character, or 0 in case of error */ -char mu_flag_char (MuFlags flag); +char mu_flag_char (MuFlags flag) G_GNUC_CONST; /** @@ -82,7 +96,7 @@ char mu_flag_char (MuFlags flag); * * @return the name (don't free) as string or NULL in case of error */ -const char* mu_flag_name (MuFlags flag); +const char* mu_flag_name (MuFlags flag) G_GNUC_CONST; /** diff --git a/src/mu-msg-file.c b/src/mu-msg-file.c index 99325ecc..0d71eeca 100644 --- a/src/mu-msg-file.c +++ b/src/mu-msg-file.c @@ -332,10 +332,15 @@ get_flags (MuMsgFile *self) { MuFlags flags; - g_return_val_if_fail (self, MU_FLAG_NONE); + g_return_val_if_fail (self, MU_FLAG_INVALID); flags = mu_maildir_get_flags_from_path (self->_path); flags |= get_content_flags (self); + + /* pseudo-flag --> unread means either NEW or NOT SEEN, just + * for searching convenience */ + if ((flags & MU_FLAG_NEW) || (!(flags & MU_FLAG_SEEN))) + flags |= MU_FLAG_UNREAD; return flags; } diff --git a/src/mu-store.cc b/src/mu-store.cc index 6e5f3e5c..819c7945 100644 --- a/src/mu-store.cc +++ b/src/mu-store.cc @@ -325,6 +325,34 @@ add_terms_values_date (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid) } } +/* TODO: we could pre-calculate the add_term values for FLAGS */ + + +/* pre-calculate; optimization */ +G_GNUC_CONST static const std::string& +prio_val (MuMsgPrio prio) +{ + static const std::string pfx (prefix(MU_MSG_FIELD_ID_PRIO)); + + static const std::string lowstr + (pfx + std::string(1, mu_msg_prio_char(MU_MSG_PRIO_LOW))); + static const std::string normalstr + (pfx + std::string(1, mu_msg_prio_char(MU_MSG_PRIO_NORMAL))); + static const std::string highstr + (pfx + std::string(1, mu_msg_prio_char(MU_MSG_PRIO_HIGH))); + + + switch (prio) { + case MU_MSG_PRIO_LOW: return lowstr; + case MU_MSG_PRIO_NORMAL: return normalstr; + case MU_MSG_PRIO_HIGH: return highstr; + default: + g_return_val_if_reached (normalstr); + return normalstr; + } +} + + static void add_terms_values_number (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid) @@ -341,10 +369,8 @@ add_terms_values_number (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid) cur && *cur; ++cur) doc.add_term (prefix(mfid) + (char)tolower (*cur)); - } else if (mfid == MU_MSG_FIELD_ID_PRIO) { - doc.add_term (prefix(mfid) + std::string(1, - mu_msg_prio_char((MuMsgPrio)num))); - } + } else if (mfid == MU_MSG_FIELD_ID_PRIO) + doc.add_term (prio_val((MuMsgPrio)num)); } diff --git a/src/tests/test-mu-msg.c b/src/tests/test-mu-msg.c index 88dc7133..2e23f24a 100644 --- a/src/tests/test-mu-msg.c +++ b/src/tests/test-mu-msg.c @@ -182,7 +182,7 @@ test_mu_msg_03 (void) ==, "\nLet's write some fünkÿ text\nusing umlauts.\n\nFoo.\n"); g_assert_cmpuint (mu_msg_get_flags(msg), - ==, MU_FLAG_NONE); + ==, MU_FLAG_UNREAD); /* not seen => unread */ mu_msg_unref (msg); } @@ -206,9 +206,9 @@ test_mu_msg_04 (void) ==, MU_MSG_PRIO_NORMAL); g_assert_cmpuint (mu_msg_get_date(msg), ==, 0); - + g_assert_cmpuint (mu_msg_get_flags(msg), - ==, MU_FLAG_HAS_ATTACH); + ==, MU_FLAG_HAS_ATTACH|MU_FLAG_UNREAD); mu_msg_unref (msg); } @@ -345,7 +345,8 @@ test_mu_msg_comp_unix_programmer (void) refs = mu_str_from_list (mu_msg_get_references(msg), ','); g_assert_cmpstr (refs, ==, - "e9065dac-13c1-4103-9e31-6974ca232a89@t15g2000prt.googlegroups.com," + "e9065dac-13c1-4103-9e31-6974ca232a89@t15g2000prt" + ".googlegroups.com," "87hbblwelr.fsf@sapphire.mobileactivedefense.com," "pql248-4va.ln1@wilbur.25thandClement.com," "ikns6r$li3$1@Iltempo.Update.UU.SE," diff --git a/www/cheatsheet.org b/www/cheatsheet.org index 1803aea7..23f35491 100644 --- a/www/cheatsheet.org +++ b/www/cheatsheet.org @@ -38,8 +38,8 @@ If =mu= did not guess the right Maildir, you can set it explicitly: *** signed messages about apples *OR* oranges #+html:
  $ mu find flag:signed apples OR oranges
-*** unseen messages about things starting with 'soc' (soccer, society, socrates, ...) -#+html:
  $ mu find 'subject:soc*' NOT flag:seen
+*** unread messages about things starting with 'soc' (soccer, society, socrates, ...) +#+html:
  $ mu find 'subject:soc*' flag:unread
Note, the '*' only works at the /end/ of a search term. (searching using the '*' wildcard is available since mu 0.9.6)