From 58dc8690176a6bee73c55bd0ed1e81d71d076fcc Mon Sep 17 00:00:00 2001 From: djcb Date: Fri, 11 May 2012 18:39:00 +0300 Subject: [PATCH] * fix: shortcut for signed is 'z', not 's'; add some unit tests as well --- man/mu-find.1 | 3 ++ src/mu-flags.c | 90 ++++++++++++++++++------------------- src/mu-store-write.cc | 13 +++--- src/tests/Makefile.am | 3 ++ src/tests/test-mu-flags.c | 24 +++++----- src/tests/test-mu-maildir.c | 4 +- src/tests/test-mu-query.c | 58 +++++++++++++++++------- 7 files changed, 112 insertions(+), 83 deletions(-) diff --git a/man/mu-find.1 b/man/mu-find.1 index efb5d700..62d6e267 100644 --- a/man/mu-find.1 +++ b/man/mu-find.1 @@ -156,6 +156,9 @@ attachment: $ mu find flag:signed flag:attach .fi +Encrypted messages may be signed as well, but this is only visible after +decrypting, and thus, is invisible to \fBmu\fR. + The message-priority has three possible values: low, normal or high. We can match them using \fBprio:\fR - for example, to get all high-priority messages with a subject containing some bird: diff --git a/src/mu-flags.c b/src/mu-flags.c index d8286346..45b8056f 100644 --- a/src/mu-flags.c +++ b/src/mu-flags.c @@ -30,17 +30,17 @@ static const FlagInfo FLAG_INFO[] = { /* NOTE: order of this is significant, due to optimizations * below */ - + { MU_FLAG_DRAFT, 'D', "draft", MU_FLAG_TYPE_MAILFILE }, { MU_FLAG_FLAGGED, 'F', "flagged", MU_FLAG_TYPE_MAILFILE }, { MU_FLAG_PASSED, 'P', "passed", MU_FLAG_TYPE_MAILFILE }, { MU_FLAG_REPLIED, 'R', "replied", MU_FLAG_TYPE_MAILFILE }, { MU_FLAG_SEEN, 'S', "seen", MU_FLAG_TYPE_MAILFILE }, { MU_FLAG_TRASHED, 'T', "trashed", MU_FLAG_TYPE_MAILFILE }, - - { MU_FLAG_NEW, 'N', "new", MU_FLAG_TYPE_MAILDIR }, - { MU_FLAG_SIGNED, 's', "signed", MU_FLAG_TYPE_CONTENT }, + { MU_FLAG_NEW, 'N', "new", MU_FLAG_TYPE_MAILDIR }, + + { MU_FLAG_SIGNED, 'z', "signed", MU_FLAG_TYPE_CONTENT }, { MU_FLAG_ENCRYPTED, 'x', "encrypted", MU_FLAG_TYPE_CONTENT }, { MU_FLAG_HAS_ATTACH, 'a', "attach", MU_FLAG_TYPE_CONTENT }, @@ -69,17 +69,17 @@ char mu_flag_char (MuFlags flag) { switch (flag) { - + case MU_FLAG_DRAFT: return 'D'; case MU_FLAG_FLAGGED: return 'F'; case MU_FLAG_PASSED: return 'P'; case MU_FLAG_REPLIED: return 'R'; case MU_FLAG_SEEN: return 'S'; case MU_FLAG_TRASHED: return 'T'; - + case MU_FLAG_NEW: return 'N'; - - case MU_FLAG_SIGNED: return 's'; + + case MU_FLAG_SIGNED: return 'z'; case MU_FLAG_ENCRYPTED: return 'x'; case MU_FLAG_HAS_ATTACH: return 'a'; @@ -96,22 +96,22 @@ static MuFlags mu_flag_from_char (char kar) { switch (kar) { - - case 'D': return MU_FLAG_DRAFT; - case 'F': return MU_FLAG_FLAGGED; - case 'P': return MU_FLAG_PASSED; - case 'R': return MU_FLAG_REPLIED; - case 'S': return MU_FLAG_SEEN; - case 'T': return MU_FLAG_TRASHED; - case 'N': return MU_FLAG_NEW; - - case 's': return MU_FLAG_SIGNED; - case 'x': return MU_FLAG_ENCRYPTED; - case 'a': return MU_FLAG_HAS_ATTACH; + case 'D': return MU_FLAG_DRAFT; + case 'F': return MU_FLAG_FLAGGED; + case 'P': return MU_FLAG_PASSED; + case 'R': return MU_FLAG_REPLIED; + case 'S': return MU_FLAG_SEEN; + case 'T': return MU_FLAG_TRASHED; + + case 'N': return MU_FLAG_NEW; + + case 'z': return MU_FLAG_SIGNED; + case 'x': return MU_FLAG_ENCRYPTED; + case 'a': return MU_FLAG_HAS_ATTACH; + + case 'u': return MU_FLAG_UNREAD; - case 'u': return MU_FLAG_UNREAD; - default: return MU_FLAG_INVALID; } @@ -123,21 +123,21 @@ const char* mu_flag_name (MuFlags flag) { switch (flag) { - case MU_FLAG_DRAFT: return "draft"; - case MU_FLAG_FLAGGED: return "flagged"; - case MU_FLAG_PASSED: return "passed"; - case MU_FLAG_REPLIED: return "replied"; - case MU_FLAG_SEEN: return "seen"; - case MU_FLAG_TRASHED: return "trashed"; - - case MU_FLAG_NEW: return "new"; - - case MU_FLAG_SIGNED: return "signed"; + case MU_FLAG_DRAFT: return "draft"; + case MU_FLAG_FLAGGED: return "flagged"; + case MU_FLAG_PASSED: return "passed"; + case MU_FLAG_REPLIED: return "replied"; + case MU_FLAG_SEEN: return "seen"; + case MU_FLAG_TRASHED: return "trashed"; + + case MU_FLAG_NEW: return "new"; + + 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"; - + case MU_FLAG_UNREAD: return "unread"; + default: return NULL; } @@ -149,13 +149,13 @@ mu_flags_to_str_s (MuFlags flags, MuFlagType types) { unsigned u,v; static char str[sizeof(FLAG_INFO) + 1]; - - for (u = 0, v = 0; u != G_N_ELEMENTS(FLAG_INFO); ++u) + + for (u = 0, v = 0; u != G_N_ELEMENTS(FLAG_INFO); ++u) if (flags & FLAG_INFO[u].flag && types & FLAG_INFO[u].flag_type) str[v++] = FLAG_INFO[u].kar; str[v] = '\0'; - + return str; } @@ -177,7 +177,7 @@ mu_flags_from_str (const char *str, MuFlagType types) if (mu_flag_type (f) & types) flag |= f; } - + return flag; } @@ -187,9 +187,9 @@ void mu_flags_foreach (MuFlagsForeachFunc func, gpointer user_data) { unsigned u; - + g_return_if_fail (func); - + for (u = 0; u != G_N_ELEMENTS(FLAG_INFO); ++u) func (FLAG_INFO[u].flag, user_data); } @@ -201,7 +201,7 @@ mu_flags_from_str_delta (const char *str, MuFlags oldflags, { const char *cur; MuFlags newflags; - + g_return_val_if_fail (str, MU_FLAG_INVALID); for (cur = str, newflags = oldflags; *cur; ++cur) { @@ -215,18 +215,16 @@ mu_flags_from_str_delta (const char *str, MuFlags oldflags, newflags |= f; else newflags &= ~f; - ++cur; + ++cur; continue; } goto error; } - + return newflags; error: g_warning ("invalid flag string"); return MU_FLAG_INVALID; - + } - - diff --git a/src/mu-store-write.cc b/src/mu-store-write.cc index 8ea98c4c..f2dce569 100644 --- a/src/mu-store-write.cc +++ b/src/mu-store-write.cc @@ -92,7 +92,7 @@ add_synonym_for_flag (MuFlags flag, Xapian::WritableDatabase *db) db->clear_synonyms (pfx + mu_flag_name (flag)); db->add_synonym (pfx + mu_flag_name (flag), pfx + - (std::string(1, tolower(mu_flag_char (flag))))); + (std::string(1, (char)(tolower(mu_flag_char(flag)))))); } @@ -219,7 +219,6 @@ flag_val (char flagchar) { static const std::string pfx (prefix(MU_MSG_FIELD_ID_FLAGS)), - /* xapian wants lowercase */ draftstr (pfx + (char)tolower(mu_flag_char(MU_FLAG_DRAFT))), flaggedstr (pfx + (char)tolower(mu_flag_char(MU_FLAG_FLAGGED))), passedstr (pfx + (char)tolower(mu_flag_char(MU_FLAG_PASSED))), @@ -228,10 +227,10 @@ flag_val (char flagchar) trashedstr (pfx + (char)tolower(mu_flag_char(MU_FLAG_TRASHED))), newstr (pfx + (char)tolower(mu_flag_char(MU_FLAG_NEW))), - signedstr (pfx + mu_flag_char(MU_FLAG_SIGNED)), - encryptedstr (pfx + mu_flag_char(MU_FLAG_ENCRYPTED)), - has_attachstr (pfx + mu_flag_char(MU_FLAG_HAS_ATTACH)), - unreadstr (pfx + mu_flag_char(MU_FLAG_UNREAD)); + signedstr (pfx + (char)tolower(mu_flag_char(MU_FLAG_SIGNED))), + encryptedstr (pfx + (char)tolower(mu_flag_char(MU_FLAG_ENCRYPTED))), + has_attachstr (pfx + (char)tolower(mu_flag_char(MU_FLAG_HAS_ATTACH))), + unreadstr (pfx + (char)tolower(mu_flag_char(MU_FLAG_UNREAD))); switch (flagchar) { @@ -244,7 +243,7 @@ flag_val (char flagchar) case 'N': return newstr; - case 's': return signedstr; + case 'z': return signedstr; case 'x': return encryptedstr; case 'a': return has_attachstr; diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 473c1561..e3392f27 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -126,6 +126,9 @@ EXTRA_DIST= \ testdir/cur/1283599333.1840_11.cthulhu!2, \ testdir/cur/1305664394.2171_402.cthulhu!2, \ testdir/cur/1252168370_3.14675.cthulhu!2,S \ + testdir/cur/signed!2,S \ + testdir/cur/encrypted!2,S \ + testdir/cur/signed-encrypted!2,S \ testdir2/bar/cur/mail1 \ testdir2/bar/cur/mail2 \ testdir2/bar/cur/mail3 \ diff --git a/src/tests/test-mu-flags.c b/src/tests/test-mu-flags.c index 0a8b96f6..43709933 100644 --- a/src/tests/test-mu-flags.c +++ b/src/tests/test-mu-flags.c @@ -14,8 +14,8 @@ ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** */ #if HAVE_CONFIG_H @@ -37,7 +37,7 @@ test_mu_flag_char (void) g_assert_cmpuint (mu_flag_char (MU_FLAG_SEEN), ==, 'S'); g_assert_cmpuint (mu_flag_char (MU_FLAG_TRASHED), ==, 'T'); g_assert_cmpuint (mu_flag_char (MU_FLAG_NEW), ==, 'N'); - g_assert_cmpuint (mu_flag_char (MU_FLAG_SIGNED), ==, 's'); + g_assert_cmpuint (mu_flag_char (MU_FLAG_SIGNED), ==, 'z'); g_assert_cmpuint (mu_flag_char (MU_FLAG_ENCRYPTED), ==, 'x'); g_assert_cmpuint (mu_flag_char (MU_FLAG_HAS_ATTACH), ==, 'a'); g_assert_cmpuint (mu_flag_char (MU_FLAG_UNREAD), ==, 'u'); @@ -68,7 +68,7 @@ test_mu_flags_to_str_s (void) { g_assert_cmpstr (mu_flags_to_str_s(MU_FLAG_PASSED|MU_FLAG_SIGNED, MU_FLAG_TYPE_ANY), - ==, "Ps"); + ==, "Pz"); g_assert_cmpstr (mu_flags_to_str_s(MU_FLAG_NEW, MU_FLAG_TYPE_ANY), ==, "N"); g_assert_cmpstr (mu_flags_to_str_s(MU_FLAG_HAS_ATTACH|MU_FLAG_TRASHED, @@ -76,10 +76,10 @@ test_mu_flags_to_str_s (void) ==, "Ta"); g_assert_cmpstr (mu_flags_to_str_s(MU_FLAG_NONE, MU_FLAG_TYPE_ANY), ==, ""); - + g_assert_cmpstr (mu_flags_to_str_s(MU_FLAG_PASSED|MU_FLAG_SIGNED, MU_FLAG_TYPE_CONTENT), - ==, "s"); + ==, "z"); g_assert_cmpstr (mu_flags_to_str_s(MU_FLAG_NEW, MU_FLAG_TYPE_MAILDIR), ==, "N"); @@ -97,18 +97,18 @@ test_mu_flags_from_str (void) { g_assert_cmpuint (mu_flags_from_str ("RP", MU_FLAG_TYPE_ANY), ==, MU_FLAG_REPLIED | MU_FLAG_PASSED); - g_assert_cmpuint (mu_flags_from_str ("Ns", MU_FLAG_TYPE_ANY), ==, + g_assert_cmpuint (mu_flags_from_str ("Nz", MU_FLAG_TYPE_ANY), ==, MU_FLAG_NEW | MU_FLAG_SIGNED); g_assert_cmpuint (mu_flags_from_str ("axD", MU_FLAG_TYPE_ANY), ==, MU_FLAG_HAS_ATTACH | MU_FLAG_ENCRYPTED | MU_FLAG_DRAFT); g_assert_cmpuint (mu_flags_from_str ("RP", MU_FLAG_TYPE_MAILFILE), ==, MU_FLAG_REPLIED | MU_FLAG_PASSED); - g_assert_cmpuint (mu_flags_from_str ("Ns", MU_FLAG_TYPE_MAILFILE), ==, + g_assert_cmpuint (mu_flags_from_str ("Nz", MU_FLAG_TYPE_MAILFILE), ==, MU_FLAG_NONE); g_assert_cmpuint (mu_flags_from_str ("qwi", MU_FLAG_TYPE_MAILFILE), ==, - MU_FLAG_INVALID); + MU_FLAG_INVALID); } static void @@ -132,9 +132,9 @@ test_mu_flags_from_str_delta (void) /* g_assert_cmpuint (mu_flags_from_str_delta ("foobar", */ /* MU_FLAG_INVALID, */ /* MU_FLAG_TYPE_ANY),==, */ - /* MU_FLAG_INVALID); */ + /* MU_FLAG_INVALID); */ } - + int @@ -156,5 +156,5 @@ main (int argc, char *argv[]) rv = g_test_run (); - return rv; + return rv; } diff --git a/src/tests/test-mu-maildir.c b/src/tests/test-mu-maildir.c index 841c0403..d4bc64d8 100644 --- a/src/tests/test-mu-maildir.c +++ b/src/tests/test-mu-maildir.c @@ -259,7 +259,7 @@ test_mu_maildir_walk_01 (void) &data); g_assert_cmpuint (MU_OK, ==, rv); - g_assert_cmpuint (data._file_count, ==, 13); + g_assert_cmpuint (data._file_count, ==, 16); g_assert_cmpuint (data._dir_entered,==, 5); g_assert_cmpuint (data._dir_left,==, 5); @@ -297,7 +297,7 @@ test_mu_maildir_walk_02 (void) &data); g_assert_cmpuint (MU_OK, ==, rv); - g_assert_cmpuint (data._file_count, ==, 9); + g_assert_cmpuint (data._file_count, ==, 12); g_assert_cmpuint (data._dir_entered,==, 4); g_assert_cmpuint (data._dir_left,==, 4); diff --git a/src/tests/test-mu-query.c b/src/tests/test-mu-query.c index dab1a147..48a39a26 100644 --- a/src/tests/test-mu-query.c +++ b/src/tests/test-mu-query.c @@ -160,7 +160,7 @@ test_mu_query_01 (void) { "foo:pepernoot", 0 }, { "funky", 1 }, { "fünkÿ", 1 }, - { "", 13 } + { "", 16 } }; xpath = fill_database (MU_TESTMAILDIR); @@ -243,9 +243,9 @@ test_mu_query_04 (void) { "baggins", 1}, { "prio:h", 1}, { "prio:high", 1}, - { "prio:normal", 5}, + { "prio:normal", 8}, { "prio:l", 7}, - { "not prio:l", 6}, + { "not prio:l", 9}, }; xpath = fill_database (MU_TESTMAILDIR); @@ -394,11 +394,11 @@ test_mu_query_dates_helsinki (void) /* { "date:20080804..20080731", 5}, */ { "date:20080731..20080804", 5}, { "date:20080731..20080804 s:gcc", 1}, - { "date:200808110803..now", 1}, - { "date:200808110803..today", 1}, + { "date:200808110803..now", 4}, + { "date:200808110803..today", 4}, /* { "date:now..2008-08-11-08-03", 1}, */ /* { "date:today..2008-08-11-08-03", 1}, */ - { "date:200808110801..now", 1}, + { "date:200808110801..now", 4}, }; old_tz = set_tz ("Europe/Helsinki"); @@ -427,11 +427,11 @@ test_mu_query_dates_sydney (void) /* { "date:20080804..20080731", 5}, */ { "date:20080731..20080804", 5}, { "date:20080731..20080804 s:gcc", 1}, - { "date:200808110803..now", 1}, - { "date:200808110803..today", 1}, + { "date:200808110803..now", 4}, + { "date:200808110803..today", 4}, /* { "date:now..2008-08-11-08-03", 1}, */ /* { "date:today..2008-08-11-08-03", 1}, */ - { "date:200808110801..now", 1}, + { "date:200808110801..now", 4}, }; old_tz = set_tz ("Australia/Sydney"); @@ -460,11 +460,11 @@ test_mu_query_dates_la (void) /* { "date:20080804..20080731", 5}, */ { "date:20080731..20080804", 5}, { "date:20080731..20080804 s:gcc", 1}, - { "date:200808110803..now", 0}, - { "date:200808110803..today", 0}, + { "date:200808110803..now", 3}, + { "date:200808110803..today", 3}, /* { "date:now..2008-08-11-08-03", 1}, */ /* { "date:today..2008-08-11-08-03", 1}, */ - { "date:200808110801..now", 0}, /* does not match in LA */ + { "date:200808110801..now", 3}, /* does not match in LA */ }; old_tz = set_tz ("America/Los_Angeles"); @@ -490,9 +490,9 @@ test_mu_query_sizes (void) int i; QResults queries[] = { - { "size:0b..2m", 13}, - { "size:2k..4k", 2}, - { "size:2m..0b", 13} + { "size:0b..2m", 16}, + { "size:2k..4k", 4}, + { "size:2m..0b", 16} }; xpath = fill_database (MU_TESTMAILDIR); @@ -560,6 +560,30 @@ test_mu_query_tags (void) } +static void +test_mu_query_signed_encrypted (void) +{ + gchar *xpath; + int i; + + QResults queries[] = { + { "flag:encrypted", 2}, + { "flag:signed", 2}, + }; + + xpath = fill_database (MU_TESTMAILDIR); + g_assert (xpath != NULL); + + /* g_print ("(%s)\n", xpath); */ + + for (i = 0; i != G_N_ELEMENTS(queries); ++i) + g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query), + ==, queries[i].count); + + g_free (xpath); +} + + static void test_mu_query_tags_02 (void) { @@ -611,7 +635,6 @@ test_mu_query_preprocess (void) - int main (int argc, char *argv[]) { @@ -627,6 +650,9 @@ main (int argc, char *argv[]) g_test_add_func ("/mu-query/test-mu-query-03", test_mu_query_03); g_test_add_func ("/mu-query/test-mu-query-04", test_mu_query_04); + g_test_add_func ("/mu-query/test-mu-query-signed-encrypted", + test_mu_query_signed_encrypted); + g_test_add_func ("/mu-query/test-mu-query-logic", test_mu_query_logic); g_test_add_func ("/mu-query/test-mu-query-accented-chars-1",