* restore flag:unread and some optimization

This commit is contained in:
Dirk-Jan C. Binnema 2011-08-13 10:40:31 +03:00
parent 8302fb23bb
commit 675b89708f
9 changed files with 92 additions and 33 deletions

View File

@ -524,10 +524,13 @@ define_symbols (void)
scm_c_define ("mu:trashed", scm_from_int(MU_FLAG_TRASHED)); 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:draft", scm_from_int(MU_FLAG_DRAFT));
scm_c_define ("mu:flagged", scm_from_int(MU_FLAG_FLAGGED)); 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:signed", scm_from_int(MU_FLAG_SIGNED));
scm_c_define ("mu:encrypted", scm_from_int(MU_FLAG_ENCRYPTED)); 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:has-attach", scm_from_int(MU_FLAG_HAS_ATTACH));
scm_c_define ("mu:unread", scm_from_int(MU_FLAG_UNREAD));
} }

View File

@ -1,4 +1,4 @@
.TH MU-EASY 1 "May 2011" "User Manuals" .TH MU-EASY 1 "August 2011" "User Manuals"
.SH NAME .SH NAME
@ -138,20 +138,20 @@ Get all messages from Jim without an attachment:
\fB$ mu find from:jim AND NOT flag:attach\fR \fB$ mu find from:jim AND NOT flag:attach\fR
.fi .fi
Get all unseen messages where the subject mentions Ångström: Get all unread messages where the subject mentions Ångström:
.nf .nf
\fB$ mu find subject:Ångström NOT flag:seen\fR \fB$ mu find subject:Ångström flag:unread\fR
.fi .fi
which is equivalent to: which is equivalent to:
.nf .nf
\fB$ mu find subject:angstrom NOT flag:seen\fR \fB$ mu find subject:angstrom flag:unread\fR
.fi .fi
because does mu is case-insensitive and accent-insensitive. 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): a Swedish rock band):
.nf .nf
\fB$ mu find date:20020301..20030831 nightingale NOT flag:seen\fR \fB$ mu find date:20020301..20030831 nightingale flag:unread\fR
.fi .fi
Get all messages received today: Get all messages received today:

View File

@ -469,7 +469,7 @@ Find all messages in the 'Archive' folder from Fred:
Find all unread messages with attachments: Find all unread messages with attachments:
.nf .nf
$ mu find flag:attach NOT flag:seen $ mu find flag:attach flag:unread
.fi .fi
@ -520,7 +520,7 @@ VFolders {
[size:1m..100m]!mu "Big" [size:1m..100m]!mu "Big"
[NOT flag:seen]!mu "Unread" [flag:unread]!mu "Unread"
} }
.fi .fi

View File

@ -42,7 +42,9 @@ static const FlagInfo FLAG_INFO[] = {
{ MU_FLAG_SIGNED, 's', "signed", MU_FLAG_TYPE_CONTENT }, { MU_FLAG_SIGNED, 's', "signed", MU_FLAG_TYPE_CONTENT },
{ MU_FLAG_ENCRYPTED, 'x', "encrypted", 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 */ /* does not use FLAG_INFO, optimized */
@ -53,9 +55,12 @@ mu_flag_type (MuFlags flag)
return MU_FLAG_TYPE_MAILFILE; return MU_FLAG_TYPE_MAILFILE;
if (flag == MU_FLAG_NEW) if (flag == MU_FLAG_NEW)
return MU_FLAG_TYPE_MAILDIR; 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) if (flag >= MU_FLAG_SIGNED && flag <= MU_FLAG_HAS_ATTACH)
return MU_FLAG_TYPE_CONTENT; return MU_FLAG_TYPE_CONTENT;
g_return_val_if_reached (MU_FLAG_TYPE_INVALID);
return 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_SIGNED: return 's';
case MU_FLAG_ENCRYPTED: return 'x'; case MU_FLAG_ENCRYPTED: return 'x';
case MU_FLAG_HAS_ATTACH: return 'a'; case MU_FLAG_HAS_ATTACH: return 'a';
case MU_FLAG_UNREAD: return 'u';
default: default:
g_message ("unsupported flag %u", flag);
g_return_val_if_reached (0); g_return_val_if_reached (0);
return 0; return 0;
} }
@ -105,9 +111,10 @@ mu_flag_from_char (char kar)
case 's': return MU_FLAG_SIGNED; case 's': return MU_FLAG_SIGNED;
case 'x': return MU_FLAG_ENCRYPTED; case 'x': return MU_FLAG_ENCRYPTED;
case 'a': return MU_FLAG_HAS_ATTACH; case 'a': return MU_FLAG_HAS_ATTACH;
case 'u': return MU_FLAG_UNREAD;
default: default:
g_message ("unsupported char %c", kar);
g_return_val_if_reached (MU_FLAG_INVALID); g_return_val_if_reached (MU_FLAG_INVALID);
return 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_SIGNED: return "signed";
case MU_FLAG_ENCRYPTED: return "encrypted"; case MU_FLAG_ENCRYPTED: return "encrypted";
case MU_FLAG_HAS_ATTACH: return "attach"; case MU_FLAG_HAS_ATTACH: return "attach";
case MU_FLAG_UNREAD: return "unread";
default: default:
g_return_val_if_reached (NULL); g_return_val_if_reached (NULL);
return NULL; return NULL;

