bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
1375d15975f97aa90ee49738366baf3fa7b8972dTimo Sirainen
1375d15975f97aa90ee49738366baf3fa7b8972dTimo Sirainen#include "lib.h"
1375d15975f97aa90ee49738366baf3fa7b8972dTimo Sirainen#include "mail-thread.h"
1375d15975f97aa90ee49738366baf3fa7b8972dTimo Sirainen
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainenstruct {
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen const char *name;
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen enum mail_thread_type type;
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen} mail_thread_type_strings[] = {
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen { "REFERENCES", MAIL_THREAD_REFERENCES },
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen { "REFS", MAIL_THREAD_REFS },
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen { "ORDEREDSUBJECT", MAIL_THREAD_ORDEREDSUBJECT }
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen};
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen
1375d15975f97aa90ee49738366baf3fa7b8972dTimo Sirainenbool mail_thread_type_parse(const char *str, enum mail_thread_type *type_r)
1375d15975f97aa90ee49738366baf3fa7b8972dTimo Sirainen{
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen unsigned int i;
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen for (i = 0; i < N_ELEMENTS(mail_thread_type_strings); i++) {
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen if (strcasecmp(str, mail_thread_type_strings[i].name) == 0) {
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen *type_r = mail_thread_type_strings[i].type;
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen return TRUE;
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen }
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen }
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen return FALSE;
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen}
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainenconst char *mail_thread_type_to_str(enum mail_thread_type type)
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen{
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen unsigned int i;
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen for (i = 0; i < N_ELEMENTS(mail_thread_type_strings); i++) {
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen if (mail_thread_type_strings[i].type == type)
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen return mail_thread_type_strings[i].name;
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen }
4fe4f6e1350c486f8e3e7ab6f9da9ff427162802Timo Sirainen i_panic("Unknown mail_thread_type %d", type);
1375d15975f97aa90ee49738366baf3fa7b8972dTimo Sirainen}