Skip to content

Commit b76ebf8

Browse files
committed
midb: consolidate open-coded flag characters
1 parent a0dae4d commit b76ebf8

File tree

3 files changed

+63
-52
lines changed

3 files changed

+63
-52
lines changed

exch/midb/mail_engine.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,8 +2179,8 @@ static int me_minst(int argc, char **argv, int sockd) try
21792179
uint64_t message_id;
21802180
char sql_string[1024];
21812181

2182-
uint8_t b_unsent = strchr(argv[4], 'U') != nullptr;
2183-
uint8_t b_read = strchr(argv[4], 'S') != nullptr;
2182+
uint8_t b_unsent = strchr(argv[4], midb_flag::unsent) != nullptr;
2183+
uint8_t b_read = strchr(argv[4], midb_flag::seen) != nullptr;
21842184
auto eml_path = make_eml_path(argv[1], argv[3]);
21852185
size_t slurp_size = 0;
21862186
std::unique_ptr<char[], stdlib_delete> pbuff(HX_slurp_file(eml_path.c_str(), &slurp_size));
@@ -2805,19 +2805,19 @@ static int simu_query(IDB_ITEM *pidb, const char *sql_string,
28052805
sn.uid = pstmt.col_int64(2);
28062806
sn.flags = "(";
28072807
if (pstmt.col_int64(3) != 0)
2808-
sn.flags += 'A';
2808+
sn.flags += midb_flag::answered;
28092809
if (pstmt.col_int64(4) != 0)
2810-
sn.flags += 'U';
2810+
sn.flags += midb_flag::unsent;
28112811
if (pstmt.col_int64(5) != 0)
2812-
sn.flags += 'F';
2812+
sn.flags += midb_flag::flagged;
28132813
if (pstmt.col_int64(6) != 0)
2814-
sn.flags += 'D';
2814+
sn.flags += midb_flag::deleted;
28152815
if (pstmt.col_int64(7) != 0)
2816-
sn.flags += 'S';
2816+
sn.flags += midb_flag::seen;
28172817
if (pstmt.col_int64(8) != 0)
2818-
sn.flags += 'R';
2818+
sn.flags += midb_flag::recent;
28192819
if (pstmt.col_int64(9) != 0)
2820-
sn.flags += 'W';
2820+
sn.flags += midb_flag::forwarded;
28212821
sn.flags += ')';
28222822
sn.size = pstmt.col_uint64(10);
28232823
temp_list.push_back(std::move(sn));
@@ -3107,12 +3107,12 @@ static int me_psflg(int argc, char **argv, int sockd)
31073107
return MIDB_E_NO_MESSAGE;
31083108
message_id = sqlite3_column_int64(pstmt, 0);
31093109
pstmt.finalize();
3110-
if (NULL != strchr(argv[4], 'A')) {
3110+
if (strchr(argv[4], midb_flag::answered) != nullptr) {
31113111
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET replied=1"
31123112
" WHERE message_id=%llu", LLU{message_id});
31133113
gx_sql_exec(pidb->psqlite, sql_string);
31143114
}
3115-
if (NULL != strchr(argv[4], 'U')) {
3115+
if (strchr(argv[4], midb_flag::unsent) != nullptr) {
31163116
static constexpr proptag_t tmp_proptag[] = {PR_MESSAGE_FLAGS};
31173117
static constexpr PROPTAG_ARRAY proptags = {std::size(tmp_proptag), deconst(tmp_proptag)};
31183118
if (!exmdb_client::get_message_properties(argv[1], NULL,
@@ -3129,26 +3129,26 @@ static int me_psflg(int argc, char **argv, int sockd)
31293129
return MIDB_E_MDB_SETMSGPROPS;
31303130
}
31313131
}
3132-
if (NULL != strchr(argv[4], 'F')) {
3132+
if (strchr(argv[4], midb_flag::flagged) != nullptr) {
31333133
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET flagged=1"
31343134
" WHERE message_id=%llu", LLU{message_id});
31353135
gx_sql_exec(pidb->psqlite, sql_string);
31363136
}
3137-
if (NULL != strchr(argv[4], 'W')) {
3137+
if (strchr(argv[4], midb_flag::forwarded) != nullptr) {
31383138
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET forwarded=1"
31393139
" WHERE message_id=%llu", LLU{message_id});
31403140
gx_sql_exec(pidb->psqlite, sql_string);
31413141
}
3142-
if (NULL != strchr(argv[4], 'D')) {
3142+
if (strchr(argv[4], midb_flag::deleted) != nullptr) {
31433143
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET deleted=1"
31443144
" WHERE message_id=%llu", LLU{message_id});
31453145
gx_sql_exec(pidb->psqlite, sql_string);
31463146
}
3147-
if (strchr(argv[4], 'S') != nullptr &&
3147+
if (strchr(argv[4], midb_flag::seen) != nullptr &&
31483148
!exmdb_client::set_message_read_state(argv[1], nullptr,
31493149
rop_util_make_eid_ex(1, message_id), 1, &read_cn))
31503150
return MIDB_E_MDB_SETMSGRD;
3151-
if (NULL != strchr(argv[4], 'R')) {
3151+
if (strchr(argv[4], midb_flag::recent) != nullptr) {
31523152
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET recent=1"
31533153
" WHERE message_id=%llu", LLU{message_id});
31543154
gx_sql_exec(pidb->psqlite, sql_string);
@@ -3189,12 +3189,12 @@ static int me_prflg(int argc, char **argv, int sockd)
31893189
return MIDB_E_NO_MESSAGE;
31903190
message_id = sqlite3_column_int64(pstmt, 0);
31913191
pstmt.finalize();
3192-
if (NULL != strchr(argv[4], 'A')) {
3192+
if (NULL != strchr(argv[4], midb_flag::answered)) {
31933193
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET replied=0"
31943194
" WHERE message_id=%llu", LLU{message_id});
31953195
gx_sql_exec(pidb->psqlite, sql_string);
31963196
}
3197-
if (NULL != strchr(argv[4], 'U')) {
3197+
if (strchr(argv[4], midb_flag::unsent) != nullptr) {
31983198
static constexpr proptag_t tmp_proptag[] = {PR_MESSAGE_FLAGS};
31993199
static constexpr PROPTAG_ARRAY proptags = {std::size(tmp_proptag), deconst(tmp_proptag)};
32003200
if (!exmdb_client::get_message_properties(argv[1], nullptr,
@@ -3211,26 +3211,26 @@ static int me_prflg(int argc, char **argv, int sockd)
32113211
return MIDB_E_MDB_SETMSGPROPS;
32123212
}
32133213
}
3214-
if (NULL != strchr(argv[4], 'F')) {
3214+
if (strchr(argv[4], midb_flag::flagged) != nullptr) {
32153215
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET flagged=0"
32163216
" WHERE message_id=%llu", LLU{message_id});
32173217
gx_sql_exec(pidb->psqlite, sql_string);
32183218
}
3219-
if (NULL != strchr(argv[4], 'W')) {
3219+
if (strchr(argv[4], midb_flag::forwarded) != nullptr) {
32203220
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET forwarded=0"
32213221
" WHERE message_id=%llu", LLU{message_id});
32223222
gx_sql_exec(pidb->psqlite, sql_string);
32233223
}
3224-
if (NULL != strchr(argv[4], 'D')) {
3224+
if (strchr(argv[4], midb_flag::deleted) != nullptr) {
32253225
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET deleted=0"
32263226
" WHERE message_id=%llu", LLU{message_id});
32273227
gx_sql_exec(pidb->psqlite, sql_string);
32283228
}
3229-
if (strchr(argv[4], 'S') != nullptr &&
3229+
if (strchr(argv[4], midb_flag::seen) != nullptr &&
32303230
!exmdb_client::set_message_read_state(argv[1], nullptr,
32313231
rop_util_make_eid_ex(1, message_id), 0, &read_cn))
32323232
return MIDB_E_MDB_SETMSGRD;
3233-
if (NULL != strchr(argv[4], 'R')) {
3233+
if (strchr(argv[4], midb_flag::recent) != nullptr) {
32343234
snprintf(sql_string, std::size(sql_string), "UPDATE messages SET recent=0"
32353235
" WHERE message_id=%llu", LLU{message_id});
32363236
gx_sql_exec(pidb->psqlite, sql_string);
@@ -3270,13 +3270,13 @@ static int me_pgflg(int argc, char **argv, int sockd) try
32703270
gx_sql_col_uint64(pstmt, 0) != folder_id)
32713271
return MIDB_E_NO_MESSAGE;
32723272
std::string ans = "TRUE (";
3273-
if (pstmt.col_int64(5) != 0) ans += 'A';
3274-
if (pstmt.col_int64(3) != 0) ans += 'U';
3275-
if (pstmt.col_int64(4) != 0) ans += 'F';
3276-
if (pstmt.col_int64(6) != 0) ans += 'W';
3277-
if (pstmt.col_int64(7) != 0) ans += 'D';
3278-
if (pstmt.col_int64(2) != 0) ans += 'S';
3279-
if (pstmt.col_int64(1) != 0) ans += 'R';
3273+
if (pstmt.col_int64(5) != 0) ans += midb_flag::answered;
3274+
if (pstmt.col_int64(3) != 0) ans += midb_flag::unsent;
3275+
if (pstmt.col_int64(4) != 0) ans += midb_flag::flagged;
3276+
if (pstmt.col_int64(6) != 0) ans += midb_flag::forwarded;
3277+
if (pstmt.col_int64(7) != 0) ans += midb_flag::deleted;
3278+
if (pstmt.col_int64(2) != 0) ans += midb_flag::seen;
3279+
if (pstmt.col_int64(1) != 0) ans += midb_flag::recent;
32803280
pstmt.finalize();
32813281
pidb.reset();
32823282
ans += ")\r\n";
@@ -3567,17 +3567,17 @@ static void notif_msg_added(IDB_ITEM *pidb,
35673567
me_insert_message(pstmt, &uidnext, message_id,
35683568
syncmessage_entry{mod_time, received_time, message_flags, str});
35693569
pstmt.finalize();
3570-
if (flags_buff.find('F') != flags_buff.npos) {
3570+
if (flags_buff.find(midb_flag::flagged) != flags_buff.npos) {
35713571
qstr = fmt::format("UPDATE messages SET "
35723572
"flagged=1 WHERE message_id={}", message_id);
35733573
gx_sql_exec(pidb->psqlite, qstr.c_str());
35743574
}
3575-
if (flags_buff.find('A') != flags_buff.npos) {
3575+
if (flags_buff.find(midb_flag::answered) != flags_buff.npos) {
35763576
qstr = fmt::format("UPDATE messages SET "
35773577
"replied=1 WHERE message_id={}", message_id);
35783578
gx_sql_exec(pidb->psqlite, qstr.c_str());
35793579
}
3580-
if (flags_buff.find('W') != flags_buff.npos) {
3580+
if (flags_buff.find(midb_flag::forwarded) != flags_buff.npos) {
35813581
qstr = fmt::format("UPDATE messages SET "
35823582
"forwarded=1 WHERE message_id={}", message_id);
35833583
gx_sql_exec(pidb->psqlite, qstr.c_str());

include/gromox/midb.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ enum {
4040
MIDB_E_ACCESS_DENIED,
4141
MIDB_E_NOTPERMITTED,
4242
};
43+
44+
enum midb_flag : char {
45+
answered = 'A',
46+
deleted = 'D',
47+
flagged = 'F',
48+
recent = 'R',
49+
seen = 'S',
50+
unsent = 'U',
51+
forwarded = 'W',
52+
};

mra/midb_agent.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-only WITH linking exception
2-
// SPDX-FileCopyrightText: 2021–2024 grommunio GmbH
2+
// SPDX-FileCopyrightText: 2021–2025 grommunio GmbH
33
// This file is part of Gromox.
44
#include <algorithm>
55
#include <atomic>
@@ -34,6 +34,7 @@
3434
#include <gromox/fileio.h>
3535
#include <gromox/json.hpp>
3636
#include <gromox/list_file.hpp>
37+
#include <gromox/midb.hpp>
3738
#include <gromox/midb_agent.hpp>
3839
#include <gromox/process.hpp>
3940
#include <gromox/range_set.hpp>
@@ -1119,17 +1120,17 @@ int remove_mail(const char *path, const std::string &folder,
11191120
static unsigned int s_to_flagbits(const char *s)
11201121
{
11211122
unsigned int fl = 0;
1122-
if (strchr(s, 'A') != nullptr)
1123+
if (strchr(s, midb_flag::answered) != nullptr)
11231124
fl |= FLAG_ANSWERED;
1124-
if (strchr(s, 'U') != nullptr)
1125+
if (strchr(s, midb_flag::unsent) != nullptr)
11251126
fl |= FLAG_DRAFT;
1126-
if (strchr(s, 'F') != nullptr)
1127+
if (strchr(s, midb_flag::flagged) != nullptr)
11271128
fl |= FLAG_FLAGGED;
1128-
if (strchr(s, 'D') != nullptr)
1129+
if (strchr(s, midb_flag::deleted) != nullptr)
11291130
fl |= FLAG_DELETED;
1130-
if (strchr(s, 'S') != nullptr)
1131+
if (strchr(s, midb_flag::seen) != nullptr)
11311132
fl |= FLAG_SEEN;
1132-
if (strchr(s, 'R') != nullptr)
1133+
if (strchr(s, midb_flag::recent) != nullptr)
11331134
fl |= FLAG_RECENT;
11341135
return fl;
11351136
}
@@ -1576,17 +1577,17 @@ int set_flags(const char *path, const std::string &folder,
15761577
flags_string[0] = '(';
15771578
int length = 1;
15781579
if (flag_bits & FLAG_ANSWERED)
1579-
flags_string[length++] = 'A';
1580+
flags_string[length++] = midb_flag::answered;
15801581
if (flag_bits & FLAG_DRAFT)
1581-
flags_string[length++] = 'U';
1582+
flags_string[length++] = midb_flag::unsent;
15821583
if (flag_bits & FLAG_FLAGGED)
1583-
flags_string[length++] = 'F';
1584+
flags_string[length++] = midb_flag::flagged;
15841585
if (flag_bits & FLAG_DELETED)
1585-
flags_string[length++] = 'D';
1586+
flags_string[length++] = midb_flag::deleted;
15861587
if (flag_bits & FLAG_SEEN)
1587-
flags_string[length++] = 'S';
1588+
flags_string[length++] = midb_flag::seen;
15881589
if (flag_bits & FLAG_RECENT)
1589-
flags_string[length++] = 'R';
1590+
flags_string[length++] = midb_flag::recent;
15901591
flags_string[length++] = ')';
15911592
flags_string[length] = '\0';
15921593
length = gx_snprintf(buff, std::size(buff), "P-SFLG %s %s %s %s\r\n",
@@ -1618,17 +1619,17 @@ int unset_flags(const char *path, const std::string &folder,
16181619
flags_string[0] = '(';
16191620
int length = 1;
16201621
if (flag_bits & FLAG_ANSWERED)
1621-
flags_string[length++] = 'A';
1622+
flags_string[length++] = midb_flag::answered;
16221623
if (flag_bits & FLAG_DRAFT)
1623-
flags_string[length++] = 'U';
1624+
flags_string[length++] = midb_flag::unsent;
16241625
if (flag_bits & FLAG_FLAGGED)
1625-
flags_string[length++] = 'F';
1626+
flags_string[length++] = midb_flag::flagged;
16261627
if (flag_bits & FLAG_DELETED)
1627-
flags_string[length++] = 'D';
1628+
flags_string[length++] = midb_flag::deleted;
16281629
if (flag_bits & FLAG_SEEN)
1629-
flags_string[length++] = 'S';
1630+
flags_string[length++] = midb_flag::seen;
16301631
if (flag_bits & FLAG_RECENT)
1631-
flags_string[length++] = 'R';
1632+
flags_string[length++] = midb_flag::recent;
16321633
flags_string[length++] = ')';
16331634
flags_string[length] = '\0';
16341635
length = gx_snprintf(buff, std::size(buff), "P-RFLG %s %s %s %s\r\n",

0 commit comments

Comments
 (0)