View File

@ -27,18 +27,31 @@ G_BEGIN_DECLS
enum _MuFlags { enum _MuFlags {
MU_FLAG_NONE = 0, 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,<fileinfo>",
* <fileinfo> consists of zero or more of the following
* characters (in ascii order) */
MU_FLAG_DRAFT = 1 << 0, MU_FLAG_DRAFT = 1 << 0,
MU_FLAG_FLAGGED = 1 << 1, MU_FLAG_FLAGGED = 1 << 1,
MU_FLAG_PASSED = 1 << 2, MU_FLAG_PASSED = 1 << 2,
MU_FLAG_REPLIED = 1 << 3, MU_FLAG_REPLIED = 1 << 3,
MU_FLAG_SEEN = 1 << 4, MU_FLAG_SEEN = 1 << 4,
MU_FLAG_TRASHED = 1 << 5, 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_SIGNED = 1 << 7,
MU_FLAG_ENCRYPTED = 1 << 8, 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; typedef enum _MuFlags MuFlags;
@ -47,7 +60,8 @@ typedef enum _MuFlags MuFlags;
enum _MuFlagType { enum _MuFlagType {
MU_FLAG_TYPE_MAILFILE = 1 << 0, MU_FLAG_TYPE_MAILFILE = 1 << 0,
MU_FLAG_TYPE_MAILDIR = 1 << 1, 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; 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 * @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 * @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 * @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;
/** /**

View File

@ -332,10 +332,15 @@ get_flags (MuMsgFile *self)
{ {
MuFlags flags; 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 = mu_maildir_get_flags_from_path (self->_path);
flags |= get_content_flags (self); 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; return flags;
} }

View File

@ -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 static void
add_terms_values_number (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid) 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) cur && *cur; ++cur)
doc.add_term (prefix(mfid) + (char)tolower (*cur)); doc.add_term (prefix(mfid) + (char)tolower (*cur));
} else if (mfid == MU_MSG_FIELD_ID_PRIO) { } else if (mfid == MU_MSG_FIELD_ID_PRIO)
doc.add_term (prefix(mfid) + std::string(1, doc.add_term (prio_val((MuMsgPrio)num));
mu_msg_prio_char((MuMsgPrio)num)));
}
} }

View File

@ -182,7 +182,7 @@ test_mu_msg_03 (void)
==, ==,
"\nLet's write some fünkÿ text\nusing umlauts.\n\nFoo.\n"); "\nLet's write some fünkÿ text\nusing umlauts.\n\nFoo.\n");
g_assert_cmpuint (mu_msg_get_flags(msg), g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_FLAG_NONE); ==, MU_FLAG_UNREAD); /* not seen => unread */
mu_msg_unref (msg); mu_msg_unref (msg);
} }
@ -206,9 +206,9 @@ test_mu_msg_04 (void)
==, MU_MSG_PRIO_NORMAL); ==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg), g_assert_cmpuint (mu_msg_get_date(msg),
==, 0); ==, 0);
g_assert_cmpuint (mu_msg_get_flags(msg), g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_FLAG_HAS_ATTACH); ==, MU_FLAG_HAS_ATTACH|MU_FLAG_UNREAD);
mu_msg_unref (msg); 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), ','); refs = mu_str_from_list (mu_msg_get_references(msg), ',');
g_assert_cmpstr (refs, ==, 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," "87hbblwelr.fsf@sapphire.mobileactivedefense.com,"
"pql248-4va.ln1@wilbur.25thandClement.com," "pql248-4va.ln1@wilbur.25thandClement.com,"
"ikns6r$li3$1@Iltempo.Update.UU.SE," "ikns6r$li3$1@Iltempo.Update.UU.SE,"

View File

@ -38,8 +38,8 @@ If =mu= did not guess the right Maildir, you can set it explicitly:
*** signed messages about apples *OR* oranges *** signed messages about apples *OR* oranges
#+html:<pre> $ mu find flag:signed apples OR oranges</pre> #+html:<pre> $ mu find flag:signed apples OR oranges</pre>
*** unseen messages about things starting with 'soc' (soccer, society, socrates, ...) *** unread messages about things starting with 'soc' (soccer, society, socrates, ...)
#+html:<pre> $ mu find 'subject:soc*' NOT flag:seen</pre> #+html:<pre> $ mu find 'subject:soc*' flag:unread</pre>
Note, the '*' only works at the /end/ of a search term. Note, the '*' only works at the /end/ of a search term.
(searching using the '*' wildcard is available since mu 0.9.6) (searching using the '*' wildcard is available since mu 0.9.6)