diff --git a/src/mu-maildir.c b/src/mu-maildir.c index c57535cc..eae032fd 100644 --- a/src/mu-maildir.c +++ b/src/mu-maildir.c @@ -830,7 +830,7 @@ char* mu_maildir_get_path_from_flags (const char *oldpath, MuMsgFlags newflags) { char *newname, *newdir, *newpath; - + g_return_val_if_fail (oldpath, NULL); g_return_val_if_fail (newflags != MU_MSG_FLAG_NONE, NULL); /* if MU_MSG_FLAG_NEW is set, it must be the only flag */ diff --git a/src/mu-msg-flags.c b/src/mu-msg-flags.c index 18a4eb3a..3599a7e6 100644 --- a/src/mu-msg-flags.c +++ b/src/mu-msg-flags.c @@ -26,39 +26,38 @@ #include "mu-msg-flags.h" -/* put these in alpha-order, so output strings are ordered thusly - * note, these should be in lower-case, otherwise Xapian gets - * confused... +/* put these in alpha-order, so output strings are ordered correctly + * (that's the way the Maildir spec teaches us) */ static const MuMsgFlags ALL_FLAGS[] = { - /* a */ MU_MSG_FLAG_HAS_ATTACH, - /* d */ MU_MSG_FLAG_DRAFT, - /* f */ MU_MSG_FLAG_FLAGGED, - /* n */ MU_MSG_FLAG_NEW, - /* p */ MU_MSG_FLAG_PASSED, - /* r */ MU_MSG_FLAG_REPLIED, - /* s */ MU_MSG_FLAG_SEEN, - /* t */ MU_MSG_FLAG_TRASHED, - /* u */ MU_MSG_FLAG_UNREAD, - /* x */ MU_MSG_FLAG_ENCRYPTED, - /* z */ MU_MSG_FLAG_SIGNED + /* a */ MU_MSG_FLAG_HAS_ATTACH, /* non-maildir flag */ + /* D */ MU_MSG_FLAG_DRAFT, + /* F */ MU_MSG_FLAG_FLAGGED, + /* N */ MU_MSG_FLAG_NEW, + /* P */ MU_MSG_FLAG_PASSED, + /* R */ MU_MSG_FLAG_REPLIED, + /* S */ MU_MSG_FLAG_SEEN, + /* T */ MU_MSG_FLAG_TRASHED, + /* U */ MU_MSG_FLAG_UNREAD, /* pseudo flag */ + /* x */ MU_MSG_FLAG_ENCRYPTED, /* non-maildir flag */ + /* z */ MU_MSG_FLAG_SIGNED /* non-maildir flag */ }; MuMsgFlags mu_msg_flag_from_char (char k) { - switch (g_ascii_tolower(k)) { - case 'n': return MU_MSG_FLAG_NEW; - case 'p': return MU_MSG_FLAG_PASSED; - case 'r': return MU_MSG_FLAG_REPLIED; - case 's': return MU_MSG_FLAG_SEEN; - case 't': return MU_MSG_FLAG_TRASHED; - case 'd': return MU_MSG_FLAG_DRAFT; - case 'f': return MU_MSG_FLAG_FLAGGED; + switch (k) { + case 'N': return MU_MSG_FLAG_NEW; + case 'P': return MU_MSG_FLAG_PASSED; + case 'R': return MU_MSG_FLAG_REPLIED; + case 'S': return MU_MSG_FLAG_SEEN; + case 'T': return MU_MSG_FLAG_TRASHED; + case 'D': return MU_MSG_FLAG_DRAFT; + case 'F': return MU_MSG_FLAG_FLAGGED; - /* NEW OR NOT SEEN */ - case 'u': return MU_MSG_FLAG_UNREAD; + /* NEW OR NOT SEEN */ + case 'U': return MU_MSG_FLAG_UNREAD; case 'z': return MU_MSG_FLAG_SIGNED; case 'x': return MU_MSG_FLAG_ENCRYPTED; @@ -75,7 +74,6 @@ mu_msg_flag_from_file_char (char k) switch (k) { case 'D': return MU_MSG_FLAG_DRAFT; case 'F': return MU_MSG_FLAG_FLAGGED; - case 'N': return MU_MSG_FLAG_NEW; case 'P': return MU_MSG_FLAG_PASSED; case 'R': return MU_MSG_FLAG_REPLIED; case 'S': return MU_MSG_FLAG_SEEN; @@ -114,18 +112,20 @@ mu_msg_flag_name (MuMsgFlags flag) char mu_msg_flag_char (MuMsgFlags flag) { + g_return_val_if_fail (flag != MU_MSG_FLAG_NONE, 0); + switch (flag) { - case MU_MSG_FLAG_NEW: return 'n'; - case MU_MSG_FLAG_PASSED: return 'p'; - case MU_MSG_FLAG_REPLIED: return 'r'; - case MU_MSG_FLAG_SEEN: return 's'; - case MU_MSG_FLAG_TRASHED: return 't'; - case MU_MSG_FLAG_DRAFT: return 'd'; - case MU_MSG_FLAG_FLAGGED: return 'f'; + case MU_MSG_FLAG_NEW: return 'N'; + case MU_MSG_FLAG_PASSED: return 'P'; + case MU_MSG_FLAG_REPLIED: return 'R'; + case MU_MSG_FLAG_SEEN: return 'S'; + case MU_MSG_FLAG_TRASHED: return 'T'; + case MU_MSG_FLAG_DRAFT: return 'D'; + case MU_MSG_FLAG_FLAGGED: return 'F'; /* NEW OR NOT SEEN */ - case MU_MSG_FLAG_UNREAD: return 'u'; + case MU_MSG_FLAG_UNREAD: return 'U'; case MU_MSG_FLAG_SIGNED: return 'z'; case MU_MSG_FLAG_ENCRYPTED: return 'x'; @@ -162,7 +162,7 @@ mu_msg_flags_from_str (const char* str) for (flags = MU_MSG_FLAG_NONE; str && *str; ++str) { MuMsgFlags flag; - if ((flag = mu_msg_flag_char (*str)) == 0) { + if ((flag = mu_msg_flag_from_char (*str)) == 0) { flags = 0; break; } @@ -184,3 +184,5 @@ mu_msg_flags_foreach (MuMsgFlagsForeachFunc func, gpointer user_data) func (ALL_FLAGS[i], user_data); } + + diff --git a/src/mu-msg-flags.h b/src/mu-msg-flags.h index 4a2f83f8..cbdf8128 100644 --- a/src/mu-msg-flags.h +++ b/src/mu-msg-flags.h @@ -71,21 +71,22 @@ enum _MuMsgFlags { /* "x"->encrypted message */ MU_MSG_FLAG_ENCRYPTED = 1 << 9, /* "a"->message has attachment */ - MU_MSG_FLAG_HAS_ATTACH = 1 << 10 + MU_MSG_FLAG_HAS_ATTACH = 1 << 10, }; typedef enum _MuMsgFlags MuMsgFlags; +#define MU_MSG_FLAG_INVALID (-1) + /** * convert the char-per-flag description into a MuMsgFlags value; the - * characters - * D=draft,F=flagged,N=new,P=passed,R=replied,S=seen,T=trashed - * a=has-attachment,s=signed, x=encrypted if any other characters are - * seen, MU_MSG_FLAG_NONE is returned. + * characters D=draft, F=flagged, N=new, P=passed, R=replied, S=seen, + * T=trashed a=has-attachment, s=signed, x=encrypted are accepted; if + * any other characters are seen, MU_MSG_FLAG_INVALID is returned. * * @param str a string * - * @return a MuMSgFlags value, or MU_MSG_FLAG_UNKNOWN in case of error + * @return a MuMSgFlags value, or MU_MSG_FLAG_INVALID in case of error */ MuMsgFlags mu_msg_flags_from_str (const char* str) G_GNUC_PURE; diff --git a/src/mu-store.cc b/src/mu-store.cc index caa2a04e..eb57d374 100644 --- a/src/mu-store.cc +++ b/src/mu-store.cc @@ -179,7 +179,8 @@ check_version (MuStore *store) } MuStore* -mu_store_new (const char* xpath, const char *contacts_cache, +mu_store_new (const char* xpath, + const char *contacts_cache, GError **err) { g_return_val_if_fail (xpath, NULL); @@ -645,7 +646,7 @@ mu_store_store_msg (MuStore *store, MuMsg *msg, gboolean replace) (msg, (MuMsgContactForeachFunc)each_contact_info, &msgdoc); - + /* add_document is slightly faster, we can use it when * we know the document does not exist yet, eg., in diff --git a/src/mu-store.h b/src/mu-store.h index f5d123cb..4a3e977d 100644 --- a/src/mu-store.h +++ b/src/mu-store.h @@ -41,16 +41,15 @@ typedef struct _MuStore MuStore; * * @return a new MuStore object, or NULL in case of error */ -MuStore* mu_store_new (const char *xpath, const char *ccachepath, - GError **err) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; - +MuStore* mu_store_new (const char *xpath, const char *ccachepath, + GError **err) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; /** * destroy the MuStore object and free resources * * @param store a valid store, or NULL */ -void mu_store_destroy (MuStore *store); +void mu_store_destroy (MuStore *store);