dovecot-2.2: lib-storage: Added mail_thread_type_to_str()
dovecot at dovecot.org
dovecot at dovecot.org
Thu Apr 23 16:21:36 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/3d7b8a09d85d
changeset: 18455:3d7b8a09d85d
user: Timo Sirainen <tss at iki.fi>
date: Thu Apr 23 19:20:00 2015 +0300
description:
lib-storage: Added mail_thread_type_to_str()
diffstat:
src/lib-storage/mail-thread.c | 38 +++++++++++++++++++++++++++++---------
src/lib-storage/mail-thread.h | 2 ++
2 files changed, 31 insertions(+), 9 deletions(-)
diffs (60 lines):
diff -r 274b42b7d0de -r 3d7b8a09d85d src/lib-storage/mail-thread.c
--- a/src/lib-storage/mail-thread.c Thu Apr 23 19:19:10 2015 +0300
+++ b/src/lib-storage/mail-thread.c Thu Apr 23 19:20:00 2015 +0300
@@ -3,15 +3,35 @@
#include "lib.h"
#include "mail-thread.h"
+struct {
+ const char *name;
+ enum mail_thread_type type;
+} mail_thread_type_strings[] = {
+ { "REFERENCES", MAIL_THREAD_REFERENCES },
+ { "REFS", MAIL_THREAD_REFS },
+ { "ORDEREDSUBJECT", MAIL_THREAD_ORDEREDSUBJECT }
+};
+
bool mail_thread_type_parse(const char *str, enum mail_thread_type *type_r)
{
- if (strcasecmp(str, "REFERENCES") == 0)
- *type_r = MAIL_THREAD_REFERENCES;
- else if (strcasecmp(str, "REFS") == 0)
- *type_r = MAIL_THREAD_REFS;
- else if (strcasecmp(str, "ORDEREDSUBJECT") == 0)
- *type_r = MAIL_THREAD_ORDEREDSUBJECT;
- else
- return FALSE;
- return TRUE;
+ unsigned int i;
+
+ for (i = 0; i < N_ELEMENTS(mail_thread_type_strings); i++) {
+ if (strcasecmp(str, mail_thread_type_strings[i].name) == 0) {
+ *type_r = mail_thread_type_strings[i].type;
+ return TRUE;
+ }
+ }
+ return FALSE;
}
+
+const char *mail_thread_type_to_str(enum mail_thread_type type)
+{
+ unsigned int i;
+
+ for (i = 0; i < N_ELEMENTS(mail_thread_type_strings); i++) {
+ if (mail_thread_type_strings[i].type == type)
+ return mail_thread_type_strings[i].name;
+ }
+ i_panic("Unknown mail_thread_type %d", type);
+}
diff -r 274b42b7d0de -r 3d7b8a09d85d src/lib-storage/mail-thread.h
--- a/src/lib-storage/mail-thread.h Thu Apr 23 19:19:10 2015 +0300
+++ b/src/lib-storage/mail-thread.h Thu Apr 23 19:20:00 2015 +0300
@@ -25,6 +25,8 @@
/* Convert thread type string to enum. Returns TRUE if ok, FALSE if type is
unknown. */
bool mail_thread_type_parse(const char *str, enum mail_thread_type *type_r);
+/* Return thread type as string. */
+const char *mail_thread_type_to_str(enum mail_thread_type type);
/* Build thread from given search arguments. args=NULL searches everything. */
int mail_thread_init(struct mailbox *box, struct mail_search_args *args,
More information about the dovecot-cvs
mailing list