@@ -201,12 +201,12 @@ static std::string make_midb_path(const char *d)
201201 return d + " /exmdb/midb.sqlite3" s;
202202}
203203
204- static std::string make_eml_path (const char *d, const char * m)
204+ static std::string make_eml_path (const char *d, std::string_view m)
205205{
206206 return d + " /eml/" s + m;
207207}
208208
209- static std::string make_ext_path (const char *d, const char * m)
209+ static std::string make_ext_path (const char *d, std::string_view m)
210210{
211211 return d + " /ext/" s + m;
212212}
@@ -1382,27 +1382,26 @@ static void me_extract_digest_fields(const Json::Value &digest, char *subject,
13821382}
13831383
13841384static void me_insert_message (xstmt &stm_insert, uint32_t *puidnext,
1385- uint64_t message_id, const char * mid_string, uint32_t message_flags,
1385+ uint64_t message_id, std::string mid_string, uint32_t message_flags,
13861386 uint64_t received_time, uint64_t mod_time) try
13871387{
13881388 size_t size;
13891389 char from[UADDR_SIZE], rcpt[UADDR_SIZE];
13901390 char subject[1024 ];
1391- char mid_string1[128 ];
13921391 MESSAGE_CONTENT *pmsgctnt;
13931392
13941393 auto dir = cu_get_maildir ();
13951394 std::string djson;
1396- if (NULL != mid_string ) {
1395+ if (mid_string. size () > 0 ) {
13971396 auto ext_path = make_ext_path (dir, mid_string);
13981397 size_t slurp_size = 0 ;
13991398 std::unique_ptr<char [], stdlib_delete> slurp_data (HX_slurp_file (ext_path.c_str (), &slurp_size));
14001399 if (slurp_data == nullptr )
1401- mid_string = nullptr ;
1400+ mid_string. clear () ;
14021401 else
14031402 djson.assign (slurp_data.get (), slurp_size);
14041403 }
1405- if (mid_string == nullptr ) {
1404+ if (mid_string. empty () ) {
14061405 if (!cu_switch_allocator ())
14071406 return ;
14081407 if (!exmdb_client::read_message (dir, nullptr , CP_ACP,
@@ -1433,10 +1432,8 @@ static void me_insert_message(xstmt &stm_insert, uint32_t *puidnext,
14331432 return ;
14341433 digest[" file" ] = " " ;
14351434 djson = json_to_str (digest);
1436- snprintf (mid_string1, std::size (mid_string1), " %lld.%u.midb" ,
1437- static_cast <long long >(time (nullptr )), ++g_sequence_id);
1438- mid_string = mid_string1;
1439- auto ext_path = make_ext_path (dir, mid_string1);
1435+ mid_string = std::to_string (time (nullptr )) + " ." + std::to_string (++g_sequence_id) + " .midb" ;
1436+ auto ext_path = make_ext_path (dir, mid_string);
14401437 wrapfd fd = open (ext_path.c_str (), O_CREAT | O_TRUNC | O_WRONLY, FMODE_PRIVATE);
14411438 if (fd.get () < 0 ) {
14421439 mlog (LV_ERR, " E-1770: open %s for write: %s" , ext_path.c_str (), strerror (errno));
@@ -1447,7 +1444,7 @@ static void me_insert_message(xstmt &stm_insert, uint32_t *puidnext,
14471444 mlog (LV_ERR, " E-1134: write %s: %s" , ext_path.c_str (), strerror (errno));
14481445 return ;
14491446 }
1450- auto eml_path = make_eml_path (dir, mid_string1 );
1447+ auto eml_path = make_eml_path (dir, mid_string );
14511448 fd = open (eml_path.c_str (), O_CREAT | O_TRUNC | O_WRONLY, FMODE_PRIVATE);
14521449 if (fd.get () < 0 ) {
14531450 mlog (LV_ERR, " E-1771: open %s for write: %s" , eml_path.c_str (), strerror (errno));
@@ -1513,8 +1510,9 @@ static void me_sync_message(IDB_ITEM *pidb, xstmt &stm_insert,
15131510 " WHERE message_id=%llu" , LLU{message_id});
15141511 if (gx_sql_exec (pidb->psqlite , sql_string) != SQLITE_OK)
15151512 return ;
1516- me_insert_message (stm_insert, puidnext, message_id,
1517- nullptr , e.msg_flags , e.recv_time , e.mod_time );
1513+ /* e.midstr is known to be empty */
1514+ me_insert_message (stm_insert, puidnext, message_id, e.midstr ,
1515+ e.msg_flags , e.recv_time , e.mod_time );
15181516}
15191517
15201518static BOOL me_sync_contents (IDB_ITEM *pidb, uint64_t folder_id) try
0 commit comments