From 895ab10a4bd7ff7d06589e19c7cd0231ec0274f2 Mon Sep 17 00:00:00 2001 From: djcb Date: Fri, 1 Jun 2012 14:03:43 +0200 Subject: [PATCH] * optionally ignore invalid (unknown) message flag letters, update callers --- lib/mu-flags.c | 10 +++++++++- lib/mu-flags.h | 9 +++++---- lib/mu-maildir.c | 5 +++-- lib/mu-msg.c | 2 +- lib/mu-msg.h | 4 ++-- mu/mu-cmd-server.c | 3 ++- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/mu-flags.c b/lib/mu-flags.c index 45b8056f..4c66002c 100644 --- a/lib/mu-flags.c +++ b/lib/mu-flags.c @@ -162,7 +162,8 @@ mu_flags_to_str_s (MuFlags flags, MuFlagType types) MuFlags -mu_flags_from_str (const char *str, MuFlagType types) +mu_flags_from_str (const char *str, MuFlagType types, + gboolean ignore_invalid) { const char *cur; MuFlags flag; @@ -174,6 +175,13 @@ mu_flags_from_str (const char *str, MuFlagType types) MuFlags f; f = mu_flag_from_char (*cur); + + if (f == MU_FLAG_INVALID) { + if (ignore_invalid) + continue; + return MU_FLAG_INVALID; + } + if (mu_flag_type (f) & types) flag |= f; } diff --git a/lib/mu-flags.h b/lib/mu-flags.h index c1cc1c85..62020d98 100644 --- a/lib/mu-flags.h +++ b/lib/mu-flags.h @@ -115,13 +115,14 @@ const char* mu_flags_to_str_s (MuFlags flags, MuFlagType types); * Get the (OR'ed) flags corresponding to a string representation * * @param str the string representation - * @param types the flag types to acceps (other will be ignored) + * @param types the flag types to accept (other will be ignored) + * @param ignore invalid if TRUE, ignore invalid flags, otherwise return + * MU_FLAG_INVALID if an invalid flag is encountered * * @return the (OR'ed) flags */ -MuFlags mu_flags_from_str (const char *str, MuFlagType types); - - +MuFlags mu_flags_from_str (const char *str, MuFlagType types, + gboolean ignore_invalid); /** * Update #oldflags with the flags in #str, where #str consists of the diff --git a/lib/mu-maildir.c b/lib/mu-maildir.c index 5a34961f..cf8b77bb 100644 --- a/lib/mu-maildir.c +++ b/lib/mu-maildir.c @@ -690,8 +690,9 @@ mu_maildir_get_flags_from_path (const char *path) (info[1] != ',')) return MU_FLAG_NONE; else - return mu_flags_from_str (&info[2], - MU_FLAG_TYPE_MAILFILE); + return mu_flags_from_str + (&info[2], MU_FLAG_TYPE_MAILFILE, + TRUE /*ignore invalid */); } } diff --git a/lib/mu-msg.c b/lib/mu-msg.c index 72c6ded4..58d2dcbe 100644 --- a/lib/mu-msg.c +++ b/lib/mu-msg.c @@ -677,7 +677,7 @@ mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func, static int -cmp_str (const char* s1, const char *s2) +cmp_str (const char *s1, const char *s2) { if (s1 == s2) return 0; diff --git a/lib/mu-msg.h b/lib/mu-msg.h index 6a846f83..679a758e 100644 --- a/lib/mu-msg.h +++ b/lib/mu-msg.h @@ -250,8 +250,8 @@ time_t mu_msg_get_date (MuMsg *msg); * * @param msg valid MuMsg* instance * - * @return the fileflags as logically OR'd #Mu MsgFlags or 0 if - * there are none. + * @return the file/content flags as logically OR'd #MuMsgFlags or 0 + * if there are none. Non-standard flags are ignored. */ MuFlags mu_msg_get_flags (MuMsg *msg); diff --git a/mu/mu-cmd-server.c b/mu/mu-cmd-server.c index 5c52eb94..c0f438d4 100644 --- a/mu/mu-cmd-server.c +++ b/mu/mu-cmd-server.c @@ -832,7 +832,8 @@ get_flags (const char *path, const char *flagstr) return mu_flags_from_str_delta (flagstr, oldflags, MU_FLAG_TYPE_ANY); } else - return mu_flags_from_str (flagstr, MU_FLAG_TYPE_ANY); + return mu_flags_from_str (flagstr, MU_FLAG_TYPE_ANY, + TRUE /*ignore invalid*/); } }