@@ -331,13 +331,7 @@ namespace midb_agent {
331331int list_mail (const char *path, const std::string &folder,
332332 std::vector<MSG_UNIT> &parray, int *pnum, uint64_t *psize)
333333{
334- int i;
335- int lines;
336- int count;
337- int offset;
338- BOOL b_fail;
339334 int last_pos;
340- int read_len;
341335 int line_pos;
342336 char temp_line[512 ];
343337 char buff[256 *1025 ];
@@ -353,24 +347,22 @@ int list_mail(const char *path, const std::string &folder,
353347 return MIDB_RDWR_ERROR;
354348
355349 *psize = 0 ;
356- count = 0 ;
357- offset = 0 ;
358- lines = -1 ;
359- b_fail = FALSE ;
350+ int count = 0 , offset = 0 , lines = -1 ;
351+ BOOL b_fail = false ;
360352 while (true ) {
361353 pfd_read.fd = pback->sockd ;
362354 pfd_read.events = POLLIN|POLLPRI;
363355 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
364356 return MIDB_RDWR_ERROR;
365357 static_assert (std::size (buff) >= 256 *1024 + 1 );
366- read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
358+ int read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
367359 if (read_len <= 0 )
368360 return MIDB_RDWR_ERROR;
369361 offset += read_len;
370362 buff[offset] = ' \0 ' ;
371363
372364 if (-1 == lines) {
373- for (i= 0 ; i< offset- 1 &&i< 36 ; i++ ) {
365+ for (int i = 0 ; i < offset - 1 && i < 36 ; ++i ) {
374366 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
375367 continue ;
376368 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -394,7 +386,7 @@ int list_mail(const char *path, const std::string &folder,
394386 }
395387 }
396388
397- for (i= last_pos; i< offset; i++ ) {
389+ for (int i = last_pos; i < offset; ++i ) {
398390 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
399391 count ++;
400392 continue ;
@@ -464,8 +456,6 @@ static int rw_command(int fd, char *buff, size_t olen, size_t ilen)
464456int delete_mail (const char *path, const std::string &folder,
465457 const std::vector<MSG_UNIT *> &plist)
466458{
467- int cmd_len;
468- int temp_len;
469459 char buff[128 *1025 ];
470460
471461 if (plist.size () == 0 )
@@ -475,11 +465,11 @@ int delete_mail(const char *path, const std::string &folder,
475465 return MIDB_NO_SERVER;
476466 auto length = gx_snprintf (buff, std::size (buff), " M-DELE %s %s" ,
477467 path, folder.c_str ());
478- cmd_len = length;
468+ int cmd_len = length;
479469
480470 for (auto pmsg : plist) {
481471 buff[length++] = ' ' ;
482- temp_len = pmsg->file_name .size ();
472+ auto temp_len = pmsg->file_name .size ();
483473 memcpy (buff + length, pmsg->file_name .c_str (), temp_len);
484474 length += temp_len;
485475 if (length <= 128 * 1024 )
@@ -826,12 +816,7 @@ int unsubscribe_folder(const char *path, const std::string &folder, int *perrno)
826816int enum_folders (const char *path, std::vector<enum_folder_t > &pfile,
827817 int *perrno) try
828818{
829- int i;
830- int lines;
831- int count;
832- int offset;
833819 int last_pos;
834- int read_len;
835820 int line_pos;
836821 char temp_line[512 ];
837822 char buff[256 *1025 ];
@@ -844,23 +829,21 @@ int enum_folders(const char *path, std::vector<enum_folder_t> &pfile,
844829 if (write (pback->sockd , buff, length) != length)
845830 return MIDB_RDWR_ERROR;
846831
847- count = 0 ;
848- offset = 0 ;
849- lines = -1 ;
832+ int count = 0 , offset = 0 , lines = -1 ;
850833 while (true ) {
851834 pfd_read.fd = pback->sockd ;
852835 pfd_read.events = POLLIN|POLLPRI;
853836 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
854837 return MIDB_RDWR_ERROR;
855838 static_assert (std::size (buff) >= 256 *1024 + 1 );
856- read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
839+ int read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
857840 if (read_len <= 0 )
858841 return MIDB_RDWR_ERROR;
859842 offset += read_len;
860843 buff[offset] = ' \0 ' ;
861844
862845 if (-1 == lines) {
863- for (i= 0 ; i< offset- 1 &&i< 36 ; i++ ) {
846+ for (int i = 0 ; i < offset - 1 && i < 36 ; ++i ) {
864847 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
865848 continue ;
866849 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -884,7 +867,7 @@ int enum_folders(const char *path, std::vector<enum_folder_t> &pfile,
884867 }
885868 }
886869
887- for (i= last_pos; i< offset; i++ ) {
870+ for (int i = last_pos; i < offset; ++i ) {
888871 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
889872 count ++;
890873 } else if (' \n ' == buff[i] && ' \r ' == buff[i - 1 ]) {
@@ -926,12 +909,7 @@ int enum_folders(const char *path, std::vector<enum_folder_t> &pfile,
926909int enum_subscriptions (const char *path, std::vector<enum_folder_t > &pfile,
927910 int *perrno) try
928911{
929- int i;
930- int lines;
931- int count;
932- int offset;
933912 int last_pos;
934- int read_len;
935913 int line_pos;
936914 char temp_line[512 ];
937915 char buff[256 *1025 ];
@@ -944,23 +922,21 @@ int enum_subscriptions(const char *path, std::vector<enum_folder_t> &pfile,
944922 if (write (pback->sockd , buff, length) != length)
945923 return MIDB_RDWR_ERROR;
946924
947- count = 0 ;
948- offset = 0 ;
949- lines = -1 ;
925+ int count = 0 , offset = 0 , lines = -1 ;
950926 while (true ) {
951927 pfd_read.fd = pback->sockd ;
952928 pfd_read.events = POLLIN|POLLPRI;
953929 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
954930 return MIDB_RDWR_ERROR;
955931 static_assert (std::size (buff) >= 256 *1024 + 1 );
956- read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
932+ int read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
957933 if (read_len <= 0 )
958934 return MIDB_RDWR_ERROR;
959935 offset += read_len;
960936 buff[offset] = ' \0 ' ;
961937
962938 if (-1 == lines) {
963- for (i= 0 ; i< offset- 1 &&i< 36 ; i++ ) {
939+ for (int i = 0 ; i < offset - 1 && i < 36 ; ++i ) {
964940 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
965941 continue ;
966942 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -984,7 +960,7 @@ int enum_subscriptions(const char *path, std::vector<enum_folder_t> &pfile,
984960 }
985961 }
986962
987- for (i= last_pos; i< offset; i++ ) {
963+ for (int i = last_pos; i < offset; ++i ) {
988964 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
989965 count ++;
990966 } else if (' \n ' == buff[i] && ' \r ' == buff[i - 1 ]) {
@@ -1051,7 +1027,6 @@ int insert_mail(const char *path, const std::string &folder,
10511027int remove_mail (const char *path, const std::string &folder,
10521028 const std::vector<MITEM *> &plist, int *perrno)
10531029{
1054- int cmd_len;
10551030 char buff[128 *1025 ];
10561031
10571032 if (plist.empty ())
@@ -1061,7 +1036,7 @@ int remove_mail(const char *path, const std::string &folder,
10611036 return MIDB_NO_SERVER;
10621037 auto length = gx_snprintf (buff, std::size (buff), " M-DELE %s %s" ,
10631038 path, folder.c_str ());
1064- cmd_len = length;
1039+ int cmd_len = length;
10651040
10661041 for (auto pitem : plist) {
10671042 buff[length++] = ' ' ;
@@ -1169,18 +1144,12 @@ static unsigned int di_to_flagbits(const Json::Value &jv)
11691144int list_deleted (const char *path, const std::string &folder, XARRAY *pxarray,
11701145 int *perrno)
11711146{
1172- int i;
1173- int lines;
1174- int count;
1175- int offset;
11761147 int last_pos;
1177- int read_len;
11781148 int line_pos;
11791149 char *pspace;
11801150 char *pspace1;
11811151 char temp_line[512 ];
11821152 char buff[256 *1025 ];
1183- BOOL b_format_error;
11841153 struct pollfd pfd_read;
11851154
11861155 auto pback = get_connection (path);
@@ -1192,24 +1161,22 @@ int list_deleted(const char *path, const std::string &folder, XARRAY *pxarray,
11921161 if (write (pback->sockd , buff, length) != length)
11931162 return MIDB_RDWR_ERROR;
11941163
1195- count = 0 ;
1196- offset = 0 ;
1197- lines = -1 ;
1198- b_format_error = FALSE ;
1164+ int count = 0 , offset = 0 , lines = -1 ;
1165+ BOOL b_format_error = false ;
11991166 while (true ) {
12001167 pfd_read.fd = pback->sockd ;
12011168 pfd_read.events = POLLIN|POLLPRI;
12021169 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
12031170 return MIDB_RDWR_ERROR;
12041171 static_assert (std::size (buff) >= 256 *1024 + 1 );
1205- read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
1172+ int read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
12061173 if (read_len <= 0 )
12071174 return MIDB_RDWR_ERROR;
12081175 offset += read_len;
12091176 buff[offset] = ' \0 ' ;
12101177
12111178 if (-1 == lines) {
1212- for (i= 0 ; i< offset- 1 &&i< 36 ; i++ ) {
1179+ for (int i = 0 ; i < offset - 1 && i < 36 ; ++i ) {
12131180 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
12141181 continue ;
12151182 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -1233,7 +1200,7 @@ int list_deleted(const char *path, const std::string &folder, XARRAY *pxarray,
12331200 }
12341201 }
12351202
1236- for (i= last_pos; i< offset; i++ ) {
1203+ for (int i = last_pos; i < offset; ++i ) {
12371204 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
12381205 count ++;
12391206 } else if (' \n ' == buff[i] && ' \r ' == buff[i - 1 ]) {
@@ -1293,18 +1260,13 @@ int list_deleted(const char *path, const std::string &folder, XARRAY *pxarray,
12931260int fetch_simple_uid (const char *path, const std::string &folder,
12941261 const imap_seq_list &list, XARRAY *pxarray, int *perrno)
12951262{
1296- int lines;
1297- int count;
1298- int offset;
12991263 int last_pos;
1300- int read_len;
13011264 int line_pos;
13021265 char *pspace;
13031266 char *pspace1;
13041267 char *pspace2;
13051268 char buff[1024 ];
13061269 char temp_line[1024 ];
1307- BOOL b_format_error;
13081270 struct pollfd pfd_read;
13091271
13101272 auto pback = get_connection (path);
@@ -1318,16 +1280,14 @@ int fetch_simple_uid(const char *path, const std::string &folder,
13181280 if (write (pback->sockd , buff, length) != length)
13191281 return MIDB_RDWR_ERROR;
13201282
1321- count = 0 ;
1322- offset = 0 ;
1323- lines = -1 ;
1324- b_format_error = FALSE ;
1283+ int count = 0 , offset = 0 , lines = -1 ;
1284+ BOOL b_format_error = false ;
13251285 while (true ) {
13261286 pfd_read.fd = pback->sockd ;
13271287 pfd_read.events = POLLIN|POLLPRI;
13281288 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
13291289 return MIDB_RDWR_ERROR;
1330- read_len = read (pback->sockd , buff + offset, std::size (buff) - 1 - offset);
1290+ int read_len = read (pback->sockd , buff + offset, std::size (buff) - 1 - offset);
13311291 if (read_len <= 0 )
13321292 return MIDB_RDWR_ERROR;
13331293 offset += read_len;
@@ -1428,17 +1388,11 @@ int fetch_simple_uid(const char *path, const std::string &folder,
14281388int fetch_detail_uid (const char *path, const std::string &folder,
14291389 const imap_seq_list &list, XARRAY *pxarray, int *perrno) try
14301390{
1431- int lines;
1432- int count;
1433- int offset;
14341391 int last_pos;
1435- int read_len;
14361392 int line_pos;
1437- int temp_len;
14381393 char *pspace;
14391394 char buff[64 *1025 ];
14401395 char temp_line[257 *1024 ];
1441- BOOL b_format_error;
14421396 struct pollfd pfd_read;
14431397
14441398 auto pback = get_connection (path);
@@ -1455,17 +1409,15 @@ int fetch_detail_uid(const char *path, const std::string &folder,
14551409 if (write (pback->sockd , buff, length) != length)
14561410 return MIDB_RDWR_ERROR;
14571411
1458- count = 0 ;
1459- offset = 0 ;
1460- lines = -1 ;
1461- b_format_error = FALSE ;
1412+ int count = 0 , offset = 0 , lines = -1 ;
1413+ BOOL b_format_error = false ;
14621414 while (true ) {
14631415 pfd_read.fd = pback->sockd ;
14641416 pfd_read.events = POLLIN|POLLPRI;
14651417 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
14661418 return MIDB_RDWR_ERROR;
14671419 static_assert (std::size (buff) >= 64 *1024 + 1 );
1468- read_len = read (pback->sockd , buff + offset, 64 *1024 - offset);
1420+ int read_len = read (pback->sockd , buff + offset, 64 *1024 - offset);
14691421 if (read_len <= 0 )
14701422 return MIDB_RDWR_ERROR;
14711423 offset += read_len;
@@ -1500,7 +1452,7 @@ int fetch_detail_uid(const char *path, const std::string &folder,
15001452 count ++;
15011453 } else if (' \n ' == buff[i] && ' \r ' == buff[i - 1 ]) {
15021454 pspace = strchr (temp_line, ' ' );
1503- temp_len = pspace == nullptr ? 0 :
1455+ int temp_len = pspace == nullptr ? 0 :
15041456 line_pos - (pspace + 1 - temp_line);
15051457 MITEM mitem;
15061458 if (pspace == nullptr ||
0 commit comments