Skip to content

Commit 1884719

Browse files
committed
imap: case insensitivity for folders
MAPI folders are already case-insensitive, so apply the same behavior for midb/imapd. With the bad encoding decisions weeded out, this should be easy... now. Fixes: gromox-0~666 References: DESK-2409
1 parent fd5fe4d commit 1884719

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

exch/midb/mail_engine.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ template<typename T> static inline bool
182182
array_find_str(const T &kwlist, const char *s)
183183
{
184184
for (const auto kw : kwlist)
185-
if (strcmp(s, kw) == 0)
185+
if (strcasecmp(s, kw) == 0)
186186
return true;
187187
return false;
188188
}
@@ -337,13 +337,13 @@ static std::unique_ptr<char[]> mail_engine_ct_decode_mime(const char *charset,
337337
end_pos - begin_pos + 1, &encode_string);
338338
auto tmp_len = strlen(encode_string.title);
339339
std::unique_ptr<char[]> tmp_string;
340-
if (0 == strcmp(encode_string.encoding, "base64")) {
340+
if (strcasecmp(encode_string.encoding, "base64") == 0) {
341341
size_t decode_len = 0;
342342
decode64(encode_string.title, tmp_len,
343343
temp_buff, std::size(temp_buff), &decode_len);
344344
temp_buff[decode_len] = '\0';
345345
tmp_string = mail_engine_ct_to_utf8(encode_string.charset, temp_buff);
346-
} else if (0 == strcmp(encode_string.encoding, "quoted-printable")){
346+
} else if (strcasecmp(encode_string.encoding, "quoted-printable") == 0) {
347347
auto decode_len = qp_decode_ex(temp_buff, std::size(temp_buff),
348348
encode_string.title, tmp_len);
349349
if (decode_len < 0)
@@ -1332,7 +1332,7 @@ static std::optional<std::vector<int>> mail_engine_ct_match(const char *charset,
13321332
static uint64_t me_get_folder_id_raw(IDB_ITEM *pidb, std::string_view name)
13331333
{
13341334
auto pstmt = gx_sql_prep(pidb->psqlite, "SELECT "
1335-
"folder_id FROM folders WHERE name=?");
1335+
"folder_id FROM folders WHERE name=? COLLATE NOCASE LIMIT 1");
13361336
if (pstmt == nullptr)
13371337
return 0;
13381338
pstmt.bind_text(1, name);
@@ -1858,7 +1858,7 @@ static BOOL mail_engine_sync_mailbox(IDB_ITEM *pidb,
18581858
parent_fid, folder_id);
18591859
gx_sql_exec(pidb->psqlite, qstr.c_str());
18601860
}
1861-
if (strcmp(encoded_name.c_str(), pstmt1.col_text(3)) != 0) {
1861+
if (strcasecmp(encoded_name.c_str(), pstmt1.col_text(3)) != 0) {
18621862
auto ust = gx_sql_prep(pidb->psqlite, "UPDATE folders SET name=? "
18631863
"WHERE folder_id=?");
18641864
if (ust == nullptr ||
@@ -2455,7 +2455,7 @@ static int mail_engine_mrenf(int argc, char **argv, int sockd)
24552455
if (!system_services_get_user_ids(pidb->username.c_str(), &user_id, nullptr, nullptr))
24562456
return MIDB_E_SSGETID;
24572457
auto pstmt = gx_sql_prep(pidb->psqlite, "SELECT folder_id,"
2458-
" parent_fid FROM folders WHERE name=?");
2458+
" parent_fid FROM folders WHERE name=? COLLATE NOCASE");
24592459
if (pstmt == nullptr)
24602460
return MIDB_E_SQLPREP;
24612461
pstmt.bind_text(1, decoded_name);

lib/dbop_sqlite.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,20 @@ static constexpr char tbl_midb_folders_0[] =
497497
" sort_field INTEGER DEFAULT 0);"
498498
"CREATE INDEX parent_fid_index ON folders(parent_fid);";
499499

500+
static constexpr char tbl_midb_folders_2[] =
501+
"CREATE TABLE folders ("
502+
" folder_id INTEGER PRIMARY KEY,"
503+
" parent_fid INTEGER NOT NULL,"
504+
" commit_max INTEGER NOT NULL,"
505+
" name TEXT NOT NULL COLLATE NOCASE UNIQUE,"
506+
" uidnext INTEGER DEFAULT 0,"
507+
" unsub INTEGER DEFAULT 0,"
508+
" sort_field INTEGER DEFAULT 0);"
509+
"CREATE INDEX parent_fid_index2 ON folders(parent_fid);";
510+
511+
static constexpr char tbl_midb_folders_move2[] =
512+
"INSERT INTO folders SELECT folder_id, parent_fid, commit_max, name, uidnext, unsub, sort_field FROM u0";
513+
500514
static constexpr char tbl_midb_msgs_0[] =
501515
"CREATE TABLE messages ("
502516
" message_id INTEGER PRIMARY KEY,"
@@ -550,7 +564,7 @@ static constexpr tbl_init tbl_midb_init_0[] = {
550564

551565
static constexpr tbl_init tbl_midb_init_top[] = {
552566
{"configurations", tbl_config_1},
553-
{"folders", tbl_midb_folders_0},
567+
{"folders", tbl_midb_folders_2},
554568
{"messages", tbl_midb_msgs_0},
555569
{"mapping", tbl_midb_mapping_0},
556570
TABLE_END,
@@ -602,6 +616,7 @@ static constexpr tblite_upgradefn tbl_pub_upgrade_list[] = {
602616

603617
static constexpr tblite_upgradefn tbl_midb_upgrade_list[] = {
604618
{1, nullptr, "configurations", tbl_config_1, tbl_config_move1},
619+
{2, nullptr, "folders", tbl_midb_folders_2, tbl_midb_folders_move2},
605620
TABLE_END,
606621
};
607622

mra/imap/imap_cmd_parser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void dir_tree::load_from_memfile(const std::vector<enum_folder_t> &pfile) try
129129
if (NULL != pnode) {
130130
do {
131131
auto pdir = static_cast<DIR_NODE *>(pnode->pdata);
132-
if (strcmp(pdir->name, ptr1) == 0)
132+
if (strcasecmp(pdir->name, ptr1) == 0)
133133
break;
134134
} while ((pnode = pnode->get_sibling()) != nullptr);
135135
}
@@ -187,9 +187,9 @@ DIR_NODE *dir_tree::match(const char *path)
187187
return NULL;
188188
do {
189189
pdir = static_cast<DIR_NODE *>(pnode->pdata);
190-
if (strcmp(pdir->name, ptr1) == 0)
190+
if (strcasecmp(pdir->name, ptr1) == 0)
191191
break;
192-
if (level == 0 && strcmp(pdir->name, "INBOX") == 0 &&
192+
if (level == 0 && strcasecmp(pdir->name, "INBOX") == 0 &&
193193
strcasecmp(ptr1, "inbox") == 0)
194194
break;
195195
} while ((pnode = pnode->get_sibling()) != nullptr);
@@ -1618,15 +1618,15 @@ int imap_cmd_parser_create(int argc, char **argv, imap_context *pcontext)
16181618
if (sys_name.size() > 0 && sys_name.back() == '/')
16191619
sys_name.pop_back();
16201620
if (std::any_of(folder_list.cbegin(), folder_list.cend(),
1621-
[&](const enum_folder_t &e) { return strcmp(e.second.c_str(), sys_name.c_str()) == 0; }))
1621+
[&](const enum_folder_t &e) { return strcasecmp(e.second.c_str(), sys_name.c_str()) == 0; }))
16221622
return 1926;
16231623
auto len = sys_name.size();
16241624
for (size_t i = 0; i <= len; ++i) {
16251625
if (sys_name[i] != '/' && sys_name[i] != '\0')
16261626
continue;
16271627
sys_name[i] = '\0';
16281628
if (std::any_of(folder_list.cbegin(), folder_list.cend(),
1629-
[&](const enum_folder_t &e) { return strcmp(e.second.c_str(), sys_name.c_str()) == 0; })) {
1629+
[&](const enum_folder_t &e) { return strcasecmp(e.second.c_str(), sys_name.c_str()) == 0; })) {
16301630
sys_name[i] = '/';
16311631
continue;
16321632
}

0 commit comments

Comments
 (0)